Webcentive RISC-V Reference

c.bnez

Branch if NOT Equal Zero

Extension
C
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
c.bnez xs1, imm
Length
16-bit (compressed)

Encoding

15131210976210
111imm[8|4:3]rs1′imm[7:6|2:1|5]01

Match 0xe001, mask 0xe003. Source: c.bnez rs1_p c_bimm9lo c_bimm9hi 1..0=1 15..13=7 in riscv-opcodes/extensions/rv_c.

FieldBitsriscv-opcodes name
imm[8|4:3]12:10c_bimm9hi
rs1′9:7rs1_p
imm[7:6|2:1|5]6:2c_bimm9lo

Description

C.BNEZ performs conditional control transfers. The offset is sign-extended and added to the pc to form the branch target address. It can therefore target a ±256 B range. C.BNEZ takes the branch if the value in register xs1' is NOT zero. It expands to bne xs1, x0, offset.

Description from riscv-unified-db, reformatted.

Operation

if (implemented?(ExtensionName::C) && MISA_CSR_IMPLEMENTED && (CSR[misa].C == 1'b0)) {
  reserved_instruction($encoding);
}
if (X[creg2reg(xs1)] != 0) {
  jump($pc + $signed(imm));
}

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

Specification and related pages