asmjit_test_unicompiler_avx2fma.cpp (1370B)
1 // This file is part of AsmJit project <https://asmjit.com> 2 // 3 // See <asmjit/core.h> or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 6 #include <asmjit/ujit.h> 7 8 #if defined(ASMJIT_UJIT_X86) 9 10 #if defined(_MSC_VER) 11 #include <intrin.h> 12 #else 13 #include <immintrin.h> 14 #endif 15 16 namespace UniCompilerTests { 17 18 // A reference implementation of MUL+ADD with the use of FMA. This has to be provided otherwise the 19 // compiler may use FPU registers in 32-bit x86 case, which would make the result different than when 20 // compiled by JIT compiler that would use XMM registers (32/64-bit SSE/AVX operations). 21 22 float fmadd_fma_ref(float a, float b, float c) noexcept { 23 __m128 av = _mm_set1_ps(a); 24 __m128 bv = _mm_set1_ps(b); 25 __m128 cv = _mm_set1_ps(c); 26 27 return _mm_cvtss_f32(_mm_fmadd_ss(av, bv, cv)); 28 } 29 30 double fmadd_fma_ref(double a, double b, double c) noexcept { 31 __m128d av = _mm_set1_pd(a); 32 __m128d bv = _mm_set1_pd(b); 33 __m128d cv = _mm_set1_pd(c); 34 35 return _mm_cvtsd_f64(_mm_fmadd_sd(av, bv, cv)); 36 } 37 38 void madd_fma_check_valgrind_bug(const float a[4], const float b[4], const float c[4], float dst[4]) noexcept { 39 __m128 av = _mm_loadu_ps(a); 40 __m128 bv = _mm_loadu_ps(b); 41 __m128 cv = _mm_loadu_ps(c); 42 43 __m128 dv = _mm_fmadd_ss(av, bv, cv); 44 _mm_storeu_ps(dst, dv); 45 } 46 47 } // {UniCompilerTests} 48 49 #endif // ASMJIT_UJIT_X86