Reputation: 101
I have a uint8x8
Neon vector which is a result of some operation. I need to perform a logical AND
operation of the all the lanes to get my final result. Each element is either 0xff
(TRUE) or 0x00
(FALSE). How do I perform it in Neon?
Upvotes: 3
Views: 1000
Reputation: 6354
In that case, you can simply do a binary negation, and check if the 64bit result is 0.
vmvn d0, d0
vpaddl.u32 d0, d0 // 64bit vceq isn't possible.
vceq.i32 d0, d0, #0
You now have the desired result in d0.
If you are working on aarch64
, 64bit cmeq
is possible
mvn v0.16b, v0.16b
cmeq v0.2d, v0.2d, #0
The best thing about this algorithm is that you don't need any other registers, because zero is the only immediate value accepted by the compare instructions.
Upvotes: 2
Reputation: 212959
Simple/obvious method (pseudo-code):
v = VAND(v, v >> 8)
v = VAND(v, v >> 16)
v = VAND(v, v >> 32)
3 x shifts and 3 x bitwise ANDs = 6 instructions.
TRUE
if sum == -8
, otherwise return FALSE
.
return v == 0xffffffffffffffff;
Doing this efficiently is left as an exercise for the reader (may require 2 x 32 bit compares ?).
Upvotes: 1