brev8

Reverse bits in bytes

This instruction is defined by:

Encoding

svg

Synopsis

Reverses the order of the bits in every byte of a register.

Access

M HS U VS VU

Always

Always

Always

Always

Always

Decode Variables

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

Execution

  • Pruned, XLEN == 64

  • Original

XReg input = X[xs1];
XReg output = 0;
for (U32 i = 0; i < 8'64; i = i + 8) {
  for (U32 j = 0; j < 8; j = j + 1) {
    output[i + (7 - j)] = input[i + j];
  }
}
X[xd] = output;
XReg input = X[xs1];
XReg output = 0;
for (U32 i = 0; i < xlen(); i = i + 8) {
  for (U32 j = 0; j < 8; j = j + 1) {
    output[i + (7 - j)] = input[i + j];
  }
}
X[xd] = output;