如何将__m128转换成整数
how invert __m128 into ints
float a[4] = {1,2,3,4}, b[4] = {4,3,2,1};
uint32_t c[4];
int main() {
__m128 pa = _mm_loadu_ps(a);
__m128 pb = _mm_loadu_ps(b);
__m128 pc = _mm_cmpgt_ps(pa, pb);
_mm_storeu_ps((float*)c, pc);
for (int i = 0;i < 4; ++i) printf("%un", c[i]);
return 0;
}
_mm_storeu_ps((float*)c, pc)
的正确指令是什么?这里,c是一个整数数组…我认为这种方式不好,有更好的吗?
在SSE2中将__m128
(float
向量)转换为__m128i
(int32_t
向量)有两个指令:_mm_cvtps_epi32
(带舍入)和_mm_cvttps_epi32
(带截断)。
__m128i vi = _mm_cvttps_epi32(pc);
_mm_storeu_si128((__m128i *)c, vi);
如果不能使用SSE2,将pc
存储为float
数组后,将float
数组转换为int
数组。
float d[4];
_mm_storeu_ps(d, pc);
c[0] = (int)d[0]; c[1] = (int)d[1]; c[2] = (int)d[2]; c[3] = (int)d[3];
相关文章:
- 努力将整数转换为链表。不知道我在这里做错了什么
- 如何在C++中将整数转换为其数字数组
- 如果整数与指针大小相同,则重新解释将整数转换为指针双射是否具有双射作用?
- 将最小值整数转换为无符号长整型
- 为什么我们不能将使用异或运算找到的整数转换为字符?
- 在C++中,将无符号整数转换为八进制表示,反之亦然的最佳方法是什么
- 将74位整数转换为以31为底的整数
- 独立于实现的浮点/整数转换
- 以最少的步骤将给定整数转换为另一个整数
- 浮点到整数转换出错(即使浮点数已经是整数)
- 了解双精度转换与整数转换中的整数与截断关系
- 禁止具有精度损失的整数转换
- 将任意整数转换为 void*
- 将 32 位大端有符号整数转换为有符号小端整数
- char a[0] 使用 itoa() 将整数转换为字符串的目的
- 使用函数时从整数转换为字符串
- 尝试从整数转换为字符串的月份
- 如何在C++中将整数转换为字节,以便 Unity 在通过 UDP 传输后能够理解它们
- 如何将 Q 格式的整数转换为浮点数(反之亦然)
- 如何避免字符串到整数转换情况下的无效参数异常