Division algorithm

This is an old revision of this page, as edited by 87.112.93.241 (talk) at 22:49, 3 September 2007 (Spelling mistake. Changed "caluclated" to "calculated".). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 where

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

Slow division methods

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

 

where:

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

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.

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}:  
Steps:
1. Mask the negative term:  
2. Form the two's complement of N:  
3. Form the positive term:  
4. Sum   and  :  

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.

Fast division methods

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  , and multiply that reciprocal by   to find the final quotient  .

The steps of Newton-Raphson are:

  1. Calculate an estimate for the reciprocal of the divisor ( ):  
  2. Compute successively more accurate estimates of the reciprocal:  
  3. Compute the quotient by multiplying the dividend by the reciprocal of the divisor:  

In order to apply Newton's method to find the reciprocal of  , it is necessary to find a function   which has a zero at  . The obvious such function is  , but the Newton-Raphson iteration for this is unhelpful since it cannot be computed without already knowing the reciprocal of  . A function which does work is  , for which the Newton-Raphson iteration gives

 

which can be calculated from   using only multiplication and subtraction.

Assuming the divisor is scaled (by a bit-shift operation) so that  , the initial estimate for the reciprocal of the divisor can be calculated using the following linear approximation:

 

To minimize the maximum of the error of this approximation on interval   one should use   and  , that is  . Using this approximation the error of the initial value is less than 0.0858, and thus since for Newton's method (for a zero of multiplicity 1) the convergence is at least quadratic, it follows that

 

steps is enough to calculate the value up to   binary places, for example,   steps is enough for   bits and   steps is enough for   bits.


Goldschmidt division

Goldschmidt (after Robert Elliott Goldschmidt)[1] 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:

 

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  , the first factor is:

 

Multiplying the dividend and divisor by the factor yields:

 

After a sufficient number of iterations k:  

  1. ^ Robert E. Goldschmidt, Applications of Division by Convergence, MSc dissertation, M.I.T., 1964