Mercurial > vec
comparison test/test_compare.h @ 9:6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
eventually this could be expanded to add floating point stuff
as well
author | Paper <paper@tflc.us> |
---|---|
date | Mon, 18 Nov 2024 13:52:09 -0500 |
parents | 75ab77f874e2 |
children | d1d5d767004c |
comparison
equal
deleted
inserted
replaced
6:978c167dcceb | 9:6ff0b7a44bb6 |
---|---|
21 } \ | 21 } \ |
22 \ | 22 \ |
23 return 0; \ | 23 return 0; \ |
24 } | 24 } |
25 | 25 |
26 #define CREATE_TESTS(sign, psign, bits, size) \ | 26 #define CREATE_TESTS_SIGN(sign, psign, bits, size) \ |
27 CREATE_TEST(sign, psign, bits, size, cmplt, orig_a[i] < orig_b[i]) \ | 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]) \ | 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]) \ | 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]) \ | 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]) | 31 CREATE_TEST(sign, psign, bits, size, cmpge, orig_a[i] >= orig_b[i]) |
32 | 32 |
33 #define CREATE_TESTS_2(bits, size) CREATE_TESTS(, d, bits, size) CREATE_TESTS(u, u, bits, size) | 33 #define CREATE_TESTS(bits, size) CREATE_TESTS_SIGN(, d, bits, size) CREATE_TESTS_SIGN(u, u, bits, size) |
34 | 34 |
35 CREATE_TESTS_2(8, 16) | 35 CREATE_TESTS(8, 16) |
36 CREATE_TESTS_2(16, 8) | 36 CREATE_TESTS(16, 8) |
37 CREATE_TESTS_2(32, 4) | 37 CREATE_TESTS(32, 4) |
38 CREATE_TESTS_2(64, 2) | 38 CREATE_TESTS(64, 2) |
39 | 39 |
40 #undef CREATE_TESTS_2 | 40 CREATE_TESTS(8, 32) |
41 CREATE_TESTS(16, 16) | |
42 CREATE_TESTS(32, 8) | |
43 CREATE_TESTS(64, 4) | |
44 | |
45 CREATE_TESTS(8, 64) | |
46 CREATE_TESTS(16, 32) | |
47 CREATE_TESTS(32, 16) | |
48 CREATE_TESTS(64, 8) | |
49 | |
50 #undef CREATE_TESTS_SIGN | |
41 #undef CREATE_TESTS | 51 #undef CREATE_TESTS |
42 #undef CREATE_TEST | 52 #undef CREATE_TEST |
43 | 53 |
44 static int test_compare(void) | 54 static int test_compare(void) |
45 { | 55 { |
46 int ret = 0; | 56 int ret = 0; |
47 | 57 |
48 #define RUN_TESTS(sign, bits, size) \ | 58 #define RUN_TESTS_SIGN(sign, bits, size) \ |
49 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \ | 59 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); \ | 60 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++) { \ | 61 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); \ | 62 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); \ | 63 ret |= test_compare_v##sign##int##bits##x##size##_cmplt(a, b); \ |
56 ret |= test_compare_v##sign##int##bits##x##size##_cmple(a, b); \ | 66 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); \ | 67 ret |= test_compare_v##sign##int##bits##x##size##_cmpge(a, b); \ |
58 } \ | 68 } \ |
59 } | 69 } |
60 | 70 |
61 #define RUN_TESTS_2(bits, size) \ | 71 #define RUN_TESTS(bits, size) \ |
62 RUN_TESTS( , bits, size) \ | 72 RUN_TESTS_SIGN( , bits, size) \ |
63 RUN_TESTS(u, bits, size) | 73 RUN_TESTS_SIGN(u, bits, size) |
64 | 74 |
65 RUN_TESTS_2(8, 16) | 75 RUN_TESTS(8, 16) |
66 RUN_TESTS_2(16, 8) | 76 RUN_TESTS(16, 8) |
67 RUN_TESTS_2(32, 4) | 77 RUN_TESTS(32, 4) |
68 RUN_TESTS_2(64, 2) | 78 RUN_TESTS(64, 2) |
69 | 79 |
70 #undef RUN_TESTS_2 | 80 RUN_TESTS(8, 32) |
81 RUN_TESTS(16, 16) | |
82 RUN_TESTS(32, 8) | |
83 RUN_TESTS(64, 4) | |
84 | |
85 RUN_TESTS(8, 64) | |
86 RUN_TESTS(16, 32) | |
87 RUN_TESTS(32, 16) | |
88 RUN_TESTS(64, 8) | |
89 | |
90 #undef RUN_TESTS_SIGN | |
71 #undef RUN_TESTS | 91 #undef RUN_TESTS |
72 | 92 |
73 return ret; | 93 return ret; |
74 } | 94 } |