XPERM4

RISC-V XPERM4 Instruction Details

Instruction ManualR-type

nibble crossbar permutation (Zbkx).

Instruction Syntax

xperm4 rd, rs1, rs2

Syntax: xperm4 rd, rs1, rs2; integer x0–x31 or ABI names, without an assembly immediate.

32-bit OP: funct7=0010100, funct3=010, opcode=0110011.

RV32/RV64 Zbkx; rs1 holds XLEN/4 4-bit entries, each rs2 element supplies an index, and out-of-range results are zero.

An x0 source is zero and writes to x0 are discarded. Overlap reads values before writeback; equal source registers share one value. No memory access.

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.

Execution Context

x0 is always zero; source values are read before writeback. Teaching steps are not processor cycles.

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 performs register lookup: rs1 holds XLEN/4 nibble entries and each nibble of rs2 selects an entry; out-of-range indexes produce zero.

Available on RV32 and RV64; each table entry and index is 4 bits.
Index 0 selects the least-significant element; out-of-range indexes produce zero without modulo wrapping.

Common Usage Scenarios

Bit Manipulation

RV32 Zbkx, x11=0x89ABCDEF, x12=0x76543210: xperm4 x10, x11, x12 gives x10=0x89ABCDEF.

Register Lookup

RV32 Zbkx, x11=0x89ABCDEF, x12=0x76543210: xperm4 x10, x11, x12 gives x10=0x89ABCDEF.

Pre-Use Checklist

Syntax Check
  • Syntax: xperm4 rd, rs1, rs2; integer x0–x31 or ABI names, without an assembly immediate.
  • 32-bit OP: funct7=0010100, funct3=010, opcode=0110011.
Semantic Check
  • RV32/RV64 Zbkx; rs1 holds XLEN/4 4-bit entries, each rs2 element supplies an index, and out-of-range results are zero.
  • An x0 source is zero and writes to x0 are discarded. Overlap reads values before writeback; equal source registers share one value. No memory access.

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.