Division (digital)

From Wikipedia, the free encyclopedia

Several algorithms exist to perform division in digital designs. These algorithms fall into two main categories: slow division and fast division. Slow division algorithms produce one digit of the final quotient per iteration. Examples of slow division include restoring, non-performing restoring, non-restoring, and SRT division. Fast division methods start with a close approximation to the final quotient and produce twice as many digits of the final quotient on each iteration. Newton-Raphson and Goldschmidt fall into this category.

The following division methods are all based on the form Q = N / D where

  • Q = Quotient
  • N = Numerator (dividend)
  • D = Denominator (divisor)

Contents

[edit] Slow division methods

Slow division methods are all based on a standard recurrence equation:

Pj+1 = R×Pj - qn-(j+1)×D

where:

  • Pj = the partial remainder of the division
  • R = the radix
  • qn-(j+1) = the digit of the quotient in position n-(j+1), where the digit positions are numbered from least-significant 0 to most significant n-1
  • n = number of digits in the quotient
  • D = the denominator

[edit] Restoring division

Restoring division operates on fixed-point fractional numbers and depends on the following assumptions:

  • N < D
  • 1/2 < N,D < 1

The quotient digits q are formed from the digit set {0,1}.

The basic algorithm for binary (radix 2) restoring division is:

P := N
for i = n-1..0 do        * for example 31..0 for 32 bits
  P := 2P - D            * trial subtraction from shifted value
  if P ≥ 0 then
    q(i) := 1            * result-bit 1
  else
    q(i) := 0            * result-bit 0
    P := P + D           * new partial remainder is (restored) shifted value
  end
end

where N=Numerator, D=Denominator, n=#bits, P=Partial remainder, q(i)=bit #i of quotient

Non-performing restoring division is similar to restoring division except that the value of 2*P[i] is saved, so D does not need to be added back in for the case of TP[i] ≤ 0.

[edit] Non-restoring division

Non-restoring division uses the digit set {−1,1} for the quotient digits instead of {0,1}. The basic algorithm for binary (radix 2) non-restoring division is:

P[0] := N
i := 0
while i < n do
  if P[i] ≥ 0 then
    q[n-(i+1)] := 1
    P[i+1] := 2*P[i] - D
  else
    q[n-(i+1)] := -1
    P[i+1] := 2*P[i] + D
  end if
  i := i + 1
end while

Following this algorithm, the quotient is in a non-standard form consisting of digits of −1 and +1. This form needs to be converted to binary to form the final quotient. Example:

Convert the following quotient to the digit set {0,1}: Q = 111\bar{1}1\bar{1}1\bar{1}
Steps:
1. Mask the negative term: N = 00010101\,
2. Form the two's complement of N: \bar{N} = 11101011
3. Form the positive term: P = 11101010\,
4. Sum P\, and \bar{N}: Q = 11010101\,

[edit] SRT division

Named for its creators (Sweeny, Robertson, and Tocher), SRT division is a popular method for division in many microprocessor implementations. SRT division is similar to non-restoring division, but it uses a lookup table based on the dividend and the divisor to determine each quotient digit. The Intel Pentium processor's infamous divider bug was caused by an incorrectly coded lookup table. Five entries that were believed to be theoretically unreachable had been omitted from the more than one thousand table entries.

[edit] Fast division methods

[edit] Newton-Raphson division

Newton-Raphson uses Newton's method to converge to the quotient. The strategy of Newton-Raphson is to find the reciprocal of D, and multiply that reciprocal by N to find the final quotient Q.

The steps of Newton-Raphson are:

  1. Calculate an estimate for the reciprocal of the divisor (D): X0
  2. Compute successively more accurate estimates of the reciprocal: (X1...Xi − 1...Xk)
  3. Compute the quotient by multiplying the dividend by the reciprocal of the divisor: Q = NXk

In order to apply Newton's method to find the reciprocal of D, it is necessary to find a function f(X) which has a zero at x = 1 / D. The obvious such function is f(X) = DX − 1, but the Newton-Raphson iteration for this is unhelpful since it cannot be computed without already knowing the reciprocal of D. A function which does work is f(X) = 1 / XD, for which the Newton-Raphson iteration gives

X_{i+1} = X_i - {f(X_i)\over f'(X_i)} = X_i - {1/X_i - D\over -1/X_i^2} = X_i + (X_i-DX_i^2) = X_i(2-DX_i)

which can be calculated from Xi using only multiplication and subtraction.

Assuming the divisor is scaled so .5 < D < 1, the initial estimate for the reciprocal of the divisor is:

X0 = 2.914 − 2D

Successively more accurate estimates of the reciprocal can be calculated using:

Xi + 1 = Xi(2 − DXi)

[edit] Goldschmidt division

Goldschmidt division uses series expansion to converge to the quotient. The strategy of Goldschmidt is repeatedly multiply the dividend and divisor by a factor F to converge the divisor to 1 as the dividend converges to the quotient Q:

Q = \frac{N}{D} \frac{F_1}{F_1} \frac{F_2}{F_2}  \frac{F_{\ldots}}{F_{\ldots}}

The steps for Goldschmidt division are:

  1. Calculate an estimate for the multiply factor F.
  2. Multiply the dividend and divisor by F.
  3. Loop to step 1.

Assuming the divisor is scaled so 0.9 < = D < = 1.1, the first factor is:

Fi + 1 = 2 − Di

Multiplying the dividend and divisor by the factor yields:

\frac{N_{i+1}}{D_{i+1}} = \frac{N_{i}}{D_{i}}\frac{F_{i}}{F_{i}}

After a sufficient number of iterations k: Q = Nk