aboutsummaryrefslogtreecommitdiff
path: root/test cases/common/139 simd/simdchecker.c
blob: 1502ae7d197cc2a4b66f642d6439d408aaa31512 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<simdfuncs.h>
#include<stdio.h>

/*
 * A function that checks at runtime which simd accelerations are
 * available and calls the best one. Falls
 * back to plain C implementation if SIMD is not available.
 */

int main(int argc, char **argv) {
    float four[4] = {2.0, 3.0, 4.0, 5.0};
    const float expected[4] = {3.0, 4.0, 5.0, 6.0};
    void (*fptr)(float[4]) = NULL;
    const char *type;
    int i;

/* Add here. The first matched one is used so put "better" instruction
 * sets at the top.
 */
#if HAVE_AVX2
    if(fptr == NULL && avx2_available()) {
        fptr = increment_avx2;
        type = "AVX2";
    }
#endif
#if HAVE_AVX
    if(fptr == NULL && avx_available()) {
        fptr = increment_avx;
        type = "AVX";
    }
#endif
#if HAVE_SSE42
    if(fptr == NULL && sse42_available()) {
        fptr = increment_sse42;
        type = "SSE42";
    }
#endif
#if HAVE_SSE41
    if(fptr == NULL && sse41_available()) {
        fptr = increment_sse41;
        type = "SSE41";
    }
#endif
#if HAVE_SSSE3
    if(fptr == NULL && ssse3_available()) {
        fptr = increment_ssse3;
        type = "SSSE3";
    }
#endif
#if HAVE_SSE3
    if(fptr == NULL && sse3_available()) {
        fptr = increment_sse3;
        type = "SSE3";
    }
#endif
#if HAVE_SSE2
    if(fptr == NULL && sse2_available()) {
        fptr = increment_sse2;
        type = "SSE2";
    }
#endif
#if HAVE_SSE
    if(fptr == NULL && sse_available()) {
        fptr = increment_sse;
        type = "SSE";
    }
#endif
#if HAVE_MMX
    if(fptr == NULL && mmx_available()) {
        fptr = increment_mmx;
        type = "MMX";
    }
#endif
    if(fptr == NULL) {
        fptr = increment_fallback;
        type = "fallback";
    }
    printf("Using %s.\n", type);
    fptr(four);
    for(i=0; i<4; i++) {
        if(four[i] != expected[i]) {
            printf("Increment function failed, got %f expected %f.\n", four[i], expected[i]);
            return 1;
        }
    }
    return 0;
}