Mercurial > vec
comparison test/test_compare.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 | 75ab77f874e2 |
comparison
equal
deleted
inserted
replaced
1:1d9d2308c1d2 | 2:f12b5dd4e18c |
---|---|
1 #define CREATE_TEST(sign, psign, bits, size, op, equiv) \ | |
2 static int test_compare_v##sign##int##bits##x##size##_##op(v##sign##int##bits##x##size a, v##sign##int##bits##x##size b) \ | |
3 { \ | |
4 sign##int##bits##_t orig_a[size], orig_b[size], orig_c[size]; \ | |
5 \ | |
6 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \ | |
7 \ | |
8 v##sign##int##bits##x##size##_store(a, orig_a); \ | |
9 v##sign##int##bits##x##size##_store(b, orig_b); \ | |
10 v##sign##int##bits##x##size##_store(c, orig_c); \ | |
11 \ | |
12 for (int i = 0; i < size; i++) { \ | |
13 if ((sign##int##bits##_t)(((equiv) ? UINT##bits##_MAX : 0)) != 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]); \ | |
15 print_v##sign##int##bits##x##size(stderr,a); \ | |
16 print_v##sign##int##bits##x##size(stderr,b); \ | |
17 print_v##sign##int##bits##x##size(stderr,c); \ | |
18 fprintf(stderr, "\n"); \ | |
19 return 1; \ | |
20 } \ | |
21 } \ | |
22 \ | |
23 return 0; \ | |
24 } | |
25 | |
26 #define CREATE_TESTS(sign, psign, bits, size) \ | |
27 CREATE_TEST(sign, psign, bits, size, cmplt, orig_a[i] < orig_b[i]) \ | |
28 CREATE_TEST(sign, psign, bits, size, cmpgt, orig_a[i] > orig_b[i]) \ | |
29 CREATE_TEST(sign, psign, bits, size, cmpeq, orig_a[i] == orig_b[i]) \ | |
30 CREATE_TEST(sign, psign, bits, size, cmple, orig_a[i] <= orig_b[i]) \ | |
31 CREATE_TEST(sign, psign, bits, size, cmpge, orig_a[i] >= orig_b[i]) | |
32 | |
33 #define CREATE_TESTS_2(bits, size) CREATE_TESTS(, d, bits, size) CREATE_TESTS(u, u, bits, size) | |
34 | |
35 CREATE_TESTS_2(8, 16) | |
36 CREATE_TESTS_2(16, 8) | |
37 CREATE_TESTS_2(32, 4) | |
38 CREATE_TESTS_2(64, 2) | |
39 | |
40 #undef CREATE_TESTS_2 | |
41 #undef CREATE_TESTS | |
42 #undef CREATE_TEST | |
43 | |
44 static int test_compare(void) | |
45 { | |
46 int ret = 0; | |
47 | |
48 #define RUN_TESTS(sign, bits, size) \ | |
49 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \ | |
50 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \ | |
51 for (size_t j = 0U; j < ARRAY_SIZE(testval##sign##bits); j++) { \ | |
52 const v##sign##int##bits##x##size b = vtest##sign##bits##x##size(j); \ | |
53 ret |= test_compare_v##sign##int##bits##x##size##_cmplt(a, b); \ | |
54 ret |= test_compare_v##sign##int##bits##x##size##_cmpgt(a, b); \ | |
55 ret |= test_compare_v##sign##int##bits##x##size##_cmpeq(a, b); \ | |
56 ret |= test_compare_v##sign##int##bits##x##size##_cmple(a, b); \ | |
57 ret |= test_compare_v##sign##int##bits##x##size##_cmpge(a, b); \ | |
58 } \ | |
59 } | |
60 | |
61 #define RUN_TESTS_2(bits, size) RUN_TESTS(, bits, size) RUN_TESTS(u, bits, size) | |
62 | |
63 RUN_TESTS_2(8, 16) | |
64 RUN_TESTS_2(16, 8) | |
65 RUN_TESTS_2(32, 4) | |
66 RUN_TESTS_2(64, 2) | |
67 | |
68 #undef RUN_TESTS_2 | |
69 #undef RUN_TESTS | |
70 | |
71 return ret; | |
72 } |