-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimulator.h
executable file
·79 lines (66 loc) · 1.2 KB
/
simulator.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/***********
Author: joishbader
Date: 2017/11/21
Title: COD_lab2.2
***********/
#include "fetch.h"
#include "decode.h"
#include "execute.h"
#include "memory.h"
#include "write.h"
uint64_t flowing(void *ins_addr, uint64_t PC, uint64_t *reg)
{
total_cycles = total_cycles + 1;
// pipeline flowing
if (!IW.cont_stall)
IW = IM;
if (!IM.cont_stall)
IM = IE;
if (!IE.cont_stall)
IE = ID;
if (!ID.cont_stall)
ID = IF;
// fetch
if (!IF.cont_stall)
ifetch(ins_addr);
// decode
if (ID.PC != PC_END)
idecode();
// memory
if (IM.PC != PC_END)
imemory();
// write back
if (IW.PC != PC_END)
iwrite();
// execute is the latest because of forwarding
if (IE.PC != PC_END)
iexecute();
}
uint64_t flowing_nopipe(void *ins_addr, uint64_t PC, uint64_t *reg)
{
// flowing no pipe
IF.init();
ID.init();
IE.init();
IM.init();
IW.init();
uint64_t total_cycles_old = total_cycles;
ifetch(ins_addr);
ID = IF;
idecode();
IE = ID;
iexecute();
IM = IE;
imemory();
IW = IM;
iwrite();
// this instr is not MUL or DIV
if (total_cycles - total_cycles_old == 1)
total_cycles += 4;
}
void Init();
void sim_display();
int sim_step(int count);
void sim_run();
void sim_showmem();
void simulate();