-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generator.sv
270 lines (243 loc) · 5.33 KB
/
Generator.sv
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
`ifndef GAURD_GENERATOR
`define GAURD_GENERATOR
//`include "params.sv"
`include "Instruction.sv"
class generator;
Instruction Instr;
mailbox #(Instruction) gen2drv;
instr_type_e prev_Instr_type;
instr_type_e q_prev_Instr[$] = {ALU,ALU,ALU,ALU,ALU,ALU};
int flag_CTRLfound;
int flag_MEMfound;
function new(mailbox #(Instruction) mbx);
this.gen2drv = mbx;
endfunction : new
task chekPrevFive_MEM();
flag_MEMfound = 0;
flag_CTRLfound = 0;
for(int i=0;i<5; i= i+1)
begin
if(q_prev_Instr[i] == MEM)
begin
flag_MEMfound = 1;
flag_CTRLfound = 1;
break;
end
end
endtask: chekPrevFive_MEM
task chekPrevFive_CTRL();
flag_MEMfound = 0;
flag_CTRLfound = 0;
for(int i=0;i<5; i= i+1)
begin
if(q_prev_Instr[i] == CTRL)
begin
flag_MEMfound = 1;
flag_CTRLfound = 1;
break;
end
end
endtask: chekPrevFive_CTRL
task chekPrevFive_BOTH();
flag_MEMfound = 0;
flag_CTRLfound = 0;
for(int i=0;i<5; i= i+1)
begin
if(q_prev_Instr[i] == CTRL)
begin
flag_CTRLfound = 1;
break;
end
end
for(int i=0;i<5; i= i+1)
begin
if(q_prev_Instr[i] == MEM)
begin
flag_MEMfound = 1;
break;
end
end
endtask: chekPrevFive_BOTH
/*task CheckPrevFive();
//This function is written to insert 6 alu instr bw mem&mem and bra&bra
for(q_prev_Instr[i]) {
if(q_prev_Instr[i] == CTRL) begin
flag_MEMfound = 0;
flag_CTRLfound = 1;
flag_NoCTRLorMEM = 0;
break;
end
else if(q_prev_Instr[i] == MEM) begin
flag_MEMfound = 1;
flag_CTRLfound = 0;
flag_NoCTRLorMEM = 0;
break;
end
else begin
flag_MEMfound = 0;
flag_CTRLfound = 0;
flag_NoCTRLorMEM = 1;
end
}
endtask*/
task set_constraints();
if (prev_Instr_type == MEM)
begin
chekPrevFive_CTRL();
if(flag_CTRLfound == 1)
begin
Instr.c_PrevIsMEM.constraint_mode(0);
Instr.c_PrevIsCTRL.constraint_mode(0);
Instr.c_ALU.constraint_mode(1);
end
else
begin
Instr.c_PrevIsMEM.constraint_mode(1);
Instr.c_PrevIsCTRL.constraint_mode(0);
Instr.c_ALU.constraint_mode(0);
end
end
else if (prev_Instr_type == CTRL)
begin
chekPrevFive_MEM();
if(flag_MEMfound == 1)
begin
Instr.c_PrevIsMEM.constraint_mode(0);
Instr.c_PrevIsCTRL.constraint_mode(0);
Instr.c_ALU.constraint_mode(1);
end
else
begin
Instr.c_PrevIsMEM.constraint_mode(0);
Instr.c_PrevIsCTRL.constraint_mode(1);
Instr.c_ALU.constraint_mode(0);
end
end
else
begin
chekPrevFive_BOTH();
if(flag_CTRLfound == 1 && flag_MEMfound == 1)
begin
Instr.c_PrevIsMEM.constraint_mode(0);
Instr.c_PrevIsCTRL.constraint_mode(0);
Instr.c_ALU.constraint_mode(1);
//$display($time,"here scheduling ALU");
end
else if(flag_CTRLfound == 1 && flag_MEMfound == 0)
begin
Instr.c_PrevIsMEM.constraint_mode(0);
Instr.c_PrevIsCTRL.constraint_mode(1);
Instr.c_ALU.constraint_mode(0);
end
else if(flag_CTRLfound == 0 && flag_MEMfound == 1)
begin
Instr.c_PrevIsMEM.constraint_mode(1);
Instr.c_PrevIsCTRL.constraint_mode(0);
Instr.c_ALU.constraint_mode(0);
end
else
begin
Instr.c_PrevIsMEM.constraint_mode(0);
Instr.c_PrevIsCTRL.constraint_mode(0);
Instr.c_ALU.constraint_mode(0);
end
end
endtask : set_constraints
/*task test();
if(flag == 0)
begin
Instr.c_MEM.constraint_mode(1);
flag = 1;
$display($time,"hello from mem randomization");
end
else if(flag == 1)
begin
Instr.c_CTRL.constraint_mode(1);
flag = 2;
end
else if(flag == 2)
begin
Instr.c_ALU.constraint_mode(1);
flag = 3;
end
else if(flag == 3)
begin
Instr.c_ALU.constraint_mode(1);
flag = 4;
end
else if(flag == 4)
begin
Instr.c_ALU.constraint_mode(1);
flag = 5;
end
else if(flag == 5)
begin
Instr.c_ALU.constraint_mode(1);
flag = 6;
end
else if(flag == 6)
begin
Instr.c_ALU.constraint_mode(1);
flag = 7;
end
else if(flag == 7)
begin
Instr.c_CTRL.constraint_mode(1);
flag = 8;
end
else if(flag == 8)
begin
Instr.c_ALU.constraint_mode(1);
flag = 9;
end
else if(flag == 9)
begin
Instr.c_ALU.constraint_mode(1);
flag = 10;
end
else if(flag == 10)
begin
Instr.c_ALU.constraint_mode(1);
flag = 11;
end
else if(flag == 11)
begin
Instr.c_ALU.constraint_mode(1);
flag = 12;
end
else if(flag == 12)
begin
Instr.c_ALU.constraint_mode(1);
flag = 0;
end
endtask: test*/
/*task set_flag();
if(prev_Instr_type == MEM)
begin
flag_MEM = 1;
$display($time,"hello mem flag");
end
if(prev_Instr_type == CTRL)
begin
flag_CTRL = 1;
$display($time,"hello ctrl flag");
end
endtask: set_flag*/
task run();
forever begin
Instr = new();
//set_flag();
set_constraints();
//test();
Instr.randomize;
//$display($time,"===>INSTR Type",Instr.Instr_type);
gen2drv.put(Instr);
prev_Instr_type = Instr.Instr_type;
q_prev_Instr.push_back(Instr.Instr_type);
q_prev_Instr.pop_front;
//$display("in generator");
end
//$display("out of generator");
endtask : run
endclass : generator
`endif