diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,6 +244,7 @@ if(NOT DEFINED X86CPU_ARCH AND ARCH STREQUAL "x86") include(DetectArchitecture) detect_x86_cpu_architecture(X86CPU_ARCH) + detect_x86_feature(sse2 HAVE_X86_SSE2_INSTRUCTIONS) endif() if(NOT DEFINED ENDIAN) include(TestBigEndian) diff --git a/SingleSource/UnitTests/Vectorizer/CMakeLists.txt b/SingleSource/UnitTests/Vectorizer/CMakeLists.txt --- a/SingleSource/UnitTests/Vectorizer/CMakeLists.txt +++ b/SingleSource/UnitTests/Vectorizer/CMakeLists.txt @@ -1,2 +1,10 @@ +# currently libmvec vectorizer only has support for x86 SSE2 - +# no need to run test if code doesn't get vectorized +if(HAVE_X86_SSE2_INSTRUCTIONS) + check_c_compiler_flag(-fveclib=libmvec COMPILER_HAS_FVECLIB_LIBMVEC_FLAG) + if(COMPILER_HAS_FVECLIB_LIBMVEC_FLAG) + add_subdirectory(Libmvec) + endif() +endif() llvm_singlesource() set_property(TARGET runtime-checks PROPERTY CXX_STANDARD 17) diff --git a/SingleSource/UnitTests/Vectorizer/Libmvec/CMakeLists.txt b/SingleSource/UnitTests/Vectorizer/Libmvec/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/Vectorizer/Libmvec/CMakeLists.txt @@ -0,0 +1,3 @@ +list(APPEND LDFLAGS -lm -fveclib=libmvec) +list(APPEND CFLAGS -fveclib=libmvec -O2 -march=native) +llvm_singlesource(PREFIX "Vectorizer-Libmvec-") diff --git a/SingleSource/UnitTests/Vectorizer/Libmvec/sincos.c b/SingleSource/UnitTests/Vectorizer/Libmvec/sincos.c new file mode 100644 --- /dev/null +++ b/SingleSource/UnitTests/Vectorizer/Libmvec/sincos.c @@ -0,0 +1,115 @@ +#define _GNU_SOURCE + +#include +#include + +// inner loop vectorization with linear access +void sincos_arr(double* sines, double* cosines, double* phases, int size) { + for (int i=0; i max_ulp_err * ulp) { + printf("%s,%s FAILED at %d: argument %g, value %g, reference %g, difference %g, (%g ULP).\n", + msg1, msg2, index, arg, val, ref, (val-ref), fabs(val-ref)/ulp); + return 1; + } + return 0; +} + +int check_arr(double* sines, double* coses, double* phases, int* indices, int size, int nests, double max_ulp_err, const char* msg) +{ + int fail = 0; + + for (int i = 0; i < size; i++) { + int j = indices ? indices[i] : i; + double ref_sin = sin(phases[j]); + double ref_cos = cos(phases[j]); + for (int k=0; k + +#define xstr(s) str(s) +#define str(s) #s + +int main(void) { + __builtin_cpu_init(); + if (__builtin_cpu_supports(xstr(FEATURE_FLAG))) { + printf("YES"); + } else { + printf("NO"); + } + return 0; +}