Module 06: Binary Division (Restoring & Non-Restoring Division Algorithms)
Tags: #◇Computer Science #◇CSARCH2 #◇Computer Architecture #◇Hardware Modeling #◇Binary Division (Restoring & Non-Restoring Division Algorithms)
◇Overview
Binary division is the most computationally demanding primitive operation in fixed-point arithmetic logic units (ALUs). Unlike multiplication, which can be parallelized via combinational tree reduction networks, division is inherently sequential due to the sequential nature of quotient bit determination and remainder feedback. This module analyzes the mathematical principles and hardware realization of unsigned binary integer division. We examine the classic Restoring Division Algorithm, where incorrect trial subtractions are restored, and the Non-Restoring Division Algorithm, which eliminates restorative addition cycles by tracking sign history and deferring corrections.
◇Key Definitions
- Dividend (): The number being divided ( bits).
- Divisor (): The number by which the dividend is divided ( or bits).
- Quotient (): The integer result of the division operation ( bits).
- Remainder (): The leftover integer quantity satisfying the division invariant, residing in accumulator ( bits).
- Division Invariant: The fundamental mathematical relation governing integer division:
- Trial Subtraction: The exploratory subtraction of the divisor from the shifted partial remainder () to test if the divisor fits into the current dividend prefix.
- Restoring Division: An algorithm where, if a trial subtraction yields a negative partial remainder (), the original value of is restored by adding the divisor back (), and the quotient bit is set to
0. - Non-Restoring Division: An optimized algorithm that avoids intermediate restoring additions by performing in the subsequent cycle if the current remainder is negative, requiring at most one final correction step.
◇Theoretical Framework / Core Concepts
1. Hardware Datapath Organization for Binary Division
The division datapath employs three primary registers, an ALU capable of addition and subtraction, and a down-counter:
+-------------------------------------------------------------------------+
| BINARY DIVISION DATAPATH |
| |
| +-----------------------------------+ |
| | Divisor Register (M) | (n+1 bits, sign-extended) |
| +-----------------------------------+ |
| | |
| v |
| +-----------------------+ |
| | ALU Adder/Subtractor | |
| +-----------------------+ |
| ^ |
| | |
| v |
| +-----------------------+ +-----------------------+ |
| |Accumulator Register(A)| <--- | Dividend Register (Q) | |
| | (n+1 bits, init to 0) | | (n bits, holds D/Q) | |
| +-----------------------+ +-----------------------+ |
| | | | ^ |
| +-------+---- Shift Left (SHL) -------+ | |
| | |
| Sign Bit An ---------------------> Quotient Inverter --+ |
| (Q0 = ~An) |
+-------------------------------------------------------------------------+
- Register Widths: If dividend is bits, accumulator and divisor must be bits wide (with leading
0s) to prevent erroneous sign overflow during trial subtractions.
2. Restoring Division Algorithm
In Restoring Division, each step tests whether the divisor can be subtracted from the current high-order remainder :
Restoring Division Cycle (Repeat n times):
1. Shift Left [A, Q] by 1 bit (Q0 becomes empty: _)
2. A = A - M
3. Test MSB of Accumulator (An):
- If An == 1 (A < 0, subtraction failed):
A = A + M (Restore previous A)
Q0 = 0
- If An == 0 (A >= 0, subtraction succeeded):
A remains unchanged
Q0 = 1
Flowchart of Restoring Division:
+-------------------------+
| Shift Left [A, Q] |
+-------------------------+
|
v
+-------------------------+
| A = A - M |
+-------------------------+
|
v
/ \
/ A < 0? \
\ (An=1) /
\ /
+-------+
/ \
YES / \ NO
v v
+-------------------+ +-------------------+
| A = A + M | | Q0 = 1 |
| Q0 = 0 | +-------------------+
+-------------------+ |
| |
+----------+----------+
|
v
Decrement Counter (n)
- Worst-Case Cost: If every trial subtraction fails, the algorithm requires additions/subtractions.
3. Non-Restoring Division Algorithm
Non-Restoring Division eliminates the intermediate restoring addition. If becomes negative (), the true mathematical value of the restored remainder before the next shift should have been . Shifting this restored remainder left by 1 bit produces:
In the next cycle, subtracting from this shifted restored value yields:
Therefore, if the current remainder is negative, the hardware simply shifts left and adds (), completely bypassing the need to restore in the previous step!
Non-Restoring Operational Rules:
- Cycle Step (Repeat times):
- If previous ():
- Shift Left .
- .
- If previous ():
- Shift Left .
- .
- Evaluate new sign bit :
- If new (): Set .
- If new (): Set .
- Post-Loop Correction Step:
- After cycles, check the sign of the final remainder :
- If final (): Perform a single final restoration .
- If final : Remainder is correct as-is.
Performance Advantage of Non-Restoring Division:
- Restoring Division: n to 2n ALU operations (variable latency)
- Non-Restoring Division: Exactly n ALU operations + at most 1 final correction
◇Worked Examples / Calculations / Hardware Traces
Example 1: Restoring Division Execution Trace ()
Problem: Divide unsigned integers: Dividend ( bits) by Divisor using the Restoring Division algorithm. Show the step-by-step register trace. Expected: , .
Setup:
- (5 bits, padded with leading 0)
- Initial state: (5 bits), , .
Execution Trace Table:
| Cycle | Operation | Count | Notes | ||
|---|---|---|---|---|---|
| 0 | Init | 00000 | 1011 | 4 | |
| 1 | Shift Left | 00001 | 011_ | 4 | with shifted in |
11110 | 011_ | 4 | () | ||
| Restore: | 00001 | 0110 | 3 | Restored ; set | |
| 2 | Shift Left | 00010 | 110_ | 3 | Shift left |
11111 | 110_ | 3 | () | ||
| Restore: | 00010 | 1100 | 2 | Restored ; set | |
| 3 | Shift Left | 00101 | 100_ | 2 | Shift left () |
00010 | 100_ | 2 | () | ||
| No Restore: | 00010 | 1001 | 1 | Subtraction positive; set | |
| 4 | Shift Left | 00101 | 001_ | 1 | Shift left () |
00010 | 001_ | 1 | () | ||
| No Restore: | 00010 | 0011 | 0 | Subtraction positive; set |
- Final Results:
- Verification:
Example 2: Non-Restoring Division Execution Trace ()
Problem: Perform the exact same division () using the Non-Restoring Division algorithm.
Setup:
- (5 bits),
- Initial state: , , .
Execution Trace Table:
| Cycle | Previous Sign | Operation | Count | Notes | ||
|---|---|---|---|---|---|---|
| 0 | — | Init | 00000 | 1011 | 4 | |
| 1 | Shift Left | 00001 | 011_ | 4 | ||
11110 | 0110 | 3 | ||||
| 2 | Shift Left | 11100 | 110_ | 3 | ||
11111 | 1100 | 2 | ||||
| 3 | Shift Left | 11111 | 100_ | 2 | (sign ext) | |
00010 | 1001 | 1 | ||||
| 4 | Shift Left | 00101 | 001_ | 1 | ||
00010 | 0011 | 0 | ||||
| Post | Final | No Correction Needed | 00010 | 0011 | 0 | Remainder is positive |
- Final Results:
- Both algorithms arrive at identical quotient and remainder values, but Non-Restoring completed in exactly 4 ALU cycles without any restoring rollbacks!
◇Complexity Analysis / Common Pitfalls
- Register Width Sizing for Accumulator : Setting register to only bits rather than bits causes catastrophic overflow errors during trial subtractions, because a negative result cannot be differentiated from unsigned high-order data.
- Forgetting the Post-Loop Correction in Non-Restoring Division: In Non-Restoring division, if the final subtraction in cycle results in , the quotient is correct, but accumulator contains an uncorrected negative value. The final step is mandatory to obtain the true remainder.
- Quotient Bit Polarity Inversion: A frequent pitfall is inverting the logic for quotient bit generation. When (), the subtraction was valid, so must be set to
1(not0).
◇References & Navigation
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
In the Restoring Division algorithm, what action is taken when a trial subtraction produces a negative accumulator value ()?
What algebraic relationship enables Non-Restoring Division to avoid restoring additions on intermediate cycles?
For an -bit dividend and divisor, what is the minimum required bit width of the accumulator register during hardware division?
In Non-Restoring Division, if the final remainder in register after cycles is negative (), what correction must be performed?
Why is hardware integer division generally slower than integer multiplication in modern superscalar processors?