Webcentive RISC-V Reference

xperm4

Crossbar permutation (nibbles)

Extension
Zbkx, Zk, Zkn, Zks
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
xperm4 xd, xs1, xs2
Length
32-bit

Encoding

31252420191514121176210
0010100rs2rs1010rd0110011

Match 0x28002033, mask 0xfe00707f. Source: xperm4 rd rs1 rs2 31..25=20 14..12=2 6..2=0x0C 1..0=3 in riscv-opcodes/extensions/rv_zbkx.

FieldBitsriscv-opcodes name
rs224:20rs2
rs119:15rs1
rd11:7rd

Description

The xperm4 instruction operates on nibbles. The xs1 register contains a vector of XLEN/4 4-bit elements. The xs2 register contains a vector of XLEN/4 4-bit indexes. The result is each element in xs2 replaced by the indexed element in xs1, or zero if the index into xs2 is out of bounds.

Description from riscv-unified-db, reformatted.

Operation

XReg input1 = X[xs1];
XReg input2 = X[xs2];
XReg output = 0;

for(U32 i=0; i < xlen(); i = i+4) {
  XReg index = input2[i+3:i];
  if(4*index < xlen()) {
    output[i+3:i] = input1[4*index+3:4*index];
  }
}

X[xd] = output;

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages