Debian Codegraph @

test cases/common/147 simd/simdchecker.c

raw
1 #include<simdfuncs.h>
2 #include<stdio.h>
3 #include<string.h>
4
5 typedef void (*simd_func)(float*);
6
7 int check_simd_implementation(float *four,
8 const float *four_initial,
9 const char *simd_type,
10 const float *expected,
11 simd_func fptr,
12 const int blocksize) {
13 int rv = 0;
14 memcpy(four, four_initial, blocksize*sizeof(float));
15 printf("Using %s.\n", simd_type);
16 fptr(four);
17 for(int i=0; i<blocksize; i++) {
18 if(four[i] != expected[i]) {
19 printf("Increment function failed, got %f expected %f.\n", four[i], expected[i]);
20 rv = 1;
21 }
22 }
23 return rv;
24 }
25
26 int main(void) {
27 static const float four_initial[4] = {2.0, 3.0, 4.0, 5.0};
28 ALIGN_16 float four[4];
29 const float expected[4] = {3.0, 4.0, 5.0, 6.0};
30 int r=0;
31 const int blocksize = 4;
32
33 /*
34 * Test all implementations that the current CPU supports.
35 */
36 #if HAVE_NEON
37 if(neon_available()) {
38 r += check_simd_implementation(four,
39 four_initial,
40 "NEON",
41 expected,
42 increment_neon,
43 blocksize);
44 }
45 #endif
46 #if HAVE_AVX2
47 if(avx2_available()) {
48 r += check_simd_implementation(four,
49 four_initial,
50 "AVX2",
51 expected,
52 increment_avx2,
53 blocksize);
54 }
55 #endif
56 #if HAVE_AVX
57 if(avx_available()) {
58 r += check_simd_implementation(four,
59 four_initial,
60 "AVC",
61 expected,
62 increment_avx,
63 blocksize);
64 }
65 #endif
66 #if HAVE_SSE42
67 if(sse42_available()) {
68 r += check_simd_implementation(four,
69 four_initial,
70 "SSR42",
71 expected,
72 increment_sse42,
73 blocksize);
74 }
75 #endif
76 #if HAVE_SSE41
77 if(sse41_available()) {
78 r += check_simd_implementation(four,
79 four_initial,
80 "SSE41",
81 expected,
82 increment_sse41,
83 blocksize);
84 }
85 #endif
86 #if HAVE_SSSE3
87 if(ssse3_available()) {
88 r += check_simd_implementation(four,
89 four_initial,
90 "SSSE3",
91 expected,
92 increment_ssse3,
93 blocksize);
94 }
95 #endif
96 #if HAVE_SSE3
97 if(sse3_available()) {
98 r += check_simd_implementation(four,
99 four_initial,
100 "SSE3",
101 expected,
102 increment_sse3,
103 blocksize);
104 }
105 #endif
106 #if HAVE_SSE2
107 if(sse2_available()) {
108 r += check_simd_implementation(four,
109 four_initial,
110 "SSE2",
111 expected,
112 increment_sse2,
113 blocksize);
114 }
115 #endif
116 #if HAVE_SSE
117 if(sse_available()) {
118 r += check_simd_implementation(four,
119 four_initial,
120 "SSE",
121 expected,
122 increment_sse,
123 blocksize);
124 }
125 #endif
126 #if HAVE_MMX
127 if(mmx_available()) {
128 r += check_simd_implementation(four,
129 four_initial,
130 "MMX",
131 expected,
132 increment_mmx,
133 blocksize);
134 }
135 #endif
136 r += check_simd_implementation(four,
137 four_initial,
138 "fallback",
139 expected,
140 increment_fallback,
141 blocksize);
142 return r;
143 }