问题
As per the Neon documentation:
- If the comparison is true for a lane, the result in that lane is all bits set to one. If the comparison is false for a lane, all bits are set to zero. The return type is an unsigned integer type.
I have written a small piece of code to check this and I observed the result as 0 and -1 instead of 0 and 1. Can any one tell me the reason behind this?
Code:
float c1[4] = {12.0f,12.0f,12.0f,12.0f};
float c2[4] = {13.0f,12.0f,9.0f,12.0f};
float32x4_t t1,t2;
uint32x4_t rq;
t1 = vld1q_f32(c1);
t2 = vld1q_f32(c2);
rq = vceqq_f32(t1,t2);
printf("start\n");
for( int i = 0;i < 4; i++){
printf("%d\n",rq[i]);
}
printf("end\n");
Result:
start
0
-1
0
-1
end
回答1:
You're displaying the values as if they are signed, because you use %d
as the printf
format specifier. If you use %u
you'll see the equivalent unsigned values (0
or UINT_MAX
).
Note that signed-ness is not particularly important in this context - you can treat the comparison results as unsigned masks (all 0s or all 1s) or as signed integer values (0 or -1) - it's the same underlying bit pattern - just use whatever makes sense in the particular context where you are using the result.
回答2:
Here as per the neon document ,It is also mentioned as all bit will set to one .
That is Here :
Binary 1111 1111 1111 1111 1111 1111 1111 1111 = Decimal 4294967295
And use %u instead of %d .You will get result as:
Result:
0
4294967295
0
4294967295
You are getting result as -1 means all bits are set to one .That You can use for further logical operation like bitwise and and bitwise or operation .
来源:https://stackoverflow.com/questions/29984542/neon-comparison