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.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #define V_SIMD 256
  2. #define V_SIMD_F64 1
  3. /***************************
  4. * Data Type
  5. ***************************/
  6. typedef __m256 v_f32;
  7. typedef __m256d v_f64;
  8. #define v_nlanes_f32 8
  9. #define v_nlanes_f64 4
  10. /***************************
  11. * Arithmetic
  12. ***************************/
  13. #define v_add_f32 _mm256_add_ps
  14. #define v_add_f64 _mm256_add_pd
  15. #define v_mul_f32 _mm256_mul_ps
  16. #define v_mul_f64 _mm256_mul_pd
  17. #ifdef HAVE_FMA3
  18. // multiply and add, a*b + c
  19. #define v_muladd_f32 _mm256_fmadd_ps
  20. #define v_muladd_f64 _mm256_fmadd_pd
  21. #else
  22. // multiply and add, a*b + c
  23. BLAS_FINLINE v_f32 v_muladd_f32(v_f32 a, v_f32 b, v_f32 c)
  24. { return v_add_f32(v_mul_f32(a, b), c); }
  25. BLAS_FINLINE v_f64 v_muladd_f64(v_f64 a, v_f64 b, v_f64 c)
  26. { return v_add_f64(v_mul_f64(a, b), c); }
  27. #endif // !HAVE_FMA3
  28. // Horizontal add: Calculates the sum of all vector elements.
  29. BLAS_FINLINE float v_sum_f32(__m256 a)
  30. {
  31. __m256 sum_halves = _mm256_hadd_ps(a, a);
  32. sum_halves = _mm256_hadd_ps(sum_halves, sum_halves);
  33. __m128 lo = _mm256_castps256_ps128(sum_halves);
  34. __m128 hi = _mm256_extractf128_ps(sum_halves, 1);
  35. __m128 sum = _mm_add_ps(lo, hi);
  36. return _mm_cvtss_f32(sum);
  37. }
  38. BLAS_FINLINE double v_sum_f64(__m256d a)
  39. {
  40. __m256d sum_halves = _mm256_hadd_pd(a, a);
  41. __m128d lo = _mm256_castpd256_pd128(sum_halves);
  42. __m128d hi = _mm256_extractf128_pd(sum_halves, 1);
  43. __m128d sum = _mm_add_pd(lo, hi);
  44. return _mm_cvtsd_f64(sum);
  45. }
  46. /***************************
  47. * memory
  48. ***************************/
  49. // unaligned load
  50. #define v_loadu_f32 _mm256_loadu_ps
  51. #define v_loadu_f64 _mm256_loadu_pd
  52. #define v_storeu_f32 _mm256_storeu_ps
  53. #define v_storeu_f64 _mm256_storeu_pd
  54. #define v_setall_f32(VAL) _mm256_set1_ps(VAL)
  55. #define v_setall_f64(VAL) _mm256_set1_pd(VAL)
  56. #define v_zero_f32 _mm256_setzero_ps
  57. #define v_zero_f64 _mm256_setzero_pd