Basically the problem is with the x86 assembler, where you have a number that you want to set either to zero or to the number itself using and. If you and, this is a negative number, you will return the number itself, but if you are andwith zero, you will get zero.
Now the problem that I encountered in SSE is that the floats do not match the binaries (or maybe I'm wrong). Anyways is the code here, I tried to use all kinds of floats to mask the second and third numbers (127.0f and 99.0f respectively), but no luck.
#include <xmmintrin.h>
#include <stdio.h>
void print_4_bit_num(const char * label, __m128 var)
{
float *val = (float *) &var;
printf("%s: %f %f %f %f\n",
label, val[3], val[2], val[1], val[0]);
}
int main()
{
__m128 v1 = _mm_set_ps(1.0f, 127.0f, 99.0f, 1.0f);
__m128 v2 = _mm_set_ps(1.0f, 65535.0f, 127.0f, 0.0f);
__m128 v = _mm_and_ps(v1, v2);
print_4_bit_num("v1", v1);
print_4_bit_num("v2", v2);
print_4_bit_num("v ", v);
return 0;
}
source
share