Webcentive RISC-V Reference

rev8

Byte-reverse register (RV64 encoding)

Extension
Zbb, Zbkb, Zk, Zkn, Zks
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
rev8 xd, xs1
Length
32-bit

Encoding

RV64 form

31201915141211760
011010111000rs1101rd0010011

Match 0x6b805013, mask 0xfff0707f. Source: rev8 rd rs1 31..20=0x6B8 14..12=5 6..0=0x13 in riscv-opcodes/extensions/rv64_zbb.

FieldBitsriscv-opcodes name
rs119:15rs1
rd11:7rd

RV32 form; listed in riscv-opcodes as a pseudo-op of rev8.rv32

31201915141211760
011010011000rs1101rd0010011

Match 0x69805013, mask 0xfff0707f. Source: $pseudo_op rv32_zbkb::rev8.rv32 rev8.rv32 rd rs1 31..20=0x698 14..12=5 6..0=0x13 in riscv-opcodes/extensions/rv32_zbb.

FieldBitsriscv-opcodes name
rs119:15rs1
rd11:7rd

Description

Reverses the order of the bytes in xs1.

Note: The rev8 mnemonic corresponds to different instruction encodings in RV32 and RV64.

Note: 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.

Description from riscv-unified-db, reformatted.

Operation

XReg input = X[xs1];
XReg output = 0;

XReg j = xlen() - 1;

for (U32 i=0; i < xlen(); i = i+8) {
  output[(i+7):i] = input[j:(j-7)];
  j = j - 8;
}

X[xd] = output;

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages