5

I'm interested in finding the fastest way (lowest cycle count) of comparing the values stored into NEON registers (say Q0 and Q3) on a Cortex-A9 core (VFP instructions allowed).

So far I have the following:

(1) Using the VFP floating point comparison:

vcmp.f64        d0, d6
vmrs            APSR_nzcv, fpscr
vcmpeq.f64      d1, d7
vmrseq          APSR_nzcv, fpscr

If the 64bit "floats" are equivalent to NaN, this version will not work.

(2) Using the NEON narrowing and the VFP comparison (this time only once and in a NaN-safe manner):

vceq.i32        q15, q0, q3
vmovn.i32       d31, q15
vshl.s16        d31, d31, #8
vcmp.f64        d31, d29
vmrs            APSR_nzcv, fpscr

The D29 register is previously preloaded with the right 16bit pattern:

vmov.i16        d29, #65280     ; 0xff00

My question is: is there any better than this? Am I overseeing some obvious way to do it?

1 Answer 1

2

I believe you can reduce it by one instruction. By using the shift left and insert (VLSI), you can combine the 4 32-bit values of Q15 into 4 16-bit values in D31. You can then compare with 0 and get the floating point flags.

vceq.i32  q15, q0, q3
vlsi.32   d31, d30, #16
vcmp.f64  d31, #0
vmrs      APSR_nzcv, fpscr
7
  • The first intruction "overwrites" the whole Q15 (i.e. D30 and D31), while the second only has D31 as a destination, therefore some information is lost and the comparison will not always yield the right result.
    – Mircea
    Jan 31, 2012 at 21:29
  • When you use vceq.i32, it places all 1's or all 0's into each of the 4 32-bit lanes. The first instruction combines the useful info from D30 and D31 into D31 (the lower 16-bits of all 4 compares). The second instruction compares the lower 64-bits which HAS all of the useful info.
    – BitBank
    Jan 31, 2012 at 21:38
  • The first instruction (i.e. vceq.i32) does not "combine" anything. Furthermore, the second one does not use D31 as an input...
    – Mircea
    Feb 1, 2012 at 2:06
  • 1
    See this page (second diagram) blogs.arm.com/software-enablement/…
    – BitBank
    Feb 1, 2012 at 14:08
  • 1
    OK, you're right, sorry for arguing. BUT the code still has the same NaN problem as my first implementation: if Q0 and Q3 are equal, D31 will end up with all the bits set (and therefore being NaN) => VCMP will not work.
    – Mircea
    Feb 1, 2012 at 14:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.