如何仅使用 SSE2 在双精度中地板/整数
How to floor/int in double using only SSE2?
在float
中,似乎很容易floor()
,并且比int()
,例如:
float z = floor(LOG2EF * x + 0.5f);
const int32_t n = int32_t(z);
成为:
__m128 z = _mm_add_ps(_mm_mul_ps(log2ef, x), half);
__m128 t = _mm_cvtepi32_ps(_mm_cvttps_epi32(z));
z = _mm_sub_ps(t, _mm_and_ps(_mm_cmplt_ps(z, t), one));
__m128i n = _mm_cvtps_epi32(z);
但是,如何在仅使用 SSE2 的double
中实现这一目标?
这是我想转换的双重版本:
double z = floor(LOG2E * x + 0.5);
const int32_t n = int32_t(z);
只需使用单精度(...ps...
)固有的双精度等效(...pd...
):
__m128i n = _mm_cvtpd_epi32(z);
根据英特尔内部函数指南,该内部函数确实可用于 SSE2:https://software.intel.com/sites/landingpage/IntrinsicsGuide/#expand=4966,1917&techs=SSE2
__m128i _mm_cvtpd_epi32 (__m128d a)
将打包的双精度(64 位)浮点元素转换为
a
中的打包 32 位整数,并将结果存储在dst
中。FOR j := 0 to 1 i := 32*j k := 64*j dst[i+31:i] := Convert_FP64_To_Int32(a[k+63:k]) ENDFOR
相关文章:
- 我可以信任表示整数的浮点或双精度来保持精度吗
- C 字符串返回字符串的整数/双精度/长整型值
- 如何防止双精度值到整数的隐式转换
- 野牛/flex:计算器将双精度值解释为整数,所以我添加了 YYSTYPE 双精度 #define 但我有多个编译错误
- 为什么输出是整数而不是双精度?
- 从字符串转换为双精度和整数 - C++
- 从双精度转换为整数的显式类型是否始终检查整数溢出?
- C++,遇到将双精度转换为整数的问题
- 用双精度除以整数
- 使用整数初始化列表初始化长双精度的向量
- 如何判断 c++ 向量中的值类型(整数或双精度)?
- 了解双精度转换与整数转换中的整数与截断关系
- 为什么使用 int64_t 会产生错误的结果,而双精度则按预期进行简单的整数乘法
- 将双精度与整数进行比较
- 64 位整数到双精度冲突
- 在编译时将整数和分数部分宏组合成一个新的宏或双精度
- 不确定输出双精度或整数的代码行
- 将 32 位浮点数和不强制转换的 32 位整数与双精度进行比较,当其中一个值可能太大而无法完全适合另一种类型时
- 使用 sprintf 格式化负整数/双精度
- 在c++中是否有一种方法可以将这种格式的输入限制为整数/双精度