comparison 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
comparison
equal deleted inserted replaced
44:b0a3f0248ecc 45:7955bed1d169
1 static int test_align(void) 1 static int test_align(void)
2 { 2 {
3 int ret = 0; 3 int ret = 0;
4 4
5 #define RUN_TEST(sign, csign, bits, size) \ 5 #define RUN_TEST(type, ctype, bits, size) \
6 do { \ 6 do { \
7 int i; \
7 /* allocate the aligned array */ \ 8 /* allocate the aligned array */ \
8 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr); \ 9 V##ctype##bits##x##size##_ALIGNED_ARRAY(vec_arr); \
9 \ 10 \
10 /* fill the values */ \ 11 /* fill the values */ \
11 for (int i = 0; i < size; i++) \ 12 for (i = 0; i < size; i++) \
12 vec_arr[i] = i; \ 13 vec_arr[i] = i; \
13 \ 14 \
14 /* try to load it */ \ 15 /* try to load it */ \
15 v##sign##int##bits##x##size vec = v##sign##int##bits##x##size##_load_aligned(vec_arr); \ 16 v##type##bits##x##size vec = v##type##bits##x##size##_load(vec_arr); \
16 \ 17 \
17 /* now allocate an output array */ \ 18 /* now allocate an output array */ \
18 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr_out); \ 19 V##ctype##bits##x##size##_ALIGNED_ARRAY(vec_arr_out); \
19 \ 20 \
20 /* try storing it */ \ 21 /* try storing it */ \
21 v##sign##int##bits##x##size##_store_aligned(vec, vec_arr_out); \ 22 v##type##bits##x##size##_store_aligned(vec, vec_arr_out); \
22 \ 23 \
23 /* mark success or failure */ \ 24 /* mark success or failure */ \
24 ret |= !!memcmp(vec_arr, vec_arr_out, size * sizeof(*vec_arr)); \ 25 ret |= !!memcmp(vec_arr, vec_arr_out, size * (bits / 8)); \
25 \ 26 \
26 ret |= !V##csign##INT##bits##x##size##_PTR_ALIGNED(vec_arr); \ 27 ret |= !V##ctype##bits##x##size##_PTR_ALIGNED(vec_arr); \
27 ret |= !V##csign##INT##bits##x##size##_PTR_ALIGNED(vec_arr_out); \ 28 ret |= !V##ctype##bits##x##size##_PTR_ALIGNED(vec_arr_out); \
28 } while (0); 29 } while (0);
29 30
30 #define RUN_TESTS(bits, size) \ 31 #define RUN_TESTS(bits, size) \
31 RUN_TEST( , , bits, size) \ 32 RUN_TEST(int, INT, bits, size) \
32 RUN_TEST(u, U, bits, size) 33 RUN_TEST(uint, UINT, bits, size)
33 34
34 RUN_TESTS(8, 2) 35 RUN_TESTS(8, 2)
35 36
36 RUN_TESTS(8, 4) 37 RUN_TESTS(8, 4)
37 RUN_TESTS(16, 2) 38 RUN_TESTS(16, 2)
54 RUN_TESTS(16, 32) 55 RUN_TESTS(16, 32)
55 RUN_TESTS(32, 16) 56 RUN_TESTS(32, 16)
56 RUN_TESTS(64, 8) 57 RUN_TESTS(64, 8)
57 58
58 #undef RUN_TESTS 59 #undef RUN_TESTS
60
61 /* floating point */
62 RUN_TEST(f, F, 32, 2)
63 RUN_TEST(f, F, 32, 4)
64 RUN_TEST(f, F, 32, 8)
65 RUN_TEST(f, F, 32, 16)
66
67 RUN_TEST(f, F, 64, 2)
68 RUN_TEST(f, F, 64, 4)
69 RUN_TEST(f, F, 64, 8)
70
59 #undef RUN_TEST 71 #undef RUN_TEST
60 72
61 return ret; 73 return ret;
62 } 74 }