The following piece of code:
__m128 a = _mm_setr_ps( 1, 2, 3, 4 );
__m128 b = _mm_set1_ps( 2 );
__m128 res = _mm_and_ps( a, b );
cout << a[0] << " " << a[1] << " " << a[2] << " " << a[3] << endl;
cout << b[0] << " " << b[1] << " " << b[2] << " " << b[3] << endl;
cout << res[0] << " " << res[1] << " " << res[2] << " " << res[3] << endl;
cout<<endl;
cout << ( 1 & 2 ) << " " << ( 2 & 2 ) << " " << ( 3 & 2 ) << " " << ( 4 & 2 ) << endl;
results in:
1 2 3 4
2 2 2 2
0 2 2 2
0 2 2 0
Shouldn't the result of the SSE operation be 0 2 2 0
because 2 = 010, 4 = 100 => 2&4 = 0
.
According to the documentation:
__m128 _mm_and_ps(__m128 a, __m128 b)
Computes the bitwise AND of the four SP FP values of a and b.
R0 R1 R2 R3
a0 & b0 a1 & b1 a2 & b2 a3 & b3