comparison test/test_arith.h @ 4:75ab77f874e2

*: aligned generics, fixed altivec, aligned tests...
author Paper <paper@tflc.us>
date Wed, 23 Oct 2024 10:13:25 -0400
parents 3c5545b1568f
children 945d410803f8 6ff0b7a44bb6
comparison
equal deleted inserted replaced
3:3c5545b1568f 4:75ab77f874e2
1 #define CREATE_TEST(sign, psign, bits, size, op, equiv) \ 1 #define CREATE_TEST(sign, psign, csign, bits, size, op, equiv) \
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) \ 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) \
3 { \ 3 { \
4 sign##int##bits##_t orig_a[size], orig_b[size], orig_c[size]; \ 4 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_a); \
5 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_b); \
6 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_c); \
5 \ 7 \
6 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \ 8 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \
7 \ 9 \
8 v##sign##int##bits##x##size##_store(a, orig_a); \ 10 v##sign##int##bits##x##size##_store_aligned(a, orig_a); \
9 v##sign##int##bits##x##size##_store(b, orig_b); \ 11 v##sign##int##bits##x##size##_store_aligned(b, orig_b); \
10 v##sign##int##bits##x##size##_store(c, orig_c); \ 12 v##sign##int##bits##x##size##_store_aligned(c, orig_c); \
11 \ 13 \
12 for (int i = 0; i < size; i++) { \ 14 for (int i = 0; i < size; i++) { \
13 if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \ 15 if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \
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]); \ 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]); \
15 print_v##sign##int##bits##x##size(stderr,a); \ 17 print_v##sign##int##bits##x##size(stderr,a); \
21 } \ 23 } \
22 \ 24 \
23 return 0; \ 25 return 0; \
24 } 26 }
25 27
26 #define CREATE_TEST_SHIFT(sign, psign, bits, size, op, equiv) \ 28 #define CREATE_TEST_SHIFT(sign, psign, csign, bits, size, op, equiv) \
27 static int test_arith_v##sign##int##bits##x##size##_##op(v##sign##int##bits##x##size a, vuint##bits##x##size b) \ 29 static int test_arith_v##sign##int##bits##x##size##_##op(v##sign##int##bits##x##size a, vuint##bits##x##size b) \
28 { \ 30 { \
29 sign##int##bits##_t orig_a[size], orig_c[size]; \ 31 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_a); \
30 uint##bits##_t orig_b[size]; \ 32 VUINT##bits##x##size##_ALIGNED_ARRAY(orig_b); \
33 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(orig_c); \
31 \ 34 \
32 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \ 35 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \
33 \ 36 \
34 v##sign##int##bits##x##size##_store(a, orig_a); \ 37 v##sign##int##bits##x##size##_store_aligned(a, orig_a); \
35 vuint##bits##x##size##_store(b, orig_b); \ 38 vuint##bits##x##size##_store_aligned(b, orig_b); \
36 v##sign##int##bits##x##size##_store(c, orig_c); \ 39 v##sign##int##bits##x##size##_store_aligned(c, orig_c); \
37 \ 40 \
38 for (int i = 0; i < size; i++) { \ 41 for (int i = 0; i < size; i++) { \
39 if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \ 42 if ((sign##int##bits##_t)(equiv) != orig_c[i]) { \
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]); \ 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, equiv, orig_c[i]); \
41 print_v##sign##int##bits##x##size(stderr,a); \ 44 print_v##sign##int##bits##x##size(stderr,a); \
47 } \ 50 } \
48 \ 51 \
49 return 0; \ 52 return 0; \
50 } 53 }
51 54
52 #define CREATE_TESTS(sign, psign, bits, size) \ 55 #define CREATE_TESTS(sign, psign, csign, bits, size) \
53 CREATE_TEST(sign, psign, bits, size, add, orig_a[i] + orig_b[i]) \ 56 CREATE_TEST(sign, psign, csign, bits, size, add, orig_a[i] + orig_b[i]) \
54 CREATE_TEST(sign, psign, bits, size, sub, orig_a[i] - orig_b[i]) \ 57 CREATE_TEST(sign, psign, csign, bits, size, sub, orig_a[i] - orig_b[i]) \
55 CREATE_TEST(sign, psign, bits, size, mul, orig_a[i] * orig_b[i]) \ 58 CREATE_TEST(sign, psign, csign, bits, size, mul, orig_a[i] * orig_b[i]) \
56 CREATE_TEST(sign, psign, bits, size, div, (orig_b[i]) ? (orig_a[i] / orig_b[i]) : 0) \ 59 CREATE_TEST(sign, psign, csign, bits, size, div, (orig_b[i]) ? (orig_a[i] / orig_b[i]) : 0) \
57 CREATE_TEST(sign, psign, bits, size, and, orig_a[i] & orig_b[i]) \ 60 CREATE_TEST(sign, psign, csign, bits, size, and, orig_a[i] & orig_b[i]) \
58 CREATE_TEST(sign, psign, bits, size, or, orig_a[i] | orig_b[i]) \ 61 CREATE_TEST(sign, psign, csign, bits, size, or, orig_a[i] | orig_b[i]) \
59 CREATE_TEST(sign, psign, bits, size, xor, orig_a[i] ^ orig_b[i]) \ 62 CREATE_TEST(sign, psign, csign, bits, size, xor, orig_a[i] ^ orig_b[i]) \
60 CREATE_TEST(sign, psign, bits, size, avg, (orig_a[i] * orig_b[i]) / 2) \ 63 CREATE_TEST(sign, psign, csign, bits, size, avg, (orig_a[i] * orig_b[i]) / 2) \
61 CREATE_TEST_SHIFT(sign, psign, bits, size, rshift, vec_##sign##rshift(orig_a[i], orig_b[i])) \ 64 CREATE_TEST_SHIFT(sign, psign, csign, bits, size, rshift, vec_##sign##rshift(orig_a[i], orig_b[i])) \
62 CREATE_TEST_SHIFT(sign, psign, bits, size, lshift, vec_##sign##lshift(orig_a[i], orig_b[i])) \ 65 CREATE_TEST_SHIFT(sign, psign, csign, bits, size, lshift, vec_##sign##lshift(orig_a[i], orig_b[i])) \
63 CREATE_TEST_SHIFT(sign, psign, bits, size, lrshift, vec_##sign##lrshift(orig_a[i], orig_b[i])) 66 CREATE_TEST_SHIFT(sign, psign, csign, bits, size, lrshift, vec_##sign##lrshift(orig_a[i], orig_b[i]))
64 67
65 #define CREATE_TESTS_2(bits, size) \ 68 #define CREATE_TESTS_2(bits, size) \
66 CREATE_TESTS(, d, bits, size) \ 69 CREATE_TESTS(, d, , bits, size) \
67 CREATE_TESTS(u, u, bits, size) 70 CREATE_TESTS(u, u, U, bits, size)
68 71
69 CREATE_TESTS_2(8, 16) 72 CREATE_TESTS_2(8, 16)
70 CREATE_TESTS_2(16, 8) 73 CREATE_TESTS_2(16, 8)
71 CREATE_TESTS_2(32, 4) 74 CREATE_TESTS_2(32, 4)
72 CREATE_TESTS_2(64, 2) 75 CREATE_TESTS_2(64, 2)
94 } \ 97 } \
95 } \ 98 } \
96 \ 99 \
97 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \ 100 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \
98 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \ 101 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \
99 for (size_t j = 0U; j < ARRAY_SIZE(testvalu##bits); j++) { \ 102 for (uint32_t j = 0U; j < bits; j++) { \
100 const vuint##bits##x##size b = vtestu##bits##x##size(j); \ 103 const vuint##bits##x##size b = vuint##bits##x##size##_splat(j); \
101 ret |= test_arith_v##sign##int##bits##x##size##_rshift(a, b); \ 104 ret |= test_arith_v##sign##int##bits##x##size##_rshift(a, b); \
102 ret |= test_arith_v##sign##int##bits##x##size##_lshift(a, b); \ 105 ret |= test_arith_v##sign##int##bits##x##size##_lshift(a, b); \
103 ret |= test_arith_v##sign##int##bits##x##size##_lrshift(a, b); \ 106 ret |= test_arith_v##sign##int##bits##x##size##_lrshift(a, b); \
104 } \ 107 } \
105 } 108 }
106 109
107 #define RUN_TESTS_2(bits, size) \ 110 #define RUN_TESTS_2(bits, size) \
108 RUN_TESTS(, bits, size) \ 111 RUN_TESTS( , bits, size) \
109 RUN_TESTS(u, bits, size) 112 RUN_TESTS(u, bits, size)
110 113
111 RUN_TESTS_2(8, 16) 114 RUN_TESTS_2(8, 16)
112 RUN_TESTS_2(16, 8) 115 RUN_TESTS_2(16, 8)
113 RUN_TESTS_2(32, 4) 116 RUN_TESTS_2(32, 4)