Webcentive RISC-V Reference

brev8

Reverse bits in bytes

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

Encoding

3120191514121176210
011010000111rs1101rd0010011

Match 0x68705013, mask 0xfff0707f. Source: brev8 rd rs1 31..20=0x687 14..12=5 6..2=0x4 1..0=0x3 in riscv-opcodes/extensions/rv_zbkb.

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

Description

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

Description from riscv-unified-db, reformatted.

Operation

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;

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

Specification and related pages