diff test/test_arith.h @ 40:55cadb1fac4b

*: add mod operation, add GCC vector backend need to test it with old gcc though. :)
author Paper <paper@tflc.us>
date Sun, 27 Apr 2025 02:49:53 -0400
parents 4b5a557aa64f
children c6e0df09b86f
line wrap: on
line diff
--- a/test/test_arith.h	Sat Apr 26 15:31:39 2025 -0400
+++ b/test/test_arith.h	Sun Apr 27 02:49:53 2025 -0400
@@ -1,21 +1,21 @@
-#define CREATE_TEST(sign, psign, csign, bits, size, op, equiv) \
-	static int test_arith_v##sign##int##bits##x##size##_##op(v##sign##int##bits##x##size a, v##sign##int##bits##x##size b) \
+#define CREATE_TEST_EX(sign, psign, csign, bits, size, op, equiv, secondsign, secondcsign) \
+	static int test_arith_v##sign##int##bits##x##size##_##op(v##sign##int##bits##x##size a, v##secondsign##int##bits##x##size b) \
 	{ \
 		V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_a); \
-		V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_b); \
+		V##secondcsign##INT##bits##x##size##_ALIGNED_ARRAY(orig_b); \
 		V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_c); \
 	\
 		v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \
 	\
 		v##sign##int##bits##x##size##_store_aligned(a, orig_a); \
-		v##sign##int##bits##x##size##_store_aligned(b, orig_b); \
+		v##secondsign##int##bits##x##size##_store_aligned(b, orig_b); \
 		v##sign##int##bits##x##size##_store_aligned(c, orig_c); \
 	\
 		for (int i = 0; i < size; i++) { \
 			if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \
-				fprintf(stderr, "v" #sign "int" #bits "x" #size "_" #op " test FAILED at index %d: (" #equiv ") [%" PRI ## psign ## bits "] does not equal result [%" PRI ## psign ## bits "]!\n", i, equiv, orig_c[i]); \
+				fprintf(stderr, "v" #sign "int" #bits "x" #size "_" #op " test FAILED at index %d: (%s) [%" PRI ## psign ## bits "] does not equal result [%" PRI ## psign ## bits "]!\n", i, #equiv, (vec_##sign##int##bits)(equiv), orig_c[i]); \
 				print_v##sign##int##bits##x##size(stderr,a); \
-				print_v##sign##int##bits##x##size(stderr,b); \
+				print_v##secondsign##int##bits##x##size(stderr,b); \
 				print_v##sign##int##bits##x##size(stderr,c); \
 				fprintf(stderr, "\n"); \
 				return 1; \
@@ -25,38 +25,18 @@
 		return 0; \
 	}
 
+#define CREATE_TEST(sign, psign, csign, bits, size, op, equiv) \
+	CREATE_TEST_EX(sign, psign, csign, bits, size, op, equiv, sign, csign)
+
 #define CREATE_TEST_SHIFT(sign, psign, csign, bits, size, op, equiv) \
-	static int test_arith_v##sign##int##bits##x##size##_##op(v##sign##int##bits##x##size a, vuint##bits##x##size b) \
-	{ \
-		V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_a); \
-		VUINT##bits##x##size##_ALIGNED_ARRAY(orig_b); \
-		V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_c); \
-	\
-		v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \
-	\
-		v##sign##int##bits##x##size##_store_aligned(a, orig_a); \
-		vuint##bits##x##size##_store_aligned(b, orig_b); \
-		v##sign##int##bits##x##size##_store_aligned(c, orig_c); \
-	\
-		for (int i = 0; i < size; i++) { \
-			if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \
-				fprintf(stderr, "v" #sign "int" #bits "x" #size "_" #op " test FAILED at index %d: (" #equiv ") [%" PRI ## psign ## bits "] does not equal result [%" PRI ## psign ## bits "]!\n", i, (sign##int##bits##_t)(equiv), orig_c[i]); \
-				print_v##sign##int##bits##x##size(stderr,a); \
-				print_vuint##bits##x##size(stderr,b); \
-				print_v##sign##int##bits##x##size(stderr,c); \
-				fprintf(stderr, "\n"); \
-				return 1; \
-			} \
-		} \
-	\
-		return 0; \
-	}
+	CREATE_TEST_EX(sign, psign, csign, bits, size, op, equiv, u, U)
 
 #define CREATE_TESTS_SIGN(sign, psign, csign, bits, size) \
 	CREATE_TEST(sign, psign, csign, bits, size, add, orig_a[i] + orig_b[i]) \
 	CREATE_TEST(sign, psign, csign, bits, size, sub, orig_a[i] - orig_b[i]) \
 	CREATE_TEST(sign, psign, csign, bits, size, mul, orig_a[i] * orig_b[i]) \
 	CREATE_TEST(sign, psign, csign, bits, size, div, (orig_b[i]) ? (orig_a[i] / orig_b[i]) : 0) \
+	CREATE_TEST(sign, psign, csign, bits, size, mod, (orig_b[i]) ? (orig_a[i] % orig_b[i]) : 0) \
 	CREATE_TEST(sign, psign, csign, bits, size, and, orig_a[i] & orig_b[i]) \
 	CREATE_TEST(sign, psign, csign, bits, size, or,  orig_a[i] | orig_b[i]) \
 	CREATE_TEST(sign, psign, csign, bits, size, xor, orig_a[i] ^ orig_b[i]) \
@@ -113,6 +93,7 @@
 			ret |= test_arith_v##sign##int##bits##x##size##_sub(a, b); \
 			ret |= test_arith_v##sign##int##bits##x##size##_mul(a, b); \
 			ret |= test_arith_v##sign##int##bits##x##size##_div(a, b); \
+			ret |= test_arith_v##sign##int##bits##x##size##_mod(a, b); \
 			ret |= test_arith_v##sign##int##bits##x##size##_and(a, b); \
 			ret |= test_arith_v##sign##int##bits##x##size##_or(a, b); \
 			ret |= test_arith_v##sign##int##bits##x##size##_xor(a, b); \