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. BizarrelyNV
behaves likeAL
! 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 withMOV
. - If the instruction is
CSINC
, replace it withADD
. - If the instruction is
CSINV
, replace it withMVN
. - If the instruction is
CSNEG
, replace it withNEG
. - Otherwise it's
CCMP
orCCMN
...
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?