annotate test/test_align.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 641d8c79b1da
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
1 static int test_align(void)
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
2 {
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
3 int ret = 0;
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
4
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
5 #define RUN_TEST(type, ctype, bits, size) \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
6 do { \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
7 int i; \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
8 /* allocate the aligned array */ \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
9 V##ctype##bits##x##size##_ALIGNED_ARRAY(vec_arr); \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
10 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
11 /* fill the values */ \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
12 for (i = 0; i < size; i++) \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
13 vec_arr[i] = i; \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
14 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
15 /* try to load it */ \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
16 v##type##bits##x##size vec = v##type##bits##x##size##_load(vec_arr); \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
17 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
18 /* now allocate an output array */ \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
19 V##ctype##bits##x##size##_ALIGNED_ARRAY(vec_arr_out); \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
20 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
21 /* try storing it */ \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
22 v##type##bits##x##size##_store_aligned(vec, vec_arr_out); \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
23 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
24 /* mark success or failure */ \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
25 ret |= !!memcmp(vec_arr, vec_arr_out, size * (bits / 8)); \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
26 \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
27 ret |= !V##ctype##bits##x##size##_PTR_ALIGNED(vec_arr); \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
28 ret |= !V##ctype##bits##x##size##_PTR_ALIGNED(vec_arr_out); \
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
29 } while (0);
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
30
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
31 #define RUN_TESTS(bits, size) \
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
32 RUN_TEST(int, INT, bits, size) \
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
33 RUN_TEST(uint, UINT, bits, size)
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
34
17
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
35 RUN_TESTS(8, 2)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
36
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
37 RUN_TESTS(8, 4)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
38 RUN_TESTS(16, 2)
41dd962abdd1 *: allow compiling vec in a C++ translation unit
Paper <paper@tflc.us>
parents: 15
diff changeset
39
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
40 RUN_TESTS(8, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
41 RUN_TESTS(16, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
42 RUN_TESTS(32, 2)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
43
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
44 RUN_TESTS(8, 16)
15
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
45 RUN_TESTS(16, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
46 RUN_TESTS(32, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
47 RUN_TESTS(64, 2)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
48
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
49 RUN_TESTS(8, 32)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
50 RUN_TESTS(16, 16)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
51 RUN_TESTS(32, 8)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
52 RUN_TESTS(64, 4)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
53
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
54 RUN_TESTS(8, 64)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
55 RUN_TESTS(16, 32)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
56 RUN_TESTS(32, 16)
e05c257c6a23 *: huge refactor, add many new x86 intrinsics and the like
Paper <paper@tflc.us>
parents: 13
diff changeset
57 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
58
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
59 #undef RUN_TESTS
45
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
60
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
61 /* floating point */
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
62 RUN_TEST(f, F, 32, 2)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
63 RUN_TEST(f, F, 32, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
64 RUN_TEST(f, F, 32, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
65 RUN_TEST(f, F, 32, 16)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
66
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
67 RUN_TEST(f, F, 64, 2)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
68 RUN_TEST(f, F, 64, 4)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
69 RUN_TEST(f, F, 64, 8)
7955bed1d169 *: add preliminary floating point support
Paper <paper@tflc.us>
parents: 30
diff changeset
70
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
71 #undef RUN_TEST
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
72
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
73 return ret;
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
74 }