xperm4

Crossbar permutation (nibbles)

This instruction is defined by:

Encoding

svg

Synopsis

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.

Access

M HS U VS VU

Always

Always

Always

Always

Always

Decode Variables

Bits<5> xs2 = $encoding[24:20];
Bits<5> xs1 = $encoding[19:15];
Bits<5> xd = $encoding[11:7];

Execution

  • Pruned, XLEN == 64

  • Original

XReg input1 = X[xs1];
XReg input2 = X[xs2];
XReg output = 0;
for (U32 i = 0; i < 8'64; i = i + 4) {
  XReg index = input2[i + 3:i];
  if (4 * index < 8'64) {
    output[i + 3:i] = input1[4 * index + 3:4 * index];
  }
}
X[xd] = output;
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;