asmjit_test_unicompiler_sse2.cpp (2105B)
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 <emmintrin.h> 14 #endif 15 16 namespace UniCompilerTests { 17 18 // A reference implementation of MUL+ADD without 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 fadd(float a, float b) noexcept { 23 return _mm_cvtss_f32(_mm_add_ss(_mm_set1_ps(a), _mm_set1_ps(b))); 24 } 25 26 float fsub(float a, float b) noexcept { 27 return _mm_cvtss_f32(_mm_sub_ss(_mm_set1_ps(a), _mm_set1_ps(b))); 28 } 29 30 float fmul(float a, float b) noexcept { 31 return _mm_cvtss_f32(_mm_mul_ss(_mm_set1_ps(a), _mm_set1_ps(b))); 32 } 33 34 float fdiv(float a, float b) noexcept { 35 return _mm_cvtss_f32(_mm_div_ss(_mm_set1_ps(a), _mm_set1_ps(b))); 36 } 37 38 float fsqrt(float a) noexcept { 39 return _mm_cvtss_f32(_mm_sqrt_ss(_mm_set1_ps(a))); 40 } 41 42 float fmadd_nofma_ref(float a, float b, float c) noexcept { 43 return _mm_cvtss_f32(_mm_add_ss(_mm_mul_ss(_mm_set1_ps(a), _mm_set1_ps(b)), _mm_set1_ps(c))); 44 } 45 46 double fadd(double a, double b) noexcept { 47 return _mm_cvtsd_f64(_mm_add_sd(_mm_set1_pd(a), _mm_set1_pd(b))); 48 } 49 50 double fsub(double a, double b) noexcept { 51 return _mm_cvtsd_f64(_mm_sub_sd(_mm_set1_pd(a), _mm_set1_pd(b))); 52 } 53 54 double fmul(double a, double b) noexcept { 55 return _mm_cvtsd_f64(_mm_mul_sd(_mm_set1_pd(a), _mm_set1_pd(b))); 56 } 57 58 double fdiv(double a, double b) noexcept { 59 return _mm_cvtsd_f64(_mm_div_sd(_mm_set1_pd(a), _mm_set1_pd(b))); 60 } 61 62 double fsqrt(double a) noexcept { 63 return _mm_cvtsd_f64(_mm_sqrt_sd(_mm_setzero_pd(), _mm_set1_pd(a))); 64 } 65 66 double fmadd_nofma_ref(double a, double b, double c) noexcept { 67 return _mm_cvtsd_f64(_mm_add_sd(_mm_mul_sd(_mm_set1_pd(a), _mm_set1_pd(b)), _mm_set1_pd(c))); 68 } 69 70 } // {UniCompilerTests} 71 72 #endif // ASMJIT_UJIT_X86