-
Notifications
You must be signed in to change notification settings - Fork 141
/
branch.h
64 lines (48 loc) · 1.94 KB
/
branch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Yauheni Sharamed SHaramed.EI@phystech.edu
* branch.h - Simulation of branch mispredict detection stage
* Copyright 2015-2018 MIPT-MIPS
*/
#ifndef BRANCH_H
#define BRANCH_H
#include <func_sim/operation.h>
#include <modules/core/perf_instr.h>
#include <modules/ports_instance.h>
class FuncMemory;
template <typename FuncInstr>
class Branch : public Module
{
using Instr = PerfInstr<FuncInstr>;
using RegisterUInt = typename FuncInstr::RegisterUInt;
using InstructionOutput = std::array< RegisterUInt, MAX_DST_NUM>;
private:
uint64 num_mispredictions = 0;
uint64 num_jumps = 0;
ReadPort<Instr>* rp_datapath = nullptr;
WritePort<Instr>* wp_datapath = nullptr;
WritePort<bool>* wp_flush_all = nullptr;
ReadPort<bool>* rp_flush = nullptr;
ReadPort<bool>* rp_trap = nullptr;
WritePort<Target>* wp_flush_target = nullptr;
WritePort<BPInterface>* wp_bp_update = nullptr;
ReadPort<Instr>* rp_recive_datapath_from_mem = nullptr;
WritePort<InstructionOutput>* wp_bypass = nullptr;
WritePort<bool>* wp_bypassing_unit_flush_notify = nullptr;
public:
explicit Branch( Module* parent);
void clock( Cycle cycle);
auto get_mispredictions_num() const { return num_mispredictions; }
auto get_jumps_num() const { return num_jumps; }
bool is_misprediction( const Instr& instr, const BPInterface& bp_data) const
{
if ( !bp_data.is_hit)
if ( ( instr.is_common_branch() && instr.is_taken())
|| ( instr.is_likely_branch() && !instr.is_taken())
|| instr.is_indirect_jump())
return true;
if ( bp_data.is_hit && ( bp_data.is_taken != instr.is_taken()))
return true;
return ( bp_data.is_taken || instr.is_indirect_jump()) && ( bp_data.target != instr.get_new_PC());
}
};
#endif // BRANCH_H