XPERM4

RISC-V XPERM4 Instruction Details

Instruction ManualR-type

nibble crossbar permutation (Zbkx).

Instruction Syntax

xperm4 rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
ZbkxBit Manipulation

Instruction Behavior

XPERM4 (Zbkx) treats rs1 as a table of XLEN/4 4-bit elements and each 4-bit element of rs2 as an index. At each result position, an index below XLEN/4 selects the corresponding 4-bit element from rs1; otherwise the result element is zero.

XPERM4 Decode And Execute Animation

Each 4-bit rs2 element indexes the rs1 element table; an out-of-range index produces a zero result element.

funct7
31..25
0010100
rs2
24..20
01100
rs1
19..15
01011
funct3
14..12
010
rd
11..7
01010
opcode
6..0
0110011

Current calculation

0: 8 -> 0 0
1: 9 -> 0 0
2: A -> 0 0
3: B -> 0 0
4: C -> 0 0
5: D -> 0 0
6: E -> 0 0
7: F -> 0 0

x[rs2] indexes 8 entries in x[rs1]; result = 0x00000000

Step: decode

Shows the instruction's fixed and register fields.

x[a0] <- 0x00000000
1/4: decode

Quick Understanding & Search Notes

XPERM4 is a Zbkx cross-register permutation instruction; this page follows the official B-extension operation.

The instruction operates on XLEN-wide 4-bit elements.
Do not modulo-wrap rs2 indexes; out-of-range result elements are zero.

Common Usage Scenarios

Bit Manipulation

Understand this scenario with real code like «xperm4 a0, a1, a2».

Register Lookup

Understand this scenario with real code like «xperm4 a0, a1, a2».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

Indexes come from each 4-bit element of rs2; rs1 is the table source.
Out-of-range indexes produce zero; they do not wrap modulo the element count.
The count of valid indexes is determined by the XLEN-wide number of 4-bit elements.

FAQ

Does XPERM4 access memory?

No. It only rearranges bit fields or performs register lookup within integer registers.

Which extension contains XPERM4?

It belongs to the Zbkx crossbar-permutation extension.