AVX将64位整数转换为64位浮点数

我想使用AVX将4个打包的64位整数转换为4个打包的64位浮点数。 我尝试过类似的东西:

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

哪个将显示在调试器中:

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

好的,到目前为止,但我能找到的唯一的演员/转换操作是_mm256i_castsi256_pd,这不能得到我想要的东西:

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

我真正想看到的是:

 (gdb) print pd $5 = {1234.0, 5678.0, 9012.0, 3456.0} 

所有的演员内在函数都会执行逐位转换,这就是为什么你没有看到有意义的结果。

不存在64位整数和64位浮点之间的向量转换( cvt内在函数)。

为了它的价值,我查看了Agner Fog的矢量类,看看他是如何做到的。 他只是将64位整数存储到一个数组中,并将每个数组值转换为double。 这是低效的,但它的工作原理。

从文件“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); }