Mercurial > vec
diff 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 |
line wrap: on
line diff
--- a/test/test_arith.h Wed Apr 30 18:36:38 2025 -0400 +++ b/test/test_arith.h Sat Aug 09 15:55:59 2025 -0400 @@ -25,6 +25,30 @@ return 0; \ } +#define CREATE_TEST_ONEPARAM(type, ctype, print, bits, size, op, equiv) \ + static int test_arith_v##type##bits##x##size##_##op(v##type##bits##x##size a) \ + { \ + V##ctype##bits##x##size##_ALIGNED_ARRAY(orig_a); \ + V##ctype##bits##x##size##_ALIGNED_ARRAY(orig_c); \ + \ + v##type##bits##x##size c = v##type##bits##x##size##_##op(a); \ + \ + v##type##bits##x##size##_store_aligned(a, orig_a); \ + v##type##bits##x##size##_store_aligned(c, orig_c); \ + \ + for (int i = 0; i < size; i++) { \ + if ((vec_##type##bits)(equiv) != orig_c[i]) { \ + 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]); \ + print_v##type##bits##x##size(stderr,a); \ + print_v##type##bits##x##size(stderr,c); \ + fprintf(stderr, "\n"); \ + return 1; \ + } \ + } \ + \ + return 0; \ + } + #define CREATE_TEST(type, ctype, print, bits, size, op, equiv) \ CREATE_TEST_EX(type, ctype, print, bits, size, op, equiv, type, ctype) @@ -55,7 +79,11 @@ CREATE_TEST(f, F, "f", bits, size, mod, (orig_b[i]) ? (fmod(orig_a[i], orig_b[i])) : 0) \ CREATE_TEST(f, F, "f", bits, size, avg, (orig_a[i] + orig_b[i]) / 2) \ CREATE_TEST(f, F, "f", bits, size, min, (orig_a[i] < orig_b[i]) ? orig_a[i] : orig_b[i]) \ - CREATE_TEST(f, F, "f", bits, size, max, (orig_a[i] > orig_b[i]) ? orig_a[i] : orig_b[i]) + CREATE_TEST(f, F, "f", bits, size, max, (orig_a[i] > orig_b[i]) ? orig_a[i] : orig_b[i]) \ + CREATE_TEST_ONEPARAM(f, F, "f", bits, size, round, round(orig_a[i])) \ + CREATE_TEST_ONEPARAM(f, F, "f", bits, size, ceil, ceil(orig_a[i])) \ + CREATE_TEST_ONEPARAM(f, F, "f", bits, size, floor, floor(orig_a[i])) \ + CREATE_TEST_ONEPARAM(f, F, "f", bits, size, trunc, trunc(orig_a[i])) #define CREATE_TESTS(bits, size) \ CREATE_TESTS_INT(int, INT, /* nothing */, PRI##d##bits, bits, size) \ @@ -151,6 +179,10 @@ ret |= test_arith_v##type##bits##x##size##_min(a, b); \ ret |= test_arith_v##type##bits##x##size##_max(a, b); \ } \ + ret |= test_arith_v##type##bits##x##size##_floor(a); \ + ret |= test_arith_v##type##bits##x##size##_ceil(a); \ + ret |= test_arith_v##type##bits##x##size##_round(a); \ + ret |= test_arith_v##type##bits##x##size##_trunc(a); \ } RUN_TESTS(8, 2)