-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecodeUnitManager.cpp
105 lines (84 loc) · 2.09 KB
/
DecodeUnitManager.cpp
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
// Luke Mitchell, 2015
#include <iostream>
#include <sstream>
#include <iomanip>
#include "DecodeUnitManager.h"
DecodeUnitManager::DecodeUnitManager(unsigned int width, ExecutionUnitManager* eum) {
// Set debugging to false, by default
debug = false;
// Store a local reference to the EU manager
this->eum = eum;
// Nothing has been issued yet...
lastIssued = 0;
// Set up the Decode Units
dus.assign(width, DecodeUnit(eum));
}
void DecodeUnitManager::setDebug(bool debug) {
this->debug = debug;
for (int i = 0; i < dus.size(); i++) {
dus[i].debug = debug;
}
}
bool DecodeUnitManager::getDebug() {
return debug;
}
std::string DecodeUnitManager::toString() {
std::ostringstream ss;
ss << "DecodeUnitManager with " << dus.size() << " DUs." << std::endl;
return ss.str();
}
void DecodeUnitManager::tick() {
// Instructions should be issued to EU oldest-first;
// as with the Fetch Units.
// Use a queue for simulation
while (!waiting.empty()){
auto i = waiting.front();
if (debug) {
std::cout << "[DU #" << i << "] trying to issue decoded instruction." << std::endl;
}
if (!dus[i].passToExecutionUnit()) {
break;
}
waiting.pop();
}
for (int i = 0; i < dus.size(); i++) {
// Skip a waiting DU
if (dus[i].decoded) {
continue;
}
if (debug) {
std::cout << "[DU #" << i << "] calling tick()." << std::endl;
}
// Call tick!
dus[i].tick();
// Add to waiting queue?
if (dus[i].decoded) {
waiting.push(i);
}
}
}
// Retrieve an available DU
// Returns the DU or NULL;
DecodeUnit* DecodeUnitManager::getAvailableDecodeUnit() {
for (int i = 0; i < dus.size(); i++) {
if (dus[i].ready && !dus[i].decoded) {
if (debug) {
std::cout << "[DU #" << i << "] I am available." << std::endl;
}
return &dus[i];
}
}
return NULL;
}
// Removes speculative values after incorrect branch prediction
void DecodeUnitManager::clearPipeline() {
// Clear the DUs
for (int i = 0; i < dus.size(); i++) {
if (dus[i].speculative) {
dus[i].clear();
}
}
// Empty the waiting queue
std::queue<int>().swap(waiting);
}