divu
lyszt.net covers divu and other RISC-V instructions in more detail.
Encoding format
Description
Divides the value of one register by another, reading both as unsigned numbers. In divu rd, rs1, rs2, the quotient of rs1 and rs2 goes to rd. The unsigned reading counts the 32 bits from 0 to about 4 billion and serves addresses, sizes, counts and pixel coordinates, where signed div returns wrong results once a value passes about 2 billion with its top bit set. A zero divisor also differs from the signed case, yielding the largest unsigned value with every bit set.
Official definition
DIV and DIVU perform an XLEN bits by XLEN bits signed and unsigned integer division of rs1 by rs2, rounding towards zero. REM and REMU provide the remainder of the corresponding division operation. For REM, the sign of a nonzero result equals the sign of the dividend.
| Condition | Dividend | Divisor | DIVU[W] | REMU[W] | DIV[W] | REM[W] |
|---|---|---|---|---|---|---|
| Division by zero Overflow (signed only) | x -2^L-1 | 0 −1 | 2^L-1 - | x - | −1 -2^L-1 | x 0 |