rev8

Byte-reverse register (RV64 encoding)

This instruction is defined by:

Encoding

svg

Synopsis

Reverses the order of the bytes in rs1.

The rev8 mnemonic corresponds to different instruction encodings in RV32 and RV64.
The byte-reverse operation is only available for the full register width. To emulate word-sized and halfword-sized byte-reversal, perform a rev8 xd,xs1 followed by a srai xd,xd,K, where K is XLEN-32 and XLEN-16, respectively.

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

if (implemented?(ExtensionName::B) && (misa.B == 1'b0)) {
  raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
}
XReg input = X[xs1];
XReg output = 0;
XReg j = 63;
for (U32 i = 0; i < (56); i = i + 8) {
  output[(i + 7):i] = input[j:(j - 7)];
  j = j - 8;
}
X[xd] = output;
if (implemented?(ExtensionName::B) && (misa.B == 1'b0)) {
  raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
}
XReg input = X[xs1];
XReg output = 0;
XReg j = xlen() - 1;
for (U32 i = 0; i < (xlen() - 8); i = i + 8) {
  output[(i + 7):i] = input[j:(j - 7)];
  j = j - 8;
}
X[xd] = output;

Exceptions

This instruction may result in the following synchronous exceptions:

  • IllegalInstruction