Merge branch 'master' of github.com:ucb-bar/riscv-tests
[riscv-tests.git] / isa / macros / scalar / test_macros.h
index b856701824d0de37e20d9ada602bb2be22ff52f6..dca9a92cc0e3923defd9599ce95140489ebeb650 100644 (file)
 test_ ## testnum: \
     code; \
     li  x29, correctval; \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     bne testreg, x29, fail;
 
 #define TEST_CASE_JUMP( testnum, testreg, correctval, code... ) \
 test_ ## testnum: \
     code; \
     li  x29, correctval; \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     beq testreg, x29, pass_ ## testnum; \
     j fail; \
 pass_ ## testnum: \
@@ -46,23 +46,25 @@ pass_ ## testnum: \
 # Tests for instructions with immediate operand
 #-----------------------------------------------------------------------
 
+#define SEXT_IMM(x) ((x) | (-(((x) >> 11) & 1) << 11))
+
 #define TEST_IMM_OP( testnum, inst, result, val1, imm ) \
     TEST_CASE( testnum, x3, result, \
       li  x1, val1; \
-      inst x3, x1, imm; \
+      inst x3, x1, SEXT_IMM(imm); \
     )
 
 #define TEST_IMM_SRC1_EQ_DEST( testnum, inst, result, val1, imm ) \
     TEST_CASE( testnum, x1, result, \
       li  x1, val1; \
-      inst x1, x1, imm; \
+      inst x1, x1, SEXT_IMM(imm); \
     )
 
 #define TEST_IMM_DEST_BYPASS( testnum, nop_cycles, inst, result, val1, imm ) \
     TEST_CASE( testnum, x6, result, \
       li  x4, 0; \
 1:    li  x1, val1; \
-      inst x3, x1, imm; \
+      inst x3, x1, SEXT_IMM(imm); \
       TEST_INSERT_NOPS_ ## nop_cycles \
       addi  x6, x3, 0; \
       addi  x4, x4, 1; \
@@ -75,7 +77,7 @@ pass_ ## testnum: \
       li  x4, 0; \
 1:    li  x1, val1; \
       TEST_INSERT_NOPS_ ## nop_cycles \
-      inst x3, x1, imm; \
+      inst x3, x1, SEXT_IMM(imm); \
       addi  x4, x4, 1; \
       li  x5, 2; \
       bne x4, x5, 1b \
@@ -83,13 +85,13 @@ pass_ ## testnum: \
 
 #define TEST_IMM_ZEROSRC1( testnum, inst, result, imm ) \
     TEST_CASE( testnum, x1, result, \
-      inst x1, x0, imm; \
+      inst x1, x0, SEXT_IMM(imm); \
     )
 
 #define TEST_IMM_ZERODEST( testnum, inst, val1, imm ) \
     TEST_CASE( testnum, x0, 0, \
       li  x1, val1; \
-      inst x0, x1, imm; \
+      inst x0, x1, SEXT_IMM(imm); \
     )
 
 #-----------------------------------------------------------------------
@@ -262,7 +264,7 @@ pass_ ## testnum: \
 
 #define TEST_LD_DEST_BYPASS( testnum, nop_cycles, inst, result, offset, base ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  la  x1, base; \
     inst x3, offset(x1); \
@@ -276,7 +278,7 @@ test_ ## testnum: \
 
 #define TEST_LD_SRC1_BYPASS( testnum, nop_cycles, inst, result, offset, base ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  la  x1, base; \
     TEST_INSERT_NOPS_ ## nop_cycles \
@@ -289,7 +291,7 @@ test_ ## testnum: \
 
 #define TEST_ST_SRC12_BYPASS( testnum, src1_nops, src2_nops, load_inst, store_inst, result, offset, base ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  la  x1, result; \
     TEST_INSERT_NOPS_ ## src1_nops \
@@ -305,7 +307,7 @@ test_ ## testnum: \
 
 #define TEST_ST_SRC21_BYPASS( testnum, src1_nops, src2_nops, load_inst, store_inst, result, offset, base ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  la  x2, base; \
     TEST_INSERT_NOPS_ ## src1_nops \
@@ -325,28 +327,28 @@ test_ ## testnum: \
 
 #define TEST_BR1_OP_TAKEN( testnum, inst, val1 ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x1, val1; \
     inst x1, 2f; \
-    bne x0, x28, fail; \
-1:  bne x0, x28, 3f; \
+    bne x0, TESTNUM, fail; \
+1:  bne x0, TESTNUM, 3f; \
 2:  inst x1, 1b; \
-    bne x0, x28, fail; \
+    bne x0, TESTNUM, fail; \
 3:
 
 #define TEST_BR1_OP_NOTTAKEN( testnum, inst, val1 ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x1, val1; \
     inst x1, 1f; \
-    bne x0, x28, 2f; \
-1:  bne x0, x28, fail; \
+    bne x0, TESTNUM, 2f; \
+1:  bne x0, TESTNUM, fail; \
 2:  inst x1, 1b; \
 3:
 
 #define TEST_BR1_SRC1_BYPASS( testnum, nop_cycles, inst, val1 ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  li  x1, val1; \
     TEST_INSERT_NOPS_ ## nop_cycles \
@@ -357,30 +359,30 @@ test_ ## testnum: \
 
 #define TEST_BR2_OP_TAKEN( testnum, inst, val1, val2 ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x1, val1; \
     li  x2, val2; \
     inst x1, x2, 2f; \
-    bne x0, x28, fail; \
-1:  bne x0, x28, 3f; \
+    bne x0, TESTNUM, fail; \
+1:  bne x0, TESTNUM, 3f; \
 2:  inst x1, x2, 1b; \
-    bne x0, x28, fail; \
+    bne x0, TESTNUM, fail; \
 3:
 
 #define TEST_BR2_OP_NOTTAKEN( testnum, inst, val1, val2 ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x1, val1; \
     li  x2, val2; \
     inst x1, x2, 1f; \
-    bne x0, x28, 2f; \
-1:  bne x0, x28, fail; \
+    bne x0, TESTNUM, 2f; \
+1:  bne x0, TESTNUM, fail; \
 2:  inst x1, x2, 1b; \
 3:
 
 #define TEST_BR2_SRC12_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  li  x1, val1; \
     TEST_INSERT_NOPS_ ## src1_nops \
@@ -393,7 +395,7 @@ test_ ## testnum: \
 
 #define TEST_BR2_SRC21_BYPASS( testnum, src1_nops, src2_nops, inst, val1, val2 ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  li  x2, val2; \
     TEST_INSERT_NOPS_ ## src1_nops \
@@ -410,24 +412,24 @@ test_ ## testnum: \
 
 #define TEST_JR_SRC1_BYPASS( testnum, nop_cycles, inst ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  la  x6, 2f; \
     TEST_INSERT_NOPS_ ## nop_cycles \
     inst x6; \
-    bne x0, x28, fail; \
+    bne x0, TESTNUM, fail; \
 2:  addi  x4, x4, 1; \
     li  x5, 2; \
     bne x4, x5, 1b \
 
 #define TEST_JALR_SRC1_BYPASS( testnum, nop_cycles, inst ) \
 test_ ## testnum: \
-    li  x28, testnum; \
+    li  TESTNUM, testnum; \
     li  x4, 0; \
 1:  la  x6, 2f; \
     TEST_INSERT_NOPS_ ## nop_cycles \
     inst x19, x6, 0; \
-    bne x0, x28, fail; \
+    bne x0, TESTNUM, fail; \
 2:  addi  x4, x4, 1; \
     li  x5, 2; \
     bne x4, x5, 1b \
@@ -443,7 +445,7 @@ test_ ## testnum: \
 
 #define TEST_FP_OP_S_INTERNAL( testnum, result, val1, val2, val3, code... ) \
 test_ ## testnum: \
-  li  x28, testnum; \
+  li  TESTNUM, testnum; \
   la  a0, test_ ## testnum ## _data ;\
   flw f0, 0(a0); \
   flw f1, 4(a0); \
@@ -462,7 +464,7 @@ test_ ## testnum: \
 
 #define TEST_FP_OP_D_INTERNAL( testnum, result, val1, val2, val3, code... ) \
 test_ ## testnum: \
-  li  x28, testnum; \
+  li  TESTNUM, testnum; \
   la  a0, test_ ## testnum ## _data ;\
   fld f0, 0(a0); \
   fld f1, 8(a0); \
@@ -529,7 +531,7 @@ test_ ## testnum: \
 
 #define TEST_INT_FP_OP_S( testnum, inst, result, val1 ) \
 test_ ## testnum: \
-  li  x28, testnum; \
+  li  TESTNUM, testnum; \
   la  a0, test_ ## testnum ## _data ;\
   lw  a3, 0(a0); \
   li  a0, val1; \
@@ -544,7 +546,7 @@ test_ ## testnum: \
 
 #define TEST_INT_FP_OP_D( testnum, inst, result, val1 ) \
 test_ ## testnum: \
-  li  x28, testnum; \
+  li  TESTNUM, testnum; \
   la  a0, test_ ## testnum ## _data ;\
   ld  a3, 0(a0); \
   li  a0, val1; \
@@ -563,9 +565,9 @@ test_ ## testnum: \
 #-----------------------------------------------------------------------
 
 #define TEST_ILLEGAL_TVEC_REGID( testnum, nxreg, nfreg, inst, reg1, reg2) \
-  setpcr status, SR_EI; \
+  csrs status, SR_EI; \
   la a0, handler ## testnum; \
-  mtpcr a0, evec; \
+  csrw evec, a0; \
   vsetcfg nxreg, nfreg; \
   li a0, 4; \
   vsetvl a0, a0; \
@@ -589,7 +591,7 @@ vtcode2 ## testnum: \
   stop; \
 handler ## testnum: \
   vxcptkill; \
-  li x28,2; \
+  li TESTNUM,2; \
   vxcptcause a0; \
   li a1,HWACHA_CAUSE_TVEC_ILLEGAL_REGID; \
   bne a0,a1,fail; \
@@ -611,22 +613,22 @@ handler ## testnum: \
   fence; \
   ld a1,0(a3); \
   li a2,5; \
-  li x28,2; \
+  li TESTNUM,2; \
   bne a1,a2,fail; \
   ld a1,8(a3); \
-  li x28,3; \
+  li TESTNUM,3; \
   bne a1,a2,fail; \
   ld a1,16(a3); \
-  li x28,4; \
+  li TESTNUM,4; \
   bne a1,a2,fail; \
   ld a1,24(a3); \
-  li x28,5; \
+  li TESTNUM,5; \
   bne a1,a2,fail; \
 
 #define TEST_ILLEGAL_VT_REGID( testnum, nxreg, nfreg, inst, reg1, reg2, reg3) \
-  setpcr status, SR_EI; \
+  csrs status, SR_EI; \
   la a0, handler ## testnum; \
-  mtpcr a0, evec; \
+  csrw evec, a0; \
   vsetcfg nxreg, nfreg; \
   li a0, 4; \
   vsetvl a0, a0; \
@@ -649,7 +651,7 @@ vtcode2 ## testnum: \
   stop; \
 handler ## testnum: \
   vxcptkill; \
-  li x28,2; \
+  li TESTNUM,2; \
   vxcptcause a0; \
   li a1,HWACHA_CAUSE_VF_ILLEGAL_REGID; \
   bne a0,a1,fail; \
@@ -670,24 +672,24 @@ handler ## testnum: \
   fence; \
   ld a1,0(a3); \
   li a2,5; \
-  li x28,2; \
+  li TESTNUM,2; \
   bne a1,a2,fail; \
   ld a1,8(a3); \
-  li x28,3; \
+  li TESTNUM,3; \
   bne a1,a2,fail; \
   ld a1,16(a3); \
-  li x28,4; \
+  li TESTNUM,4; \
   bne a1,a2,fail; \
   ld a1,24(a3); \
-  li x28,5; \
+  li TESTNUM,5; \
   bne a1,a2,fail; \
 
 #-----------------------------------------------------------------------
-# Pass and fail code (assumes test num is in x28)
+# Pass and fail code (assumes test num is in TESTNUM)
 #-----------------------------------------------------------------------
 
 #define TEST_PASSFAIL \
-        bne x0, x28, pass; \
+        bne x0, TESTNUM, pass; \
 fail: \
         RVTEST_FAIL \
 pass: \