我有这段代码:
#include <immintrin.h>
#include <stdio.h>
void main(){
int i;
__m128 x_v, y_v, e_v;
__m128i mask_v;
float x[8]={1.0f,2.0f,3.0f,4.0f};
float y[8]={1.0f,2.0f,3.0f,4.0f};
int exp0mask = 0xFFFFFFFF;
for(i=0; i+3<4; i+=4) {
x_v = _mm_loadu_ps(x+i);
y_v = _mm_loadu_ps(y+i);
mask_v = _mm_set1_epi32(exp0mask);
e_v = _mm_and_ps(x_v, _mm_castsi128_ps(mask_v));
e_v = _mm_castsi128_ps(_mm_srli_epi32(_mm_castps_si128(e_v), 23));
_mm_storeu_ps(y+i, e_v);
printf("%f\n", y[i]);
printf("%f\n", y[i+1]);
printf("%f\n", y[i+2]);
printf("%f\n", y[i+3]);
}
}
这就是结果:
0.000000
0.000000
0.000000
0.000000
x[i]
(浮点数组)中的值不为零。我观察到,零结果发生在移位操作_mm_srli_epi32
之后。但为什么会这样,我该怎么办?