xperm4

Crossbar permutation (nibbles)

This instruction is defined by:

  • Zbkx, version >= 0

This instruction is included in the following profiles:

Encoding

svg

Assembly format

xperm4 rd, rs1, rs2

Synopsis

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

Access

M HS U VS VU

Always

Always

Always

Always

Always

Decode Variables

Bits<5> rs2 = $encoding[24:20];
Bits<5> rs1 = $encoding[19:15];
Bits<5> rd = $encoding[11:7];

Execution

  • IDL

  • Sail

XReg input1 = X[rs1];
XReg input2 = X[rs2];
XReg output = 0;
for (U32 i = 0; i < (xlen() - 4); i = i + 4) {
  XReg index = input2[i + 3:i];
  if (4 * index < xlen()) {
    output[i + 3:i] = input1[4 * index + 3:4 * index];
  }
}
X[rd] = output;
val xperm4_lookup : (bits(4), xlenbits) -> bits(4)
function xperm4_lookup (idx, lut) = {
  (lut >> (idx @ 0b00))[3..0]
}
function clause execute ( XPERM_4 (rs2,rs1,rd)) = {
  result : xlenbits = EXTZ(0b0);
  foreach(i from 0 to xlen by 4) {
    result[i+3..i] = xperm4_lookup(X(rs2)[i+3..i], X(rs1));
  };
  X(rd) = result;
  RETIRE_SUCCESS
}