annotate test/test_compare.h @ 45:7955bed1d169 default tip

*: add preliminary floating point support no x86 intrinsics just yet, but I did add altivec since it's (arguably) the simplest :)
author Paper <paper@tflc.us>
date Wed, 30 Apr 2025 18:36:38 -0400
parents 4b5a557aa64f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
1 #define CREATE_TEST(type, print, bits, size, op, equiv) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
2 static int test_compare_v##type##bits##x##size##_##op(v##type##bits##x##size a, v##type##bits##x##size b) \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
3 { \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
4 vec_##type##bits orig_a[size], orig_b[size], orig_c[size]; \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
5 \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
6 v##type##bits##x##size c = v##type##bits##x##size##_##op(a, b); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
7 \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
8 v##type##bits##x##size##_store(a, orig_a); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
9 v##type##bits##x##size##_store(b, orig_b); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
10 v##type##bits##x##size##_store(c, orig_c); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
11 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
12 for (int i = 0; i < size; i++) { \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
13 uint##bits##_t res = (((equiv) ? UINT##bits##_MAX : 0)); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
14 if (memcmp(&res, orig_c + i, sizeof(res))) { \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
15 fprintf(stderr, "v" #type #bits "x" #size "_" #op " test FAILED at index %d: (" #equiv ") [%d] does not equal result [%" print "]!\n", i, equiv, orig_c[i]); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
16 print_v##type##bits##x##size(stderr,a); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
17 print_v##type##bits##x##size(stderr,b); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
18 print_v##type##bits##x##size(stderr,c); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
19 fprintf(stderr, "\n"); \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
20 return 1; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
21 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
22 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
23 \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
24 return 0; \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
25 }
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
26
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
27 #define CREATE_TESTS_SIGN(type, print, bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
28 CREATE_TEST(type, print, bits, size, cmplt, orig_a[i] < orig_b[i]) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
29 CREATE_TEST(type, print, bits, size, cmpgt, orig_a[i] > orig_b[i]) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
30 CREATE_TEST(type, print, bits, size, cmpeq, orig_a[i] == orig_b[i]) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
31 CREATE_TEST(type, print, bits, size, cmple, orig_a[i] <= orig_b[i]) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
32 CREATE_TEST(type, print, bits, size, cmpge, orig_a[i] >= orig_b[i])
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
33
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
34 #define CREATE_TESTS_INT(bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
35 CREATE_TESTS_SIGN(int, PRI##d##bits, bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
36 CREATE_TESTS_SIGN(uint, PRI##u##bits, bits, size)
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
37
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
38 #define CREATE_TESTS_FLOAT(bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
39 CREATE_TESTS_SIGN(f, "f", bits, size)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
40
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
41 CREATE_TESTS_INT(8, 2)
9
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
42
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
43 CREATE_TESTS_INT(8, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
44 CREATE_TESTS_INT(16, 2)
17
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
45
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
46 CREATE_TESTS_INT(8, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
47 CREATE_TESTS_INT(16, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
48 CREATE_TESTS_INT(32, 2)
17
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
49
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
50 CREATE_TESTS_INT(8, 16)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
51 CREATE_TESTS_INT(16, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
52 CREATE_TESTS_INT(32, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
53 CREATE_TESTS_INT(64, 2)
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
54
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
55 CREATE_TESTS_INT(8, 32)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
56 CREATE_TESTS_INT(16, 16)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
57 CREATE_TESTS_INT(32, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
58 CREATE_TESTS_INT(64, 4)
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
59
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
60 CREATE_TESTS_INT(8, 64)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
61 CREATE_TESTS_INT(16, 32)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
62 CREATE_TESTS_INT(32, 16)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
63 CREATE_TESTS_INT(64, 8)
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
64
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
65 CREATE_TESTS_FLOAT(32, 2)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
66 CREATE_TESTS_FLOAT(32, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
67 CREATE_TESTS_FLOAT(32, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
68 CREATE_TESTS_FLOAT(32, 16)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
69
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
70 CREATE_TESTS_FLOAT(64, 2)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
71 CREATE_TESTS_FLOAT(64, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
72 CREATE_TESTS_FLOAT(64, 8)
9
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
73
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
74 #undef CREATE_TESTS_SIGN
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
75 #undef CREATE_TESTS_INT
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
76 #undef CREATE_TESTS_FLOAT
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
77 #undef CREATE_TEST
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
78
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
79 static int test_compare(void)
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
80 {
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
81 int ret = 0;
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
82
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
83 #define RUN_TESTS_SIGN(shorttype, type, bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
84 for (size_t i = 0U; i < ARRAY_SIZE(testval##shorttype##bits); i++) { \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
85 const v##type##bits##x##size a = vtest##shorttype##bits##x##size(i); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
86 for (size_t j = 0U; j < ARRAY_SIZE(testval##shorttype##bits); j++) { \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
87 const v##type##bits##x##size b = vtest##shorttype##bits##x##size(j); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
88 ret |= test_compare_v##type##bits##x##size##_cmplt(a, b); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
89 ret |= test_compare_v##type##bits##x##size##_cmpgt(a, b); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
90 ret |= test_compare_v##type##bits##x##size##_cmpeq(a, b); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
91 ret |= test_compare_v##type##bits##x##size##_cmple(a, b); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
92 ret |= test_compare_v##type##bits##x##size##_cmpge(a, b); \
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
93 } \
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
94 }
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
95
9
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
96 #define RUN_TESTS(bits, size) \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
97 RUN_TESTS_SIGN( , int, bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
98 RUN_TESTS_SIGN(u, uint, bits, size)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
99
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
100 #define RUN_TESTS_FLOAT(bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
101 RUN_TESTS_SIGN(f, f, bits, size)
9
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
102
17
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
103 RUN_TESTS(8, 2)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
104
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
105 RUN_TESTS(8, 4)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
106 RUN_TESTS(16, 2)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
107
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
108 RUN_TESTS(8, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
109 RUN_TESTS(16, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
110 RUN_TESTS(32, 2)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
111
9
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
112 RUN_TESTS(8, 16)
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
113 RUN_TESTS(16, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
114 RUN_TESTS(32, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
115 RUN_TESTS(64, 2)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
116
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
117 RUN_TESTS(8, 32)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
118 RUN_TESTS(16, 16)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
119 RUN_TESTS(32, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
120 RUN_TESTS(64, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
121
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
122 RUN_TESTS(8, 64)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
123 RUN_TESTS(16, 32)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
124 RUN_TESTS(32, 16)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
125 RUN_TESTS(64, 8)
9
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
126
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
127 RUN_TESTS_FLOAT(32, 2)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
128 RUN_TESTS_FLOAT(32, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
129 RUN_TESTS_FLOAT(32, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
130 RUN_TESTS_FLOAT(32, 16)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
131
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
132 RUN_TESTS_FLOAT(64, 2)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
133 RUN_TESTS_FLOAT(64, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
134 RUN_TESTS_FLOAT(64, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
135
9
6ff0b7a44bb6 generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents: 4
diff changeset
136 #undef RUN_TESTS_SIGN
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 37
diff changeset
137 #undef RUN_TESTS_FLOAT
2
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
138 #undef RUN_TESTS
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
139
f12b5dd4e18c *: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff changeset
140 return ret;
20
627d548b23c8 impl/generic: fix load and store implementations
Paper <paper@tflc.us>
parents: 17
diff changeset
141 }