annotate test/test_align.h @ 3:3c5545b1568f

*: much better alignment support & tests
author Paper <paper@tflc.us>
date Tue, 22 Oct 2024 23:27:15 -0400
parents
children 75ab77f874e2
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
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
5 #define RUN_TEST(sign, csign, bits, size) \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
6 do { \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
7 /* allocate the aligned array */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
8 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr); \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
9 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
10 /* fill the values */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
11 for (int i = 0; i < V##csign##INT##bits##x##size##_ALIGNED_ARRAY_LENGTH(vec_arr); i++) \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
12 vec_arr[i] = i; \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
13 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
14 /* try to load it */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
15 v##sign##int##bits##x##size vec = v##sign##int##bits##x##size##_load_aligned(vec_arr); \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
16 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
17 /* now allocate an output array */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
18 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr_out); \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
19 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
20 /* try storing it */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
21 v##sign##int##bits##x##size##_store_aligned(vec, vec_arr_out); \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
22 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
23 /* mark success or failure */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
24 ret |= !!memcmp(vec_arr, vec_arr_out, V##csign##INT##bits##x##size##_ALIGNED_ARRAY_LENGTH(vec_arr)); \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
25 } while (0);
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
26
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
27 #define RUN_TESTS(bits, size) \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
28 RUN_TEST( , , bits, size) \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
29 RUN_TEST(u, U, bits, size)
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 RUN_TESTS(8, 16)
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
32 RUN_TESTS(16, 8)
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
33 RUN_TESTS(32, 4)
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
34 RUN_TESTS(64, 2)
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
35
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
36 #undef RUN_TESTS
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
37 #undef RUN_TEST
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
38
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
39 return ret;
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
40 }