在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);但是如何在double中使用仅使用的 SSE2来实现这一点呢?
这是我想转换的双版本:
double z = floor(LOG2E * x + 0.5);
const int32_t n = int32_t(z);发布于 2019-01-28 16:59:50
只需使用单精度(...ps...)内在特性的双精度等效(...ps...):
__m128i n = _mm_cvtpd_epi32(z);根据英特尔Intrinsics指南,这个内在特性确实适用于SSE2:https://software.intel.com/sites/landingpage/IntrinsicsGuide/#expand=4966,1917&techs=SSE2
__m128i _mm_cvtpd_epi32 (__m128d a)将a中的填充双精度(64位)浮点元素转换为32位整数,并将结果存储在dst中。 J := 0 to 1 i := 32*j k := 64*j dsti+31:i := Convert_FP64_To_Int32(ak+63:k)
https://stackoverflow.com/questions/54406161
复制相似问题