rev16
Reverse Bytes in Halfwords
REV16 <Wd>, <Wn>
Reverses bytes in each 16-bit halfword.
Details
Reverses the byte order within each 16-bit halfword of a 32-bit register independently, leaving halfword boundaries intact. Condition flags are not affected by this instruction. This is useful for converting individual 16-bit values between endianness without affecting the halfword order.
Pseudocode Operation
result[7:0] ← Wn[15:8]
result[15:8] ← Wn[7:0]
result[23:16] ← Wn[31:24]
result[31:24] ← Wn[23:16]
Wd ← result
Example
REV16 w0, w1
Encoding
Binary Layout
0
1
0
11010110
00000
0000
01
Rn
Rd
Operands
-
Wd
Destination 32-bit integer register -
Wn
First source / base 32-bit integer register
Reference (Arm A64 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x0E201800 | REV16 <Vd>.<T>, <Vn>.<T> | A64 | 0 | Q | 0 | 01110 | size | 100000000 | 1 | 10 | Rn | Rd | ||
| 0x5AC00400 | REV16 <Wd>, <Wn> | A64 | 0 | 1 | 0 | 11010110 | 00000 | 0000 | 01 | Rn | Rd | ||
| 0xDAC00400 | REV16 <Xd>, <Xn> | A64 | 1 | 1 | 0 | 11010110 | 00000 | 0000 | 01 | Rn | Rd |
Description
Reverse bytes in 16-bit halfwords reverses the byte order in each 16-bit halfword of a register.
Operation
bits(datasize) operand = X[n, datasize];
bits(datasize) result;
constant integer containers = datasize DIV container_size;
for c = 0 to containers-1
bits(container_size) container = Elem[operand, c, container_size];
Elem[result, c, container_size] = Reverse(container, 8);
X[d, datasize] = result;