AVX转换64位整数到64位浮点数
AVX convert 64 bit integer to 64 bit float
我想使用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的vectorclass,看看他是如何做到的。他只是将64位整数存储到一个数组中,并将每个数组值强制转换为双精度类型。这是低效的,但它是有效的。
From 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);
}
相关文章:
- 使用英特尔内联函数将打包的 8 位整数乘以浮点数向量
- 在数学上将浮点数四舍五入到 N 位小数
- 位设置为浮点数或双精度值 c++
- 浮点数为 32 位和 64 位二进制表示形式
- 使用 int 指针的浮点数的位表示形式
- OpenCV矩阵奇怪的加法,乘法与浮点数和8位值
- 使用按位 AND 和 popcount 而不是实际的 int 或浮点数乘法进行大 (0,1) 矩阵乘法
- 如何在C++中进行32位十进制浮点数乘法?
- 如何在 c++ 中使用 FFT 从 32 位浮点数组中提取频率
- 将 32 位浮点数和不强制转换的 32 位整数与双精度进行比较,当其中一个值可能太大而无法完全适合另一种类型时
- 为什么 std::setprecision 显示不存在的精度位以及如何查看实际浮点数
- 每个值64位整数的数字应转换为位等效的64位浮数
- 在 C/C+ 中从 16 位线性 PCM 音频转换为 32 位浮点数的最佳方法
- 移植将 32 位浮点数与使用 64 位进行比较的代码,此值表示什么
- 如何将32位整数转换为32位浮点数,以保持顺序
- AVX转换64位整数到64位浮点数
- 正确(独立于32位/64位)将浮点数保存为二进制流
- 80位浮点数和次正规数
- 64位浮点日期和时间值为DateTime c#
- 将16位无符号整型数组转换为32位浮点数组