annotate test/test_arith.h @ 2:f12b5dd4e18c

*: many new operations and a real test suite
author Paper <paper@tflc.us>
date Tue, 22 Oct 2024 22:39:05 -0400
parents
children 3c5545b1568f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
1 #define CREATE_TEST(sign, psign, bits, size, op, equiv) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
2 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) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
3 { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
4 sign##int##bits##_t orig_a[size], orig_b[size], orig_c[size]; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
5 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
6 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
7 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
8 v##sign##int##bits##x##size##_store(a, orig_a); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
9 v##sign##int##bits##x##size##_store(b, orig_b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
10 v##sign##int##bits##x##size##_store(c, orig_c); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
11 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
12 for (int i = 0; i < size; i++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
13 if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
14 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]); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
15 print_v##sign##int##bits##x##size(stderr,a); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
16 print_v##sign##int##bits##x##size(stderr,b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
17 print_v##sign##int##bits##x##size(stderr,c); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
18 fprintf(stderr, "\n"); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
19 return 1; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
20 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
21 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
22 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
23 return 0; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
24 }
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
25
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
26 #define CREATE_TEST_SHIFT(sign, psign, bits, size, op, equiv) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
27 static int test_arith_v##sign##int##bits##x##size##_##op(v##sign##int##bits##x##size a, vuint##bits##x##size b) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
28 { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
29 sign##int##bits##_t orig_a[size], orig_c[size]; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
30 uint##bits##_t orig_b[size]; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
31 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
32 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
33 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
34 v##sign##int##bits##x##size##_store(a, orig_a); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
35 vuint##bits##x##size##_store(b, orig_b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
36 v##sign##int##bits##x##size##_store(c, orig_c); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
37 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
38 for (int i = 0; i < size; i++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
39 if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
40 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]); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
41 print_v##sign##int##bits##x##size(stderr,a); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
42 print_vuint##bits##x##size(stderr,b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
43 print_v##sign##int##bits##x##size(stderr,c); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
44 fprintf(stderr, "\n"); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
45 return 1; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
46 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
47 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
48 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
49 return 0; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
50 }
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
51
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
52 #define CREATE_TESTS(sign, psign, bits, size) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
53 CREATE_TEST(sign, psign, bits, size, add, orig_a[i] + orig_b[i]) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
54 CREATE_TEST(sign, psign, bits, size, sub, orig_a[i] - orig_b[i]) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
55 CREATE_TEST(sign, psign, bits, size, mul, orig_a[i] * orig_b[i]) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
56 CREATE_TEST(sign, psign, bits, size, div, (orig_b[i]) ? (orig_a[i] / orig_b[i]) : 0) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
57 CREATE_TEST(sign, psign, bits, size, and, orig_a[i] & orig_b[i]) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
58 CREATE_TEST(sign, psign, bits, size, or, orig_a[i] | orig_b[i]) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
59 CREATE_TEST(sign, psign, bits, size, xor, orig_a[i] ^ orig_b[i]) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
60 CREATE_TEST(sign, psign, bits, size, avg, (orig_a[i] * orig_b[i]) / 2) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
61 CREATE_TEST_SHIFT(sign, psign, bits, size, rshift, vec_##sign##rshift(orig_a[i], orig_b[i])) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
62 CREATE_TEST_SHIFT(sign, psign, bits, size, lshift, vec_##sign##lshift(orig_a[i], orig_b[i])) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
63 CREATE_TEST_SHIFT(sign, psign, bits, size, lrshift, vec_##sign##lrshift(orig_a[i], orig_b[i]))
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
64
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
65 #define CREATE_TESTS_2(bits, size) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
66 CREATE_TESTS(, d, bits, size) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
67 CREATE_TESTS(u, u, bits, size)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
68
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
69 CREATE_TESTS_2(8, 16)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
70 CREATE_TESTS_2(16, 8)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
71 CREATE_TESTS_2(32, 4)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
72 CREATE_TESTS_2(64, 2)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
73
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
74 #undef CREATE_TESTS_2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
75 #undef CREATE_TESTS
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
76 #undef CREATE_TEST
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
77
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
78 static int test_arith(void)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
79 {
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
80 int ret = 0;
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
81
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
82 #define RUN_TESTS(sign, bits, size) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
83 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
84 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
85 for (size_t j = 0U; j < ARRAY_SIZE(testval##sign##bits); j++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
86 const v##sign##int##bits##x##size b = vtest##sign##bits##x##size(j); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
87 ret |= test_arith_v##sign##int##bits##x##size##_add(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
88 ret |= test_arith_v##sign##int##bits##x##size##_sub(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
89 ret |= test_arith_v##sign##int##bits##x##size##_mul(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
90 ret |= test_arith_v##sign##int##bits##x##size##_div(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
91 ret |= test_arith_v##sign##int##bits##x##size##_and(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
92 ret |= test_arith_v##sign##int##bits##x##size##_or(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
93 ret |= test_arith_v##sign##int##bits##x##size##_xor(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
94 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
95 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
96 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
97 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
98 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
99 for (size_t j = 0U; j < ARRAY_SIZE(testvalu##bits); j++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
100 const vuint##bits##x##size b = vtestu##bits##x##size(j); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
101 ret |= test_arith_v##sign##int##bits##x##size##_rshift(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
102 ret |= test_arith_v##sign##int##bits##x##size##_lshift(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
103 ret |= test_arith_v##sign##int##bits##x##size##_lrshift(a, b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
104 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
105 }
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
106
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
107 #define RUN_TESTS_2(bits, size) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
108 RUN_TESTS(, bits, size) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
109 RUN_TESTS(u, bits, size)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
110
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
111 RUN_TESTS_2(8, 16)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
112 RUN_TESTS_2(16, 8)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
113 RUN_TESTS_2(32, 4)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
114 RUN_TESTS_2(64, 2)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
115
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
116 #undef RUN_TESTS_2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
117 #undef RUN_TESTS
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
118
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
119 return ret;
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
120 }