-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbranch.cpp
More file actions
108 lines (97 loc) · 2.51 KB
/
branch.cpp
File metadata and controls
108 lines (97 loc) · 2.51 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "./headers/branch.h"
#include "./headers/clock.h"
extern unordered_map <string, int> RAT;
extern vector<int*> clk_wait_list;
extern branchCtrl brcUnit;
extern instr_queue *instr_Q;
extern ROB *CPU_ROB;
extern memory main_mem;
extern FU_CDB fCDB;
extern vector<intAdder*> iAdder;
extern vector<flpAdder*> fAdder;
extern vector<flpMtplr*> fMtplr;
extern vector<ldsdUnit*> lsUnit;
extern nopBublr* nopBub;
extern cond_t squash_cond;
extern mutex_t squash_mutex;
BTB::BTB()
{
for (auto b : buf)
b.predicted = false;
}
void BTB::addEntry(int _instr_i, int _target)
{
int index = _instr_i%BTB_LEN;
buf[index].target = _target;
buf[index].predicted = true;
buf[index].taken = true;
}
BTBEntry* BTB::getEntry(int _instr_i)
{
int index = _instr_i%BTB_LEN;
if (buf[index].predicted)
return &buf[index];
else
return nullptr;
}
branchCtrl::branchCtrl()
{
ROB_i = -1;
}
void branchCtrl::to_squash(int _ROB_i)
{
ROB_i = _ROB_i;
}
void branchCtrl::to_target(int _target)
{
target = _target;
}
int branchCtrl::squash_ROB_i()
{
return ROB_i;
}
void branchCtrl::branch_automat()
{
next_vdd = 0;
while (true)
{
at_rising_edge(next_vdd);
at_falling_edge(next_vdd);
if (ROB_i>-1)
{
pthread_mutex_lock(&squash_mutex);
while (!instr_Q->squash)
pthread_cond_wait(&squash_cond, &squash_mutex);
pthread_mutex_unlock(&squash_mutex);
ROBEntry *R = CPU_ROB->get_entry(ROB_i);
RAT = R->bkupRAT;
at_falling_edge(next_vdd);
for (auto fu : iAdder)
fu->squash(ROB_i);
for (auto fu : fAdder)
fu->squash(ROB_i);
for (auto fu : fMtplr)
fu->squash(ROB_i);
for (auto fu : lsUnit)
fu->squash(ROB_i);
nopBub->squash(ROB_i);
main_mem.squash(ROB_i);
fCDB.squash(ROB_i);
R->finished = true;
CPU_ROB->squash(ROB_i);
at_rising_edge(next_vdd);
instr_Q->move_ptr(target);
msg_log("squash finished", 3);
at_falling_edge(next_vdd);
at_rising_edge(next_vdd);
instr_Q->squash = false;
ROB_i = -1;
at_falling_edge(next_vdd);
}
}
}
void init_brcUnit()
{
while(pthread_create(&brcUnit.handle, NULL, [](void *arg)->void*{brcUnit.branch_automat(); return nullptr;}, NULL));
clk_wait_list.push_back(&brcUnit.next_vdd);
}