§ 5.1.1. Multiply and Divide Units¶
RV32IM adds eight instructions to RV32I: four multiplies (MUL, MULH,
MULHSU, MULHU) and four divides (DIV, DIVU, REM, REMU). Their
hardware is built the way a person multiplies and divides on paper: one bit
per clock edge, with a small adder or subtractor doing each step. A 32-bit
operation takes one launch edge and then 32 step edges.
| Component | Description | Structural | Behavioral |
|---|---|---|---|
MultiplyStep<W> |
One shift-and-add step: add the multiplicand when the current bit is 1 | Yes | Yes, explicit gate-list form |
DivideStep<W> |
One restoring-division step: subtract the divisor when it fits | Yes | Yes, explicit gate-list form |
Multiplier<W> |
W steps of MultiplyStep<W> with a launch/result handshake |
Yes | No |
Divider<W> |
W steps of DivideStep<W> with the same handshake |
Yes | No |
MulDivUnit<W> |
A multiplier and a divider behind one interface, selected by the instruction's funct3 | Yes | Yes (W = 32) |
All five support W = 4, 8, 16 and 32 (catalog arithmetic.multiply-step.W,
arithmetic.divide-step.W, arithmetic.iterative.multiplier.W,
arithmetic.iterative.divider.W, arithmetic.iterative.mul-div.W). The
core uses W = 32; the 4-bit forms are small enough to inspect bit by bit.
The step components' compact forms come from the shared gate-list registry.
They are selected by an explicit choice, such as collapsing that component
in the explorer; general compact preferences keep their gates. This does
not add compact standalone Multiplier<W> or Divider<W> roots.
A worked example¶
7 × 5 with W = 4 (A = 0111, B = 0101). Each step looks at one bit of
B, from the lowest, and adds A into the high half when that bit is 1;
then the pair (high half, low half) shifts right one place.
| Step | Bit of B | High half before | Added | Sum (carry, 4 bits) | After shift: high · low |
|---|---|---|---|---|---|
| 1 | 1 | 0000 | 0111 | 0 0111 | 0011 · 1... |
| 2 | 0 | 0011 | 0000 | 0 0011 | 0001 · 11.. |
| 3 | 1 | 0001 | 0111 | 0 1000 | 0100 · 011. |
| 4 | 0 | 0100 | 0000 | 0 0100 | 0010 · 0011 |
The result is high 0010, low 0011: 0010 0011 = 35. Division runs the same way backwards: shift one dividend bit into the remainder, and subtract the divisor when it fits, writing a quotient bit of 1.
5.1.1.1. MultiplyStep<W>¶
IO pins¶
| Pin | Direction | Width | Meaning |
|---|---|---|---|
A |
Input | W | Multiplicand |
BIT |
Input | 1 | Current multiplier bit |
HI |
Input | W | Running high half |
CARRY |
Output | 1 | Carry out of the addition |
SUM |
Output | W | HI + (BIT ? A : 0), W bits |
Behavior¶
SUM and CARRY are HI + (BIT ? A : 0) as a W+1-bit result. The part is
combinational. BIT = 0 adds nothing.
C++ reference¶
#include <cstdint>
#include <utility>
template<unsigned W>
std::pair<uint32_t, bool> multiply_step_ref(uint32_t hi, uint32_t a, bool bit) {
static_assert(W == 4 || W == 8 || W == 16 || W == 32);
constexpr uint64_t mask = (uint64_t{1} << W) - 1;
const uint64_t sum = (hi & mask) + (bit ? (a & mask) : 0);
return {uint32_t(sum & mask), bool(sum >> W)}; // SUM, CARRY
}
This is a binary settled-value reference, with a wide temporary so the carry
is retained even at W = 32. It does not model gate delays or four-state values.
In the circuit, a known BIT = 0 masks even unknown bits of A; uncertainty
in HI can still reach the sum. With BIT = X or Z, each AND lane uses
the usual four-state rules rather than choosing a host-language branch.
Implementation¶
One ANDGate<W> masks A with BIT (the bit is spread to every lane by
wiring), and an adder adds the result to HI: full adders at W = 4, the
ParallelPrefixAdder<W> of § 2 at 8, 16 and 32 bits.
No host multiplication runs inside the component.
Timing follows the masking gate and the adder's carry paths. The explicit compact step evaluates this same gate list, including four-state masking, and derives its delays when first built. There is no stored step-delay table in the current generated files; numeric path rows require an export of that derived table for the chosen width. A compact parent unit also includes these same gates in its compiled circuit.
Examples¶
All 7 recorded rows of MultiplyStepScenarioTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-compact-v1 / structural (763e0b8bac717d60). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 4 bit |
BITInput · 1 bit |
HIInput · 4 bit |
CARRYExpected output · 1 bit |
SUMExpected output · 4 bit |
|---|---|---|---|---|---|---|
#0reset | 5 | 0x0 |
0 |
0x0 |
not checked | not checked |
#1add-selected | 14 | 0xB |
1 |
0xD |
1 |
0x8 |
#2skip | 23 | 0xB |
0 |
0xD |
0 |
0xD |
#3zero | 26 | 0x0 |
1 |
0x0 |
0 |
0x0 |
#4maximum-carry | 31 | 0xF |
1 |
0xF |
1 |
0xE |
#5carry-boundary | 40 | 0x1 |
1 |
0xF |
1 |
0x0 |
#6maximum-skip | 50 | 0x1 |
0 |
0xF |
0 |
0xF |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
5.1.1.2. DivideStep<W>¶
IO pins¶
| Pin | Direction | Width | Meaning |
|---|---|---|---|
BIT |
Input | 1 | Next dividend bit shifted in |
DIVISOR |
Input | W | Divisor |
REMAINDER |
Input | W | Partial remainder |
NEXT_REMAINDER |
Output | W | Remainder after this step |
QUOTIENT_BIT |
Output | 1 | 1 when the divisor was subtracted |
Behavior¶
Shift REMAINDER left by one place, bring in BIT, and compare the W+1-bit
result with DIVISOR. When it is at least the divisor, subtract and set
QUOTIENT_BIT; otherwise keep it. NEXT_REMAINDER is the low W bits. Every
binary input is defined, including a zero divisor (the step always
subtracts).
C++ reference¶
#include <cstdint>
#include <utility>
template<unsigned W>
std::pair<uint32_t, bool> divide_step_ref(uint32_t remainder,
uint32_t divisor, bool bit) {
static_assert(W == 4 || W == 8 || W == 16 || W == 32);
constexpr uint64_t mask = (uint64_t{1} << W) - 1;
const uint64_t shifted = (uint64_t(remainder & mask) << 1) | bit;
const uint64_t d = divisor & mask;
const bool subtract = shifted >= d;
return {uint32_t((subtract ? shifted - d : shifted) & mask), subtract};
}
The wide temporary matters: discarding the old remainder's top bit before
the comparison gives the wrong quotient bit. The result pair is
NEXT_REMAINDER, QUOTIENT_BIT. Unknown inputs in the circuit propagate
through subtraction and selection; this binary reference does not assign
an integer value to X or Z.
Implementation¶
A subtractor computes the shifted remainder minus the divisor; the bit that
was shifted out of the remainder and the subtractor's carry together decide
whether the divisor fits, so no W+1-bit pin is needed. One Mux<2,W> chooses
the difference or the shifted remainder.
Its explicit compact form evaluates the same combinational gates, with four-state values and width-specific delays derived at build time. As with the multiply step, there is no current stored table to render here without exporting the chosen configuration's derived paths.
Examples¶
All 7 recorded rows of DivideStepScenarioTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-compact-v1 / structural (763e0b8bac717d60). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | BITInput · 1 bit |
DIVISORInput · 4 bit |
REMAINDERInput · 4 bit |
NEXT_REMAINDERExpected output · 4 bit |
QUOTIENT_BITExpected output · 1 bit |
|---|---|---|---|---|---|---|
#0reset | 11 | 0 |
0x0 |
0x0 |
not checked | not checked |
#1subtract | 22 | 1 |
0x5 |
0x3 |
0x2 |
1 |
#2retain | 32 | 0 |
0x5 |
0x1 |
0x2 |
0 |
#3equal | 46 | 1 |
0x5 |
0x2 |
0x0 |
1 |
#4high-remainder | 56 | 1 |
0xF |
0xF |
0x0 |
1 |
#5zero-divisor | 68 | 0 |
0x0 |
0x0 |
0x0 |
1 |
#6below-divisor | 77 | 1 |
0xF |
0x0 |
0x1 |
0 |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
5.1.1.3. Multiplier<W>¶
IO pins¶
| Pin | Direction | Width | Meaning |
|---|---|---|---|
A |
Input | W | First operand |
B |
Input | W | Second operand |
CANCEL |
Input | 1 | Synchronously discard the operation, even while paused |
CLK |
Input | 1 | Rising edges launch and step the operation |
ENABLE |
Input | 1 | Low pauses iteration and completion |
RST |
Input | 1 | Active-high reset: discards any operation |
SIGNED_A |
Input | 1 | Treat A as signed for HI |
SIGNED_B |
Input | 1 | Treat B as signed for HI |
START |
Input | 1 | Launch request |
TAKE |
Input | 1 | Consume a completed result |
BUSY |
Output | 1 | An operation is iterating |
DONE |
Output | 1 | A result is held |
HI |
Output | W | High W bits of the product |
LO |
Output | W | Low W bits of the product |
READY |
Output | 1 | A launch would be accepted |
Behavior¶
Edge (with ENABLE = 1) |
Effect |
|---|---|
START and READY |
Capture A, B and the signedness; BUSY rises |
| Each of the next W edges | One MultiplyStep<W>: add, then shift the product pair |
| After the last step | DONE rises; HI, LO hold the product |
TAKE while DONE |
Release the result; READY rises |
LO is the low half for every signedness. For HI, a signed operand that
is negative contributes a correction: the unsigned high half minus the other
operand. ENABLE = 0 pauses the steps and holds a finished result. CANCEL
discards the operation on the next edge even while paused; RST clears
everything at once. A START while not READY is ignored; changing A or
B after launch has no effect.
Implementation¶
| Group | Contents |
|---|---|
CONTROL |
Busy and done state, a log2(W)-bit step counter, enables |
OPERANDS |
The captured operands and signedness |
DATAPATH |
High and low product registers, MultiplyStep<W>, next-value muxes |
RESULT |
The signed correction of the high half |
Examples¶
The recording covers unsigned, signed and mixed-sign products, high-word boundaries, a pause, a held result, consumption, cancellation while paused and reset during an operation.
All 29 recorded rows of MultiplierWidth32ScenarioTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-compact-v1 / structural (763e0b8bac717d60). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 32 bit |
BInput · 32 bit |
CANCELInput · 1 bit |
CLKInput · 1 bit |
ENABLEInput · 1 bit |
RSTInput · 1 bit |
SIGNED_AInput · 1 bit |
SIGNED_BInput · 1 bit |
STARTInput · 1 bit |
TAKEInput · 1 bit |
BUSYExpected output · 1 bit |
DONEExpected output · 1 bit |
HIExpected output · 32 bit |
LOExpected output · 32 bit |
READYExpected output · 1 bit |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
#0reset | 25 | 0x00000000 |
0x00000000 |
0 |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
not checked | not checked | not checked | not checked | not checked |
#1ready | 37 | 0x00000000 |
0x00000000 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
not checked | not checked | not checked | not checked | not checked |
#2unsigned-launch | 55 | 0x0000000D |
0x00000011 |
0 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
not checked | not checked | 0 |
#3unsigned-paused | 77 | 0x0000000D |
0x00000011 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
not checked | not checked | 0 |
#4unsigned-complete | 707 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0x00000000 |
0x000000DD |
0 |
#5unsigned-held | 714 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
0x00000000 |
0x000000DD |
0 |
#6unsigned-take | 729 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
not checked | not checked | 1 |
#7signed-launch | 760 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
1 |
0 |
not checked | not checked | 0 |
#8signed-complete | 1685 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
0 |
1 |
0xFFFFFFFF |
0xFFFFFFEB |
0 |
#9signed-held | 1692 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
0xFFFFFFFF |
0xFFFFFFEB |
0 |
#10signed-take | 1707 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
not checked | not checked | 1 |
#11mixed-sign-launch | 1736 | 0x80000000 |
0xFFFFFFFF |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
1 |
0 |
not checked | not checked | 0 |
#12mixed-sign-complete | 2290 | 0x80000000 |
0xFFFFFFFF |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
0x80000000 |
0x80000000 |
0 |
#13mixed-sign-held | 2297 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
1 |
0x80000000 |
0x80000000 |
0 |
#14mixed-sign-take | 2312 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
not checked | not checked | 1 |
#15signed-minimum-launch | 2343 | 0x80000000 |
0xFFFFFFFF |
0 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
1 |
0 |
not checked | not checked | 0 |
#16signed-minimum-complete | 2897 | 0x80000000 |
0xFFFFFFFF |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
0 |
1 |
0x00000000 |
0x80000000 |
0 |
#17signed-minimum-held | 2904 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
1 |
1 |
1 |
0 |
0 |
1 |
0x00000000 |
0x80000000 |
0 |
#18signed-minimum-take | 2919 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
not checked | not checked | 1 |
#19unsigned-high-launch | 2951 | 0xFFFFFFFF |
0xFFFFFFFF |
0 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
not checked | not checked | 0 |
#20unsigned-high-complete | 3694 | 0xFFFFFFFF |
0xFFFFFFFF |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0xFFFFFFFE |
0x00000001 |
0 |
#21unsigned-high-held | 3701 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
0xFFFFFFFE |
0x00000001 |
0 |
#22unsigned-high-take | 3716 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
not checked | not checked | 1 |
#23cancel-launch | 3746 | 0x0000000D |
0x00000011 |
0 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
not checked | not checked | not checked |
#24cancel-while-paused | 3760 | 0x0000000D |
0x00000011 |
1 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
not checked | not checked | 0 |
#25canceled-ready | 3766 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
not checked | not checked | 1 |
#26reset-launch | 3785 | 0x0000000D |
0x00000011 |
0 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
1 |
not checked | not checked | not checked | not checked |
#27reset-in-flight | 3796 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
not checked | not checked | 0 |
#28reset-released | 3801 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
not checked | not checked | 1 |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
5.1.1.4. Divider<W>¶
IO pins¶
| Pin | Direction | Width | Meaning |
|---|---|---|---|
A |
Input | W | Dividend |
B |
Input | W | Divisor |
CANCEL |
Input | 1 | Synchronously discard the operation, even while paused |
CLK |
Input | 1 | Rising edges launch and step the operation |
ENABLE |
Input | 1 | Low pauses iteration and completion |
RST |
Input | 1 | Active-high reset: discards any operation |
SIGNED |
Input | 1 | Signed division |
START |
Input | 1 | Launch request |
TAKE |
Input | 1 | Consume a completed result |
BUSY |
Output | 1 | An operation is iterating |
DONE |
Output | 1 | A result is held |
QUOTIENT |
Output | W | Quotient |
READY |
Output | 1 | A launch would be accepted |
REMAINDER |
Output | W | Remainder |
Behavior¶
The same handshake as the multiplier: one launch edge, W step edges, a held
result. SIGNED divides the magnitudes and then fixes the signs: the
quotient rounds toward zero and the remainder takes the dividend's sign.
Two cases follow the RISC-V M rules rather than trapping:
| Case | Quotient | Remainder |
|---|---|---|
| Divide by zero | all ones (2^W − 1, or −1 signed) | the dividend |
| Signed overflow (most negative ÷ −1) | the most negative value | 0 |
Implementation¶
| Group | Contents |
|---|---|
CONTROL |
Busy and done state, step counter, enables |
OPERANDS |
Divisor magnitude, dividend magnitude, captured signs |
DATAPATH |
Quotient and remainder registers, DivideStep<W>, next-value muxes |
RESULT |
Sign correction and the divide-by-zero rule |
Examples¶
The recording covers nonzero remainders, each negative operand, division by zero, signed overflow, pause, hold, consume, cancellation while paused and reset during an operation.
All 29 recorded rows of DividerWidth32ScenarioTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-compact-v1 / structural (763e0b8bac717d60). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 32 bit |
BInput · 32 bit |
CANCELInput · 1 bit |
CLKInput · 1 bit |
ENABLEInput · 1 bit |
RSTInput · 1 bit |
SIGNEDInput · 1 bit |
STARTInput · 1 bit |
TAKEInput · 1 bit |
BUSYExpected output · 1 bit |
DONEExpected output · 1 bit |
QUOTIENTExpected output · 32 bit |
READYExpected output · 1 bit |
REMAINDERExpected output · 32 bit |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
#0reset | 20 | 0x00000000 |
0x00000000 |
0 |
0 |
1 |
1 |
0 |
0 |
0 |
not checked | not checked | not checked | not checked | not checked |
#1ready | 32 | 0x00000000 |
0x00000000 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
not checked | not checked | not checked | not checked | not checked |
#2unsigned-launch | 62 | 0x00000064 |
0x00000007 |
0 |
1 |
1 |
0 |
0 |
1 |
0 |
1 |
0 |
not checked | 0 |
not checked |
#3unsigned-paused | 84 | 0x00000064 |
0x00000007 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
not checked | 0 |
not checked |
#4unsigned-complete | 650 | 0x00000064 |
0x00000007 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
1 |
0x0000000E |
0 |
0x00000002 |
#5unsigned-held | 666 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
0x0000000E |
0 |
0x00000002 |
#6unsigned-take | 681 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
0 |
not checked | 1 |
not checked |
#7negative-dividend-launch | 709 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
not checked | 0 |
not checked |
#8negative-dividend-complete | 1302 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
0xFFFFFFFE |
0 |
0xFFFFFFFF |
#9negative-dividend-held | 1318 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0xFFFFFFFE |
0 |
0xFFFFFFFF |
#10negative-dividend-take | 1333 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked | 1 |
not checked |
#11negative-divisor-launch | 1360 | 0x00000007 |
0xFFFFFFFD |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
not checked | 0 |
not checked |
#12negative-divisor-complete | 1953 | 0x00000007 |
0xFFFFFFFD |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
0xFFFFFFFE |
0 |
0x00000001 |
#13negative-divisor-held | 1969 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0xFFFFFFFE |
0 |
0x00000001 |
#14negative-divisor-take | 1984 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked | 1 |
not checked |
#15divide-zero-launch | 2008 | 0x0000000D |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
not checked | 0 |
not checked |
#16divide-zero-complete | 2565 | 0x0000000D |
0x00000000 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
0xFFFFFFFF |
0 |
0x0000000D |
#17divide-zero-held | 2574 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0xFFFFFFFF |
0 |
0x0000000D |
#18divide-zero-take | 2589 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked | 1 |
not checked |
#19signed-overflow-launch | 2626 | 0x80000000 |
0xFFFFFFFF |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
not checked | 0 |
not checked |
#20signed-overflow-complete | 3200 | 0x80000000 |
0xFFFFFFFF |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
0x80000000 |
0 |
0x00000000 |
#21signed-overflow-held | 3216 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
0 |
1 |
0x80000000 |
0 |
0x00000000 |
#22signed-overflow-take | 3231 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked | 1 |
not checked |
#23cancel-launch | 3260 | 0x0000000D |
0x00000011 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
0 |
not checked | not checked | not checked |
#24cancel-while-paused | 3274 | 0x0000000D |
0x00000011 |
1 |
1 |
0 |
0 |
1 |
0 |
0 |
0 |
0 |
not checked | 0 |
not checked |
#25canceled-ready | 3280 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
0 |
not checked | 1 |
not checked |
#26reset-launch | 3299 | 0x0000000D |
0x00000011 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
not checked | not checked | not checked | not checked |
#27reset-in-flight | 3317 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
1 |
1 |
0 |
0 |
0 |
0 |
not checked | 0 |
not checked |
#28reset-released | 3322 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0 |
1 |
0 |
0 |
0 |
0 |
not checked | 1 |
not checked |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
5.1.1.5. MulDivUnit<W>¶
IO pins¶
| Pin | Direction | Width | Meaning |
|---|---|---|---|
A |
Input | W | rs1 value |
B |
Input | W | rs2 value |
CANCEL |
Input | 1 | Synchronously discard the operation, even while paused |
CLK |
Input | 1 | Rising edges launch and step the operation |
ENABLE |
Input | 1 | Low pauses iteration and completion |
OP |
Input | 3 | Operation: instruction funct3 |
RST |
Input | 1 | Active-high reset: discards any operation |
START |
Input | 1 | Launch request |
TAKE |
Input | 1 | Consume a completed result |
BUSY |
Output | 1 | An operation is iterating |
DONE |
Output | 1 | A result is held |
READY |
Output | 1 | A launch would be accepted |
RESULT |
Output | W | Selected result |
Behavior¶
OP is the instruction's funct3:
| OP | Instruction | RESULT |
|---|---|---|
| 0 | MUL |
Low half of the product |
| 1 | MULH |
High half, both signed |
| 2 | MULHSU |
High half, A signed, B unsigned |
| 3 | MULHU |
High half, both unsigned |
| 4 | DIV |
Signed quotient |
| 5 | DIVU |
Unsigned quotient |
| 6 | REM |
Signed remainder |
| 7 | REMU |
Unsigned remainder |
The launch captures OP with the operands; the handshake, latency and
cancellation are those of the units inside.
READY describes an idle slot, not permission to ignore ENABLE: a launch
needs ENABLE && START && READY. While disabled, TAKE does not release a
finished result. CANCEL has priority over normal busy/done updates even
when disabled, but does not promise that the old result bits become zero;
only a result with DONE = 1 is valid. Consuming a result and launching the
next operation require separate edges because READY is low while DONE
is high. Reset clears the stored state after its propagation delay.
The numerical instruction results and latency tests use known binary operands and controls after reset. Four-state signals still flow through the gates; no numerical multiply/divide result is promised for unknown operands or ambiguous clock edges.
Implementation¶
Structural implementation¶
A Multiplier<W> and a Divider<W> side by side, an operation register and
RESULT_SELECTION, the muxes that pick the product half or the quotient or
remainder. Exactly one engine takes each launch.
Behavioral implementation¶
At W = 32, the compact form runs this unit's own gates as a compiled gate list with characterized register state, and a delay table proven on the same circuit. It keeps the 33-edge latency and the handshake; it is not a host multiplication.
Timing. Under a synchronous binary boundary, the structural unit
certifies a minimum clock period of 48 unit ticks, 2322 ps (embedded) and
1620 ps (desktop); RV32IMTimingTest derives each.
The selected paths below come directly from the stored default 32-bit table, with reset inactive. Setup and clock-to-output values describe propagation around an edge; the 33-edge algorithm latency is separate. The standalone clock certificate also accounts for the falling-edge input constraints and can exceed the table's internal register-to-register period.
Latest time each path can still change after its input (for a setup row: how long before the edge the input must be stable), proven on the gate-level form.
| Path | unitticks | embeddedps | desktopps |
|---|---|---|---|
Edge to result CLK ↑ → RESULT | 34 | 1,965 | 1,367 |
Launch setup START before CLK ↑ | 16 | 715 | 498 |
Operand setup A before CLK ↑ | 22 | 1,159 | 808 |
Cancel to ready CANCEL → READY | 4 | 182 | 127 |
Examples¶
The recording runs all eight operations, divide by zero, signed overflow, and the pause, cancel and reset transitions.
All 49 recorded rows of MulDivUnitWidth32ScenarioTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-logic-v1 / structural (3c048584c5332bb2). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | AInput · 32 bit |
BInput · 32 bit |
CANCELInput · 1 bit |
CLKInput · 1 bit |
ENABLEInput · 1 bit |
OPInput · 3 bit |
RSTInput · 1 bit |
STARTInput · 1 bit |
TAKEInput · 1 bit |
BUSYExpected output · 1 bit |
DONEExpected output · 1 bit |
READYExpected output · 1 bit |
RESULTExpected output · 32 bit |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
#0reset | 26 | 0x00000000 |
0x00000000 |
0 |
0 |
1 |
0x0 |
1 |
0 |
0 |
not checked | not checked | not checked | not checked |
#1ready | 39 | 0x00000000 |
0x00000000 |
0 |
0 |
1 |
0x0 |
0 |
0 |
0 |
not checked | not checked | not checked | not checked |
#2MUL-launch | 65 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x0 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#3MUL-paused | 87 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
0 |
0x0 |
0 |
0 |
0 |
1 |
0 |
0 |
not checked |
#4MUL-complete | 971 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x0 |
0 |
0 |
0 |
0 |
1 |
0 |
0xFFFFFFEB |
#5MUL-held | 988 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x0 |
0 |
1 |
0 |
0 |
1 |
0 |
0xFFFFFFEB |
#6MUL-take | 1004 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x0 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#7MULH-launch | 1044 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x1 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#8MULH-complete | 2026 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x1 |
0 |
0 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#9MULH-held | 2043 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x1 |
0 |
1 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#10MULH-take | 2059 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x1 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#11MULHSU-launch | 2087 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x2 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#12MULHSU-complete | 3069 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x2 |
0 |
0 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#13MULHSU-held | 3086 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x2 |
0 |
1 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#14MULHSU-take | 3102 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x2 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#15MULHU-launch | 3144 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x3 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#16MULHU-complete | 4118 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x3 |
0 |
0 |
0 |
0 |
1 |
0 |
0x00000002 |
#17MULHU-held | 4135 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x3 |
0 |
1 |
0 |
0 |
1 |
0 |
0x00000002 |
#18MULHU-take | 4151 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x3 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#19DIV-launch | 4183 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x4 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#20DIV-complete | 4890 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x4 |
0 |
0 |
0 |
0 |
1 |
0 |
0xFFFFFFFE |
#21DIV-held | 4907 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x4 |
0 |
1 |
0 |
0 |
1 |
0 |
0xFFFFFFFE |
#22DIV-take | 4923 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x4 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#23DIVU-launch | 4950 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x5 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#24DIVU-complete | 5622 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x5 |
0 |
0 |
0 |
0 |
1 |
0 |
0x55555553 |
#25DIVU-held | 5639 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x5 |
0 |
1 |
0 |
0 |
1 |
0 |
0x55555553 |
#26DIVU-take | 5655 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x5 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#27REM-launch | 5680 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x6 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#28REM-complete | 6300 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x6 |
0 |
0 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#29REM-held | 6317 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x6 |
0 |
1 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#30REM-take | 6333 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x6 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#31REMU-launch | 6360 | 0xFFFFFFF9 |
0x00000003 |
0 |
1 |
1 |
0x7 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#32REMU-complete | 7032 | 0xFFFFFFF9 |
0x00000003 |
0 |
0 |
1 |
0x7 |
0 |
0 |
0 |
0 |
1 |
0 |
0x00000000 |
#33REMU-held | 7049 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x7 |
0 |
1 |
0 |
0 |
1 |
0 |
0x00000000 |
#34REMU-take | 7065 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x7 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#35divide-zero-launch | 7092 | 0x0000000D |
0x00000000 |
0 |
1 |
1 |
0x4 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#36divide-zero-complete | 7650 | 0x0000000D |
0x00000000 |
0 |
0 |
1 |
0x4 |
0 |
0 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#37divide-zero-held | 7663 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x4 |
0 |
1 |
0 |
0 |
1 |
0 |
0xFFFFFFFF |
#38divide-zero-take | 7679 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x4 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#39signed-overflow-launch | 7713 | 0x80000000 |
0xFFFFFFFF |
0 |
1 |
1 |
0x4 |
0 |
1 |
0 |
1 |
0 |
0 |
not checked |
#40signed-overflow-complete | 8302 | 0x80000000 |
0xFFFFFFFF |
0 |
0 |
1 |
0x4 |
0 |
0 |
0 |
0 |
1 |
0 |
0x80000000 |
#41signed-overflow-held | 8319 | 0x00000063 |
0x00000000 |
0 |
1 |
0 |
0x4 |
0 |
1 |
0 |
0 |
1 |
0 |
0x80000000 |
#42signed-overflow-take | 8335 | 0x00000063 |
0x00000000 |
0 |
1 |
1 |
0x4 |
0 |
0 |
1 |
0 |
0 |
1 |
not checked |
#43cancel-launch | 8365 | 0x0000000D |
0x00000011 |
0 |
1 |
1 |
0x4 |
0 |
1 |
0 |
1 |
0 |
not checked | not checked |
#44cancel-while-paused | 8380 | 0x0000000D |
0x00000011 |
1 |
1 |
0 |
0x4 |
0 |
0 |
0 |
0 |
0 |
0 |
not checked |
#45canceled-ready | 8387 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0x4 |
0 |
0 |
0 |
0 |
0 |
1 |
not checked |
#46reset-launch | 8409 | 0x0000000D |
0x00000011 |
0 |
1 |
1 |
0x4 |
0 |
1 |
0 |
1 |
not checked | not checked | not checked |
#47reset-in-flight | 8431 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0x4 |
1 |
0 |
0 |
0 |
0 |
0 |
not checked |
#48reset-released | 8437 | 0x0000000D |
0x00000011 |
0 |
0 |
1 |
0x4 |
0 |
0 |
0 |
0 |
0 |
1 |
not checked |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
Source and tests¶
- Interfaces and supported widths
- Structural assembly, iteration, datapath and sign-correction groups
- Compact gate-list implementation, functional tests, clock certificates
- Shared explicit compact registry adds the step forms after module registration.
| Test | Coverage |
|---|---|
MultiplyStepTest, DivideStepTest |
Every 4-bit input combination and 128 spread input cases at each of 8, 16 and 32 bits (64 operand pairs × both BIT values), against an integer reference, structural and with compact children |
MultiplierWidth32Test, DividerWidth32Test, MulDivUnitWidth32Test |
Launch, latency, pause, hold, cancel, reset; signed and unsigned boundaries |
MulDivGateLevelTest |
The fully gate-level unit: an exhaustive 4-bit MulDivUnit<4>, boundary 8/16/32-bit operands |
WidthComponentsTest |
Latency and results at W = 4, 8, 16, 32 |
GateListCompactEquivalenceTest |
Explicit compact step forms versus their gates: binary, dense four-state and single-X/Z vectors |
*ScenarioTest |
The recorded examples above, both available fidelities |