Skip to content

Commit ffc0800

Browse files
committed
mips_isa.ac with set_cycles annotation per instruction
1 parent 869a736 commit ffc0800

File tree

1 file changed

+64
-41
lines changed

1 file changed

+64
-41
lines changed

mips_isa.ac

+64-41
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
*
1414
* @version 1.0
1515
* @date Thu, 29 Jun 2006 14:49:08 -0300
16-
*
16+
*
1717
* @brief The ArchC MIPS-I functional model.
18-
*
18+
*
1919
* @attention Copyright (C) 2002-2006 --- The ArchC Team
2020
*
2121
*/
@@ -31,7 +31,7 @@ AC_ISA(mips){
3131
ac_instr<Type_I> addi, addiu, slti, sltiu, andi, ori, xori, lui;
3232
ac_instr<Type_R> add, addu, sub, subu, slt, sltu;
3333
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;
3535
ac_instr<Type_R> mult, multu, div, divu;
3636
ac_instr<Type_R> mfhi, mthi, mflo, mtlo;
3737
ac_instr<Type_J> j, jal;
@@ -51,9 +51,9 @@ AC_ISA(mips){
5151
"$fp" = 30;
5252
"$ra" = 31;
5353
}
54-
54+
5555
ISA_CTOR(mips){
56-
56+
5757
lb.set_asm("lb %reg, \%lo(%exp)(%reg)", rt, imm, rs);
5858
lb.set_asm("lb %reg, (%reg)", rt, rs, imm=0);
5959
lb.set_asm("lb %reg, %imm (%reg)", rt, imm, rs);
@@ -116,7 +116,8 @@ AC_ISA(mips){
116116
addi.set_asm("add %reg, %reg, %exp", rt, rs, imm);
117117
addi.set_asm("add %reg, $0, %exp", rt, imm, rs=0);
118118
addi.set_decoder(op=0x08);
119-
119+
addi.set_cycles(4);
120+
120121
addiu.set_asm("addiu %reg, %reg, %exp", rt, rs, imm);
121122
addiu.set_asm("addiu %reg, %reg, \%lo(%exp)", rt, rs, imm);
122123
addiu.set_asm("addu %reg, %reg, %exp", rt, rs, imm);
@@ -129,42 +130,53 @@ AC_ISA(mips){
129130
sltiu.set_asm("sltiu %reg, %reg, %exp", rt, rs, imm);
130131
sltiu.set_asm("sltu %reg, %reg, %exp", rt, rs, imm);
131132
sltiu.set_decoder(op=0x0B);
132-
133+
133134
andi.set_asm("andi %reg, %reg, %imm", rt, rs, imm);
134135
andi.set_asm("and %reg, %reg, %imm", rt, rs, imm);
135136
andi.set_decoder(op=0x0C);
137+
andi.set_cycles(1);
136138

137139
ori.set_asm("ori %reg, %reg, %imm", rt, rs, imm);
138140
ori.set_asm("or %reg, %reg, %imm", rt, rs, imm);
139141
ori.set_decoder(op=0x0D);
142+
ori.set_cycles(1);
143+
140144

141145
xori.set_asm("xori %reg, %reg, %imm", rt, rs, imm);
142146
xori.set_asm("xor %reg, %reg, %imm", rt, rs, imm);
143147
xori.set_decoder(op=0x0E);
148+
ori.set_cycles(1);
144149

145150
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);
147152
lui.set_asm("lui %reg, \%hi(%exp(carry))", rt, imm);
148153
lui.set_decoder(op=0x0F, rs=0x00);
154+
lui.set_cycles(1);
149155

150156
add.set_asm("add %reg, %reg, %reg", rd, rs, rt);
151157
add.set_decoder(op=0x00, func=0x20);
158+
add.set_cycles(4);
152159

153160
addu.set_asm("addu %reg, %reg, %reg", rd, rs, rt);
154161
addu.set_asm("move %reg, %reg", rd, rs, rt="$zero");
155162
addu.set_decoder(op=0x00, func=0x21);
163+
addu.set_cycles(4);
156164

157165
sub.set_asm("sub %reg, %reg, %reg", rd, rs, rt);
158166
sub.set_decoder(op=0x00, func=0x22);
159-
167+
sub.set_cycles(4);
168+
160169
subu.set_asm("subu %reg, %reg, %reg", rd, rs, rt);
161170
subu.set_decoder(op=0x00, func=0x23);
171+
subu.set_cycles(4);
162172

163173
slt.set_asm("slt %reg, %reg, %reg", rd, rs, rt);
164174
slt.set_decoder(op=0x00, func=0x2A);
165-
175+
slt.set_cycles(1);
176+
166177
sltu.set_asm("sltu %reg, %reg, %reg", rd, rs, rt);
167178
sltu.set_decoder(op=0x00, func=0x2B);
179+
slt.set_cycles(1);
168180

169181
instr_and.set_asm("and %reg, %reg, %reg", rd, rs, rt);
170182
instr_and.set_decoder(op=0x00, func=0x24);
@@ -178,38 +190,52 @@ AC_ISA(mips){
178190
instr_nor.set_asm("nor %reg, %reg, %reg", rd, rs, rt);
179191
instr_nor.set_decoder(op=0x00, func=0x27);
180192

193+
nop.set_asm("nop", rs=0, rt=0, shamt=0);
194+
nop.set_decoder(op=0x00, rd=0x00, func=0x00);
195+
181196
sll.set_asm("sll %reg, %reg, %imm", rd, rt, shamt);
182197
sll.set_decoder(op=0x00, func= 0x00);
183-
198+
sll.set_cycles(1);
199+
184200
srl.set_asm("srl %reg, %reg, %imm", rd, rt, shamt);
185201
srl.set_decoder(op=0x00, func= 0x02);
186-
202+
sll.set_cycles(1);
203+
187204
sra.set_asm("sra %reg, %reg, %imm", rd, rt, shamt);
188205
sra.set_decoder(op=0x00, func= 0x03);
189-
206+
sll.set_cycles(1);
207+
190208
sllv.set_asm("sllv %reg, %reg, %reg", rd, rt, rs);
191209
sllv.set_asm("sll %reg, %reg, %reg", rd, rt, rs); // gas
192210
sllv.set_decoder(op=0x00, func= 0x04);
193-
211+
sllv.set_cycles(1);
212+
194213
srlv.set_asm("srlv %reg, %reg, %reg", rd, rt, rs);
195214
srlv.set_asm("srl %reg, %reg, %reg", rd, rt, rs); // gas
196215
srlv.set_decoder(op=0x00, func= 0x06);
197-
216+
srlv.set_cycles(1);
217+
198218
srav.set_asm("srav %reg, %reg, %reg", rd, rt, rs);
199219
srav.set_asm("sra %reg, %reg, %reg", rd, rt, rs); // gas
200220
srav.set_decoder(op=0x00, func= 0x07);
201-
221+
srlv.set_cycles(1);
222+
202223
mult.set_asm("mult %reg, %reg", rs, rt);
203224
mult.set_decoder(op=0x00, func=0x18);
225+
mult.set_cycles(4);
204226

205227
multu.set_asm("multu %reg, %reg", rs, rt);
206228
multu.set_decoder(op=0x00, func=0x19);
229+
multu.set_cycles(4);
207230

208231
div.set_asm("div %reg, %reg", rs, rt);
209232
div.set_decoder(op=0x00, func=0x1A);
233+
div.set_cycles(30);//media
210234

211235
divu.set_asm("divu %reg, %reg", rs, rt);
212236
divu.set_decoder(op=0x00, func=0x1B);
237+
divu.set_cycles(30);//media
238+
213239

214240
mfhi.set_asm("mfhi %reg", rd);
215241
mfhi.set_decoder(op=0x00, func=0x10);
@@ -234,12 +260,12 @@ AC_ISA(mips){
234260
jr.set_asm("j %reg", rs);
235261
jr.set_asm("ret", rs = "$ra");
236262
jr.set_decoder(op=0x00, func= 0x08);
237-
263+
238264
jalr.set_asm("jalr %reg, %reg", rd, rs);
239265
jalr.set_asm("jalr %reg", rs, rd="$ra");
240266
jalr.set_asm("jal %reg", rs, rd="$ra"); // gas
241267
jalr.set_decoder(op=0x00, func= 0x09);
242-
268+
243269
beq.set_asm("beq %reg, %reg, %exp(pcrel)", rs, rt, imm);
244270
beq.set_asm("b %exp(pcrel)", imm, rs=0, rt=0); // gas
245271
beq.set_asm("beqz %reg, %exp(pcrel)", rs, imm, rt=0); // gas
@@ -249,45 +275,42 @@ AC_ISA(mips){
249275
bne.set_asm("bne %reg, %reg, %exp(pcrel)", rs, rt, imm);
250276
bne.set_asm("bnez %reg, %exp(pcrel)", rs, imm, rt=0);
251277
bne.set_decoder(op=0x05);
252-
278+
253279
blez.set_asm("blez %reg, %exp(pcrel)", rs, imm);
254280
blez.set_decoder(op=0x06, rt=0x00);
255-
281+
256282
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+
259285
bltz.set_asm("bltz %reg, %exp(pcrel)", rs, imm);
260286
bltz.set_decoder(op=0x01, rt=0x00);
261-
287+
262288
bgez.set_asm("bgez %reg, %exp(pcrel)", rs, imm);
263289
bgez.set_decoder(op=0x01, rt=0x01);
264-
290+
265291
bltzal.set_asm("bltzal %reg, %exp(pcrel)", rs, imm);
266292
bltzal.set_decoder(op=0x01, rt=0x10);
267-
293+
268294
bgezal.set_asm("bgezal %reg, %exp(pcrel)", rs, imm);
269295
bgezal.set_decoder(op=0x01, rt=0x11);
270-
296+
271297
sys_call.set_asm("syscall");
272298
sys_call.set_decoder(op=0x00, func=0x0C);
273-
299+
274300
instr_break.set_asm("break", rt=0);
275301
instr_break.set_asm("break %imm", rt);
276302
instr_break.set_decoder(op=0x00, func=0x0D);
277303

278-
pseudo_instr("nop") {
279-
"sll $0, $0, 0";
280-
}
281304

282305
pseudo_instr("li %reg, %imm") {
283306
"lui %0, \%hi(%1)";
284307
"ori %0, %0, %1";
285308
}
286309

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+
}
291314

292315
pseudo_instr("sw %reg, %exp") {
293316
"lui $at, \%hi(%1)";
@@ -296,9 +319,9 @@ AC_ISA(mips){
296319

297320
pseudo_instr("lw %reg, %exp") {
298321
"lui %0, \%hi(%1)";
299-
"lw %0, \%lo(%1)(%0)";
322+
"lw %0, \%lo(%1)(%0)";
300323
}
301-
324+
302325
pseudo_instr("subu %reg, %reg, %imm") {
303326
"addiu %0, %1, -%2";
304327
}
@@ -312,7 +335,7 @@ AC_ISA(mips){
312335
"slti $at, %0, %1+1";
313336
"bne $at, $zero, %2";
314337
}
315-
338+
316339
pseudo_instr("mul %reg, %reg, %reg") {
317340
"multu %1, %2";
318341
"mflo %0";
@@ -333,19 +356,19 @@ AC_ISA(mips){
333356
"mult %1, $at";
334357
"mflo %0";
335358
}
336-
359+
337360
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 :/
339362
- this only works when %exp < 2^16-1 - should be enough for validation */
340363
"lui %0, %1";
341364
"addu %0, %0, %2";
342365
"lw %0, (%0)";
343366
}
344367

345368
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 :/
347370
- this only works when %exp < 2^16-1 - should be enough for validation */
348-
"lui $at, %1";
371+
"lui $at, %1";
349372
"addu $at, $at, %2";
350373
"sw %0, ($at)";
351374
}

0 commit comments

Comments
 (0)