-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimulator.java
More file actions
194 lines (171 loc) · 4.84 KB
/
Copy pathSimulator.java
File metadata and controls
194 lines (171 loc) · 4.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package simulator;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Formatter;
import java.util.Scanner;
/**
*
* @author Kore
*/
public class Simulator
{
public static int memoryData[]=new int[65];
public static String memory[][];
public static int fetchStage[];
public static int decodeStage[];
public static int readOperand[];
public static int executeStage[];
public static int writeBackStage[];
public static String isRAW[];
public static String isWAW[];
public static String isWAR[];
public static String isSTRUC[];
public static int regOperand1[];
public static int regOperand2[];
public static int instructionNum;//number of instructions
public static int FPadder=0;
public static int FPmultiplier=0;
public static int FPdivider=0;
public static int integerUnit=1;
public static int FPadderInc=0;
public static int FPmultiplierInc=0;
public static int FPdividerInc=0;
public static int integerUnitInc=0;
public static int cycleNum=1;
public static int start=0;
public static boolean notHLT=true;
public static Cache cache=new Cache();
public static String instFile,regFile,dataFile,configFile,resultfile;
public static String commandArguments[]=new String[6];
public static boolean isFPadderPipe;
public static boolean isFPmultiplierPipe;
public static boolean isFPdividerPipe;
public static int memoryCycle;
public static int IcacheCycle;
public static int DcacheCycle;
public static int FPadd;
public static int FPmult;
public static int FPdiv;
public static void main(String[] args) throws FileNotFoundException, IOException
{
Scoreboard.getCommandLine();//command
Scoreboard.initializeScoreboard();
PipeLine.initializePipeLine(instFile);
Scoreboard.readConfigFile(configFile);
Scoreboard.readRegMem(regFile, dataFile);
Scoreboard.readInst(instFile);
Simulator.startPipeLine();
Scoreboard.writeOnScoreBoard(start, instructionNum-1);
Scoreboard.fillScoreboard.format("%n%nTotal number of access requests for instruction cache: %d %n", cache.access_Icache-1);
Scoreboard.fillScoreboard.format("Number of instruction cache hits: %d %n", cache.cacheHit_I-1);
Scoreboard.fillScoreboard.format("Total number of access requests for data cache: %d %n", cache.access_Dcache);
Scoreboard.fillScoreboard.format("Number of data cache hits: %d %n", cache.cacheHit_D );
Scoreboard.fillScoreboard.close();
}
public static void startPipeLine() throws FileNotFoundException, IOException
{
try
{
while(notHLT)
{
notHLT=false;
for(int i=0;i<FPadderInc;i++)
{
FPadder++;
}
for(int i=0;i<FPmultiplierInc;i++)
{
FPmultiplier++;
}
for(int i=0;i<FPdividerInc;i++)
{
FPdivider++;
}
for(int i=0;i<integerUnitInc;i++)
{
integerUnit++;
}
FPadderInc=0;
FPmultiplierInc=0;
FPdividerInc=0;
integerUnitInc=0;
for(int i=start;i<instructionNum;i++)
{
if(decodeStage[i]==0)
{
notHLT=true;
if(fetchStage[i]<cycleNum &&fetchStage[i]!=0)
{
if(i==start)
{
ID.decode(start, cycleNum);
break;
}
else
if(decodeStage[i-1]!=0 && decodeStage[i-1]!=cycleNum)
{
ID.decode(i, cycleNum);
break;
}
}
}
}
for(int i=start;i<instructionNum;i++)
{
if(fetchStage[i]==0)
{
notHLT=true;
if(i==start)
{
IF.fetch(cycleNum, start);
break;
}
else if(decodeStage[i-1]!=0 && decodeStage[i-1]<=cycleNum)
{
IF.fetch(cycleNum,i);
break;
}
}
}
for(int i=start;i<instructionNum;i++)
{
if(readOperand[i]==0 && decodeStage[i]!=0 && decodeStage[i]<cycleNum )
{
ID.checkRegOperands(i, cycleNum);
notHLT=true;
}
}
for(int i=start;i<instructionNum;i++)
{
if (readOperand[i]!=0 && readOperand[i]<cycleNum && executeStage[i]==0 )
{
notHLT=true;
EX.execute(i,cycleNum);
}
}
for(int i=start;i<instructionNum;i++)
{
if(executeStage[i]!=0 && executeStage[i]<cycleNum && writeBackStage[i]==0)
{
WB.writeBack(i, cycleNum);
notHLT=true;
}
}
cycleNum++;
}//END WHILE
}
catch(FileNotFoundException noFile)
{
noFile.printStackTrace();
}
catch(IOException io)
{
io.printStackTrace();
}
}
}