PROJECTENGRAM

BINARY DIVISION (RESTORING & NON-RESTORING DIVISION ALGORITHMS)

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 (QQ): The number being divided (nn bits).
  • Divisor (MM): The number by which the dividend is divided (nn or n+1n+1 bits).
  • Quotient (QQ): The integer result of the division operation (nn bits).
  • Remainder (AA): The leftover integer quantity satisfying the division invariant, residing in accumulator AA (n+1n+1 bits).
  • Division Invariant: The fundamental mathematical relation governing integer division:
    Dividend D=(Quotient Q×Divisor M)+Remainder Rwhere 0≤R<M\text{Dividend } D = (\text{Quotient } Q \times \text{Divisor } M) + \text{Remainder } R \quad \text{where } 0 \le R < M
  • Trial Subtraction: The exploratory subtraction of the divisor from the shifted partial remainder (A←A−MA \leftarrow A - M) 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 (A<0A < 0), the original value of AA is restored by adding the divisor back (A←A+MA \leftarrow A + M), and the quotient bit Q0Q_0 is set to 0.
  • Non-Restoring Division: An optimized algorithm that avoids intermediate restoring additions by performing A←A+MA \leftarrow A + M 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:

『』
TEXT
+-------------------------------------------------------------------------+
|                        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 QQ is nn bits, accumulator AA and divisor MM must be n+1n+1 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 MM can be subtracted from the current high-order remainder AA:

『』
TEXT
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
『』
TEXT
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 2n2n additions/subtractions.

3. Non-Restoring Division Algorithm

Non-Restoring Division eliminates the intermediate restoring addition. If AA becomes negative (A<0A < 0), the true mathematical value of the restored remainder before the next shift should have been A+MA + M. Shifting this restored remainder left by 1 bit produces:
2×(A+M)=2A+2M2 \times (A + M) = 2A + 2M

In the next cycle, subtracting MM from this shifted restored value yields:
(2A+2M)−M=2A+M(2A + 2M) - M = 2A + M

Therefore, if the current remainder is negative, the hardware simply shifts left and adds MM (A←2A+MA \leftarrow 2A + M), completely bypassing the need to restore AA in the previous step!

Non-Restoring Operational Rules:

  1. Cycle Step (Repeat nn times):
    • If previous A≥0A \ge 0 (An=0A_n = 0):
  • Shift Left [A,Q][A, Q].
  • A←A−MA \leftarrow A - M.
    • If previous A<0A < 0 (An=1A_n = 1):
  • Shift Left [A,Q][A, Q].
  • A←A+MA \leftarrow A + M.
    • Evaluate new sign bit AnA_n:
  • If new A≥0A \ge 0 (An=0A_n = 0): Set Q0=1Q_0 = 1.
  • If new A<0A < 0 (An=1A_n = 1): Set Q0=0Q_0 = 0.
  1. Post-Loop Correction Step:
    • After nn cycles, check the sign of the final remainder AA:
    • If final A<0A < 0 (An=1A_n = 1): Perform a single final restoration A←A+MA \leftarrow A + M.
    • If final A≥0A \ge 0: Remainder AA is correct as-is.
『』
TEXT
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 (11/311 / 3)

Problem: Divide unsigned integers: Dividend D=1110=10112D = 11_{10} = 1011_2 (n=4n=4 bits) by Divisor M=310=00112M = 3_{10} = 0011_2 using the Restoring Division algorithm. Show the step-by-step register trace. Expected: Quotient=3 (00112)\text{Quotient} = 3\ (0011_2), Remainder=2 (00102)\text{Remainder} = 2\ (0010_2).

Setup:

  • n=4n = 4
  • M=000112M = 00011_2 (5 bits, padded with leading 0)
  • Initial state: A=000002A = 00000_2 (5 bits), Q=10112Q = 1011_2, Count=4\text{Count} = 4.

Execution Trace Table:

CycleOperationAAQQCountNotes
0Init0000010114A=00000,Q=1011,M=00011A=00000, Q=1011, M=00011
1Shift Left [A,Q][A, Q]00001011_4A←A≪1A \leftarrow A \ll 1 with Q3Q_3 shifted in
A←A−MA \leftarrow A - M11110011_400001−00011=−200001 - 00011 = -2 (A4=1A_4 = 1)
Restore: A←A+M,Q0←0A \leftarrow A + M, Q_0 \leftarrow 00000101103Restored AA; set Q0=0Q_0 = 0
2Shift Left [A,Q][A, Q]00010110_3Shift left
A←A−MA \leftarrow A - M11111110_300010−00011=−100010 - 00011 = -1 (A4=1A_4 = 1)
Restore: A←A+M,Q0←0A \leftarrow A + M, Q_0 \leftarrow 00001011002Restored AA; set Q0=0Q_0 = 0
3Shift Left [A,Q][A, Q]00101100_2Shift left (A=510A = 5_{10})
A←A−MA \leftarrow A - M00010100_200101−00011=+200101 - 00011 = +2 (A4=0A_4 = 0)
No Restore: Q0←1Q_0 \leftarrow 10001010011Subtraction positive; set Q0=1Q_0 = 1
4Shift Left [A,Q][A, Q]00101001_1Shift left (A=510A = 5_{10})
A←A−MA \leftarrow A - M00010001_100101−00011=+200101 - 00011 = +2 (A4=0A_4 = 0)
No Restore: Q0←1Q_0 \leftarrow 10001000110Subtraction positive; set Q0=1Q_0 = 1
  • Final Results:
    • Quotient in Q=00112=310\text{Quotient in } Q = 0011_2 = 3_{10}
    • Remainder in A=000102=210\text{Remainder in } A = 00010_2 = 2_{10}
    • Verification: 11=(3×3)+2=9+2=11✓11 = (3 \times 3) + 2 = 9 + 2 = 11 \quad \checkmark

Example 2: Non-Restoring Division Execution Trace (11/311 / 3)

Problem: Perform the exact same division (11/311 / 3) using the Non-Restoring Division algorithm.

Setup:

  • n=4n = 4
  • M=000112M = 00011_2 (5 bits), −M=111012-M = 11101_2
  • Initial state: A=000002A = 00000_2, Q=10112Q = 1011_2, Count=4\text{Count} = 4.

Execution Trace Table:

CyclePrevious AA SignOperationAAQQCountNotes
0—Init0000010114A≥0A \ge 0
1A≥0  ⟹  SHL, SUB MA \ge 0 \implies \text{SHL, SUB } MShift Left [A,Q][A, Q]00001011_4
A←A−MA \leftarrow A - M1111001103A<0  ⟹  Q0=0A < 0 \implies Q_0 = 0
2A<0  ⟹  SHL, ADD MA < 0 \implies \text{SHL, ADD } MShift Left [A,Q][A, Q]11100110_3
A←A+MA \leftarrow A + M111111100211100+00011=11111 (<0)  ⟹  Q0=011100 + 00011 = 11111\ (< 0) \implies Q_0 = 0
3A<0  ⟹  SHL, ADD MA < 0 \implies \text{SHL, ADD } MShift Left [A,Q][A, Q]11111100_2(11111≪1)+1=11111(11111 \ll 1) + 1 = 11111 (sign ext)
A←A+MA \leftarrow A + M000101001111111+00011=00010 (≥0)  ⟹  Q0=111111 + 00011 = 00010\ (\ge 0) \implies Q_0 = 1
4A≥0  ⟹  SHL, SUB MA \ge 0 \implies \text{SHL, SUB } MShift Left [A,Q][A, Q]00101001_1
A←A−MA \leftarrow A - M000100011000101−00011=00010 (≥0)  ⟹  Q0=100101 - 00011 = 00010\ (\ge 0) \implies Q_0 = 1
PostFinal A≥0A \ge 0No Correction Needed0001000110Remainder is positive
  • Final Results:
    • Quotient in Q=00112=310\text{Quotient in } Q = 0011_2 = 3_{10}
    • Remainder in A=000102=210\text{Remainder in } A = 00010_2 = 2_{10}
    • 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 AA: Setting register AA to only nn bits rather than n+1n+1 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 nn results in A<0A < 0, the quotient QQ is correct, but accumulator AA contains an uncorrected negative value. The final step A←A+MA \leftarrow A + M is mandatory to obtain the true remainder.
  • Quotient Bit Polarity Inversion: A frequent pitfall is inverting the logic for quotient bit generation. When A≥0A \ge 0 (An=0A_n = 0), the subtraction was valid, so Q0Q_0 must be set to 1 (not 0).

◇References & Navigation

CONFIRMATION // 理解度の確認

ACTIVE RECALL VERIFICATION

Select an answer to verify conceptual comprehension and reveal the technical rationale.

Q1

In the Restoring Division algorithm, what action is taken when a trial subtraction produces a negative accumulator value (A<0A < 0)?

Q2

What algebraic relationship enables Non-Restoring Division to avoid restoring additions on intermediate cycles?

Q3

For an nn-bit dividend and divisor, what is the minimum required bit width of the accumulator register AA during hardware division?

Q4

In Non-Restoring Division, if the final remainder in register AA after nn cycles is negative (An=1A_n = 1), what correction must be performed?

Q5

Why is hardware integer division generally slower than integer multiplication in modern superscalar processors?