comparison test/test.c @ 15:e05c257c6a23

*: huge refactor, add many new x86 intrinsics and the like ALSO!! now intrinsics are enabled at runtime, depending on what is detected. altivec *should* still work but I only tested compiling it. the major version has been updated to 2.0 for this...
author Paper <paper@tflc.us>
date Wed, 20 Nov 2024 04:10:37 -0500
parents
children 41dd962abdd1
comparison
equal deleted inserted replaced
14:981cf0bc7f3a 15:e05c257c6a23
1 #include "vec/vec.h"
2
3 #include <stdio.h>
4 #include <inttypes.h>
5
6 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
7
8 static const int8_t testval8[] = {
9 INT8_C(-80), INT8_C(-3), INT8_C(25), INT8_C(0x7F),
10 INT8_C(-42), INT8_C(27), INT8_C(24), INT8_C(0x40),
11 };
12
13 static const uint8_t testvalu8[] = {
14 UINT8_C(0x00), UINT8_C(0xFF), UINT8_C(0xFE), UINT8_C(0x7F),
15 UINT8_C(0xC0), UINT8_C(0x80), UINT8_C(0x20), UINT8_C(0x50),
16 };
17
18 static const int16_t testval16[] = {
19 INT16_C(-8000), INT16_C(-30), INT16_MAX, INT16_C(0x4000),
20 INT16_C(-42), INT16_C(250), INT16_MIN, INT16_C(0x500),
21 };
22
23 static const uint16_t testvalu16[] = {
24 UINT16_C(0x0000), UINT16_C(0xFFFF), UINT16_C(0xFEA), UINT16_C(0x7FF),
25 UINT16_C(0x7FFF), UINT16_C(0x8000), UINT16_C(0x20B), UINT16_C(0x50C),
26 };
27
28 static const int32_t testval32[] = {
29 INT32_C(-1000000), INT32_C(-3), INT32_C(0x00000000), INT32_C(0xFFFFFFFF),
30 INT32_C( -42), INT32_C(27), INT32_C(0xABCDEF03), INT32_C(0x00000FFF),
31 INT32_C(0xFFFFFFFF), INT32_C( 0), INT32_C(0xFFFFFFFE), INT32_C( 1),
32 };
33
34 static const uint32_t testvalu32[] = {
35 UINT32_C(0x00000000), UINT32_C(0xDEADBEEF), UINT32_C(42), UINT32_C(0x12340000),
36 UINT32_C(0xFFFFFFFF), UINT32_C(0xFEDCBA98), UINT32_C(17), UINT32_C(0x00012345),
37 UINT32_C(0xFFFFFFFF), UINT32_C(0xFFFFFFFE), UINT32_C( 0), UINT32_C( 1),
38 };
39
40 static const int64_t testval64[] = {
41 INT64_MAX, INT64_C(-3), INT64_C(0x00000000), INT64_C(0xFFFFFFFFF),
42 INT64_MIN, INT64_C(645366), INT64_C(0x12345ABCDE), INT64_C(0xF00000FFF),
43 };
44
45 static const uint64_t testvalu64[] = {
46 UINT64_MAX, UINT64_C(0x44354365), UINT64_C(0x00000000), UINT64_C(0xFFFFFFFFF),
47 UINT64_C(0xff), UINT64_C(645366), UINT64_C(0x12345ABCDE), UINT64_C(0xF00000FFF),
48 };
49
50 #define VTEST(sign, csign, bits, size) \
51 static inline v##sign##int##bits##x##size vtest##sign##bits##x##size(const size_t start) \
52 { \
53 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(x); \
54 for (size_t i = 0; i < size; i++) \
55 x[i] = testval##sign##bits[(start + i) % ARRAY_SIZE(testval##sign##bits)]; \
56 return v##sign##int##bits##x##size##_load_aligned(x); \
57 }
58
59 #define VPRINT(sign, csign, psign, bits, size) \
60 static inline void print_v##sign##int##bits##x##size(FILE *file, v##sign##int##bits##x##size vec) \
61 { \
62 fputs("vector: ", file); \
63 \
64 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(v); \
65 \
66 v##sign##int##bits##x##size##_store_aligned(vec, v); \
67 \
68 fprintf(file, "%" PRI ## psign ## bits, v[0]); \
69 \
70 for (int i = 1; i < size; i++) \
71 fprintf(file, ", %" PRI ## psign ## bits, v[i]); \
72 \
73 fputs("\n", file); \
74 \
75 }
76
77 #define DEF_VEC_TEST_FUNCS(bits, size) \
78 VTEST(, , bits, size) VTEST(u, U, bits, size) \
79 VPRINT(, , d, bits, size) VPRINT(u, U, u, bits, size)
80
81 DEF_VEC_TEST_FUNCS(8, 8)
82 DEF_VEC_TEST_FUNCS(16, 4)
83 DEF_VEC_TEST_FUNCS(32, 2)
84
85 DEF_VEC_TEST_FUNCS(8, 16)
86 DEF_VEC_TEST_FUNCS(16, 8)
87 DEF_VEC_TEST_FUNCS(32, 4)
88 DEF_VEC_TEST_FUNCS(64, 2)
89
90 DEF_VEC_TEST_FUNCS(8, 32)
91 DEF_VEC_TEST_FUNCS(16, 16)
92 DEF_VEC_TEST_FUNCS(32, 8)
93 DEF_VEC_TEST_FUNCS(64, 4)
94
95 DEF_VEC_TEST_FUNCS(8, 64)
96 DEF_VEC_TEST_FUNCS(16, 32)
97 DEF_VEC_TEST_FUNCS(32, 16)
98 DEF_VEC_TEST_FUNCS(64, 8)
99
100 #undef DEF_VEC_TEST_FUNCS
101 #undef VPRINT
102 #undef VTEST
103
104 // ------------------------------------------------------------
105
106 #include "test_align.h"
107 #include "test_arith.h"
108 #include "test_compare.h"
109
110 // ------------------------------------------------------------
111
112 int main(void)
113 {
114 int ret = 0;
115
116 vec_init();
117
118 ret |= test_align();
119 ret |= test_arith();
120 ret |= test_compare();
121
122 return ret;
123 }