+#define MASK_XLEN(x) ((x) & ((1 << (__riscv_xlen - 1) << 1) - 1))
+
#define SV_REMAP_CSR(reg0, shape0, reg1, shape1, reg2, shape2) \
(reg0 | (reg1<<8) | (reg2<<8) | \
(shape0<<24) | (shape0<<26) | (shape0<<28))
li x1, SV_REG_CSR( type, regkey, elwidth, regidx, isvec); \
csrrw x0, 0x4c0, x1
+#define SET_SV_CSR2( type, regkey, elwidth, regidx, isvec) \
+ li x1, SV_REG_CSR( type, regkey, elwidth, regidx, isvec); \
+ csrrw x0, 0x4c1, x1
+
#define SET_SV_PRED_CSR( type, regkey, zero, inv, regidx, packed ) \
li x1, SV_PRED_CSR( type, regkey, zero, inv, regidx, packed ); \
csrrw x0, 0x4c8, x1
la x1, from; \
flw reg, offs(x1)
+#define TEST_SV_IMMW( reg, imm ) \
+ li t6, MASK_XLEN(imm) ; \
+ bne reg, t6, fail
+
#define TEST_SV_IMM( reg, imm ) \
li t6, ((imm) & 0xffffffffffffffff); \
bne reg, t6, fail
--- /dev/null
+#include "riscv_test.h"
+#include "sv_test_macros.h"
+
+RVTEST_RV32U # Define TVM used by program.
+
+// TODO: add extra "code" argument and "testdata" argument,
+// replace "sraw" with "code"
+// TODO: move SV_ELWIDTH_TEST to sv_test_macros.h
+// TODO: probably remove testing of x15 and x16 (or pass in as extra args?)
+
+#define SV_ELWIDTH_TEST( vl, wid1, wid2, wid3, isvec1, isvec2, isvec3, \
+ expect1, expect2, expect3 ) \
+ \
+ SV_LD_DATA( x12, testdata , 0); \
+ SV_LD_DATA( x13, testdata+4 , 0); \
+ SV_LD_DATA( x14, testdata+8, 0); \
+ SV_LD_DATA( x15, testdata+12, 0); \
+ SV_LD_DATA( x16, testdata+16, 0); \
+ SV_LD_DATA( x17, testdata+20, 0); \
+ \
+ li x28, 0xa5a5a5a5; \
+ li x29, 0xa5a5a5a5; \
+ li x30, 0xa5a5a5a5; \
+ \
+ SET_SV_MVL( vl ); \
+ SET_SV_2CSRS( SV_REG_CSR( 1, 15, wid1, 15, isvec1), \
+ SV_REG_CSR( 1, 12, wid2, 12, isvec2) ); \
+ SET_SV_CSR2( 1, 28, wid3, 28, isvec3); \
+ SET_SV_VL( vl ); \
+ \
+ mulhu x28, x15, x12; \
+ \
+ CLR_SV_CSRS(); \
+ SET_SV_VL( 1); \
+ SET_SV_MVL( 1); \
+ \
+ TEST_SV_IMMW( x28, expect1 ); \
+ TEST_SV_IMMW( x29, expect2 ); \
+ TEST_SV_IMMW( x30, expect3 );
+
+
+# SV test: vector-vector add
+#
+# sets up x3 and x4 with data, sets VL to 2, and carries out
+# an "add 1 to x3". which actually means "add 1 to x3 *AND* add 1 to x4"
+
+# Test code region.
+RVTEST_CODE_BEGIN # Start of test code.
+
+ # TODO: add "sraw" argument, add testdata argument
+ SV_ELWIDTH_TEST( 3, 0, 0, 0, 1, 1, 1,
+ 0x7fffc000, 0x0001fefe, 0xfe010000 )
+/*
+ SV_ELWIDTH_TEST( 3, 0, 0, 3, 1, 1, 1,
+ 0x0000008200000021, 0xa5a5a5a500000000, 0xa5a5a5a5a5a5a5a5 )
+ SV_ELWIDTH_TEST( 3, 1, 1, 0, 1, 1, 1,
+ 0x9, 0x11, 0x19 )
+ SV_ELWIDTH_TEST( 3, 1, 1, 3, 1, 1, 1,
+ 0x0000001100000009, 0xa5a5a5a500000019, 0xa5a5a5a5a5a5a5a5 )
+ SV_ELWIDTH_TEST( 3, 1, 1, 2, 1, 1, 1,
+ 0xa5a5001900110009, 0xa5a5a5a5a5a5a5a5, 0xa5a5a5a5a5a5a5a5 )
+ SV_ELWIDTH_TEST( 3, 1, 1, 1, 1, 1, 1,
+ 0xa5a5a5a5a5191109, 0xa5a5a5a5a5a5a5a5, 0xa5a5a5a5a5a5a5a5 )
+*/
+ RVTEST_PASS # Signal success.
+fail:
+ RVTEST_FAIL
+RVTEST_CODE_END # End of test code.
+
+# Input data section.
+# This section is optional, and this data is NOT saved in the output.
+.data
+ .align 3
+testdata:
+ .word 0x80000000
+ .word 0xaaaaaaab
+ .word 0xff000000
+ .word 0xffff8000
+ .word 0x0002fe7d
+ .word 0xff000000
+
+# Output data section.
+RVTEST_DATA_BEGIN # Start of test output data region.
+ .align 3
+result:
+ .dword -1
+ .dword -1
+ .dword -1
+RVTEST_DATA_END # End of test output data region.
+