1 #ifndef __TEST_MACROS_VECTOR_H
2 #define __TEST_MACROS_VECTOR_H
5 #define EXTRA_INIT RVTEST_VEC_ENABLE
7 #-----------------------------------------------------------------------
9 #-----------------------------------------------------------------------
11 #define TEST_CASE( testnum, testreg, correctval, code... ) \
12 TEST_CASE_NREG( testnum, 32, 32, testreg, correctval, code )
14 # We use j fail, because for some cases branches are not enough to jump to fail
16 #define TEST_CASE_NREG( testnum, nxreg, nfreg, testreg, correctval, code... ) \
18 vsetcfg nxreg,nfreg; \
21 lui a0,%hi(vtcode ## testnum ); \
22 vf %lo(vtcode ## testnum )(a0); \
24 vsd v ## testreg, a4; \
29 test_loop ## testnum: \
31 beq a0,a1,skip ## testnum; \
36 bne a2,a3,test_loop ## testnum; \
43 # We use a macro hack to simpify code generation for various numbers
46 #define TEST_INSERT_NOPS_0
47 #define TEST_INSERT_NOPS_1 nop; TEST_INSERT_NOPS_0
48 #define TEST_INSERT_NOPS_2 nop; TEST_INSERT_NOPS_1
49 #define TEST_INSERT_NOPS_3 nop; TEST_INSERT_NOPS_2
50 #define TEST_INSERT_NOPS_4 nop; TEST_INSERT_NOPS_3
51 #define TEST_INSERT_NOPS_5 nop; TEST_INSERT_NOPS_4
52 #define TEST_INSERT_NOPS_6 nop; TEST_INSERT_NOPS_5
53 #define TEST_INSERT_NOPS_7 nop; TEST_INSERT_NOPS_6
54 #define TEST_INSERT_NOPS_8 nop; TEST_INSERT_NOPS_7
55 #define TEST_INSERT_NOPS_9 nop; TEST_INSERT_NOPS_8
56 #define TEST_INSERT_NOPS_10 nop; TEST_INSERT_NOPS_9
59 #-----------------------------------------------------------------------
61 #-----------------------------------------------------------------------
63 #-----------------------------------------------------------------------
64 # Tests for instructions with immediate operand
65 #-----------------------------------------------------------------------
67 #define TEST_IMM_OP( testnum, inst, result, val1, imm ) \
68 TEST_CASE_NREG( testnum, 4, 0, x3, result, \
73 #define TEST_IMM_SRC1_EQ_DEST( testnum, inst, result, val1, imm ) \
74 TEST_CASE_NREG( testnum, 2, 0, x1, result, \
79 #define TEST_IMM_DEST_BYPASS( testnum, nop_cycles, inst, result, val1, imm ) \
80 TEST_CASE_NREG( testnum, 5, 0, x4, result, \
83 TEST_INSERT_NOPS_ ## nop_cycles \
87 #define TEST_IMM_SRC1_BYPASS( testnum, nop_cycles, inst, result, val1, imm ) \
88 TEST_CASE_NREG( testnum, 4, 0, x3, result, \
90 TEST_INSERT_NOPS_ ## nop_cycles \
94 #define TEST_IMM_ZEROSRC1( testnum, inst, result, imm ) \
95 TEST_CASE_NREG( testnum, 2, 0, x1, result, \
99 #define TEST_IMM_ZERODEST( testnum, inst, val1, imm ) \
100 TEST_CASE_NREG( testnum, 2, 0, x0, 0, \
105 #-----------------------------------------------------------------------
106 # Tests for an instruction with register operands
107 #-----------------------------------------------------------------------
109 #define TEST_R_OP( testnum, inst, result, val1 ) \
110 TEST_CASE_NREG( testnum, 4, 0, x3, result, \
115 #define TEST_R_SRC1_EQ_DEST( testnum, inst, result, val1 ) \
116 TEST_CASE_NREG( testnum, 2, 0, x1, result, \
121 #define TEST_R_DEST_BYPASS( testnum, nop_cycles, inst, result, val1 ) \
122 TEST_CASE_NREG( testnum, 5, 0, x4, result, \
125 TEST_INSERT_NOPS_ ## nop_cycles \
129 #-----------------------------------------------------------------------
130 # Tests for an instruction with register-register operands
131 #-----------------------------------------------------------------------
133 #define TEST_RR_OP( testnum, inst, result, val1, val2 ) \
134 TEST_CASE_NREG( testnum, 4, 0, x3, result, \
140 #define TEST_RR_SRC1_EQ_DEST( testnum, inst, result, val1, val2 ) \
141 TEST_CASE_NREG( testnum, 3, 0, x1, result, \
147 #define TEST_RR_SRC2_EQ_DEST( testnum, inst, result, val1, val2 ) \
148 TEST_CASE_NREG( testnum, 3, 0, x2, result, \
154 #define TEST_RR_SRC12_EQ_DEST( testnum, inst, result, val1 ) \
155 TEST_CASE_NREG( testnum, 2, 0, x1, result, \
160 #define TEST_RR_DEST_BYPASS( testnum, nop_cycles, inst, result, val1, val2 ) \
161 TEST_CASE_NREG( testnum, 5, 0, x4, result, \
165 TEST_INSERT_NOPS_ ## nop_cycles \
169 #define TEST_RR_SRC12_BYPASS( testnum, src1_nops, src2_nops, inst, result, val1, val2 ) \
170 TEST_CASE_NREG( testnum, 4, 0, x3, result, \
172 TEST_INSERT_NOPS_ ## src1_nops \
174 TEST_INSERT_NOPS_ ## src2_nops \
178 #define TEST_RR_SRC21_BYPASS( testnum, src1_nops, src2_nops, inst, result, val1, val2 ) \
179 TEST_CASE_NREG( testnum, 4, 0, x3, result, \
181 TEST_INSERT_NOPS_ ## src1_nops \
183 TEST_INSERT_NOPS_ ## src2_nops \
187 #define TEST_RR_ZEROSRC1( testnum, inst, result, val ) \
188 TEST_CASE_NREG( testnum, 3, 0, x2, result, \
193 #define TEST_RR_ZEROSRC2( testnum, inst, result, val ) \
194 TEST_CASE_NREG( testnum, 3, 0, x2, result, \
199 #define TEST_RR_ZEROSRC12( testnum, inst, result ) \
200 TEST_CASE_NREG( testnum, 2, 0, x1, result, \
204 #define TEST_RR_ZERODEST( testnum, inst, val1, val2 ) \
205 TEST_CASE_NREG( testnum, 3, 0, x0, 0, \
212 #-----------------------------------------------------------------------
214 #-----------------------------------------------------------------------
216 #-----------------------------------------------------------------------
217 # Tests floating-point instructions
218 #-----------------------------------------------------------------------
220 #define TEST_FP_OP_S_INTERNAL_NREG( testnum, nxreg, nfreg, result, val1, val2, val3, code... ) \
222 vsetcfg nxreg,nfreg; \
225 la a5, test_ ## testnum ## _data ;\
226 vflstw vf0, a5, x0; \
228 vflstw vf1, a5, x0; \
230 vflstw vf2, a5, x0; \
232 lui a0,%hi(vtcode ## testnum ); \
233 vf %lo(vtcode ## testnum )(a0); \
240 test_loop ## testnum: \
242 beq a0,a1,skip ## testnum; \
247 bne a2,a3,test_loop ## testnum; \
249 vtcode ## testnum : \
253 test_ ## testnum ## _data: \
260 #define TEST_FP_OP_D_INTERNAL_NREG( testnum, nxreg, nfreg, result, val1, val2, val3, code... ) \
262 vsetcfg nxreg,nfreg; \
265 la a5, test_ ## testnum ## _data ;\
266 vflstd vf0, a5, x0; \
268 vflstd vf1, a5, x0; \
270 vflstd vf2, a5, x0; \
272 lui a0,%hi(vtcode ## testnum ); \
273 vf %lo(vtcode ## testnum )(a0); \
280 test_loop ## testnum: \
282 beq a0,a1,skip ## testnum; \
287 bne a2,a3,test_loop ## testnum; \
289 vtcode ## testnum : \
293 test_ ## testnum ## _data: \
300 #define TEST_FCVT_S_D( testnum, result, val1 ) \
301 TEST_FP_OP_D_INTERNAL_NREG( testnum, 2, 4, double result, val1, 0.0, 0.0, \
302 fcvt.s.d f3, f0; fcvt.d.s f3, f3; fmv.x.d x1, f3)
304 #define TEST_FCVT_D_S( testnum, result, val1 ) \
305 TEST_FP_OP_S_INTERNAL_NREG( testnum, 2, 4, float result, val1, 0.0, 0.0, \
306 fcvt.d.s f3, f0; fcvt.s.d f3, f3; fmv.x.s x1, f3)
308 #define TEST_FP_OP2_S( testnum, inst, result, val1, val2 ) \
309 TEST_FP_OP_S_INTERNAL_NREG( testnum, 2, 4, float result, val1, val2, 0.0, \
310 inst f3, f0, f1; fmv.x.s x1, f3)
312 #define TEST_FP_OP2_D( testnum, inst, result, val1, val2 ) \
313 TEST_FP_OP_D_INTERNAL_NREG( testnum, 2, 4, double result, val1, val2, 0.0, \
314 inst f3, f0, f1; fmv.x.d x1, f3)
316 #define TEST_FP_OP3_S( testnum, inst, result, val1, val2, val3 ) \
317 TEST_FP_OP_S_INTERNAL_NREG( testnum, 2, 4, float result, val1, val2, val3, \
318 inst f3, f0, f1, f2; fmv.x.s x1, f3)
320 #define TEST_FP_OP3_D( testnum, inst, result, val1, val2, val3 ) \
321 TEST_FP_OP_D_INTERNAL_NREG( testnum, 2, 4, double result, val1, val2, val3, \
322 inst f3, f0, f1, f2; fmv.x.d x1, f3)
324 #define TEST_FP_INT_OP_S( testnum, inst, result, val1, rm ) \
325 TEST_FP_OP_S_INTERNAL_NREG( testnum, 2, 4, word result, val1, 0.0, 0.0, \
328 #define TEST_FP_INT_OP_D( testnum, inst, result, val1, rm ) \
329 TEST_FP_OP_D_INTERNAL_NREG( testnum, 2, 4, dword result, val1, 0.0, 0.0, \
332 #define TEST_FP_CMP_OP_S( testnum, inst, result, val1, val2 ) \
333 TEST_FP_OP_S_INTERNAL_NREG( testnum, 2, 4, word result, val1, val2, 0.0, \
336 #define TEST_FP_CMP_OP_D( testnum, inst, result, val1, val2 ) \
337 TEST_FP_OP_D_INTERNAL_NREG( testnum, 2, 4, dword result, val1, val2, 0.0, \
340 #define TEST_INT_FP_OP_S( testnum, inst, result, val1 ) \
345 lui a0,%hi(vtcode ## testnum ); \
346 vf %lo(vtcode ## testnum )(a0); \
350 la a5, test_ ## testnum ## _data ;\
354 test_loop ## testnum: \
356 beq a0,a1,skip ## testnum; \
361 bne a2,a3,test_loop ## testnum; \
363 vtcode ## testnum : \
369 test_ ## testnum ## _data: \
373 #define TEST_INT_FP_OP_D( testnum, inst, result, val1 ) \
378 lui a0,%hi(vtcode ## testnum ); \
379 vf %lo(vtcode ## testnum )(a0); \
383 la a5, test_ ## testnum ## _data ;\
387 test_loop ## testnum: \
389 beq a0,a1,skip ## testnum; \
394 bne a2,a3,test_loop ## testnum; \
396 vtcode ## testnum : \
402 test_ ## testnum ## _data: \
407 #-----------------------------------------------------------------------
409 #-----------------------------------------------------------------------
411 #-----------------------------------------------------------------------
412 # Test branch instructions
413 #-----------------------------------------------------------------------
415 #define TEST_BR2_OP_TAKEN( testnum, inst, val1, val2) \
416 TEST_CASE_NREG( testnum, 4, 0, x3, 0, \
424 2: inst x1, x2, 1b; \
429 #define TEST_BR2_OP_NOTTAKEN( testnum, inst, val1, val2 ) \
430 TEST_CASE_NREG( testnum, 4, 0, x3, 0, \
438 2: inst x1, x2, 1b; \
442 #define TEST_BR2_SRC12_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
443 TEST_CASE_NREG( testnum, 6, 0, x3, 0, \
447 TEST_INSERT_NOPS_ ## src1_nops \
449 TEST_INSERT_NOPS_ ## src2_nops \
459 #define TEST_BR2_SRC21_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
460 TEST_CASE_NREG( testnum, 6, 0, x3, 0, \
464 TEST_INSERT_NOPS_ ## src1_nops \
466 TEST_INSERT_NOPS_ ## src2_nops \
476 #define TEST_BR2_DIVERGED_ODD_EVEN( testnum, inst, n, result, code...) \
477 TEST_CASE_NREG( testnum, 5, 0, x3, result, \
493 #define TEST_BR2_DIVERGED_FULL12( testnum, inst, n, result, code... ) \
494 TEST_CASE_NREG( testnum, 5, 0, x3, result, \
508 #define TEST_BR2_DIVERGED_FULL21( testnum, inst, n, result, code... ) \
509 TEST_CASE_NREG( testnum, 5, 0, x3, result, \
523 #define TEST_CASE_NREG_MEM( testnum, nxreg, nfreg, correctval, code... ) \
525 vsetcfg nxreg,nfreg; \
528 lui a0,%hi(vtcode ## testnum ); \
529 vf %lo(vtcode ## testnum )(a0); \
535 test_loop ## testnum: \
537 beq a0,a1,skip ## testnum; \
542 bne a2,a3,test_loop ## testnum; \
544 vtcode ## testnum : \
549 #define TEST_BR2_DIVERGED_MEM_FULL12( testnum, inst, n) \
550 TEST_CASE_NREG_MEM( testnum, 7, 0, 1, \
570 #define TEST_BR2_DIVERGED_MEM_FULL21( testnum, inst, n) \
571 TEST_CASE_NREG_MEM( testnum, 7, 0, 1, \
591 #-----------------------------------------------------------------------
592 # Pass and fail code (assumes test num is in x28)
593 #-----------------------------------------------------------------------
595 #define TEST_PASSFAIL \
603 #-----------------------------------------------------------------------
605 #-----------------------------------------------------------------------