1 #include <stdio.h>
2 #include "const.h"
3
4 #define TEST1(RSval, RD) \
5 { \
6 unsigned long long out = 0; \
7 __asm__ __volatile__( \
8 ".set noreorder" "\n\t" \
9 "move $"#RD", %1" "\n\t" \
10 "b end"#RD "\n\t" \
11 "nop" "\n\t" \
12 "daddi $"#RD", $"#RD", 5" "\n\t" \
13 "end"#RD":" "\n\t" \
14 "daddi $"#RD", $"#RD", 1" "\n\t" \
15 "move %0, $"#RD "\n\t" \
16 ".set reorder" "\n\t" \
17 : "=r" (out) \
18 : "r" (RSval) \
19 : #RD \
20 ); \
21 printf("B :: 0x%llx, RSval: 0x%llx\n", \
22 out, (long long) RSval); \
23 }
24
25 #define TEST2(RSval, RD) \
26 { \
27 unsigned long long out = 0; \
28 __asm__ __volatile__( \
29 ".set noreorder" "\n\t" \
30 "move $"#RD", %1" "\n\t" \
31 "bal end1"#RD "\n\t" \
32 "nop" "\n\t" \
33 "daddi $"#RD", $"#RD", 5" "\n\t" \
34 "b r_end"#RD "\n\t" \
35 "nop" "\n\t" \
36 "end1"#RD":" "\n\t" \
37 "daddi $"#RD", $"#RD", 1" "\n\t" \
38 "jr $ra" "\n\t" \
39 "nop" "\n\t" \
40 "r_end"#RD":" "\n\t" \
41 "move %0, $"#RD "\n\t" \
42 ".set reorder" "\n\t" \
43 : "=r" (out) \
44 : "r" (RSval) \
45 : #RD, "ra" \
46 ); \
47 printf("B BAL JR :: 0x%llx, RSval: 0x%llx\n", \
48 out, (long long) RSval); \
49 }
50
51 #define TEST2a(RSval, RD) \
52 { \
53 unsigned long long out = 0; \
54 __asm__ __volatile__( \
55 ".set noreorder" "\n\t" \
56 "move $"#RD", %1" "\n\t" \
57 "bal end12"#RD "\n\t" \
58 "nop" "\n\t" \
59 "daddi $"#RD", $"#RD", 5" "\n\t" \
60 "move $t9, $ra" "\n\t" \
61 "jr $t9" "\n\t" \
62 "nop" "\n\t" \
63 "daddi $"#RD", $"#RD", 1" "\n\t" \
64 "end12"#RD":" "\n\t" \
65 "daddi $"#RD", $"#RD", 1" "\n\t" \
66 "move $t9, $ra" "\n\t" \
67 "jal $t9" "\n\t" \
68 "nop" "\n\t" \
69 "move %0, $"#RD "\n\t" \
70 ".set reorder" "\n\t" \
71 : "=r" (out) \
72 : "r" (RSval) \
73 : #RD, "t9", "ra" \
74 ); \
75 printf("BAL JR JAL :: 0x%llx, RSval: 0x%llx\n", \
76 out, (long long) RSval); \
77 }
78
79 #define TEST2b(RSval, RD) \
80 { \
81 unsigned long long out = 0; \
82 __asm__ __volatile__( \
83 ".set noreorder" "\n\t" \
84 "move $"#RD", %1" "\n\t" \
85 "bal end13"#RD "\n\t" \
86 "nop" "\n\t" \
87 "daddi $"#RD", $"#RD", 5" "\n\t" \
88 "move $t9, $t0" "\n\t" \
89 "j $t9" "\n\t" \
90 "nop" "\n\t" \
91 "daddi $"#RD", $"#RD", 1" "\n\t" \
92 "end13"#RD":" "\n\t" \
93 "daddi $"#RD", $"#RD", 1" "\n\t" \
94 "move $t9, $ra" "\n\t" \
95 "jalr $t0, $t9" "\n\t" \
96 "nop" "\n\t" \
97 "move %0, $"#RD "\n\t" \
98 ".set reorder" "\n\t" \
99 : "=r" (out) \
100 : "r" (RSval) \
101 : #RD, "t0", "t9", "ra" \
102 ); \
103 printf("BAL JR JAL :: 0x%llx, RSval: 0x%llx\n", \
104 out, (long long) RSval); \
105 }
106
107 #define TEST3(instruction, RDval, RSval, RTval, RD, RS, RT) \
108 { \
109 unsigned long long out = 0; \
110 __asm__ __volatile__( \
111 ".set noreorder" "\n\t" \
112 "move $"#RS", %1" "\n\t" \
113 "move $"#RT", %2" "\n\t" \
114 "move $"#RD", %3" "\n\t" \
115 instruction" $"#RS", $"#RT", end"instruction#RDval "\n\t" \
116 "nop" "\n\t" \
117 "daddi $"#RD", $"#RD", 5" "\n\t" \
118 "end"instruction#RDval":" "\n\t" \
119 "daddi $"#RD", $"#RD", 1" "\n\t" \
120 "move %0, $"#RD "\n\t" \
121 ".set reorder" "\n\t" \
122 : "=r" (out) \
123 : "r" (RSval), "r" (RTval), "r" (RDval) \
124 : #RD, #RS, #RT \
125 ); \
126 printf(instruction" :: out: 0x%llx, RSval: 0x%llx, RTval: 0x%llx\n", \
127 out, (long long) RSval, (long long) RTval); \
128 }
129
130 #define TEST4(instruction, RDval, RSval, RD, RS) \
131 { \
132 unsigned long long out = 0; \
133 __asm__ __volatile__( \
134 ".set noreorder" "\n\t" \
135 "move $"#RS", %1" "\n\t" \
136 "move $"#RD", %2" "\n\t" \
137 instruction" $"#RS", end"instruction#RDval "\n\t" \
138 "nop" "\n\t" \
139 "daddi $"#RD", $"#RD", 8" "\n\t" \
140 "end"instruction#RDval":" "\n\t" \
141 "daddi $"#RD", $"#RD", 1" "\n\t" \
142 "move %0, $"#RD "\n\t" \
143 ".set reorder" "\n\t" \
144 : "=r" (out) \
145 : "r" (RSval), "r" (RDval) \
146 : #RD, #RS \
147 ); \
148 printf(instruction" :: out: 0x%llx, RSval: 0x%llx\n", \
149 out, (long long) RSval); \
150 }
151
152 #define TEST5(instruction, RDval, RSval, RD, RS) \
153 { \
154 unsigned long long out = 0; \
155 __asm__ __volatile__( \
156 ".set noreorder" "\n\t" \
157 "move $"#RD", %2" "\n\t" \
158 "move $"#RS", %1" "\n\t" \
159 instruction" $"#RS", end21"instruction#RDval "\n\t" \
160 "nop" "\n\t" \
161 "daddi $"#RD", $"#RD", 5" "\n\t" \
162 "b r_end"instruction#RDval "\n\t" \
163 "nop" "\n\t" \
164 "end21"instruction#RDval":" "\n\t" \
165 "daddi $"#RD", $"#RD", 1" "\n\t" \
166 "jr $ra" "\n\t" \
167 "r_end"instruction#RDval":" "\n\t" \
168 "move %0, $"#RD "\n\t" \
169 ".set reorder" "\n\t" \
170 : "=r" (out) \
171 : "r" (RSval), "r" (RDval) \
172 : #RD, #RS, "ra" \
173 ); \
174 printf(instruction" :: out: 0x%llx, RSval: 0x%llx\n", \
175 out, (long long) RSval); \
176 }
177
main()178 int main()
179 {
180 int i;
181 init_reg_val2();
182
183 printf("B \n");
184 for (i = 0; i < N; i++)
185 TEST1(reg_val1[i], t0);
186
187 printf("BAL \n");
188 for (i = 0; i < N; i++)
189 TEST2(reg_val1[i], t0);
190
191 printf("--- BEQ --- if RSval == RTval then " \
192 "out = RDval + 1 else out = RDval + 6\n");
193 TEST3("beq", 0, 0, 1, 2, 3, 4);
194 TEST3("beq", 1, 1, 1, 3, 4, 5);
195 TEST3("beq", 2, 0xffffffff, 0xffffffff, 4, 5, 6);
196 TEST3("beq", 3, 0xffffffff, 0xfffffffe, 5, 6, 7);
197 TEST3("beq", 4, 0xfffffffe, 0xffffffff, 6, 7, 8);
198 TEST3("beq", 5, 0xffffffff, 0xffffffff, 7, 8, 9);
199 TEST3("beq", 6, 0x5, 0x5, 8, 9, 10);
200 TEST3("beq", 7, -3, -4, 9, 10, 11);
201 TEST3("beq", 8, 125, 125, 10, 11, 12);
202 TEST3("beq", 9, 0x80000000, 0x80000000, 11, 12, 15);
203 TEST3("beq", 10, 0xffffffff, 0x80000000, 12, 13, 14);
204 TEST3("beq", 11, 0x256, 0x256, 13, 14, 15);
205 TEST3("beq", 12, 0x55, 0x55, 14, 15, 16);
206 TEST3("beq", 13, 0xfff, 0xdd, 15, 16, 17);
207 TEST3("beq", 14, -1, 0x5, 16, 17, 18);
208 TEST3("beq", 15, -1, -1, 17, 18, 19);
209
210 printf("--- BGEZ --- if RSval >= 0 then " \
211 "out = RDval + 1 else out = RDval + 9\n");
212 TEST4("bgez", 0, 0, 2, 3);
213 TEST4("bgez", 1, 1, 3, 4);
214 TEST4("bgez", 2, 0xffffffff, 4, 5);
215 TEST4("bgez", 3, 0xffffffff, 5, 6);
216 TEST4("bgez", 4, 0xfffffffe, 6, 7);
217 TEST4("bgez", 5, 0xffffffff, 7, 8);
218 TEST4("bgez", 6, 0x5, 8, 9);
219 TEST4("bgez", 7, -3, 9, 10);
220 TEST4("bgez", 8, 125, 10, 11);
221 TEST4("bgez", 9, 0x80000000, 11, 12);
222 TEST4("bgez", 10, 0xffffffff, 12, 13);
223 TEST4("bgez", 11, 0x256, 13, 14);
224 TEST4("bgez", 12, 0x55, 14, 15);
225 TEST4("bgez", 13, 0xfff, 15, 16);
226 TEST4("bgez", 14, -1, 16, 17);
227 TEST4("bgez", 15, -1, 17, 18);
228
229 printf("--- BGEZAL --- if RSval >= 0 then " \
230 "out = RDval + 1 else out = RDval + 6\n");
231 TEST5("bgezal", 0, 0, 2, 3);
232 TEST5("bgezal", 1, 1, 3, 4);
233 TEST5("bgezal", 2, 0xffffffff, 4, 5);
234 TEST5("bgezal", 3, 0xffffffff, 5, 6);
235 TEST5("bgezal", 4, 0xfffffffe, 6, 7);
236 TEST5("bgezal", 5, 0xffffffff, 7, 8);
237 TEST5("bgezal", 6, 0x5, 8, 9);
238 TEST5("bgezal", 7, -3, 9, 10);
239 TEST5("bgezal", 8, 125, 10, 11);
240 TEST5("bgezal", 9, 0x80000000, 11, 12);
241 TEST5("bgezal", 10, 0xffffffff, 12, 13);
242 TEST5("bgezal", 11, 0x256, 13, 14);
243 TEST5("bgezal", 12, 0x55, 14, 15);
244 TEST5("bgezal", 13, 0xfff, 15, 16);
245 TEST5("bgezal", 14, -1, 16, 17);
246 TEST5("bgezal", 15, -1, 17, 18);
247
248 printf("--- BGTZ --- if RSval > 0 then " \
249 "out = RDval + 1 else out = RDval + 9\n");
250 TEST4("bgtz", 0, 0, 2, 3);
251 TEST4("bgtz", 1, 1, 3, 4);
252 TEST4("bgtz", 2, 0xffffffff, 4, 5);
253 TEST4("bgtz", 3, 0xffffffff, 5, 6);
254 TEST4("bgtz", 4, 0xfffffffe, 6, 7);
255 TEST4("bgtz", 5, 0xffffffff, 7, 8);
256 TEST4("bgtz", 6, 0x5, 8, 9);
257 TEST4("bgtz", 7, -3, 9, 10);
258 TEST4("bgtz", 8, 125, 10, 11);
259 TEST4("bgtz", 9, 0x80000000, 11, 12);
260 TEST4("bgtz", 10, 0xffffffff, 12, 13);
261 TEST4("bgtz", 11, 0x256, 13, 14);
262 TEST4("bgtz", 12, 0x55, 14, 15);
263 TEST4("bgtz", 13, 0xfff, 15, 16);
264 TEST4("bgtz", 14, -1, 16, 17);
265 TEST4("bgtz", 15, -1, 17, 18);
266
267 printf("--- BLEZ --- if RSval <= 0 then " \
268 "out = RDval + 1 else out = RDval + 9\n");
269 TEST4("blez", 0, 0, 2, 3);
270 TEST4("blez", 1, 1, 3, 4);
271 TEST4("blez", 2, 0xffffffff, 4, 5);
272 TEST4("blez", 3, 0xffffffff, 5, 6);
273 TEST4("blez", 4, 0xfffffffe, 6, 7);
274 TEST4("blez", 5, 0xffffffff, 7, 8);
275 TEST4("blez", 6, 0x5, 8, 9);
276 TEST4("blez", 7, -3, 9, 10);
277 TEST4("blez", 8, 125, 10, 11);
278 TEST4("blez", 9, 0x80000000, 11, 12);
279 TEST4("blez", 10, 0xffffffff, 12, 13);
280 TEST4("blez", 11, 0x256, 13, 14);
281 TEST4("blez", 12, 0x55, 14, 15);
282 TEST4("blez", 13, 0xfff, 15, 16);
283 TEST4("blez", 14, -1, 16, 17);
284 TEST4("blez", 15, -1, 17, 18);
285
286 printf("--- BLTZ --- if RSval < 0 then " \
287 "out = RDval + 1 else out = RDval + 9\n");
288 TEST4("bltz", 0, 0, 2, 3);
289 TEST4("bltz", 1, 1, 3, 4);
290 TEST4("bltz", 2, 0xffffffff, 4, 5);
291 TEST4("bltz", 3, 0xffffffff, 5, 6);
292 TEST4("bltz", 4, 0xfffffffe, 6, 7);
293 TEST4("bltz", 5, 0xffffffff, 7, 8);
294 TEST4("bltz", 6, 0x5, 8, 9);
295 TEST4("bltz", 7, -3, 9, 10);
296 TEST4("bltz", 8, 125, 10, 11);
297 TEST4("bltz", 9, 0x80000000, 11, 12);
298 TEST4("bltz", 10, 0xffffffff, 12, 13);
299 TEST4("bltz", 11, 0x256, 13, 14);
300 TEST4("bltz", 12, 0x55, 14, 15);
301 TEST4("bltz", 13, 0xfff, 15, 16);
302 TEST4("bltz", 14, -1, 16, 17);
303 TEST4("bltz", 15, -1, 17, 18);
304
305 printf("--- BLTZAL --- if RSval < 0 then " \
306 "out = RDval + 1 else out = RDval + 6\n");
307 TEST5("bltzal", 0, 0, 2, 3);
308 TEST5("bltzal", 1, 1, 3, 4);
309 TEST5("bltzal", 2, 0xffffffff, 4, 5);
310 TEST5("bltzal", 3, 0xffffffff, 5, 6);
311 TEST5("bltzal", 4, 0xfffffffe, 6, 7);
312 TEST5("bltzal", 5, 0xffffffff, 7, 8);
313 TEST5("bltzal", 6, 0x5, 8, 9);
314 TEST5("bltzal", 7, -3, 9, 10);
315 TEST5("bltzal", 8, 125, 10, 11);
316 TEST5("bltzal", 9, 0x80000000, 11, 12);
317 TEST5("bltzal", 10, 0xffffffff, 12, 13);
318 TEST5("bltzal", 11, 0x256, 13, 14);
319 TEST5("bltzal", 12, 0x55, 14, 15);
320 TEST5("bltzal", 13, 0xfff, 15, 16);
321 TEST5("bltzal", 14, -1, 16, 17);
322 TEST5("bltzal", 15, -1, 17, 18);
323
324 printf("--- BNE --- if RSval != RTval then " \
325 "out = RDval + 1 else out = RDval + 6\n");
326 TEST3("bne", 0, 0, 1, 2, 3, 4);
327 TEST3("bne", 1, 1, 1, 3, 4, 5);
328 TEST3("bne", 2, 0xffffffff, 0xffffffff, 4, 5, 6);
329 TEST3("bne", 3, 0xffffffff, 0xfffffffe, 5, 6, 7);
330 TEST3("bne", 4, 0xfffffffe, 0xffffffff, 6, 7, 8);
331 TEST3("bne", 5, 0xffffffff, 0xffffffff, 7, 8, 9);
332 TEST3("bne", 6, 0x5, 0x5, 8, 9, 10);
333 TEST3("bne", 7, -3, -4, 9, 10, 11);
334 TEST3("bne", 8, 125, 125, 10, 11, 12);
335 TEST3("bne", 9, 0x80000000, 0x80000000, 11, 12, 15);
336 TEST3("bne", 10, 0xffffffff, 0x80000000, 12, 13, 14);
337 TEST3("bne", 11, 0x256, 0x256, 13, 14, 15);
338 TEST3("bne", 12, 0x55, 0x55, 14, 15, 16);
339 TEST3("bne", 13, 0xfff, 0xdd, 15, 16, 17);
340 TEST3("bne", 14, -1, 0x5, 16, 17, 18);
341 TEST3("bne", 15, -1, -1, 17, 18, 19);
342
343 printf("JAL, JR \n");
344 for (i = 0; i < N; i++)
345 TEST2a(reg_val1[i], t0);
346
347 printf("J, JALR \n");
348 for (i = 0; i < N; i++)
349 TEST2b(reg_val1[i], t1);
350
351 return 0;
352 }
353