Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comparision with zero using neon instruction

I have the below code

if(value  == 0)
{
    value = 1;
}

Using NEON vectorized instructions I need to perform the above. How do I compare a NEON register value with 0 for equality at a time 4 elements and change the value to 1 if the element is zero.

like image 478
ravi Avatar asked Sep 14 '25 04:09

ravi


1 Answers

If you want to check if any element of a vector is non-zero and branch on that:


You can use get min/max across vector lanes.

if(vmaxvq_u32(value) == 0) { // Max value across quad vector, equals zero?
    value = vmovq_n_u32(1); // Set all lanes to 1
}

For double vectors

if(vmaxv_u32(value) == 0) { // Max value across double vector, equals zero?
    value = vmov_n_u32(1); // Set all lanes to 1
}

Notice the only difference is the 'q' which is used to indicate quad 128-bit vector or 64-bit double vector if not. The compiler will use a mov instruction to transfer from a neon single to arm generic register to do the comparison.

like image 75
Rauli Kumpulainen Avatar answered Sep 17 '25 19:09

Rauli Kumpulainen