blez
pseudolyszt.net covers blez and other RISC-V instructions in more detail.
Description
blez takes a branch when the value in a register is zero or negative. The name means branch if less than or equal to zero. The form below jumps to the labeled position when rs is at most zero, and falls through to the next instruction otherwise.
blez rs, label
The assembler treats it as a pseudo-instruction and rewrites it to the instruction below, which asks whether zero is greater than or equal to the register.
bge zero, rs, label
The operands are swapped because RISC-V has no less-than-or-equal branch, so bge does the work, the same way ble is built. The comparison is signed. Zero branches, which separates blez from bltz, and it is the opposite of bgtz, so for any value exactly one of the two takes the branch. See bge for the underlying branch.
blez fits a check that nothing is left to do. A loop that processes a count of remaining items can leave as soon as the count is zero or has gone below it.
blez t0, done
The line above jumps to done when t0 is 0 or negative.
Expands to
bge zero, rs, label
The assembler replaces this pseudo-instruction with the real instruction or instructions listed above.
Example
li t0, 0 blez t0, done # t0 <= 0, so jump to 'done'
