Mercurial > vec
annotate test/test_compare.h @ 37:4b5a557aa64f
*: turns out extern is a practical joke. rewrite to be always inline again
the sample benchmark performs about 3x as well with optimizations
disabled :)
author | Paper <paper@tflc.us> |
---|---|
date | Sat, 26 Apr 2025 01:04:35 -0400 |
parents | 627d548b23c8 |
children |
rev | line source |
---|---|
2
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
1 #define CREATE_TEST(sign, psign, bits, size, op, equiv) \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
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) \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
3 { \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
4 sign##int##bits##_t orig_a[size], orig_b[size], orig_c[size]; \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
5 \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
6 v##sign##int##bits##x##size c = v##sign##int##bits##x##size##_##op(a, b); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
7 \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
8 v##sign##int##bits##x##size##_store(a, orig_a); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
9 v##sign##int##bits##x##size##_store(b, orig_b); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
10 v##sign##int##bits##x##size##_store(c, orig_c); \ |
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++) { \ |
37
4b5a557aa64f
*: turns out extern is a practical joke. rewrite to be always inline again
Paper <paper@tflc.us>
parents:
20
diff
changeset
|
13 if ((vec_##sign##int##bits)(((equiv) ? UINT##bits##_MAX : 0)) != orig_c[i]) { \ |
4b5a557aa64f
*: turns out extern is a practical joke. rewrite to be always inline again
Paper <paper@tflc.us>
parents:
20
diff
changeset
|
14 printf("%lld %lld\n", (long long)(vec_##sign##int##bits)(((equiv) ? UINT##bits##_MAX : 0)), (long long)orig_c[i]); \ |
7
945d410803f8
*: fix clang & gcc warnings, add avg test, etc
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
15 fprintf(stderr, "v" #sign "int" #bits "x" #size "_" #op " test FAILED at index %d: (" #equiv ") [%d] does not equal result [%" PRI ## psign ## bits "]!\n", i, equiv, orig_c[i]); \ |
2
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
16 print_v##sign##int##bits##x##size(stderr,a); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
17 print_v##sign##int##bits##x##size(stderr,b); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
18 print_v##sign##int##bits##x##size(stderr,c); \ |
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 |
9
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
27 #define CREATE_TESTS_SIGN(sign, psign, bits, size) \ |
2
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
28 CREATE_TEST(sign, psign, bits, size, cmplt, orig_a[i] < orig_b[i]) \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
29 CREATE_TEST(sign, psign, bits, size, cmpgt, orig_a[i] > orig_b[i]) \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
30 CREATE_TEST(sign, psign, bits, size, cmpeq, orig_a[i] == orig_b[i]) \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
31 CREATE_TEST(sign, psign, bits, size, cmple, orig_a[i] <= orig_b[i]) \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
32 CREATE_TEST(sign, psign, bits, size, cmpge, orig_a[i] >= orig_b[i]) |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
33 |
9
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
34 #define CREATE_TESTS(bits, size) CREATE_TESTS_SIGN(, d, bits, size) CREATE_TESTS_SIGN(u, u, bits, size) |
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
35 |
17
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
36 CREATE_TESTS(8, 2) |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
37 |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
38 CREATE_TESTS(8, 4) |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
39 CREATE_TESTS(16, 2) |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
40 |
15
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
41 CREATE_TESTS(8, 8) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
42 CREATE_TESTS(16, 4) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
43 CREATE_TESTS(32, 2) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
44 |
9
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
45 CREATE_TESTS(8, 16) |
15
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
46 CREATE_TESTS(16, 8) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
47 CREATE_TESTS(32, 4) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
48 CREATE_TESTS(64, 2) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
49 |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
50 CREATE_TESTS(8, 32) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
51 CREATE_TESTS(16, 16) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
52 CREATE_TESTS(32, 8) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
53 CREATE_TESTS(64, 4) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
54 |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
55 CREATE_TESTS(8, 64) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
56 CREATE_TESTS(16, 32) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
57 CREATE_TESTS(32, 16) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
58 CREATE_TESTS(64, 8) |
9
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
59 |
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
60 #undef CREATE_TESTS_SIGN |
2
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
61 #undef CREATE_TESTS |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
62 #undef CREATE_TEST |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
63 |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
64 static int test_compare(void) |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
65 { |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
66 int ret = 0; |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
67 |
9
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
68 #define RUN_TESTS_SIGN(sign, bits, size) \ |
2
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
69 for (size_t i = 0U; i < ARRAY_SIZE(testval##sign##bits); i++) { \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
70 const v##sign##int##bits##x##size a = vtest##sign##bits##x##size(i); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
71 for (size_t j = 0U; j < ARRAY_SIZE(testval##sign##bits); j++) { \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
72 const v##sign##int##bits##x##size b = vtest##sign##bits##x##size(j); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
73 ret |= test_compare_v##sign##int##bits##x##size##_cmplt(a, b); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
74 ret |= test_compare_v##sign##int##bits##x##size##_cmpgt(a, b); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
75 ret |= test_compare_v##sign##int##bits##x##size##_cmpeq(a, b); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
76 ret |= test_compare_v##sign##int##bits##x##size##_cmple(a, b); \ |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
77 ret |= test_compare_v##sign##int##bits##x##size##_cmpge(a, b); \ |
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 } |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
80 |
9
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
81 #define RUN_TESTS(bits, size) \ |
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
82 RUN_TESTS_SIGN( , bits, size) \ |
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
83 RUN_TESTS_SIGN(u, bits, size) |
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
84 |
17
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
85 RUN_TESTS(8, 2) |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
86 |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
87 RUN_TESTS(8, 4) |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
88 RUN_TESTS(16, 2) |
41dd962abdd1
*: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents:
15
diff
changeset
|
89 |
15
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
90 RUN_TESTS(8, 8) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
91 RUN_TESTS(16, 4) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
92 RUN_TESTS(32, 2) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
93 |
9
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
94 RUN_TESTS(8, 16) |
15
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
95 RUN_TESTS(16, 8) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
96 RUN_TESTS(32, 4) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
97 RUN_TESTS(64, 2) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
98 |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
99 RUN_TESTS(8, 32) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
100 RUN_TESTS(16, 16) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
101 RUN_TESTS(32, 8) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
102 RUN_TESTS(64, 4) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
103 |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
104 RUN_TESTS(8, 64) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
105 RUN_TESTS(16, 32) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
106 RUN_TESTS(32, 16) |
e05c257c6a23
*: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
13
diff
changeset
|
107 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
|
108 |
6ff0b7a44bb6
generic: add initial support for 256-bit and 512-bit types
Paper <paper@tflc.us>
parents:
4
diff
changeset
|
109 #undef RUN_TESTS_SIGN |
2
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
110 #undef RUN_TESTS |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
111 |
f12b5dd4e18c
*: many new operations and a real test suite
Paper <paper@tflc.us>
parents:
diff
changeset
|
112 return ret; |
20
627d548b23c8
impl/generic: fix load and store implementations
Paper <paper@tflc.us>
parents:
17
diff
changeset
|
113 } |