You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

intrin_sse.h 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #define V_SIMD 128
  2. #define V_SIMD_F64 1
  3. /***************************
  4. * Data Type
  5. ***************************/
  6. typedef __m128 v_f32;
  7. typedef __m128d v_f64;
  8. #define v_nlanes_f32 4
  9. #define v_nlanes_f64 2
  10. /***************************
  11. * Arithmetic
  12. ***************************/
  13. #define v_add_f32 _mm_add_ps
  14. #define v_add_f64 _mm_add_pd
  15. #define v_mul_f32 _mm_mul_ps
  16. #define v_mul_f64 _mm_mul_pd
  17. #ifdef HAVE_FMA3
  18. // multiply and add, a*b + c
  19. #define v_muladd_f32 _mm_fmadd_ps
  20. #define v_muladd_f64 _mm_fmadd_pd
  21. #elif defined(HAVE_FMA4)
  22. // multiply and add, a*b + c
  23. #define v_muladd_f32 _mm_macc_ps
  24. #define v_muladd_f64 _mm_macc_pd
  25. #else
  26. // multiply and add, a*b + c
  27. BLAS_FINLINE v_f32 v_muladd_f32(v_f32 a, v_f32 b, v_f32 c)
  28. { return v_add_f32(v_mul_f32(a, b), c); }
  29. BLAS_FINLINE v_f64 v_muladd_f64(v_f64 a, v_f64 b, v_f64 c)
  30. { return v_add_f64(v_mul_f64(a, b), c); }
  31. #endif // HAVE_FMA3
  32. // Horizontal add: Calculates the sum of all vector elements.
  33. BLAS_FINLINE float v_sum_f32(__m128 a)
  34. {
  35. #ifdef HAVE_SSE3
  36. __m128 sum_halves = _mm_hadd_ps(a, a);
  37. return _mm_cvtss_f32(_mm_hadd_ps(sum_halves, sum_halves));
  38. #else
  39. __m128 t1 = _mm_movehl_ps(a, a);
  40. __m128 t2 = _mm_add_ps(a, t1);
  41. __m128 t3 = _mm_shuffle_ps(t2, t2, 1);
  42. __m128 t4 = _mm_add_ss(t2, t3);
  43. return _mm_cvtss_f32(t4);
  44. #endif
  45. }
  46. BLAS_FINLINE double v_sum_f64(__m128d a)
  47. {
  48. #ifdef HAVE_SSE3
  49. return _mm_cvtsd_f64(_mm_hadd_pd(a, a));
  50. #else
  51. return _mm_cvtsd_f64(_mm_add_pd(a, _mm_unpackhi_pd(a, a)));
  52. #endif
  53. }
  54. /***************************
  55. * memory
  56. ***************************/
  57. // unaligned load
  58. #define v_loadu_f32 _mm_loadu_ps
  59. #define v_loadu_f64 _mm_loadu_pd
  60. #define v_storeu_f32 _mm_storeu_ps
  61. #define v_storeu_f64 _mm_storeu_pd
  62. #define v_setall_f32(VAL) _mm_set1_ps(VAL)
  63. #define v_setall_f64(VAL) _mm_set1_pd(VAL)
  64. #define v_zero_f32 _mm_setzero_ps
  65. #define v_zero_f64 _mm_setzero_pd