6650fa86533d3bb02dc0c1d37c80f8fadece6c79
1 // See LICENSE for license details.
3 #ifndef __TEST_MACROS_SCALAR_H
4 #define __TEST_MACROS_SCALAR_H
7 #-----------------------------------------------------------------------
9 #-----------------------------------------------------------------------
11 #define MASK_XLEN(x) ((x) & ((1 << (__riscv_xlen - 1) << 1) - 1))
13 #define TEST_CASE( testnum, testreg, correctval, code... ) \
16 li x29, MASK_XLEN(correctval); \
17 li TESTNUM, testnum; \
18 bne testreg, x29, fail;
20 # We use a macro hack to simpify code generation for various numbers
23 #define TEST_INSERT_NOPS_0
24 #define TEST_INSERT_NOPS_1 nop; TEST_INSERT_NOPS_0
25 #define TEST_INSERT_NOPS_2 nop; TEST_INSERT_NOPS_1
26 #define TEST_INSERT_NOPS_3 nop; TEST_INSERT_NOPS_2
27 #define TEST_INSERT_NOPS_4 nop; TEST_INSERT_NOPS_3
28 #define TEST_INSERT_NOPS_5 nop; TEST_INSERT_NOPS_4
29 #define TEST_INSERT_NOPS_6 nop; TEST_INSERT_NOPS_5
30 #define TEST_INSERT_NOPS_7 nop; TEST_INSERT_NOPS_6
31 #define TEST_INSERT_NOPS_8 nop; TEST_INSERT_NOPS_7
32 #define TEST_INSERT_NOPS_9 nop; TEST_INSERT_NOPS_8
33 #define TEST_INSERT_NOPS_10 nop; TEST_INSERT_NOPS_9
36 #-----------------------------------------------------------------------
38 #-----------------------------------------------------------------------
40 #-----------------------------------------------------------------------
41 # Tests for instructions with immediate operand
42 #-----------------------------------------------------------------------
44 #define SEXT_IMM(x) ((x) | (-(((x) >> 11) & 1) << 11))
46 #define TEST_IMM_OP( testnum, inst, result, val1, imm ) \
47 TEST_CASE( testnum, x30, result, \
48 li x1, MASK_XLEN(val1); \
49 inst x30, x1, SEXT_IMM(imm); \
52 #define TEST_IMM_SRC1_EQ_DEST( testnum, inst, result, val1, imm ) \
53 TEST_CASE( testnum, x1, result, \
54 li x1, MASK_XLEN(val1); \
55 inst x1, x1, SEXT_IMM(imm); \
58 #define TEST_IMM_DEST_BYPASS( testnum, nop_cycles, inst, result, val1, imm ) \
59 TEST_CASE( testnum, x6, result, \
61 1: li x1, MASK_XLEN(val1); \
62 inst x30, x1, SEXT_IMM(imm); \
63 TEST_INSERT_NOPS_ ## nop_cycles \
70 #define TEST_IMM_SRC1_BYPASS( testnum, nop_cycles, inst, result, val1, imm ) \
71 TEST_CASE( testnum, x30, result, \
73 1: li x1, MASK_XLEN(val1); \
74 TEST_INSERT_NOPS_ ## nop_cycles \
75 inst x30, x1, SEXT_IMM(imm); \
81 #define TEST_IMM_ZEROSRC1( testnum, inst, result, imm ) \
82 TEST_CASE( testnum, x1, result, \
83 inst x1, x0, SEXT_IMM(imm); \
86 #define TEST_IMM_ZERODEST( testnum, inst, val1, imm ) \
87 TEST_CASE( testnum, x0, 0, \
88 li x1, MASK_XLEN(val1); \
89 inst x0, x1, SEXT_IMM(imm); \
92 #-----------------------------------------------------------------------
93 # Tests for an instruction with register operands
94 #-----------------------------------------------------------------------
96 #define TEST_R_OP( testnum, inst, result, val1 ) \
97 TEST_CASE( testnum, x30, result, \
102 #define TEST_R_SRC1_EQ_DEST( testnum, inst, result, val1 ) \
103 TEST_CASE( testnum, x1, result, \
108 #define TEST_R_DEST_BYPASS( testnum, nop_cycles, inst, result, val1 ) \
109 TEST_CASE( testnum, x6, result, \
113 TEST_INSERT_NOPS_ ## nop_cycles \
120 #-----------------------------------------------------------------------
121 # Tests for an instruction with register-register operands
122 #-----------------------------------------------------------------------
124 #define TEST_RR_OP( testnum, inst, result, val1, val2 ) \
125 TEST_CASE( testnum, x30, result, \
126 li x1, MASK_XLEN(val1); \
127 li x2, MASK_XLEN(val2); \
131 #define TEST_RR_SRC1_EQ_DEST( testnum, inst, result, val1, val2 ) \
132 TEST_CASE( testnum, x1, result, \
133 li x1, MASK_XLEN(val1); \
134 li x2, MASK_XLEN(val2); \
138 #define TEST_RR_SRC2_EQ_DEST( testnum, inst, result, val1, val2 ) \
139 TEST_CASE( testnum, x2, result, \
140 li x1, MASK_XLEN(val1); \
141 li x2, MASK_XLEN(val2); \
145 #define TEST_RR_SRC12_EQ_DEST( testnum, inst, result, val1 ) \
146 TEST_CASE( testnum, x1, result, \
147 li x1, MASK_XLEN(val1); \
151 #define TEST_RR_DEST_BYPASS( testnum, nop_cycles, inst, result, val1, val2 ) \
152 TEST_CASE( testnum, x6, result, \
154 1: li x1, MASK_XLEN(val1); \
155 li x2, MASK_XLEN(val2); \
157 TEST_INSERT_NOPS_ ## nop_cycles \
164 #define TEST_RR_SRC12_BYPASS( testnum, src1_nops, src2_nops, inst, result, val1, val2 ) \
165 TEST_CASE( testnum, x30, result, \
167 1: li x1, MASK_XLEN(val1); \
168 TEST_INSERT_NOPS_ ## src1_nops \
169 li x2, MASK_XLEN(val2); \
170 TEST_INSERT_NOPS_ ## src2_nops \
177 #define TEST_RR_SRC21_BYPASS( testnum, src1_nops, src2_nops, inst, result, val1, val2 ) \
178 TEST_CASE( testnum, x30, result, \
180 1: li x2, MASK_XLEN(val2); \
181 TEST_INSERT_NOPS_ ## src1_nops \
182 li x1, MASK_XLEN(val1); \
183 TEST_INSERT_NOPS_ ## src2_nops \
190 #define TEST_RR_ZEROSRC1( testnum, inst, result, val ) \
191 TEST_CASE( testnum, x2, result, \
192 li x1, MASK_XLEN(val); \
196 #define TEST_RR_ZEROSRC2( testnum, inst, result, val ) \
197 TEST_CASE( testnum, x2, result, \
198 li x1, MASK_XLEN(val); \
202 #define TEST_RR_ZEROSRC12( testnum, inst, result ) \
203 TEST_CASE( testnum, x1, result, \
207 #define TEST_RR_ZERODEST( testnum, inst, val1, val2 ) \
208 TEST_CASE( testnum, x0, 0, \
209 li x1, MASK_XLEN(val1); \
210 li x2, MASK_XLEN(val2); \
214 #-----------------------------------------------------------------------
215 # Test memory instructions
216 #-----------------------------------------------------------------------
218 #define TEST_LD_OP( testnum, inst, result, offset, base ) \
219 TEST_CASE( testnum, x30, result, \
221 inst x30, offset(x1); \
224 #define TEST_ST_OP( testnum, load_inst, store_inst, result, offset, base ) \
225 TEST_CASE( testnum, x30, result, \
228 store_inst x2, offset(x1); \
229 load_inst x30, offset(x1); \
232 #define TEST_LD_DEST_BYPASS( testnum, nop_cycles, inst, result, offset, base ) \
234 li TESTNUM, testnum; \
237 inst x30, offset(x1); \
238 TEST_INSERT_NOPS_ ## nop_cycles \
246 #define TEST_LD_SRC1_BYPASS( testnum, nop_cycles, inst, result, offset, base ) \
248 li TESTNUM, testnum; \
251 TEST_INSERT_NOPS_ ## nop_cycles \
252 inst x30, offset(x1); \
254 bne x30, x29, fail; \
259 #define TEST_ST_SRC12_BYPASS( testnum, src1_nops, src2_nops, load_inst, store_inst, result, offset, base ) \
261 li TESTNUM, testnum; \
264 TEST_INSERT_NOPS_ ## src1_nops \
266 TEST_INSERT_NOPS_ ## src2_nops \
267 store_inst x1, offset(x2); \
268 load_inst x30, offset(x2); \
270 bne x30, x29, fail; \
275 #define TEST_ST_SRC21_BYPASS( testnum, src1_nops, src2_nops, load_inst, store_inst, result, offset, base ) \
277 li TESTNUM, testnum; \
280 TEST_INSERT_NOPS_ ## src1_nops \
282 TEST_INSERT_NOPS_ ## src2_nops \
283 store_inst x1, offset(x2); \
284 load_inst x30, offset(x2); \
286 bne x30, x29, fail; \
291 #define TEST_BR2_OP_TAKEN( testnum, inst, val1, val2 ) \
293 li TESTNUM, testnum; \
297 bne x0, TESTNUM, fail; \
298 1: bne x0, TESTNUM, 3f; \
299 2: inst x1, x2, 1b; \
300 bne x0, TESTNUM, fail; \
303 #define TEST_BR2_OP_NOTTAKEN( testnum, inst, val1, val2 ) \
305 li TESTNUM, testnum; \
309 bne x0, TESTNUM, 2f; \
310 1: bne x0, TESTNUM, fail; \
311 2: inst x1, x2, 1b; \
314 #define TEST_BR2_SRC12_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
316 li TESTNUM, testnum; \
319 TEST_INSERT_NOPS_ ## src1_nops \
321 TEST_INSERT_NOPS_ ## src2_nops \
327 #define TEST_BR2_SRC21_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
329 li TESTNUM, testnum; \
332 TEST_INSERT_NOPS_ ## src1_nops \
334 TEST_INSERT_NOPS_ ## src2_nops \
340 #-----------------------------------------------------------------------
341 # Test jump instructions
342 #-----------------------------------------------------------------------
344 #define TEST_JR_SRC1_BYPASS( testnum, nop_cycles, inst ) \
346 li TESTNUM, testnum; \
349 TEST_INSERT_NOPS_ ## nop_cycles \
351 bne x0, TESTNUM, fail; \
356 #define TEST_JALR_SRC1_BYPASS( testnum, nop_cycles, inst ) \
358 li TESTNUM, testnum; \
361 TEST_INSERT_NOPS_ ## nop_cycles \
363 bne x0, TESTNUM, fail; \
369 #-----------------------------------------------------------------------
371 #-----------------------------------------------------------------------
373 #-----------------------------------------------------------------------
374 # Tests floating-point instructions
375 #-----------------------------------------------------------------------
377 #define qNaNf 0f:7fc00000
378 #define sNaNf 0f:7f800001
379 #define qNaN 0d:7ff8000000000000
380 #define sNaN 0d:7ff0000000000001
382 #define TEST_FP_OP_S_INTERNAL( testnum, flags, result, val1, val2, val3, code... ) \
384 li TESTNUM, testnum; \
385 la a0, test_ ## testnum ## _data ;\
395 .pushsection .data; \
397 test_ ## testnum ## _data: \
404 #define TEST_FP_OP_D_INTERNAL( testnum, flags, result, val1, val2, val3, code... ) \
406 li TESTNUM, testnum; \
407 la a0, test_ ## testnum ## _data ;\
417 .pushsection .data; \
419 test_ ## testnum ## _data: \
426 #define TEST_FCVT_S_D( testnum, result, val1 ) \
427 TEST_FP_OP_D_INTERNAL( testnum, 0, double result, val1, 0.0, 0.0, \
428 fcvt.s.d f3, f0; fcvt.d.s f3, f3; fmv.x.d a0, f3)
430 #define TEST_FCVT_D_S( testnum, result, val1 ) \
431 TEST_FP_OP_S_INTERNAL( testnum, 0, float result, val1, 0.0, 0.0, \
432 fcvt.d.s f3, f0; fcvt.s.d f3, f3; fmv.x.s a0, f3)
434 #define TEST_FP_OP1_S( testnum, inst, flags, result, val1 ) \
435 TEST_FP_OP_S_INTERNAL( testnum, flags, float result, val1, 0.0, 0.0, \
436 inst f3, f0; fmv.x.s a0, f3)
438 #define TEST_FP_OP1_D( testnum, inst, flags, result, val1 ) \
439 TEST_FP_OP_D_INTERNAL( testnum, flags, double result, val1, 0.0, 0.0, \
440 inst f3, f0; fmv.x.d a0, f3)
442 #define TEST_FP_OP1_S_DWORD_RESULT( testnum, inst, flags, result, val1 ) \
443 TEST_FP_OP_S_INTERNAL( testnum, flags, dword result, val1, 0.0, 0.0, \
444 inst f3, f0; fmv.x.s a0, f3)
446 #define TEST_FP_OP1_D_DWORD_RESULT( testnum, inst, flags, result, val1 ) \
447 TEST_FP_OP_D_INTERNAL( testnum, flags, dword result, val1, 0.0, 0.0, \
448 inst f3, f0; fmv.x.d a0, f3)
450 #define TEST_FP_OP2_S( testnum, inst, flags, result, val1, val2 ) \
451 TEST_FP_OP_S_INTERNAL( testnum, flags, float result, val1, val2, 0.0, \
452 inst f3, f0, f1; fmv.x.s a0, f3)
454 #define TEST_FP_OP2_D( testnum, inst, flags, result, val1, val2 ) \
455 TEST_FP_OP_D_INTERNAL( testnum, flags, double result, val1, val2, 0.0, \
456 inst f3, f0, f1; fmv.x.d a0, f3)
458 #define TEST_FP_OP3_S( testnum, inst, flags, result, val1, val2, val3 ) \
459 TEST_FP_OP_S_INTERNAL( testnum, flags, float result, val1, val2, val3, \
460 inst f3, f0, f1, f2; fmv.x.s a0, f3)
462 #define TEST_FP_OP3_D( testnum, inst, flags, result, val1, val2, val3 ) \
463 TEST_FP_OP_D_INTERNAL( testnum, flags, double result, val1, val2, val3, \
464 inst f3, f0, f1, f2; fmv.x.d a0, f3)
466 #define TEST_FP_INT_OP_S( testnum, inst, flags, result, val1, rm ) \
467 TEST_FP_OP_S_INTERNAL( testnum, flags, word result, val1, 0.0, 0.0, \
470 #define TEST_FP_INT_OP_D( testnum, inst, flags, result, val1, rm ) \
471 TEST_FP_OP_D_INTERNAL( testnum, flags, dword result, val1, 0.0, 0.0, \
474 #define TEST_FP_CMP_OP_S( testnum, inst, flags, result, val1, val2 ) \
475 TEST_FP_OP_S_INTERNAL( testnum, flags, word result, val1, val2, 0.0, \
478 #define TEST_FP_CMP_OP_D( testnum, inst, flags, result, val1, val2 ) \
479 TEST_FP_OP_D_INTERNAL( testnum, flags, dword result, val1, val2, 0.0, \
482 #define TEST_FCLASS_S(testnum, correct, input) \
483 TEST_CASE(testnum, a0, correct, li a0, input; fmv.s.x fa0, a0; \
486 #define TEST_FCLASS_D(testnum, correct, input) \
487 TEST_CASE(testnum, a0, correct, li a0, input; fmv.d.x fa0, a0; \
490 #define TEST_INT_FP_OP_S( testnum, inst, result, val1 ) \
492 li TESTNUM, testnum; \
493 la a0, test_ ## testnum ## _data ;\
500 .pushsection .data; \
502 test_ ## testnum ## _data: \
506 #define TEST_INT_FP_OP_D( testnum, inst, result, val1 ) \
508 li TESTNUM, testnum; \
509 la a0, test_ ## testnum ## _data ;\
516 .pushsection .data; \
518 test_ ## testnum ## _data: \
522 #-----------------------------------------------------------------------
523 # Pass and fail code (assumes test num is in TESTNUM)
524 #-----------------------------------------------------------------------
526 #define TEST_PASSFAIL \
527 bne x0, TESTNUM, pass; \
534 #-----------------------------------------------------------------------
536 #-----------------------------------------------------------------------