csneg

Conditional Select Negate

CSNEG <Wd>, <Wn>, <Wm>, <cond>

Selects Wn if cond true, else -Wm.

Details

Conditionally selects between two values: if the condition is true, writes Wn to Wd; otherwise writes the arithmetic negation of Wm to Wd. The upper 32 bits of Xd are zeroed. No flags are affected by this instruction. Available in AArch64 only.

Pseudocode Operation

if ConditionHolds(cond) then
  Wd ← Wn
else
  Wd ← -Wm

Example

CSNEG w0, w1, w2, cond

Encoding

Binary Layout
0
1
0
11010100
Rm
cond
0
1
Rn
Rd
 
Format Cond Select
Opcode 0x5A800400
Extension Base

Operands

  • Wd
    Destination 32-bit integer register
  • Wn
    True Src
  • Wm
    False Src
  • cond
    Cond

Reference (Arm A64 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x5A800400 CSNEG <Wd>, <Wn>, <Wm>, <cond> A64 0 | 1 | 0 | 11010100 | Rm | cond | 0 | 1 | Rn | Rd
0xDA800400 CSNEG <Xd>, <Xn>, <Xm>, <cond> A64 1 | 1 | 0 | 11010100 | Rm | cond | 0 | 1 | Rn | Rd

Description

Conditional Select Negation returns, in the destination register, the value of the first source register if the condition is TRUE, and otherwise returns the negated value of the second source register.

Operation

bits(datasize) result;
if ConditionHolds(cond) then
    result = X[n, datasize];
else
    result = X[m, datasize];
    result = NOT(result);
    result = result + 1;

X[d, datasize] = result;