Mercurial > vec
comparison test/test_arith.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 |
---|---|
50 } \ | 50 } \ |
51 \ | 51 \ |
52 return 0; \ | 52 return 0; \ |
53 } | 53 } |
54 | 54 |
55 #define CREATE_TESTS(sign, psign, csign, bits, size) \ | 55 #define CREATE_TESTS_SIGN(sign, psign, csign, bits, size) \ |
56 CREATE_TEST(sign, psign, csign, bits, size, add, orig_a[i] + orig_b[i]) \ | 56 CREATE_TEST(sign, psign, csign, bits, size, add, orig_a[i] + orig_b[i]) \ |
57 CREATE_TEST(sign, psign, csign, bits, size, sub, orig_a[i] - orig_b[i]) \ | 57 CREATE_TEST(sign, psign, csign, bits, size, sub, orig_a[i] - orig_b[i]) \ |
58 CREATE_TEST(sign, psign, csign, bits, size, mul, orig_a[i] * orig_b[i]) \ | 58 CREATE_TEST(sign, psign, csign, bits, size, mul, orig_a[i] * orig_b[i]) \ |
59 CREATE_TEST(sign, psign, csign, 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) \ |
60 CREATE_TEST(sign, psign, csign, bits, size, and, orig_a[i] & orig_b[i]) \ | 60 CREATE_TEST(sign, psign, csign, bits, size, and, orig_a[i] & orig_b[i]) \ |
63 CREATE_TEST(sign, psign, csign, 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) \ |
64 CREATE_TEST_SHIFT(sign, psign, csign, 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])) \ |
65 CREATE_TEST_SHIFT(sign, psign, csign, 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])) \ |
66 CREATE_TEST_SHIFT(sign, psign, csign, 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])) |
67 | 67 |
68 #define CREATE_TESTS_2(bits, size) \ | 68 #define CREATE_TESTS(bits, size) \ |
69 CREATE_TESTS(, d, , bits, size) \ | 69 CREATE_TESTS_SIGN(, d, , bits, size) \ |
70 CREATE_TESTS(u, u, U, bits, size) | 70 CREATE_TESTS_SIGN(u, u, U, bits, size) |
71 | 71 |
72 CREATE_TESTS_2(8, 16) | 72 CREATE_TESTS(8, 16) |
73 CREATE_TESTS_2(16, 8) | 73 CREATE_TESTS(16, 8) |
74 CREATE_TESTS_2(32, 4) | 74 CREATE_TESTS(32, 4) |
75 CREATE_TESTS_2(64, 2) | 75 CREATE_TESTS(64, 2) |
76 | 76 |
77 #undef CREATE_TESTS_2 | 77 CREATE_TESTS(8, 32) |
78 CREATE_TESTS(16, 16) | |
79 CREATE_TESTS(32, 8) | |
80 CREATE_TESTS(64, 4) | |
81 | |
82 CREATE_TESTS(8, 64) | |
83 CREATE_TESTS(16, 32) | |
84 CREATE_TESTS(32, 16) | |
85 CREATE_TESTS(64, 8) | |
86 | |
87 #undef CREATE_TESTS_SIGN | |
78 #undef CREATE_TESTS | 88 #undef CREATE_TESTS |
79 #undef CREATE_TEST | 89 #undef CREATE_TEST |
80 | 90 |
81 static int test_arith(void) | 91 static int test_arith(void) |
82 { | 92 { |
83 int ret = 0; | 93 int ret = 0; |
84 | 94 |
85 #define RUN_TESTS(sign, bits, size) \ | 95 #define RUN_TESTS_SIGN(sign, bits, size) \ |
86 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \ | 96 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \ |
87 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \ | 97 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \ |
88 for (size_t j = 0U; j < ARRAY_SIZE(testval##sign##bits); j++) { \ | 98 for (size_t j = 0U; j < ARRAY_SIZE(testval##sign##bits); j++) { \ |
89 const v##sign##int##bits##x##size b = vtest##sign##bits##x##size(j); \ | 99 const v##sign##int##bits##x##size b = vtest##sign##bits##x##size(j); \ |
90 ret |= test_arith_v##sign##int##bits##x##size##_add(a, b); \ | 100 ret |= test_arith_v##sign##int##bits##x##size##_add(a, b); \ |
105 ret |= test_arith_v##sign##int##bits##x##size##_lshift(a, b); \ | 115 ret |= test_arith_v##sign##int##bits##x##size##_lshift(a, b); \ |
106 ret |= test_arith_v##sign##int##bits##x##size##_lrshift(a, b); \ | 116 ret |= test_arith_v##sign##int##bits##x##size##_lrshift(a, b); \ |
107 } \ | 117 } \ |
108 } | 118 } |
109 | 119 |
110 #define RUN_TESTS_2(bits, size) \ | 120 #define RUN_TESTS(bits, size) \ |
111 RUN_TESTS( , bits, size) \ | 121 RUN_TESTS_SIGN( , bits, size) \ |
112 RUN_TESTS(u, bits, size) | 122 RUN_TESTS_SIGN(u, bits, size) |
113 | 123 |
114 RUN_TESTS_2(8, 16) | 124 RUN_TESTS(8, 16) |
115 RUN_TESTS_2(16, 8) | 125 RUN_TESTS(16, 8) |
116 RUN_TESTS_2(32, 4) | 126 RUN_TESTS(32, 4) |
117 RUN_TESTS_2(64, 2) | 127 RUN_TESTS(64, 2) |
118 | 128 |
119 #undef RUN_TESTS_2 | 129 RUN_TESTS(8, 32) |
130 RUN_TESTS(16, 16) | |
131 RUN_TESTS(32, 8) | |
132 RUN_TESTS(64, 4) | |
133 | |
134 RUN_TESTS(8, 64) | |
135 RUN_TESTS(16, 32) | |
136 RUN_TESTS(32, 16) | |
137 RUN_TESTS(64, 8) | |
138 | |
139 #undef RUN_TESTS_SIGN | |
120 #undef RUN_TESTS | 140 #undef RUN_TESTS |
121 | 141 |
122 return ret; | 142 return ret; |
123 } | 143 } |