csel

Conditional Select

CSEL <Wd>, <Wn>, <Wm>, <cond>

Selects between two registers based on condition.

Details

Selects one of two source registers and writes it to the destination based on the evaluated condition code. If the condition is true, Wn is selected; otherwise Wm is selected. Condition flags (N, Z, C, V) are not affected. Executes in AArch64 state only.

Pseudocode Operation

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

Example

CSEL w0, w1, w2, cond

Encoding

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

Operands

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

Reference (Arm A64 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x1A800000 CSEL <Wd>, <Wn>, <Wm>, <cond> A64 0 | 0 | 0 | 11010100 | Rm | cond | 0 | 0 | Rn | Rd
0x9A800000 CSEL <Xd>, <Xn>, <Xm>, <cond> A64 1 | 0 | 0 | 11010100 | Rm | cond | 0 | 0 | Rn | Rd

Description

If the condition is true, Conditional Select writes the value of the first source register to the destination register. If the condition is false, it writes the value of the second source register to the destination register.

Operation

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

X[d, datasize] = result;