AVX converts a 64-bit integer to a 64-bit float

I would like to convert 4 packed 64-bit integers to 4 packed 64-bit floats using AVX. I tried something like:

int_64t *ls = (int64_t *) _mm_malloc(256, 32); ls[0] = a; //... ls[3] = d; __mm256i packed = _mm256_load_si256((__m256i const *)ls); 

which will be displayed in the debugger:

 (gdb) print packed $4 = {1234, 5678, 9012, 3456} 

Ok, but the only cast / transform operation I can find is _mm256i_castsi256_pd, which does not give me what I want:

 __m256d pd = _mm256_castsi256_pd(packed); (gdb) print pd $5 = {6.0967700696809824e-321, 2.8053047370865979e-320, 4.4525196003213139e-320, 1.7074908720273481e-320} 

I would really like to see:

 (gdb) print pd $5 = {1234.0, 5678.0, 9012.0, 3456.0} 
+4
source share
2 answers

All executable clips perform bitwise clicking, so you do not see significant results.

Vector conversion (embedded cvt) between a 64-bit integer and a 64-bit float does not exist.

+5
source

For what it's worth, I looked into the Agner Fog vector class to see how it does it. It just stores 64-bit integers in an array and translates each array value into double. It is inefficient, but it works.

From the file "vectorf256.h":

 // function to_double: convert integer vector elements to double vector (inefficient) static inline Vec4d to_double(Vec4q const & a) { int64_t aa[4]; a.store(aa); return Vec4d(double(aa[0]), double(aa[1]), double(aa[2]), double(aa[3])); } // function to_double: convert integer vector to double vector static inline Vec4d to_double(Vec4i const & a) { return _mm256_cvtepi32_pd(a); } 
+2
source

Source: https://habr.com/ru/post/1480389/


All Articles