annotate test/test_arith.h @ 7:945d410803f8

*: fix clang & gcc warnings, add avg test, etc
author Paper <paper@tflc.us>
date Wed, 23 Oct 2024 20:07:08 -0400
parents 75ab77f874e2
children d1d5d767004c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
1 #define CREATE_TEST(sign, psign, csign, bits, size, op, equiv) \
2
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 { \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
4 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_a); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
5 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_b); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
6 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_c); \
2
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 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
9 \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
10 v##sign##int##bits##x##size##_store_aligned(a, orig_a); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
11 v##sign##int##bits##x##size##_store_aligned(b, orig_b); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
12 v##sign##int##bits##x##size##_store_aligned(c, orig_c); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
13 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
14 for (int i = 0; i < size; i++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
15 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
16 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
17 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
18 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
19 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
20 fprintf(stderr, "\n"); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
21 return 1; \
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 } \
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 return 0; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
26 }
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
27
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
28 #define CREATE_TEST_SHIFT(sign, psign, csign, bits, size, op, equiv) \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
29 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
30 { \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
31 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_a); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
32 VUINT##bits##x##size##_ALIGNED_ARRAY(orig_b); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
33 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_c); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
34 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
35 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
36 \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
37 v##sign##int##bits##x##size##_store_aligned(a, orig_a); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
38 vuint##bits##x##size##_store_aligned(b, orig_b); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
39 v##sign##int##bits##x##size##_store_aligned(c, orig_c); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
40 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
41 for (int i = 0; i < size; i++) { \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
42 if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \
7
945d410803f8 *: fix clang & gcc warnings, add avg test, etc
Paper <paper@tflc.us>
parents: 4
diff changeset
43 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]); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
44 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
45 print_vuint##bits##x##size(stderr,b); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
46 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
47 fprintf(stderr, "\n"); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
48 return 1; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
49 } \
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 return 0; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
53 }
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
54
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
55 #define CREATE_TESTS(sign, psign, csign, bits, size) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
56 CREATE_TEST(sign, psign, csign, bits, size, add, orig_a[i] + orig_b[i]) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
57 CREATE_TEST(sign, psign, csign, bits, size, sub, orig_a[i] - orig_b[i]) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
58 CREATE_TEST(sign, psign, csign, bits, size, mul, orig_a[i] * orig_b[i]) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
59 CREATE_TEST(sign, psign, csign, bits, size, div, (orig_b[i]) ? (orig_a[i] / orig_b[i]) : 0) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
60 CREATE_TEST(sign, psign, csign, bits, size, and, orig_a[i] & orig_b[i]) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
61 CREATE_TEST(sign, psign, csign, bits, size, or, orig_a[i] | orig_b[i]) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
62 CREATE_TEST(sign, psign, csign, bits, size, xor, orig_a[i] ^ orig_b[i]) \
7
945d410803f8 *: fix clang & gcc warnings, add avg test, etc
Paper <paper@tflc.us>
parents: 4
diff changeset
63 CREATE_TEST(sign, psign, csign, bits, size, avg, (sign##int##bits##_t)(orig_a[i] + orig_b[i]) / 2) \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
64 CREATE_TEST_SHIFT(sign, psign, csign, bits, size, rshift, vec_##sign##rshift(orig_a[i], orig_b[i])) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
65 CREATE_TEST_SHIFT(sign, psign, csign, bits, size, lshift, vec_##sign##lshift(orig_a[i], orig_b[i])) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
66 CREATE_TEST_SHIFT(sign, psign, csign, bits, size, lrshift, vec_##sign##lrshift(orig_a[i], orig_b[i]))
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
67
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
68 #define CREATE_TESTS_2(bits, size) \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
69 CREATE_TESTS(, d, , bits, size) \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
70 CREATE_TESTS(u, u, U, bits, size)
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
71
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
72 CREATE_TESTS_2(8, 16)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
73 CREATE_TESTS_2(16, 8)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
74 CREATE_TESTS_2(32, 4)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
75 CREATE_TESTS_2(64, 2)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
76
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
77 #undef CREATE_TESTS_2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
78 #undef CREATE_TESTS
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
79 #undef CREATE_TEST
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
80
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
81 static int test_arith(void)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
82 {
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
83 int ret = 0;
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
84
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
85 #define RUN_TESTS(sign, bits, size) \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94 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
95 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
96 ret |= test_arith_v##sign##int##bits##x##size##_xor(a, b); \
7
945d410803f8 *: fix clang & gcc warnings, add avg test, etc
Paper <paper@tflc.us>
parents: 4
diff changeset
97 ret |= test_arith_v##sign##int##bits##x##size##_avg(a, b); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
98 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
99 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
100 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
101 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
102 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
103 for (uint32_t j = 0U; j < bits; j++) { \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
104 const vuint##bits##x##size b = vuint##bits##x##size##_splat(j); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
105 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
106 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
107 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
108 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
109 }
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 #define RUN_TESTS_2(bits, size) \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
112 RUN_TESTS( , bits, size) \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
113 RUN_TESTS(u, bits, size)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
114
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
115 RUN_TESTS_2(8, 16)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
116 RUN_TESTS_2(16, 8)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
117 RUN_TESTS_2(32, 4)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
118 RUN_TESTS_2(64, 2)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
119
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
120 #undef RUN_TESTS_2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
121 #undef RUN_TESTS
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
122
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
123 return ret;
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents: 2
diff changeset
124 }