谁能建议一种快速的方法来计算float楼层/天花板使用之前的SSE4.1SIMD?我需要正确地处理所有的边角情况,例如,当我有一个32位float不能表示的int值时。
目前我使用的代码类似于下面的代码(我使用C内部函数,为了清楚起见,我将其转换为asm ):
;make many copies of the data
movaps xmm0, [float_value]
movaps xmm1, xmm0
movaps xmm2, xmm0
;check if the value is not too large in magnitude
andps xmm1, [exp_mask]
pcmpgtd xmm1, [max_exp]
;calculate the floor()
cvttps2dq xmm3, xmm2
psrld xmm2, 31
psubd xmm3, xmm2
cvtsq2ps xmm2, xmm3
;combine the results
andps xmm0, xmm1
andnps xmm1, xmm2
orps xmm0, xmm1有没有更有效的方法来检查32位整数的浮点值是否太大?
发布于 2011-03-11 09:46:47
下面是可以直接转换为向量指令的单个元素的伪代码:
float f;
int i = (int)f; /* 0x80000000 if out of range (as from cvtps2dq) */
if (i == 0x80000000)
return f;
else
return (float)i;您将对第二行中的int类型转换使用舍入模式。您还可以测试MXCSR中的IE标志,以检测超出范围的值。
https://stackoverflow.com/questions/5268036
复制相似问题