brev8

Reverse bits in bytes

This instruction is defined by:

  • Zbkb, version >= 0

This instruction is included in the following profiles:

Encoding

svg

Assembly format

brev8 rd, rs1

Synopsis

This instruction 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> rs1 = $encoding[19:15];
Bits<5> rd = $encoding[11:7];

Execution

  • IDL

  • Sail

XReg input = X[rs1];
XReg output = 0;
for (U32 i = 0; i < (xlen() - 8); i = i + 8) {
  for (U32 j = 0; j < 8; j = j + 1) {
    output[(i * 8) + (7 - j)] = input[(i * 8) + j];
  }
}
X[rd] = output;
result : xlenbits = EXTZ(0b0);
foreach (i from 0 to sizeof(xlen) by 8) {
  result[i+7..i] = reverse_bits_in_byte(X(rs1)[i+7..i]);
};
X(rd) = result;