comparison test/test_arith.h @ 46:31cee67540b5

f32/f64: add floor, ceil, round, and trunc operations we also need saturated add sub mul etc
author Paper <paper@tflc.us>
date Sat, 09 Aug 2025 15:55:59 -0400
parents 7955bed1d169
children
comparison
equal deleted inserted replaced
45:7955bed1d169 46:31cee67540b5
14 for (int i = 0; i < size; i++) { \ 14 for (int i = 0; i < size; i++) { \
15 if ((vec_##type##bits)(equiv) != orig_c[i]) { \ 15 if ((vec_##type##bits)(equiv) != orig_c[i]) { \
16 fprintf(stderr, "v" #type #bits "x" #size "_" #op " test FAILED at index %d: (%s) [%" print "] does not equal result [%" print "]!\n", i, #equiv, (vec_##type##bits)(equiv), orig_c[i]); \ 16 fprintf(stderr, "v" #type #bits "x" #size "_" #op " test FAILED at index %d: (%s) [%" print "] does not equal result [%" print "]!\n", i, #equiv, (vec_##type##bits)(equiv), orig_c[i]); \
17 print_v##type##bits##x##size(stderr,a); \ 17 print_v##type##bits##x##size(stderr,a); \
18 print_v##secondtype##bits##x##size(stderr,b); \ 18 print_v##secondtype##bits##x##size(stderr,b); \
19 print_v##type##bits##x##size(stderr,c); \
20 fprintf(stderr, "\n"); \
21 return 1; \
22 } \
23 } \
24 \
25 return 0; \
26 }
27
28 #define CREATE_TEST_ONEPARAM(type, ctype, print, bits, size, op, equiv) \
29 static int test_arith_v##type##bits##x##size##_##op(v##type##bits##x##size a) \
30 { \
31 V##ctype##bits##x##size##_ALIGNED_ARRAY(orig_a); \
32 V##ctype##bits##x##size##_ALIGNED_ARRAY(orig_c); \
33 \
34 v##type##bits##x##size c = v##type##bits##x##size##_##op(a); \
35 \
36 v##type##bits##x##size##_store_aligned(a, orig_a); \
37 v##type##bits##x##size##_store_aligned(c, orig_c); \
38 \
39 for (int i = 0; i < size; i++) { \
40 if ((vec_##type##bits)(equiv) != orig_c[i]) { \
41 fprintf(stderr, "v" #type #bits "x" #size "_" #op " test FAILED at index %d: (%s) [%" print "] does not equal result [%" print "]!\n", i, #equiv, (vec_##type##bits)(equiv), orig_c[i]); \
42 print_v##type##bits##x##size(stderr,a); \
19 print_v##type##bits##x##size(stderr,c); \ 43 print_v##type##bits##x##size(stderr,c); \
20 fprintf(stderr, "\n"); \ 44 fprintf(stderr, "\n"); \
21 return 1; \ 45 return 1; \
22 } \ 46 } \
23 } \ 47 } \
53 CREATE_TEST(f, F, "f", bits, size, mul, orig_a[i] * orig_b[i]) \ 77 CREATE_TEST(f, F, "f", bits, size, mul, orig_a[i] * orig_b[i]) \
54 CREATE_TEST(f, F, "f", bits, size, div, (orig_b[i]) ? (orig_a[i] / orig_b[i]) : 0) \ 78 CREATE_TEST(f, F, "f", bits, size, div, (orig_b[i]) ? (orig_a[i] / orig_b[i]) : 0) \
55 CREATE_TEST(f, F, "f", bits, size, mod, (orig_b[i]) ? (fmod(orig_a[i], orig_b[i])) : 0) \ 79 CREATE_TEST(f, F, "f", bits, size, mod, (orig_b[i]) ? (fmod(orig_a[i], orig_b[i])) : 0) \
56 CREATE_TEST(f, F, "f", bits, size, avg, (orig_a[i] + orig_b[i]) / 2) \ 80 CREATE_TEST(f, F, "f", bits, size, avg, (orig_a[i] + orig_b[i]) / 2) \
57 CREATE_TEST(f, F, "f", bits, size, min, (orig_a[i] < orig_b[i]) ? orig_a[i] : orig_b[i]) \ 81 CREATE_TEST(f, F, "f", bits, size, min, (orig_a[i] < orig_b[i]) ? orig_a[i] : orig_b[i]) \
58 CREATE_TEST(f, F, "f", bits, size, max, (orig_a[i] > orig_b[i]) ? orig_a[i] : orig_b[i]) 82 CREATE_TEST(f, F, "f", bits, size, max, (orig_a[i] > orig_b[i]) ? orig_a[i] : orig_b[i]) \
83 CREATE_TEST_ONEPARAM(f, F, "f", bits, size, round, round(orig_a[i])) \
84 CREATE_TEST_ONEPARAM(f, F, "f", bits, size, ceil, ceil(orig_a[i])) \
85 CREATE_TEST_ONEPARAM(f, F, "f", bits, size, floor, floor(orig_a[i])) \
86 CREATE_TEST_ONEPARAM(f, F, "f", bits, size, trunc, trunc(orig_a[i]))
59 87
60 #define CREATE_TESTS(bits, size) \ 88 #define CREATE_TESTS(bits, size) \
61 CREATE_TESTS_INT(int, INT, /* nothing */, PRI##d##bits, bits, size) \ 89 CREATE_TESTS_INT(int, INT, /* nothing */, PRI##d##bits, bits, size) \
62 CREATE_TESTS_INT(uint, UINT, u, PRI##u##bits, bits, size) 90 CREATE_TESTS_INT(uint, UINT, u, PRI##u##bits, bits, size)
63 91
149 ret |= test_arith_v##type##bits##x##size##_mod(a, b); \ 177 ret |= test_arith_v##type##bits##x##size##_mod(a, b); \
150 ret |= test_arith_v##type##bits##x##size##_avg(a, b); \ 178 ret |= test_arith_v##type##bits##x##size##_avg(a, b); \
151 ret |= test_arith_v##type##bits##x##size##_min(a, b); \ 179 ret |= test_arith_v##type##bits##x##size##_min(a, b); \
152 ret |= test_arith_v##type##bits##x##size##_max(a, b); \ 180 ret |= test_arith_v##type##bits##x##size##_max(a, b); \
153 } \ 181 } \
182 ret |= test_arith_v##type##bits##x##size##_floor(a); \
183 ret |= test_arith_v##type##bits##x##size##_ceil(a); \
184 ret |= test_arith_v##type##bits##x##size##_round(a); \
185 ret |= test_arith_v##type##bits##x##size##_trunc(a); \
154 } 186 }
155 187
156 RUN_TESTS(8, 2) 188 RUN_TESTS(8, 2)
157 189
158 RUN_TESTS(8, 4) 190 RUN_TESTS(8, 4)