The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.1 KiB
94 lines
2.1 KiB
8 years ago
|
#include<simdfuncs.h>
|
||
|
#include<stdio.h>
|
||
|
|
||
|
/*
|
||
8 years ago
|
* 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.
|
||
8 years ago
|
*/
|
||
|
|
||
|
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;
|
||
8 years ago
|
const char *type;
|
||
8 years ago
|
int i;
|
||
8 years ago
|
|
||
8 years ago
|
/* Add here. The first matched one is used so put "better" instruction
|
||
|
* sets at the top.
|
||
|
*/
|
||
8 years ago
|
#if HAVE_NEON
|
||
|
if(fptr == NULL && neon_available()) {
|
||
|
fptr = increment_neon;
|
||
|
type = "NEON";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_AVX2
|
||
|
if(fptr == NULL && avx2_available()) {
|
||
|
fptr = increment_avx2;
|
||
|
type = "AVX2";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_AVX
|
||
|
if(fptr == NULL && avx_available()) {
|
||
|
fptr = increment_avx;
|
||
|
type = "AVX";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_SSE42
|
||
|
if(fptr == NULL && sse42_available()) {
|
||
|
fptr = increment_sse42;
|
||
|
type = "SSE42";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_SSE41
|
||
|
if(fptr == NULL && sse41_available()) {
|
||
|
fptr = increment_sse41;
|
||
|
type = "SSE41";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_SSSE3
|
||
|
if(fptr == NULL && ssse3_available()) {
|
||
|
fptr = increment_ssse3;
|
||
|
type = "SSSE3";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_SSE3
|
||
|
if(fptr == NULL && sse3_available()) {
|
||
|
fptr = increment_sse3;
|
||
|
type = "SSE3";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_SSE2
|
||
|
if(fptr == NULL && sse2_available()) {
|
||
|
fptr = increment_sse2;
|
||
|
type = "SSE2";
|
||
|
}
|
||
|
#endif
|
||
8 years ago
|
#if HAVE_SSE
|
||
8 years ago
|
if(fptr == NULL && sse_available()) {
|
||
|
fptr = increment_sse;
|
||
|
type = "SSE";
|
||
|
}
|
||
|
#endif
|
||
|
#if HAVE_MMX
|
||
8 years ago
|
if(fptr == NULL && mmx_available()) {
|
||
8 years ago
|
fptr = increment_mmx;
|
||
8 years ago
|
type = "MMX";
|
||
8 years ago
|
}
|
||
|
#endif
|
||
|
if(fptr == NULL) {
|
||
|
fptr = increment_fallback;
|
||
8 years ago
|
type = "fallback";
|
||
8 years ago
|
}
|
||
8 years ago
|
printf("Using %s.\n", type);
|
||
8 years ago
|
fptr(four);
|
||
8 years ago
|
for(i=0; i<4; i++) {
|
||
8 years ago
|
if(four[i] != expected[i]) {
|
||
8 years ago
|
printf("Increment function failed, got %f expected %f.\n", four[i], expected[i]);
|
||
8 years ago
|
return 1;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|