How to set the NZCV flags to constants in a single ARMv8 instruction

Viewed 531

I'd like to write a function that takes an ARMv8 instruction containing a condition code, and returns an ARMv8 instruction whose effect is the same as the original but with the condition inverted.

Most cases are easy:

  • If the condition code is not AL, then just toggle bit 0 of the condition code.
  • Otherwise (if the condition code is AL) there is no inverse condition code. Bizarrely NV behaves like AL! Instead we have to rewrite the instruction to pretend that its condition is always false:
    • If the instruction is a branch, replace it with a no-op.
    • If the instruction is CSEL, replace it with MOV.
    • If the instruction is CSINC, replace it with ADD.
    • If the instruction is CSINV, replace it with MVN.
    • If the instruction is CSNEG, replace it with NEG.
    • Otherwise it's CCMP or CCMN...

It's the last case that is causing me trouble. It doesn't matter whether the instruction is CCMP or CCMN since the arithmetic operation isn't going to happen anyway. What is needed is a way of setting the N, Z, C and V flags to arbitrary constant values in a single instruction. Is it possible?

0 Answers
Related