Debian Codegraph @

test cases/common/147 simd/simd_avx.c

raw
1 #include<simdheader.h>
2
3 #ifndef I_CAN_HAZ_SIMD
4 #error The correct internal header was not used
5 #endif
6
7 #include<simdconfig.h>
8 #include<simdfuncs.h>
9 #include<stdint.h>
10
11 #ifdef _MSC_VER
12 #include<intrin.h>
13 int avx_available(void) {
14 return 1;
15 }
16 #else
17 #include<immintrin.h>
18 #include<cpuid.h>
19
20 #ifdef __APPLE__
21 /*
22 * Apple ships a broken __builtin_cpu_supports and
23 * some machines in the CI farm seem to be too
24 * old to have AVX so just always return 0 here.
25 */
26 int avx_available(void) { return 0; }
27 #else
28
29 int avx_available(void) {
30 return __builtin_cpu_supports("avx");
31 }
32 #endif
33 #endif
34
35 void increment_avx(float arr[4]) {
36 double darr[4];
37 darr[0] = arr[0];
38 darr[1] = arr[1];
39 darr[2] = arr[2];
40 darr[3] = arr[3];
41 __m256d val = _mm256_loadu_pd(darr);
42 __m256d one = _mm256_set1_pd(1.0);
43 __m256d result = _mm256_add_pd(val, one);
44 _mm256_storeu_pd(darr, result);
45 arr[0] = (float)darr[0];
46 arr[1] = (float)darr[1];
47 arr[2] = (float)darr[2];
48 arr[3] = (float)darr[3];
49 }