-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
135 lines (118 loc) · 3.84 KB
/
Copy pathtest.cpp
File metadata and controls
135 lines (118 loc) · 3.84 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//this is a test environment for each cpu core
#include "src/RegisterFile.h"
#include<iostream>
#include<string>
#include<bitset>
#include<array>
#include "src/CPUcore.h"
#include <vector>
using namespace std;
void dumpSelectedReg(CPUcore core, int reg1_index, int reg2_index, int reg3_index) {
cout<<"Reg "<<reg1_index<<" :"<<core.registerFile.read(reg1_index)<<endl;
cout<<"Reg "<<reg2_index<<" :"<<core.registerFile.read(reg2_index)<<endl;
cout<<"Reg "<<reg3_index<<" :"<<core.registerFile.read(reg3_index)<<endl;
}
void RunCommands(CPUcore &core, L2Cache& l2cache, RAM &ram) {
uint32_t commands[] = {
// //double stall test
// // lw x1,0(x0)
// 0b00000000000000000010000010000011,
//
// // add x2,x1,x1
// 0b00000000000100001000000100110011,
//
// // lw x3,4(x0)
// 0b00000000010000000010000110000011,
//
// // add x4,x3,x3
// 0b00000000001100011000001000110011
//branch test
// // addi x1,x0,5
// 0b00000000010100000000000010010011,
//
// // addi x2,x0,5
// 0b00000000010100000000000100010011,
//
// // beq x1,x2,+8
// 0b00000000001000001000010001100011,
//
// // addi x3,x0,1
// 0b00000000000100000000000110010011,
//
// // addi x4,x0,2
// 0b00000000001000000000001000010011
// // addi x1,x0,5
// 0b00000000010100000000000010010011,
//
// // addi x2,x0,6
// 0b00000000011000000000000100010011,
//
// // beq x1,x2,+8
// 0b00000000001000001000010001100011,
//
// // addi x3,x0,1
// 0b00000000000100000000000110010011,
//
// // addi x4,x0,2
// 0b00000000001000000000001000010011
// // addi x1,x0,2
// 0b00000000001000000000000010010011,
//
// // addi x1,x1,-1
// 0b11111111111100001000000010010011,
//
// // bne x1,x0,-4
// 0b11111110000000001001111011100011
// // addi x1,x0,1
// 0b00000000000100000000000010010011,
//
// // jal x5,8
// 0b00000000100000000000001011101111,
//
// // addi x1,x0,99
// 0b00000110001100000000000010010011,
//
// // addi x2,x0,2
// 0b00000000001000000000000100010011
// addi x5,x0,12
0b00000000110000000000001010010011,
// jalr x1,0(x5)
0b00000000000000101000000011100111,
// addi x2,x0,99
0b00000110001100000000000100010011,
// addi x3,x0,3
0b00000000001100000000000110010011
};
ram.loadCommands(commands, 4);
cout<<core.l1_cache.Load(READWORD,UNSIGN,0,l2cache,ram)<<endl;
// for (int i=0;i<20;i++) {
// cout<<endl;
// cout<<"================================"<<endl;
// cout<<"->Cycle "<<i<<endl;
// core.Step(l2cache,ram);
// }
// core.registerFile.dumpRawValue();
int min_cycles = 0;
for (int i=0;i<size(commands)*5;i++) {
cout<<endl;
cout<<"================================"<<endl;
cout<<"->Cycle "<<i<<endl;
core.Step(l2cache,ram);
if (i != 0 and core.pipeline_registers_read.IF_ID_register.valid == 0
and core.pipeline_registers_read.ID_EX_register.valid == 0
and core.pipeline_registers_read.EX_MEM_register.valid == 0
and core.pipeline_registers_read.MEM_WB_register.valid == 0) {
min_cycles = i+1;
break;
}
}
core.registerFile.dumpRawValue();
cout<<"In total "<<min_cycles<<" cycles operated"<<endl;
cout<<min_cycles<<" is the minimum cycles to fully run the commands"<<endl;
}
int main() {
RAM ram = RAM();
L2Cache l2cache = L2Cache(ram);
CPUcore core0 = CPUcore(0,11);
RunCommands(core0,l2cache,ram);
}