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_avx.h 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #define V_SIMD 256
  2. #define V_SIMD_F64 1
  3. /***************************
  4. * Data Type
  5. ***************************/
  6. typedef __m256 v_f32;
  7. #define v_nlanes_f32 8
  8. /***************************
  9. * Arithmetic
  10. ***************************/
  11. #define v_add_f32 _mm256_add_ps
  12. #define v_mul_f32 _mm256_mul_ps
  13. #ifdef HAVE_FMA3
  14. // multiply and add, a*b + c
  15. #define v_muladd_f32 _mm256_fmadd_ps
  16. #else
  17. // multiply and add, a*b + c
  18. BLAS_FINLINE v_f32 v_muladd_f32(v_f32 a, v_f32 b, v_f32 c)
  19. { return v_add_f32(v_mul_f32(a, b), c); }
  20. #endif // !HAVE_FMA3
  21. // Horizontal add: Calculates the sum of all vector elements.
  22. BLAS_FINLINE float v_sum_f32(__m256 a)
  23. {
  24. __m256 sum_halves = _mm256_hadd_ps(a, a);
  25. sum_halves = _mm256_hadd_ps(sum_halves, sum_halves);
  26. __m128 lo = _mm256_castps256_ps128(sum_halves);
  27. __m128 hi = _mm256_extractf128_ps(sum_halves, 1);
  28. __m128 sum = _mm_add_ps(lo, hi);
  29. return _mm_cvtss_f32(sum);
  30. }
  31. /***************************
  32. * memory
  33. ***************************/
  34. // unaligned load
  35. #define v_loadu_f32 _mm256_loadu_ps
  36. #define v_storeu_f32 _mm256_storeu_ps
  37. #define v_setall_f32(VAL) _mm256_set1_ps(VAL)
  38. #define v_zero_f32 _mm256_setzero_ps