13
13
*
14
14
* @version 1.0
15
15
* @date Thu, 29 Jun 2006 14:49:08 -0300
16
- *
16
+ *
17
17
* @brief The ArchC MIPS-I functional model.
18
- *
18
+ *
19
19
* @attention Copyright (C) 2002-2006 --- The ArchC Team
20
20
*
21
21
*/
@@ -31,7 +31,7 @@ AC_ISA(mips){
31
31
ac_instr<Type_I> addi, addiu, slti, sltiu, andi, ori, xori, lui;
32
32
ac_instr<Type_R> add, addu, sub, subu, slt, sltu;
33
33
ac_instr<Type_R> instr_and, instr_or, instr_xor, instr_nor;
34
- ac_instr<Type_R> sll, srl, sra, sllv, srlv, srav;
34
+ ac_instr<Type_R> nop, sll, srl, sra, sllv, srlv, srav;
35
35
ac_instr<Type_R> mult, multu, div, divu;
36
36
ac_instr<Type_R> mfhi, mthi, mflo, mtlo;
37
37
ac_instr<Type_J> j, jal;
@@ -51,9 +51,9 @@ AC_ISA(mips){
51
51
"$fp" = 30;
52
52
"$ra" = 31;
53
53
}
54
-
54
+
55
55
ISA_CTOR(mips){
56
-
56
+
57
57
lb.set_asm("lb %reg, \%lo(%exp)(%reg)", rt, imm, rs);
58
58
lb.set_asm("lb %reg, (%reg)", rt, rs, imm=0);
59
59
lb.set_asm("lb %reg, %imm (%reg)", rt, imm, rs);
@@ -116,7 +116,8 @@ AC_ISA(mips){
116
116
addi.set_asm("add %reg, %reg, %exp", rt, rs, imm);
117
117
addi.set_asm("add %reg, $0, %exp", rt, imm, rs=0);
118
118
addi.set_decoder(op=0x08);
119
-
119
+ addi.set_cycles(4);
120
+
120
121
addiu.set_asm("addiu %reg, %reg, %exp", rt, rs, imm);
121
122
addiu.set_asm("addiu %reg, %reg, \%lo(%exp)", rt, rs, imm);
122
123
addiu.set_asm("addu %reg, %reg, %exp", rt, rs, imm);
@@ -129,42 +130,53 @@ AC_ISA(mips){
129
130
sltiu.set_asm("sltiu %reg, %reg, %exp", rt, rs, imm);
130
131
sltiu.set_asm("sltu %reg, %reg, %exp", rt, rs, imm);
131
132
sltiu.set_decoder(op=0x0B);
132
-
133
+
133
134
andi.set_asm("andi %reg, %reg, %imm", rt, rs, imm);
134
135
andi.set_asm("and %reg, %reg, %imm", rt, rs, imm);
135
136
andi.set_decoder(op=0x0C);
137
+ andi.set_cycles(1);
136
138
137
139
ori.set_asm("ori %reg, %reg, %imm", rt, rs, imm);
138
140
ori.set_asm("or %reg, %reg, %imm", rt, rs, imm);
139
141
ori.set_decoder(op=0x0D);
142
+ ori.set_cycles(1);
143
+
140
144
141
145
xori.set_asm("xori %reg, %reg, %imm", rt, rs, imm);
142
146
xori.set_asm("xor %reg, %reg, %imm", rt, rs, imm);
143
147
xori.set_decoder(op=0x0E);
148
+ ori.set_cycles(1);
144
149
145
150
lui.set_asm("lui %reg, %exp", rt, imm);
146
- lui.set_asm("lui %reg, \%hi(%imm(carry))", rt, imm);
151
+ lui.set_asm("lui %reg, \%hi(%imm(carry))", rt, imm);
147
152
lui.set_asm("lui %reg, \%hi(%exp(carry))", rt, imm);
148
153
lui.set_decoder(op=0x0F, rs=0x00);
154
+ lui.set_cycles(1);
149
155
150
156
add.set_asm("add %reg, %reg, %reg", rd, rs, rt);
151
157
add.set_decoder(op=0x00, func=0x20);
158
+ add.set_cycles(4);
152
159
153
160
addu.set_asm("addu %reg, %reg, %reg", rd, rs, rt);
154
161
addu.set_asm("move %reg, %reg", rd, rs, rt="$zero");
155
162
addu.set_decoder(op=0x00, func=0x21);
163
+ addu.set_cycles(4);
156
164
157
165
sub.set_asm("sub %reg, %reg, %reg", rd, rs, rt);
158
166
sub.set_decoder(op=0x00, func=0x22);
159
-
167
+ sub.set_cycles(4);
168
+
160
169
subu.set_asm("subu %reg, %reg, %reg", rd, rs, rt);
161
170
subu.set_decoder(op=0x00, func=0x23);
171
+ subu.set_cycles(4);
162
172
163
173
slt.set_asm("slt %reg, %reg, %reg", rd, rs, rt);
164
174
slt.set_decoder(op=0x00, func=0x2A);
165
-
175
+ slt.set_cycles(1);
176
+
166
177
sltu.set_asm("sltu %reg, %reg, %reg", rd, rs, rt);
167
178
sltu.set_decoder(op=0x00, func=0x2B);
179
+ slt.set_cycles(1);
168
180
169
181
instr_and.set_asm("and %reg, %reg, %reg", rd, rs, rt);
170
182
instr_and.set_decoder(op=0x00, func=0x24);
@@ -178,38 +190,52 @@ AC_ISA(mips){
178
190
instr_nor.set_asm("nor %reg, %reg, %reg", rd, rs, rt);
179
191
instr_nor.set_decoder(op=0x00, func=0x27);
180
192
193
+ nop.set_asm("nop", rs=0, rt=0, shamt=0);
194
+ nop.set_decoder(op=0x00, rd=0x00, func=0x00);
195
+
181
196
sll.set_asm("sll %reg, %reg, %imm", rd, rt, shamt);
182
197
sll.set_decoder(op=0x00, func= 0x00);
183
-
198
+ sll.set_cycles(1);
199
+
184
200
srl.set_asm("srl %reg, %reg, %imm", rd, rt, shamt);
185
201
srl.set_decoder(op=0x00, func= 0x02);
186
-
202
+ sll.set_cycles(1);
203
+
187
204
sra.set_asm("sra %reg, %reg, %imm", rd, rt, shamt);
188
205
sra.set_decoder(op=0x00, func= 0x03);
189
-
206
+ sll.set_cycles(1);
207
+
190
208
sllv.set_asm("sllv %reg, %reg, %reg", rd, rt, rs);
191
209
sllv.set_asm("sll %reg, %reg, %reg", rd, rt, rs); // gas
192
210
sllv.set_decoder(op=0x00, func= 0x04);
193
-
211
+ sllv.set_cycles(1);
212
+
194
213
srlv.set_asm("srlv %reg, %reg, %reg", rd, rt, rs);
195
214
srlv.set_asm("srl %reg, %reg, %reg", rd, rt, rs); // gas
196
215
srlv.set_decoder(op=0x00, func= 0x06);
197
-
216
+ srlv.set_cycles(1);
217
+
198
218
srav.set_asm("srav %reg, %reg, %reg", rd, rt, rs);
199
219
srav.set_asm("sra %reg, %reg, %reg", rd, rt, rs); // gas
200
220
srav.set_decoder(op=0x00, func= 0x07);
201
-
221
+ srlv.set_cycles(1);
222
+
202
223
mult.set_asm("mult %reg, %reg", rs, rt);
203
224
mult.set_decoder(op=0x00, func=0x18);
225
+ mult.set_cycles(4);
204
226
205
227
multu.set_asm("multu %reg, %reg", rs, rt);
206
228
multu.set_decoder(op=0x00, func=0x19);
229
+ multu.set_cycles(4);
207
230
208
231
div.set_asm("div %reg, %reg", rs, rt);
209
232
div.set_decoder(op=0x00, func=0x1A);
233
+ div.set_cycles(30);//media
210
234
211
235
divu.set_asm("divu %reg, %reg", rs, rt);
212
236
divu.set_decoder(op=0x00, func=0x1B);
237
+ divu.set_cycles(30);//media
238
+
213
239
214
240
mfhi.set_asm("mfhi %reg", rd);
215
241
mfhi.set_decoder(op=0x00, func=0x10);
@@ -234,12 +260,12 @@ AC_ISA(mips){
234
260
jr.set_asm("j %reg", rs);
235
261
jr.set_asm("ret", rs = "$ra");
236
262
jr.set_decoder(op=0x00, func= 0x08);
237
-
263
+
238
264
jalr.set_asm("jalr %reg, %reg", rd, rs);
239
265
jalr.set_asm("jalr %reg", rs, rd="$ra");
240
266
jalr.set_asm("jal %reg", rs, rd="$ra"); // gas
241
267
jalr.set_decoder(op=0x00, func= 0x09);
242
-
268
+
243
269
beq.set_asm("beq %reg, %reg, %exp(pcrel)", rs, rt, imm);
244
270
beq.set_asm("b %exp(pcrel)", imm, rs=0, rt=0); // gas
245
271
beq.set_asm("beqz %reg, %exp(pcrel)", rs, imm, rt=0); // gas
@@ -249,45 +275,42 @@ AC_ISA(mips){
249
275
bne.set_asm("bne %reg, %reg, %exp(pcrel)", rs, rt, imm);
250
276
bne.set_asm("bnez %reg, %exp(pcrel)", rs, imm, rt=0);
251
277
bne.set_decoder(op=0x05);
252
-
278
+
253
279
blez.set_asm("blez %reg, %exp(pcrel)", rs, imm);
254
280
blez.set_decoder(op=0x06, rt=0x00);
255
-
281
+
256
282
bgtz.set_asm("bgtz %reg, %exp(pcrel)", rs, imm);
257
- bgtz.set_decoder(op=0x07, rt=0x00);
258
-
283
+ bgtz.set_decoder(op=0x07, rt=0x00);
284
+
259
285
bltz.set_asm("bltz %reg, %exp(pcrel)", rs, imm);
260
286
bltz.set_decoder(op=0x01, rt=0x00);
261
-
287
+
262
288
bgez.set_asm("bgez %reg, %exp(pcrel)", rs, imm);
263
289
bgez.set_decoder(op=0x01, rt=0x01);
264
-
290
+
265
291
bltzal.set_asm("bltzal %reg, %exp(pcrel)", rs, imm);
266
292
bltzal.set_decoder(op=0x01, rt=0x10);
267
-
293
+
268
294
bgezal.set_asm("bgezal %reg, %exp(pcrel)", rs, imm);
269
295
bgezal.set_decoder(op=0x01, rt=0x11);
270
-
296
+
271
297
sys_call.set_asm("syscall");
272
298
sys_call.set_decoder(op=0x00, func=0x0C);
273
-
299
+
274
300
instr_break.set_asm("break", rt=0);
275
301
instr_break.set_asm("break %imm", rt);
276
302
instr_break.set_decoder(op=0x00, func=0x0D);
277
303
278
- pseudo_instr("nop") {
279
- "sll $0, $0, 0";
280
- }
281
304
282
305
pseudo_instr("li %reg, %imm") {
283
306
"lui %0, \%hi(%1)";
284
307
"ori %0, %0, %1";
285
308
}
286
309
287
- pseudo_instr("la %reg, %addr") {
288
- "lui %0, \%hi(%1)";
289
- "addiu %0, %0, \%lo(%1)";
290
- }
310
+ pseudo_instr("la %reg, %addr") {
311
+ "lui %0, \%hi(%1)";
312
+ "addiu %0, %0, \%lo(%1)";
313
+ }
291
314
292
315
pseudo_instr("sw %reg, %exp") {
293
316
"lui $at, \%hi(%1)";
@@ -296,9 +319,9 @@ AC_ISA(mips){
296
319
297
320
pseudo_instr("lw %reg, %exp") {
298
321
"lui %0, \%hi(%1)";
299
- "lw %0, \%lo(%1)(%0)";
322
+ "lw %0, \%lo(%1)(%0)";
300
323
}
301
-
324
+
302
325
pseudo_instr("subu %reg, %reg, %imm") {
303
326
"addiu %0, %1, -%2";
304
327
}
@@ -312,7 +335,7 @@ AC_ISA(mips){
312
335
"slti $at, %0, %1+1";
313
336
"bne $at, $zero, %2";
314
337
}
315
-
338
+
316
339
pseudo_instr("mul %reg, %reg, %reg") {
317
340
"multu %1, %2";
318
341
"mflo %0";
@@ -333,19 +356,19 @@ AC_ISA(mips){
333
356
"mult %1, $at";
334
357
"mflo %0";
335
358
}
336
-
359
+
337
360
pseudo_instr("lw %reg, %exp (%reg)") {
338
- /* this should be 'li %0, %1', but 'li' is a conditional pseudo in gas :/
361
+ /* this should be 'li %0, %1', but 'li' is a conditional pseudo in gas :/
339
362
- this only works when %exp < 2^16-1 - should be enough for validation */
340
363
"lui %0, %1";
341
364
"addu %0, %0, %2";
342
365
"lw %0, (%0)";
343
366
}
344
367
345
368
pseudo_instr("sw %reg, %exp (%reg)") {
346
- /* this should be 'li %0, %1', but 'li' is a conditional pseudo in gas :/
369
+ /* this should be 'li %0, %1', but 'li' is a conditional pseudo in gas :/
347
370
- this only works when %exp < 2^16-1 - should be enough for validation */
348
- "lui $at, %1";
371
+ "lui $at, %1";
349
372
"addu $at, $at, %2";
350
373
"sw %0, ($at)";
351
374
}
0 commit comments