Home/Instructions/Reverse Bits in Each Byte
BREV8

RISC-V BREV8 Instruction Details

Instruction ManualI-type

bit reverse in bytes (Zbkb).

Instruction Syntax

brev8 rd, rs1
Operand Breakdown
rd: receives the XLEN-bit result with each byte's bit order reversed.
rs1: supplies the XLEN-bit source grouped into 8-bit bytes.
Bits 31..20 are fixed to 011010000111; this is the BREV8 encoding selector, not an assembly immediate.
ZbkbBit Manipulation

Instruction Behavior

BREV8 reverses bits within each byte of rs1 (bit 0↔7, 1↔6, ... per byte), writing the result to rd. Part of the Zbkb scalar bit-manipulation extension.

BREV8 Decode & Execute Animation

Shows only official encodings, conditions, and architectural results; it does not imply a microarchitecture.

brev8 a0, a1
Execution context
x[a0] <- 0x80C4A2E691D5B3F7
Encoding fields
31..20
imm[11:0]
011010000111
19..15
rs1
01011
14..12
funct3
101
11..7
rd
01010
6..0
opcode
0010011
Encoding fields identify the instruction.
0x0123456789ABCDEF -> 0x80C4A2E691D5B3F7 (each byte reverses independently)
x[a0] <- 0x80C4A2E691D5B3F7
Architectural state has not been committed.

Quick Understanding & Search Notes

BREV8 belongs to Zbkb and operates on a 32/64-bit integer source on RV32/RV64. It reverses bits independently in each byte while keeping byte positions unchanged.

Within every byte, bits 0/7, 1/6, 2/5 and 3/4 exchange positions.
The encoding uses OP-IMM, imm[11:0]=011010000111 and funct3=101; this is not a variable shift.

Common Usage Scenarios

byte-local bit permutation

Understand this scenario with real code like «brev8 a0, a1 # Reverse bits in each byte of a1».

per-byte bit reversal

Understand this scenario with real code like «brev8 a0, a1 # Reverse bits in each byte of a1».

Pre-Use Checklist

Syntax Check
  • Confirm the assembly operands are only rd, rs1; bits 31..20 value 011010000111 is a fixed encoding selector, not an immediate.
  • Confirm the target implements Zbkb and reads rs1 and writes rd at the current XLEN.
Semantic Check
  • Confirm each 8-bit byte reverses bit[7:0] independently; no byte positions are exchanged.
  • Confirm this is a register-only bit permutation: it neither accesses memory nor treats the fixed encoding bits as runtime input.

Pitfalls / Common Confusions

Do not confuse it with REV8: BREV8 reverses bits within bytes, not byte order.
RV32/RV64 operate on XLEN=32/64 bits respectively; it accesses integer registers, not memory.

FAQ

Does BREV8 access memory?

No. It only rearranges bit fields within each byte of an integer register.

Which extension contains BREV8?

It belongs to the Zbkb cryptographic bit-manipulation extension.