1 #include <stdio.h>
2
3 #define TESTINST1(RSval, RD) \
4 { \
5 unsigned int out = 0; \
6 __asm__ __volatile__( \
7 ".set noreorder" "\n\t" \
8 "move $"#RD", %1" "\n\t" \
9 "b end"#RSval "\n\t" \
10 "nop" "\n\t" \
11 "addi $"#RD", $"#RD", 5" "\n\t" \
12 "end"#RSval":" "\n\t" \
13 "addi $"#RD", $"#RD", 1" "\n\t" \
14 "move %0, $"#RD "\n\t" \
15 ".set reorder" "\n\t" \
16 : "=r" (out) \
17 : "r" (RSval) \
18 : #RD \
19 ); \
20 printf("B :: %d, RSval: %d\n", \
21 out, RSval); \
22 }
23
24 #define TESTINST2(RSval, RD) \
25 { \
26 unsigned int out = 0; \
27 __asm__ __volatile__( \
28 ".set noreorder" "\n\t" \
29 "move $"#RD", %1" "\n\t" \
30 "b end12"#RSval "\n\t" \
31 "addi $"#RD", $"#RD", 3" "\n\t" \
32 "addi $"#RD", $"#RD", 5" "\n\t" \
33 "end12"#RSval":" "\n\t" \
34 "addi $"#RD", $"#RD", 3" "\n\t" \
35 "move %0, $"#RD "\n\t" \
36 ".set reorder" "\n\t" \
37 : "=r" (out) \
38 : "r" (RSval) \
39 : #RD \
40 ); \
41 printf("B :: %d, RSval: %d\n", \
42 out, RSval); \
43 }
44
45 #define TESTINST3(RSval, RD) \
46 { \
47 unsigned int out = 0; \
48 __asm__ __volatile__( \
49 ".set noreorder" "\n\t" \
50 "move $"#RD", %1" "\n\t" \
51 "bal end21"#RSval "\n\t" \
52 "nop" "\n\t" \
53 "addi $"#RD", $"#RD", 5" "\n\t" \
54 "b r_end"#RSval "\n\t" \
55 "nop" "\n\t" \
56 "addi $"#RD", $"#RD", 1" "\n\t" \
57 "end21"#RSval":" "\n\t" \
58 "addi $"#RD", $"#RD", 1" "\n\t" \
59 "jr $ra" "\n\t" \
60 "nop" "\n\t" \
61 "r_end"#RSval":" "\n\t" \
62 "move %0, $"#RD "\n\t" \
63 ".set reorder" "\n\t" \
64 : "=r" (out) \
65 : "r" (RSval) \
66 : #RD, "ra" \
67 ); \
68 printf("B BAL JR :: %d, RSval: %d\n", \
69 out, RSval); \
70 }
71
72 #define TESTINST3j(RSval, RD) \
73 { \
74 unsigned int out = 0; \
75 __asm__ __volatile__( \
76 ".set noreorder" "\n\t" \
77 "move $"#RD", %1" "\n\t" \
78 "dla $t9, end31"#RSval "\n\t" \
79 "jal $t9" "\n\t" \
80 "nop" "\n\t" \
81 "addi $"#RD", $"#RD", 5" "\n\t" \
82 "dla $t9, r_end11"#RSval "\n\t" \
83 "j $t9" "\n\t" \
84 "nop" "\n\t" \
85 "end31"#RSval":" "\n\t" \
86 "addi $"#RD", $"#RD", 1" "\n\t" \
87 "jr $ra" "\n\t" \
88 "nop" "\n\t" \
89 "r_end11"#RSval":" "\n\t" \
90 "move %0, $"#RD "\n\t" \
91 ".set reorder" "\n\t" \
92 : "=r" (out) \
93 : "r" (RSval) \
94 : #RD, "t9" \
95 ); \
96 printf("J JAL JR :: %d, RSval: %d\n", \
97 out, RSval); \
98 }
99
100 #define TESTINST3ja(RSval, RD) \
101 { \
102 unsigned int out = 0; \
103 __asm__ __volatile__( \
104 ".set noreorder" "\n\t" \
105 "move $"#RD", %1" "\n\t" \
106 "dla $t9, end41"#RSval "\n\t" \
107 "jalr $t0, $t9" "\n\t" \
108 "nop" "\n\t" \
109 "addi $"#RD", $"#RD", 5" "\n\t" \
110 "dla $t9, r_end21"#RSval "\n\t" \
111 "j $t9" "\n\t" \
112 "nop" "\n\t" \
113 "addi $"#RD", $"#RD", 1" "\n\t" \
114 "end41"#RSval":" "\n\t" \
115 "addi $"#RD", $"#RD", 1" "\n\t" \
116 "move $t9, $t0" "\n\t" \
117 "jr $t9" "\n\t" \
118 "nop" "\n\t" \
119 "r_end21"#RSval":" "\n\t" \
120 "move %0, $"#RD "\n\t" \
121 ".set reorder" "\n\t" \
122 : "=r" (out) \
123 : "r" (RSval) \
124 : #RD, "t0", "t9" \
125 ); \
126 printf("J JALR JR :: %d, RSval: %d\n", \
127 out, RSval); \
128 }
129
130 #define TESTINST4(instruction, RDval, RSval, RTval, RD, RS, RT) \
131 { \
132 unsigned int out = 0; \
133 __asm__ __volatile__( \
134 ".set noreorder" "\n\t" \
135 "move $"#RS", %1" "\n\t" \
136 "move $"#RT", %2" "\n\t" \
137 "move $"#RD", %3" "\n\t" \
138 instruction" $"#RS", $"#RT", end"instruction#RDval "\n\t" \
139 "nop" "\n\t" \
140 "addi $"#RD", $"#RD", 5" "\n\t" \
141 "end"instruction#RDval":" "\n\t" \
142 "addi $"#RD", $"#RD", 1" "\n\t" \
143 "move %0, $" #RD "\n\t" \
144 ".set reorder" "\n\t" \
145 : "=r" (out) \
146 : "r" (RSval), "r" (RTval), "r" (RDval) \
147 : #RD, #RS, #RT \
148 ); \
149 printf(instruction" :: out: %d, RDval: %d, RSval: %d, RTval: %d\n", \
150 out, RDval, RSval, RTval); \
151 }
152
153 #define TESTINST5(instruction, RDval, RSval, RD, RS) \
154 { \
155 unsigned int out = 0; \
156 __asm__ __volatile__( \
157 ".set noreorder" "\n\t" \
158 "move $"#RS", %1" "\n\t" \
159 "move $"#RD", %2" "\n\t" \
160 instruction" $"#RS", end"instruction#RDval "\n\t" \
161 "nop" "\n\t" \
162 "addi $"#RD", $"#RD", 5" "\n\t" \
163 "end"instruction#RDval":" "\n\t" \
164 "addi $"#RD", $"#RD", 1" "\n\t" \
165 "move %0, $"#RD "\n\t" \
166 ".set reorder" "\n\t" \
167 : "=r" (out) \
168 : "r" (RSval), "r" (RDval) \
169 : #RD, #RS \
170 ); \
171 printf(instruction" :: out: %d, RDval: %d, RSval: %d\n", \
172 out, RDval, RSval); \
173 }
174
175 #define TESTINST6(instruction, RDval, RSval, RD, RS) \
176 { \
177 unsigned int out = 0; \
178 __asm__ __volatile__( \
179 ".set noreorder" "\n\t" \
180 "move $"#RD", %2" "\n\t" \
181 "move $"#RS", %1" "\n\t" \
182 instruction" $"#RS", end21"instruction#RDval "\n\t" \
183 "nop" "\n\t" \
184 "addi $"#RD", $"#RD", 5" "\n\t" \
185 "b r_end"instruction#RDval "\n\t" \
186 "nop" "\n\t" \
187 "end21"instruction#RDval":" "\n\t" \
188 "addi $"#RD", $"#RD", 1" "\n\t" \
189 "jr $ra" "\n\t" \
190 "r_end"instruction#RDval":" "\n\t" \
191 "move %0, $"#RD "\n\t" \
192 ".set reorder" "\n\t" \
193 : "=r" (out) \
194 : "r" (RSval), "r" (RDval) \
195 : #RD, #RS, "ra" \
196 ); \
197 printf(instruction" :: out: %d, RDval: %d, RSval: %d\n", \
198 out, RDval, RSval); \
199 }
200
201 #define TESTINST4l(instruction, RDval, RSval, RTval, RD, RS, RT) \
202 { \
203 unsigned int out = 0; \
204 __asm__ __volatile__( \
205 ".set noreorder" "\n\t" \
206 "move $"#RS", %1" "\n\t" \
207 "move $"#RT", %2" "\n\t" \
208 "move $"#RD", %3" "\n\t" \
209 instruction" $"#RS", $"#RT", end"instruction#RDval "\n\t" \
210 "addi $"#RD", $"#RD", 3" "\n\t" \
211 "addi $"#RD", $"#RD", 5" "\n\t" \
212 "end"instruction#RDval":" "\n\t" \
213 "addi $"#RD", $"#RD", 1" "\n\t" \
214 "move %0, $"#RD "\n\t" \
215 ".set reorder" "\n\t" \
216 : "=r" (out) \
217 : "r" (RSval), "r" (RTval), "r" (RDval) \
218 : #RD, #RS, #RT \
219 ); \
220 printf(instruction" :: out: %d, RDval: %d, RSval: %d, RTval: %d\n", \
221 out, RDval, RSval, RTval); \
222 }
223
224 #define TESTINST5l(instruction, RDval, RSval, RD, RS) \
225 { \
226 unsigned int out = 0; \
227 __asm__ __volatile__( \
228 ".set noreorder" "\n\t" \
229 "move $"#RS", %1" "\n\t" \
230 "move $"#RD", %2" "\n\t" \
231 instruction" $"#RS", end"instruction#RDval "\n\t" \
232 "addi $"#RD", $"#RD", 3" "\n\t" \
233 "addi $"#RD", $"#RD", 5" "\n\t" \
234 "end"instruction#RDval":" "\n\t" \
235 "addi $"#RD", $"#RD", 1" "\n\t" \
236 "move %0, $"#RD "\n\t" \
237 ".set reorder" "\n\t" \
238 : "=r" (out) \
239 : "r" (RSval), "r" (RDval) \
240 : #RD, #RS \
241 ); \
242 printf(instruction" :: out: %d, RDval: %d, RSval: %d\n", \
243 out, RDval, RSval); \
244 }
245
246 #define TESTINST6l(instruction, RDval, RSval, RD, RS) \
247 { \
248 unsigned int out = 0; \
249 __asm__ __volatile__( \
250 ".set noreorder" "\n\t" \
251 "move $"#RD", %2" "\n\t" \
252 "move $"#RS", %1" "\n\t" \
253 instruction" $"#RS", end21"instruction#RDval "\n\t" \
254 "addi $"#RD", $"#RD", 3" "\n\t" \
255 "addi $"#RD", $"#RD", 5" "\n\t" \
256 "b r_end"instruction#RDval "\n\t" \
257 "nop" "\n\t" \
258 "end21"instruction#RDval":" "\n\t" \
259 "addi $"#RD", $"#RD", 1" "\n\t" \
260 "jr $ra" "\n\t" \
261 "nop" "\n\t" \
262 "r_end"instruction#RDval":" "\n\t" \
263 "move %0, $"#RD "\n\t" \
264 ".set reorder" "\n\t" \
265 : "=r" (out) \
266 : "r" (RSval), "r" (RDval) \
267 : #RD, #RS, "ra" \
268 ); \
269 printf(instruction" :: out: %d, RDval: %d, RSval: %d\n", \
270 out, RDval, RSval); \
271 }
272
273
main()274 int main()
275 {
276 printf("b\n");
277 TESTINST1(0, 2);
278 TESTINST1(1, 3);
279 TESTINST1(2, 4);
280 TESTINST1(3, 5);
281 TESTINST1(4, 6);
282 TESTINST1(5, 7);
283 TESTINST1(6, 8);
284 TESTINST1(7, 9);
285 TESTINST1(8, 10);
286 TESTINST1(9, 11);
287 TESTINST1(10, 12);
288 TESTINST1(11, 13);
289 TESTINST1(12, 14);
290 TESTINST1(13, 15);
291 TESTINST1(14, 16);
292 TESTINST1(15, 17);
293 TESTINST1(16, 18);
294 TESTINST1(17, 19);
295 TESTINST1(18, 20);
296 TESTINST1(19, 21);
297 TESTINST1(20, 22);
298 TESTINST1(21, 23);
299 TESTINST1(22, 24);
300 TESTINST1(23, 25);
301
302 printf("b\n");
303 TESTINST2(0, 2);
304 TESTINST2(1, 3);
305 TESTINST2(2, 4);
306 TESTINST2(3, 5);
307 TESTINST2(4, 6);
308 TESTINST2(5, 7);
309 TESTINST2(6, 8);
310 TESTINST2(7, 9);
311 TESTINST2(8, 10);
312 TESTINST2(9, 11);
313 TESTINST2(10, 12);
314 TESTINST2(11, 13);
315 TESTINST2(12, 14);
316 TESTINST2(13, 15);
317 TESTINST2(14, 16);
318 TESTINST2(15, 17);
319 TESTINST2(16, 18);
320 TESTINST2(17, 19);
321 TESTINST2(18, 20);
322 TESTINST2(19, 21);
323 TESTINST2(20, 22);
324 TESTINST2(21, 23);
325 TESTINST2(22, 24);
326 TESTINST2(23, 25);
327
328 printf("b, bal, jr\n");
329 TESTINST3(0, 2);
330 TESTINST3(1, 3);
331 TESTINST3(2, 4);
332 TESTINST3(3, 5);
333 TESTINST3(4, 6);
334 TESTINST3(5, 7);
335 TESTINST3(6, 8);
336 TESTINST3(7, 9);
337 TESTINST3(8, 10);
338 TESTINST3(9, 11);
339 TESTINST3(10, 12);
340 TESTINST3(11, 13);
341 TESTINST3(12, 14);
342 TESTINST3(13, 15);
343 TESTINST3(14, 16);
344 TESTINST3(15, 17);
345 TESTINST3(16, 18);
346 TESTINST3(17, 19);
347 TESTINST3(18, 20);
348 TESTINST3(19, 21);
349 TESTINST3(20, 22);
350 TESTINST3(21, 23);
351 TESTINST3(22, 24);
352 TESTINST3(23, 25);
353
354 printf("--- BEQ --- if RSval == RTval then " \
355 "out = RDval + 1 else out = RDval + 6\n");
356 TESTINST4("beq", 0, 0, 1, 2, 3 , 4);
357 TESTINST4("beq", 1, 1, 1, 3, 4, 5);
358 TESTINST4("beq", 2, 0xffffffff, 0xffffffff, 4, 5, 6);
359 TESTINST4("beq", 3, 0xffffffff, 0xfffffffe, 5, 6, 7);
360 TESTINST4("beq", 4, 0xfffffffe, 0xffffffff, 6, 8, 9);
361 TESTINST4("beq", 5, 0xffffffff, 0xffffffff, 7, 8, 9);
362 TESTINST4("beq", 6, 0x5, 0x5, 8, 9, 10);
363 TESTINST4("beq", 7, -3, -4, 9, 10, 11);
364 TESTINST4("beq", 8, 125, 125, 10, 11, 12);
365 TESTINST4("beq", 9, 0x80000000, 0x80000000, 11, 12, 13);
366 TESTINST4("beq", 10, 0xffffffff, 0x80000000, 12, 13, 14);
367 TESTINST4("beq", 11, 0x256, 0x256, 13, 14, 15);
368 TESTINST4("beq", 12, 0x55, 0x55, 14, 15, 16);
369 TESTINST4("beq", 13, 0xfff, 0xdd, 16, 17, 18);
370 TESTINST4("beq", 14, -1, 0x5, 2, 25, 24);
371 TESTINST4("beq", 15, -1, -1, 25, 24, 7);
372
373 printf("--- BNE --- if RSval != RTval then " \
374 "out = RDval + 1 else out = RDval + 6\n");
375 TESTINST4("bne", 0, 0, 1, 2, 3, 4);
376 TESTINST4("bne", 1, 1, 1, 3, 4, 5);
377 TESTINST4("bne", 2, 0xffffffff, 0xffffffff, 4, 5, 6);
378 TESTINST4("bne", 3, 0xffffffff, 0xfffffffe, 5, 6, 7);
379 TESTINST4("bne", 4, 0xfffffffe, 0xffffffff, 6, 8, 9);
380 TESTINST4("bne", 5, 0xffffffff, 0xffffffff, 7, 8, 9);
381 TESTINST4("bne", 6, 0x5, 0x5, 8, 9, 10);
382 TESTINST4("bne", 7, -3, -4, 9, 10, 11);
383 TESTINST4("bne", 8, 125, 125, 10, 11, 12);
384 TESTINST4("bne", 9, 0x80000000, 0x80000000, 11, 12, 13);
385 TESTINST4("bne", 10, 0xffffffff, 0x80000000, 12, 13, 14);
386 TESTINST4("bne", 11, 0x256, 0x256, 13, 14, 15);
387 TESTINST4("bne", 12, 0x55, 0x55, 14, 15, 16);
388 TESTINST4("bne", 13, 0xfff, 0xdd, 16, 17, 18);
389 TESTINST4("bne", 14, -1, 0x5, 2, 25, 24);
390 TESTINST4("bne", 15, -1, -1, 25, 24, 7);
391
392 printf("--- BEQZ --- if RSval == 0 then " \
393 "out = RDval + 1 else out = RDval + 6\n");
394 TESTINST5("beqz", 0, 0, 2, 3);
395 TESTINST5("beqz", 1, 1, 3, 4);
396 TESTINST5("beqz", 2, 0xffffffff, 4, 5);
397 TESTINST5("beqz", 3, 0xffffffff, 5, 6);
398 TESTINST5("beqz", 4, 0xfffffffe, 6, 8);
399 TESTINST5("beqz", 5, 0xffffffff, 7, 8);
400 TESTINST5("beqz", 6, 0x5, 8, 9);
401 TESTINST5("beqz", 7, -3, 9, 10);
402 TESTINST5("beqz", 8, 125, 10, 11);
403 TESTINST5("beqz", 9, 0x80000000, 11, 12);
404 TESTINST5("beqz", 10, 0xffffffff, 12, 13);
405 TESTINST5("beqz", 11, 0x256, 13, 14);
406 TESTINST5("beqz", 12, 0x55, 14, 15);
407 TESTINST5("beqz", 13, 0xfff, 16, 17);
408 TESTINST5("beqz", 14, -1, 2, 25);
409 TESTINST5("beqz", 15, -1, 25, 24);
410
411 printf("--- BGEZ --- if RSval >= 0 then " \
412 "out = RDval + 1 else out = RDval + 6\n");
413 TESTINST5("bgez", 0, 0, 2, 3);
414 TESTINST5("bgez", 1, 1, 3, 4);
415 TESTINST5("bgez", 2, 0xffffffff, 4, 5);
416 TESTINST5("bgez", 3, 0xffffffff, 5, 6);
417 TESTINST5("bgez", 4, 0xfffffffe, 6, 8);
418 TESTINST5("bgez", 5, 0xffffffff, 7, 8);
419 TESTINST5("bgez", 6, 0x5, 8, 9);
420 TESTINST5("bgez", 7, -3, 9, 10);
421 TESTINST5("bgez", 8, 125, 10, 11);
422 TESTINST5("bgez", 9, 0x80000000, 11, 12);
423 TESTINST5("bgez", 10, 0xffffffff, 12, 13);
424 TESTINST5("bgez", 11, 0x256, 13, 14);
425 TESTINST5("bgez", 12, 0x55, 14, 15);
426 TESTINST5("bgez", 13, 0xfff, 16, 17);
427 TESTINST5("bgez", 14, -1, 2, 25);
428 TESTINST5("bgez", 15, -1, 25, 24);
429
430 printf("--- BGTZ --- if RSval > 0 then " \
431 "out = RDval + 1 else out = RDval + 6\n");
432 TESTINST5("bgtz", 0, 0, 2, 3);
433 TESTINST5("bgtz", 1, 1, 3, 4);
434 TESTINST5("bgtz", 2, 0xffffffff, 4, 5);
435 TESTINST5("bgtz", 3, 0xffffffff, 5, 6);
436 TESTINST5("bgtz", 4, 0xfffffffe, 6, 8);
437 TESTINST5("bgtz", 5, 0xffffffff, 7, 8);
438 TESTINST5("bgtz", 6, 0x5, 8, 9);
439 TESTINST5("bgtz", 7, -3, 9, 10);
440 TESTINST5("bgtz", 8, 125, 10, 11);
441 TESTINST5("bgtz", 9, 0x80000000, 11, 12);
442 TESTINST5("bgtz", 10, 0xffffffff, 12, 13);
443 TESTINST5("bgtz", 11, 0x256, 13, 14);
444 TESTINST5("bgtz", 12, 0x55, 14, 15);
445 TESTINST5("bgtz", 13, 0xfff, 16, 17);
446 TESTINST5("bgtz", 14, -1, 2, 25);
447 TESTINST5("bgtz", 15, -1, 25, 24);
448
449 printf("--- BLEZ --- if RSval <= 0 then " \
450 "out = RDval + 1 else out = RDval + 6\n");
451 TESTINST5("blez", 0, 0, 2, 3);
452 TESTINST5("blez", 1, 1, 3, 4);
453 TESTINST5("blez", 2, 0xffffffff, 4, 5);
454 TESTINST5("blez", 3, 0xffffffff, 5, 6);
455 TESTINST5("blez", 4, 0xfffffffe, 6, 8);
456 TESTINST5("blez", 5, 0xffffffff, 7, 8);
457 TESTINST5("blez", 6, 0x5, 8, 9);
458 TESTINST5("blez", 7, -3, 9, 10);
459 TESTINST5("blez", 8, 125, 10, 11);
460 TESTINST5("blez", 9, 0x80000000, 11, 12);
461 TESTINST5("blez", 10, 0xffffffff, 12, 13);
462 TESTINST5("blez", 11, 0x256, 13, 14);
463 TESTINST5("blez", 12, 0x55, 14, 15);
464 TESTINST5("blez", 13, 0xfff, 16, 17);
465 TESTINST5("blez", 14, -1, 2, 25);
466 TESTINST5("blez", 15, -1, 25, 24);
467
468 printf("--- BLTZ --- if RSval < 0 then " \
469 "out = RDval + 1 else out = RDval + 6\n");
470 TESTINST5("bltz", 0, 0, 2, 3);
471 TESTINST5("bltz", 1, 1, 3, 4);
472 TESTINST5("bltz", 2, 0xffffffff, 4, 5);
473 TESTINST5("bltz", 3, 0xffffffff, 5, 6);
474 TESTINST5("bltz", 4, 0xfffffffe, 6, 8);
475 TESTINST5("bltz", 5, 0xffffffff, 7, 8);
476 TESTINST5("bltz", 6, 0x5, 8, 9);
477 TESTINST5("bltz", 7, -3, 9, 10);
478 TESTINST5("bltz", 8, 125, 10, 11);
479 TESTINST5("bltz", 9, 0x80000000, 11, 12);
480 TESTINST5("bltz", 10, 0xffffffff, 12, 13);
481 TESTINST5("bltz", 11, 0x256, 13, 14);
482 TESTINST5("bltz", 12, 0x55, 14, 15);
483 TESTINST5("bltz", 13, 0xfff, 16, 17);
484 TESTINST5("bltz", 14, -1, 2, 25);
485 TESTINST5("bltz", 15, -1, 25, 24);
486
487 printf("--- BGEZAL --- if RSval >= 0 then " \
488 "out = RDval + 6 else out = RDval + 5\n");
489 TESTINST6("bgezal", 0, 0, 2, 3);
490 TESTINST6("bgezal", 1, 1, 3, 4);
491 TESTINST6("bgezal", 2, 0xffffffff, 4, 5);
492 TESTINST6("bgezal", 3, 0xffffffff, 5, 6);
493 TESTINST6("bgezal", 4, 0xfffffffe, 6, 8);
494 TESTINST6("bgezal", 5, 0xffffffff, 7, 8);
495 TESTINST6("bgezal", 6, 0x5, 8, 9);
496 TESTINST6("bgezal", 7, -3, 9, 10);
497 TESTINST6("bgezal", 8, 125, 10, 11);
498 TESTINST6("bgezal", 9, 0x80000000, 11, 12);
499 TESTINST6("bgezal", 10, 0xffffffff, 12, 13);
500 TESTINST6("bgezal", 11, 0x256, 13, 14);
501 TESTINST6("bgezal", 12, 0x55, 14, 15);
502 TESTINST6("bgezal", 13, 0xfff, 16, 17);
503 TESTINST6("bgezal", 14, -1, 2, 25);
504 TESTINST6("bgezal", 15, -1, 25, 24);
505
506 printf("--- BLTZAL --- if RSval < 0 then " \
507 "out = RDval + 6 else out = RDval + 5\n");
508 TESTINST6("bltzal", 0, 0, 2, 3);
509 TESTINST6("bltzal", 1, 1, 3, 4);
510 TESTINST6("bltzal", 2, 0xffffffff, 4, 5);
511 TESTINST6("bltzal", 3, 0xffffffff, 5, 6);
512 TESTINST6("bltzal", 4, 0xfffffffe, 6, 8);
513 TESTINST6("bltzal", 5, 0xffffffff, 7, 8);
514 TESTINST6("bltzal", 6, 0x5, 8, 9);
515 TESTINST6("bltzal", 7, -3, 9, 10);
516 TESTINST6("bltzal", 8, 125, 10, 11);
517 TESTINST6("bltzal", 9, 0x80000000, 11, 12);
518 TESTINST6("bltzal", 10, 0xffffffff, 12, 13);
519 TESTINST6("bltzal", 11, 0x256, 13, 14);
520 TESTINST6("bltzal", 12, 0x55, 14, 15);
521 TESTINST6("bltzal", 13, 0xfff, 16, 17);
522 TESTINST6("bltzal", 14, -1, 2, 25);
523 TESTINST6("bltzal", 15, -1, 25, 24);
524
525 printf("--- BNEZ --- if RSval != 0 then " \
526 "out = RDval + 1 else out = RDval + 6\n");
527 TESTINST5("bnez", 0, 0, 2, 3);
528 TESTINST5("bnez", 1, 1, 3, 4);
529 TESTINST5("bnez", 2, 0xffffffff, 4, 5);
530 TESTINST5("bnez", 3, 0xffffffff, 5, 6);
531 TESTINST5("bnez", 4, 0xfffffffe, 6, 8);
532 TESTINST5("bnez", 5, 0xffffffff, 7, 8);
533 TESTINST5("bnez", 6, 0x5, 8, 9);
534 TESTINST5("bnez", 7, -3, 9, 10);
535 TESTINST5("bnez", 8, 125, 10, 11);
536 TESTINST5("bnez", 9, 0x80000000, 11, 12);
537 TESTINST5("bnez", 10, 0xffffffff, 12, 13);
538 TESTINST5("bnez", 11, 0x256, 13, 14);
539 TESTINST5("bnez", 12, 0x55, 14, 15);
540 TESTINST5("bnez", 13, 0xfff, 16, 17);
541 TESTINST5("bnez", 14, -1, 2, 25);
542 TESTINST5("bnez", 15, -1, 25, 24);
543
544 printf("--- BEQL --- if RSval == RTval then " \
545 "out = RDval + 4 else out = RDval + 6\n");
546 TESTINST4l("beql", 0, 0, 1, 2, 3, 4);
547 TESTINST4l("beql", 1, 1, 1, 3, 4, 5);
548 TESTINST4l("beql", 2, 0xffffffff, 0xffffffff, 4, 5, 6);
549 TESTINST4l("beql", 3, 0xffffffff, 0xfffffffe, 5, 6, 7);
550 TESTINST4l("beql", 4, 0xfffffffe, 0xffffffff, 6, 8, 9);
551 TESTINST4l("beql", 5, 0xffffffff, 0xffffffff, 7, 8, 9);
552 TESTINST4l("beql", 6, 0x5, 0x5, 8, 9, 10);
553 TESTINST4l("beql", 7, -3, -4, 9, 10, 11);
554 TESTINST4l("beql", 8, 125, 125, 10, 11, 12);
555 TESTINST4l("beql", 9, 0x80000000, 0x80000000, 11, 12, 13);
556 TESTINST4l("beql", 10, 0xffffffff, 0x80000000, 12, 13, 14);
557 TESTINST4l("beql", 11, 0x256, 0x256, 13, 14, 15);
558 TESTINST4l("beql", 12, 0x55, 0x55, 14, 15, 16);
559 TESTINST4l("beql", 13, 0xfff, 0xdd, 16, 17, 18);
560 TESTINST4l("beql", 14, -1, 0x5, 2, 25, 24);
561 TESTINST4l("beql", 15, -1, -1, 25, 24, 7);
562
563 printf("--- BGEZALL --- if RSval >= 0 then " \
564 "out = RDval + 4 else out = RDval + 6\n");
565 TESTINST5l("bgezall", 0, 0, 2, 3);
566 TESTINST5l("bgezall", 1, 1, 3, 4);
567 TESTINST5l("bgezall", 2, 0xffffffff, 4, 5);
568 TESTINST5l("bgezall", 3, 0xffffffff, 5, 6);
569 TESTINST5l("bgezall", 4, 0xfffffffe, 6, 8);
570 TESTINST5l("bgezall", 5, 0xffffffff, 7, 8);
571 TESTINST5l("bgezall", 6, 0x5, 8, 9);
572 TESTINST5l("bgezall", 7, -3, 9, 10);
573 TESTINST5l("bgezall", 8, 125, 10, 11);
574 TESTINST5l("bgezall", 9, 0x80000000, 11, 12);
575 TESTINST5l("bgezall", 10, 0xffffffff, 12, 13);
576 TESTINST5l("bgezall", 11, 0x256, 13, 14);
577 TESTINST5l("bgezall", 12, 0x55, 14, 15);
578 TESTINST5l("bgezall", 13, 0xfff, 16, 17);
579 TESTINST5l("bgezall", 14, -1, 2, 25);
580 TESTINST5l("bgezall", 15, -1, 25, 24);
581
582 printf("--- BLTZALL --- if RSval < 0 then " \
583 "out = RDval + 4 else out = RDval + 6\n");
584 TESTINST5l("bltzall", 0, 0, 2, 3);
585 TESTINST5l("bltzall", 1, 1, 3, 4);
586 TESTINST5l("bltzall", 2, 0xffffffff, 4, 5);
587 TESTINST5l("bltzall", 3, 0xffffffff, 5, 6);
588 TESTINST5l("bltzall", 4, 0xfffffffe, 6, 8);
589 TESTINST5l("bltzall", 5, 0xffffffff, 7, 8);
590 TESTINST5l("bltzall", 6, 0x5, 8, 9);
591 TESTINST5l("bltzall", 7, -3, 9, 10);
592 TESTINST5l("bltzall", 8, 125, 10, 11);
593 TESTINST5l("bltzall", 9, 0x80000000, 11, 12);
594 TESTINST5l("bltzall", 10, 0xffffffff, 12, 13);
595 TESTINST5l("bltzall", 11, 0x256, 13, 14);
596 TESTINST5l("bltzall", 12, 0x55, 14, 15);
597 TESTINST5l("bltzall", 13, 0xfff, 16, 17);
598 TESTINST5l("bltzall", 14, -1, 2, 25);
599 TESTINST5l("bltzall", 15, -1, 25, 24);
600
601 printf("--- BGEZL --- if RSval >= 0 then " \
602 "out = RDval + 4 else out = RDval + 6\n");
603 TESTINST5l("bgezl", 0, 0, 2, 3);
604 TESTINST5l("bgezl", 1, 1, 3, 4);
605 TESTINST5l("bgezl", 2, 0xffffffff, 4, 5);
606 TESTINST5l("bgezl", 3, 0xffffffff, 5, 6);
607 TESTINST5l("bgezl", 4, 0xfffffffe, 6, 8);
608 TESTINST5l("bgezl", 5, 0xffffffff, 7, 8);
609 TESTINST5l("bgezl", 6, 0x5, 8, 9);
610 TESTINST5l("bgezl", 7, -3, 9, 10);
611 TESTINST5l("bgezl", 8, 125, 10, 11);
612 TESTINST5l("bgezl", 9, 0x80000000, 11, 12);
613 TESTINST5l("bgezl", 10, 0xffffffff, 12, 13);
614 TESTINST5l("bgezl", 11, 0x256, 13, 14);
615 TESTINST5l("bgezl", 12, 0x55, 14, 15);
616 TESTINST5l("bgezl", 13, 0xfff, 16, 17);
617 TESTINST5l("bgezl", 14, -1, 2, 25);
618 TESTINST5l("bgezl", 15, -1, 25, 24);
619
620 printf("--- BGTZL --- if RSval > 0 then " \
621 "out = RDval + 4 else out = RDval + 6\n");
622 TESTINST5l("bgtzl", 0, 0, 2, 3);
623 TESTINST5l("bgtzl", 1, 1, 3, 4);
624 TESTINST5l("bgtzl", 2, 0xffffffff, 4, 5);
625 TESTINST5l("bgtzl", 3, 0xffffffff, 5, 6);
626 TESTINST5l("bgtzl", 4, 0xfffffffe, 6, 8);
627 TESTINST5l("bgtzl", 5, 0xffffffff, 7, 8);
628 TESTINST5l("bgtzl", 6, 0x5, 8, 9);
629 TESTINST5l("bgtzl", 7, -3, 9, 10);
630 TESTINST5l("bgtzl", 8, 125, 10, 11);
631 TESTINST5l("bgtzl", 9, 0x80000000, 11, 12);
632 TESTINST5l("bgtzl", 10, 0xffffffff, 12, 13);
633 TESTINST5l("bgtzl", 11, 0x256, 13, 14);
634 TESTINST5l("bgtzl", 12, 0x55, 14, 15);
635 TESTINST5l("bgtzl", 13, 0xfff, 16, 17);
636 TESTINST5l("bgtzl", 14, -1, 2, 25);
637 TESTINST5l("bgtzl", 15, -1, 25, 24);
638
639 printf("--- BLEZL --- if RSval <= 0 then " \
640 "out = RDval + 4 else out = RDval + 6\n");
641 TESTINST5l("blezl", 0, 0, 2, 3);
642 TESTINST5l("blezl", 1, 1, 3, 4);
643 TESTINST5l("blezl", 2, 0xffffffff, 4, 5);
644 TESTINST5l("blezl", 3, 0xffffffff, 5, 6);
645 TESTINST5l("blezl", 4, 0xfffffffe, 6, 8);
646 TESTINST5l("blezl", 5, 0xffffffff, 7, 8);
647 TESTINST5l("blezl", 6, 0x5, 8, 9);
648 TESTINST5l("blezl", 7, -3, 9, 10);
649 TESTINST5l("blezl", 8, 125, 10, 11);
650 TESTINST5l("blezl", 9, 0x80000000, 11, 12);
651 TESTINST5l("blezl", 10, 0xffffffff, 12, 13);
652 TESTINST5l("blezl", 11, 0x256, 13, 14);
653 TESTINST5l("blezl", 12, 0x55, 14, 15);
654 TESTINST5l("blezl", 13, 0xfff, 16, 17);
655 TESTINST5l("blezl", 14, -1, 2, 25);
656 TESTINST5l("blezl", 15, -1, 25, 24);
657
658 printf("--- BGEZALL --- if RSval >= 0 then " \
659 "out = RDval + 9 else out = RDval + 5\n");
660 TESTINST6l("bgezall", 0, 0, 2, 3);
661 TESTINST6l("bgezall", 1, 1, 3, 4);
662 TESTINST6l("bgezall", 2, 0xffffffff, 4, 5);
663 TESTINST6l("bgezall", 3, 0xffffffff, 5, 6);
664 TESTINST6l("bgezall", 4, 0xfffffffe, 6, 8);
665 TESTINST6l("bgezall", 5, 0xffffffff, 7, 8);
666 TESTINST6l("bgezall", 6, 0x5, 8, 9);
667 TESTINST6l("bgezall", 7, -3, 9, 10);
668 TESTINST6l("bgezall", 8, 125, 10, 11);
669 TESTINST6l("bgezall", 9, 0x80000000, 11, 12);
670 TESTINST6l("bgezall", 10, 0xffffffff, 12, 13);
671 TESTINST6l("bgezall", 11, 0x256, 13, 14);
672 TESTINST6l("bgezall", 12, 0x55, 14, 15);
673 TESTINST6l("bgezall", 13, 0xfff, 16, 17);
674 TESTINST6l("bgezall", 14, -1, 2, 25);
675 TESTINST6l("bgezall", 15, -1, 25, 24);
676
677 printf("--- BLTZL --- if RSval < 0 then " \
678 "out = RDval + 4 else out = RDval + 6\n");
679 TESTINST5l("bltzl", 0, 0, 2, 3);
680 TESTINST5l("bltzl", 1, 1, 3, 4);
681 TESTINST5l("bltzl", 2, 0xffffffff, 4, 5);
682 TESTINST5l("bltzl", 3, 0xffffffff, 5, 6);
683 TESTINST5l("bltzl", 4, 0xfffffffe, 6, 8);
684 TESTINST5l("bltzl", 5, 0xffffffff, 7, 8);
685 TESTINST5l("bltzl", 6, 0x5, 8, 9);
686 TESTINST5l("bltzl", 7, -3, 9, 10);
687 TESTINST5l("bltzl", 8, 125, 10, 11);
688 TESTINST5l("bltzl", 9, 0x80000000, 11, 12);
689 TESTINST5l("bltzl", 10, 0xffffffff, 12, 13);
690 TESTINST5l("bltzl", 11, 0x256, 13, 14);
691 TESTINST5l("bltzl", 12, 0x55, 14, 15);
692 TESTINST5l("bltzl", 13, 0xfff, 16, 17);
693 TESTINST5l("bltzl", 14, -1, 2, 25);
694 TESTINST5l("bltzl", 15, -1, 25, 24);
695
696 printf("--- BNEL --- if RSval != RTval then " \
697 "out = RDval + 4 else out = RDval + 5\n");
698 TESTINST4l("bnel", 0, 0, 1, 2, 3, 4);
699 TESTINST4l("bnel", 1, 1, 1, 3, 4, 5);
700 TESTINST4l("bnel", 2, 0xffffffff, 0xffffffff, 4, 5, 6);
701 TESTINST4l("bnel", 3, 0xffffffff, 0xfffffffe, 5, 6, 7);
702 TESTINST4l("bnel", 4, 0xfffffffe, 0xffffffff, 6, 8, 9);
703 TESTINST4l("bnel", 5, 0xffffffff, 0xffffffff, 7, 8, 9);
704 TESTINST4l("bnel", 6, 0x5, 0x5, 8, 9, 10);
705 TESTINST4l("bnel", 7, -3, -4, 9, 10, 11);
706 TESTINST4l("bnel", 8, 125, 125, 10, 11, 12);
707 TESTINST4l("bnel", 9, 0x80000000, 0x80000000, 11, 12, 13);
708 TESTINST4l("bnel", 10, 0xffffffff, 0x80000000, 12, 13, 14);
709 TESTINST4l("bnel", 11, 0x256, 0x256, 13, 14, 15);
710 TESTINST4l("bnel", 12, 0x55, 0x55, 14, 15, 16);
711 TESTINST4l("bnel", 13, 0xfff, 0xdd, 16, 17, 18);
712 TESTINST4l("bnel", 14, -1, 0x5, 2, 25, 24);
713 TESTINST4l("bnel", 15, -1, -1, 25, 24, 7);
714
715 printf("j, jal, jr\n");
716 TESTINST3j(0, 2);
717 TESTINST3j(1, 3);
718 TESTINST3j(2, 4);
719 TESTINST3j(3, 5);
720 TESTINST3j(4, 6);
721 TESTINST3j(5, 7);
722 TESTINST3j(6, 4);
723 TESTINST3j(7, 9);
724 TESTINST3j(8, 10);
725 TESTINST3j(9, 11);
726 TESTINST3j(10, 12);
727 TESTINST3j(11, 13);
728 TESTINST3j(12, 14);
729 TESTINST3j(13, 15);
730 TESTINST3j(14, 16);
731 TESTINST3j(15, 17);
732 TESTINST3j(16, 18);
733 TESTINST3j(17, 19);
734 TESTINST3j(18, 20);
735 TESTINST3j(19, 21);
736 TESTINST3j(20, 22);
737 TESTINST3j(21, 23);
738 TESTINST3j(22, 24);
739 TESTINST3j(23, 24);
740
741 printf("j, jalr, jr\n");
742 TESTINST3ja(0, 2);
743 TESTINST3ja(1, 3);
744 TESTINST3ja(2, 4);
745 TESTINST3ja(3, 5);
746 TESTINST3ja(4, 6);
747 TESTINST3ja(5, 7);
748 TESTINST3ja(6, 4);
749 TESTINST3ja(7, 7);
750 TESTINST3ja(8, 10);
751 TESTINST3ja(9, 11);
752 TESTINST3ja(11, 13);
753 TESTINST3ja(12, 14);
754 TESTINST3ja(13, 15);
755 TESTINST3ja(14, 16);
756 TESTINST3ja(15, 17);
757 TESTINST3ja(16, 18);
758 TESTINST3ja(17, 19);
759 TESTINST3ja(18, 20);
760 TESTINST3ja(19, 21);
761 TESTINST3ja(20, 22);
762 TESTINST3ja(21, 23);
763 TESTINST3ja(22, 24);
764 TESTINST3ja(23, 24);
765
766 return 0;
767 }
768