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 4-bit elements and each 4-bit element of rs2 as an index. For each result position, if the index is less than XLEN/4, the corresponding 4-bit element from rs1 is written to rd; otherwise that result element is written as zero. It is used for constant-time S-boxes, permutations, and cryptographic bit manipulation.

Quick Understanding & Search Notes

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

When available on RV32/RV64, operation width follows XLEN.
Do not modulo-wrap rs2 indexes; out-of-range result elements are zero.

Common Usage Scenarios

Immediates & Constants

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

Network & Byte Order

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

Vector Operations

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

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

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 instruction is only a permutation/table-lookup primitive; algorithm security still depends on the whole implementation.
Indexes come from rs2 and rs1 is the lookup table; out-of-range indexes produce zero rather than wrapping.

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.