avx.hpp 545 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef AVX_HPP
  2. #define AVX_HPP
  3. #include <cstdint>
  4. union v8f{
  5. __m256 avx;
  6. float f[8];
  7. };
  8. union v8i{
  9. __m256 avx;
  10. uint32_t i[8];
  11. };
  12. float hadd(const v8f& u);
  13. void display(const v8f& u);
  14. inline float
  15. hadd(const v8f& u){
  16. v8f v={_mm256_hadd_ps(u.avx,u.avx)};
  17. return v.f[0]+v.f[2]+v.f[4]+v.f[6];
  18. }
  19. inline void
  20. display(const v8f& u){
  21. cout<<'['<<u.f[0];
  22. cout<<','<<u.f[1];
  23. cout<<','<<u.f[2];
  24. cout<<','<<u.f[3];
  25. cout<<','<<u.f[4];
  26. cout<<','<<u.f[5];
  27. cout<<','<<u.f[6];
  28. cout<<','<<u.f[7];
  29. cout<<','<<']';
  30. }
  31. #endif