annotate test/test_align.h @ 29:e59c91d050c0

*: add aligned malloc stuff :)
author Paper <paper@tflc.us>
date Thu, 24 Apr 2025 17:12:05 -0400
parents 41dd962abdd1
children 641d8c79b1da
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;
29
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
4 int i;
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
5
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
6 #define RUN_TEST(sign, csign, bits, size) \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
7 do { \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
8 /* allocate the aligned array */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
9 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr); \
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 */ \
29
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
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 */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
16 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
17 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
18 /* now allocate an output array */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
19 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(vec_arr_out); \
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 */ \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
22 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
23 \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
24 /* mark success or failure */ \
13
53197dbf4e8e vec.h: initial refactor for runtime SSE and stuff
Paper <paper@tflc.us>
parents: 9
diff changeset
25 ret |= !!memcmp(vec_arr, vec_arr_out, size * sizeof(*vec_arr)); \
4
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
26 \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
27 ret |= !V##csign##INT##bits##x##size##_PTR_ALIGNED(vec_arr); \
75ab77f874e2 *: aligned generics, fixed altivec, aligned tests...
Paper <paper@tflc.us>
parents: 3
diff changeset
28 ret |= !V##csign##INT##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) \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
32 RUN_TEST( , , bits, size) \
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
33 RUN_TEST(u, U, bits, size)
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
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
60 #undef RUN_TEST
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
61
29
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
62 for (i = 0; i < 50; i++) {
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
63 void *q = vec_malloc(i);
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
64
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
65 ret |= !!((uintptr_t)q & 63);
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
66
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
67 /* try a bigger size */
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
68 q = vec_realloc(q, i + 10);
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
69
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
70 ret |= !!((uintptr_t)q & 63);
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
71
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
72 /* now a smaller one */
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
73 q = vec_realloc(q, i - 10);
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
74
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
75 ret |= !!((uintptr_t)q & 63);
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
76
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
77 vec_free(q);
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
78 }
e59c91d050c0 *: add aligned malloc stuff :)
Paper <paper@tflc.us>
parents: 17
diff changeset
79
3
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
80 return ret;
3c5545b1568f *: much better alignment support & tests
Paper <paper@tflc.us>
parents:
diff changeset
81 }