XPERM8

RISC-V XPERM8 Instruction Details

Instruction ManualR-type

byte crossbar permutation (Zbkx).

Instruction Syntax

xperm8 rd, rs1, rs2

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

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

RV32/RV64 Zbkx; rs1 holds XLEN/8 8-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

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

XPERM8 Decode And Execute Animation

Each 8-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
100
rd
11..7
01010
opcode
6..0
0110011

Current calculation

0: 0 -> D4
1: 1 -> C3
2: 2 -> B2
3: 3 -> A1

x[rs2] indexes 4 entries in x[rs1]; result = 0xA1B2C3D4

Step: decode

Shows the instruction's fixed and register fields.

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

Quick Understanding & Search Notes

XPERM8 performs register lookup: rs1 holds XLEN/8 byte entries and each byte of rs2 selects an entry; out-of-range indexes produce zero.

Available on RV32 and RV64; each table entry and index is 8 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=0xA1B2C3D4, x12=0x00010203: xperm8 x10, x11, x12 gives x10=0xD4C3B2A1.

Register Lookup

RV32 Zbkx, x11=0xA1B2C3D4, x12=0x00010203: xperm8 x10, x11, x12 gives x10=0xD4C3B2A1.

Pre-Use Checklist

Syntax Check
  • Syntax: xperm8 rd, rs1, rs2; integer x0–x31 or ABI names, without an assembly immediate.
  • 32-bit OP: funct7=0010100, funct3=100, opcode=0110011.
Semantic Check
  • RV32/RV64 Zbkx; rs1 holds XLEN/8 8-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 8-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 8-bit elements.

FAQ

Does XPERM8 access memory?

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

Which extension contains XPERM8?

It belongs to the Zbkx crossbar-permutation extension.