annotate test/test.c @ 29:e59c91d050c0

*: add aligned malloc stuff :)
author Paper <paper@tflc.us>
date Thu, 24 Apr 2025 17:12:05 -0400
parents cf04071d2148
children 641d8c79b1da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
1 #include "vec/vec.h"
29
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 18
diff changeset
2 #include "vec/mem.h"
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
3
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
4 #include <stdio.h>
17
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
5 #include <string.h>
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
6 #include <inttypes.h>
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
7
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
8 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
9
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
10 static const int8_t testval8[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
11 INT8_C(-80), INT8_C(-3), INT8_C(25), INT8_C(0x7F),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
12 INT8_C(-42), INT8_C(27), INT8_C(24), INT8_C(0x40),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
13 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
14
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
15 static const uint8_t testvalu8[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
16 UINT8_C(0x00), UINT8_C(0xFF), UINT8_C(0xFE), UINT8_C(0x7F),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
17 UINT8_C(0xC0), UINT8_C(0x80), UINT8_C(0x20), UINT8_C(0x50),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
18 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
19
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
20 static const int16_t testval16[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
21 INT16_C(-8000), INT16_C(-30), INT16_MAX, INT16_C(0x4000),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
22 INT16_C(-42), INT16_C(250), INT16_MIN, INT16_C(0x500),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
23 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
24
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
25 static const uint16_t testvalu16[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
26 UINT16_C(0x0000), UINT16_C(0xFFFF), UINT16_C(0xFEA), UINT16_C(0x7FF),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
27 UINT16_C(0x7FFF), UINT16_C(0x8000), UINT16_C(0x20B), UINT16_C(0x50C),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
28 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
29
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
30 static const int32_t testval32[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
31 INT32_C(-1000000), INT32_C(-3), INT32_C(0x00000000), INT32_C(0xFFFFFFFF),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
32 INT32_C( -42), INT32_C(27), INT32_C(0xABCDEF03), INT32_C(0x00000FFF),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
33 INT32_C(0xFFFFFFFF), INT32_C( 0), INT32_C(0xFFFFFFFE), INT32_C( 1),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
34 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
35
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
36 static const uint32_t testvalu32[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
37 UINT32_C(0x00000000), UINT32_C(0xDEADBEEF), UINT32_C(42), UINT32_C(0x12340000),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
38 UINT32_C(0xFFFFFFFF), UINT32_C(0xFEDCBA98), UINT32_C(17), UINT32_C(0x00012345),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
39 UINT32_C(0xFFFFFFFF), UINT32_C(0xFFFFFFFE), UINT32_C( 0), UINT32_C( 1),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
40 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
41
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
42 static const int64_t testval64[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
43 INT64_MAX, INT64_C(-3), INT64_C(0x00000000), INT64_C(0xFFFFFFFFF),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
44 INT64_MIN, INT64_C(645366), INT64_C(0x12345ABCDE), INT64_C(0xF00000FFF),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
45 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
46
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
47 static const uint64_t testvalu64[] = {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
48 UINT64_MAX, UINT64_C(0x44354365), UINT64_C(0x00000000), UINT64_C(0xFFFFFFFFF),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
49 UINT64_C(0xff), UINT64_C(645366), UINT64_C(0x12345ABCDE), UINT64_C(0xF00000FFF),
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
50 };
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
51
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
52 #define VTEST(sign, csign, bits, size) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
53 static inline v##sign##int##bits##x##size vtest##sign##bits##x##size(const size_t start) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
54 { \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
55 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(x); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
56 for (size_t i = 0; i < size; i++) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
57 x[i] = testval##sign##bits[(start + i) % ARRAY_SIZE(testval##sign##bits)]; \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
58 return v##sign##int##bits##x##size##_load_aligned(x); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
59 }
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
60
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
61 #define VPRINT(sign, csign, psign, bits, size) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
62 static inline void print_v##sign##int##bits##x##size(FILE *file, v##sign##int##bits##x##size vec) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
63 { \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
64 fputs("vector: ", file); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
65 \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
66 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(v); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
67 \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
68 v##sign##int##bits##x##size##_store_aligned(vec, v); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
69 \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
70 fprintf(file, "%" PRI ## psign ## bits, v[0]); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
71 \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
72 for (int i = 1; i < size; i++) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
73 fprintf(file, ", %" PRI ## psign ## bits, v[i]); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
74 \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
75 fputs("\n", file); \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
76 \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
77 }
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
78
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
79 #define DEF_VEC_TEST_FUNCS(bits, size) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
80 VTEST(, , bits, size) VTEST(u, U, bits, size) \
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
81 VPRINT(, , d, bits, size) VPRINT(u, U, u, bits, size)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
82
17
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
83 DEF_VEC_TEST_FUNCS(8, 2)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
84
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
85 DEF_VEC_TEST_FUNCS(8, 4)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
86 DEF_VEC_TEST_FUNCS(16, 2)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
87
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
88 DEF_VEC_TEST_FUNCS(8, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
89 DEF_VEC_TEST_FUNCS(16, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
90 DEF_VEC_TEST_FUNCS(32, 2)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
91
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
92 DEF_VEC_TEST_FUNCS(8, 16)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
93 DEF_VEC_TEST_FUNCS(16, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
94 DEF_VEC_TEST_FUNCS(32, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
95 DEF_VEC_TEST_FUNCS(64, 2)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
96
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
97 DEF_VEC_TEST_FUNCS(8, 32)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
98 DEF_VEC_TEST_FUNCS(16, 16)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
99 DEF_VEC_TEST_FUNCS(32, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
100 DEF_VEC_TEST_FUNCS(64, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
101
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
102 DEF_VEC_TEST_FUNCS(8, 64)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
103 DEF_VEC_TEST_FUNCS(16, 32)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
104 DEF_VEC_TEST_FUNCS(32, 16)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
105 DEF_VEC_TEST_FUNCS(64, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
106
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
107 #undef DEF_VEC_TEST_FUNCS
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
108 #undef VPRINT
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
109 #undef VTEST
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
110
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
111 // ------------------------------------------------------------
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
112
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
113 #include "test_align.h"
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
114 #include "test_arith.h"
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
115 #include "test_compare.h"
18
cf04071d2148 impl: initial NEON support; test: verify bit shifting functions
Paper <paper@tflc.us>
parents: 17
diff changeset
116 #include "test_shift.h"
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
117
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
118 // ------------------------------------------------------------
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
119
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
120 int main(void)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
121 {
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
122 int ret = 0;
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
123
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
124 vec_init();
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
125
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
126 ret |= test_align();
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
127 ret |= test_arith();
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
128 ret |= test_compare();
18
cf04071d2148 impl: initial NEON support; test: verify bit shifting functions
Paper <paper@tflc.us>
parents: 17
diff changeset
129 ret |= test_shift();
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
130
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
131 return ret;
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents:
diff changeset
132 }