This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
Add 32:32->32 division operations (where the lower 32 bits are zero) #111
Open
Description
The following two instructions would be useful:
Instruction | Description |
---|---|
DIVHI | Compute (a << 32) / b , signed |
DIVHIU | Compute (a << 32) / b , unsigned |
If the first source operand is larger than the second source operand, an overflow will occur. This should produce the same result as division by zero (as specified for DIV and DIVU).
One use case for these instructions is to implement fixed point division, such that:
div s3, s1, s2 ; s3 = 32-bit integer part of division (a / b)
rem s4, s1, s2 ; s4 = division remainder (a % b)
divhi s4, s4, s2 ; s4 = 32-bit fractional part of division (((a % b) << 32) / b)