Fast Division Algorithm with a Small Lookup Table Patrick Hung

Fast Division Algorithm with a Small Lookup Table Patrick Hung

Fast Division Algorithm with a Small Lookup Table Patrick Hung, Hossam Fahmy, Oskar Mencer, Michael J. Flynn Computer Systems Laboratory Stanford University, CA 94305 email: hung, hfahmy, oskar, ¯ynn @arithmetic.stanford.edu Abstract 2. Basic Algorithm This paper presents a new division algorithm, which requires Let and be two -bit ®xed point numbers between one two multiplication operations and a single lookup in a small and two de®ned by Equations 1 and 2 where . table. The division algorithm takes two steps. The table lookup and the ®rst multiplication are processed concurrently (1) in the ®rst step, and the second multiplication is executed (2) in the next step. This divider uses a single multiplier and a lookup table with bits to produce -bit results To calculate , is ®rst decomposed into two groups: that are guaranteed correct to one ulp. By using a multiplier the higher order bits ( ) and the lower order bits ( ). and a KB lookup table, the basic algorithm generates a contains the most signi®cant bits and contains the -bit result in two cycles. remaining bits. (3) 1. Introduction (4) Division is an important operation in many areas of comput- The range of is between and ( ), and ing, such as signal processing, computer graphics, network- the range of is between and ( ). ing, numerical and scienti®c applications. In general, divi- Dividing by , we get Equations 5 and 6. Since sion algorithms may be divided into ®ve categories: digit re- , the maximum fractional error in Equation 6 is less currence, functional iteration, high radix, table lookup, and than (or ulp). variable latency. These algorithms differ in overall latency and area requirements. An overview of division algorithms (5) can be found in [4]. This paper introduces a new high radix division algorithm (6) based on the well-known Taylor series expansion. A number of high radix division algorithms were also proposed in the Using Taylor series, Equation 5 can be expanded at as past based on the Taylor series. For example, Farmwald [2] in Equation 7. The approximation in Equation 6 is equivalent proposed using multiple tables to look up the ®rst few terms to combining the ®rst two terms in the Taylor series. in the Taylor series. Later, Wong [5] proposed an elaborate iterative quotient approximation with multiple lookup tables. Wong demonstrated that only the ®rst two terms in the Taylor (7) series are necessary to achieve fast division because it takes a long time to evaluate all the power terms. Figure 1 shows the block diagram of the algorithm. In The previous algorithms consider each individual term in the ®rst step, the algorithm retrieves the value of from a the Taylor series separately; hence, many lookup tables are lookup table and multiplies with at the same time. needed and the designs are complicated. Our proposed algo- In the second step, and are multiplied rithm combines the ®rst two terms of Taylor series together, together to generate the result. and only requires a small lookup table to generate accurate results. This algorithm achieves fast division by multiplying 2.1. Lookup Table Construction the dividend in the ®rst step, which is done in parallel with the table lookup. In the second step, another multiplication To minimize the size of the lookup table, the table entries are operation is executed to generate the quotient. normalized such that the most signi®cant bit (MSB) of each encoding schemes. In Booth 2 encoding, the multiplier is par- titioned into overlapping strings of 3 bits, and each string is used to select a single partial product. Unlike conventional Booth 2 encoding, the encoding of consists of four types of encoders. Figure 2 shows the locations of these four types of encoders: the group contains all the 3-bit strings that reside entirely within ; the boundary string contains some bits as well as some bits; the ®rst string is located next to the boundary string; the group contains all the remaining strings within . Figure 1: Basic Algorithm Figure 2: Booth Encoding entry is one. These MSB's are therefore not stored in the The bits represent positive numbers, whereas the table. bits represent negative numbers. Hence, conventional Booth A lookup table with = is shown in Table 1. 2 encoding is used in the group but the partial products represents the truncated value of to signi®cant in the group are negated. As shown in the diagram, the bits. The exponent part of the may be stored in the boundary region between and requires two additional same table, but can simply be determined by some simple special encoders. Depending on whether is even or odd, logic gates. In this example, the exponent is when the encoding schemes for these two encoders are different. It , the exponent is when and is possible that only one such encoder is used in the bound- , the exponent is when . ary region, but it implies that this encoder needs to generate multiplicand (for even ). In order to speed up the Table 1: A simple lookup table example ( ) multiplication and simplify the encoding logic, two special encoders are used to avoid the ªdif®cultº multiples. Table entry Table 2 summarizes the four different encoding schemes for both even and odd . It is important to note that the ®rst encoder actually needs to examine both the ®rst string and the boundary string when is odd. If the boundary string is , the LSB of the ®rst string is set to instead of . If the boundary string is not , the LSB of the ®rst string is set to be the MSB of the boundary string (as usual). This encoding scheme uses all but two normal Booth encoders and is particularly useful if the same multiplier is used for both the ®rst and the second multiplications. 2.2. Booth Encoding 2.3. Error Analysis Booth encoding algorithm [1] has widely been used to min- There are four sources of errors: Taylor series approximation imize the number of partial product terms in a multiplier. In error ( ), lookup table rounding error ( ), the rounding our division algorithm, special Booth encoders are needed to error of the ®rst multiplication ( ), and the rounding error achieve the multiplication without explicitly cal- of the second multiplication ( ). culating the value of . Lyu and Matula [3] proposed The total error is equal to . a general redundant binary booth recoding scheme. In our To minimize this error, the divider can be designed such that case, the and bits are non-overlapping, and a cheaper , , , and . This means and faster encoding scheme is feasible. that the table entries are truncated to bits, the ®rst We use Booth 2 encoding to illustrate our encoding al- multiplication is truncated to bits, and the second gorithm, but the same principle can apply to the other Booth multiplication is rounded up to bits. In order to minimize , is set to be slightly larger Table 2: Booth Encoding of than . For each , the optimum table entry is deter- Boundary First mined by setting the maximum positive error (at ) to even odd even odd be the same as the maximum negative error (at ). Bits Group Group Equation 10 shows the expression for the optimum table entry . (10) The approximation error is at its maximum when and . Using Equation 9, the maximum approximation error can easily be derived as in Equation 11. In this case, is slightly less than ulp. The Taylor series approximation error ( ) is determined (11) by Equation 8. This error is most signi®cant for large and small . The maximum approximation error is slightly less than ulp when and . Using round-to-nearest rounding mode, ulp, ulp, and ulp. As in Section 2.3, the total error of the alternative lookup table is also less than (8) ulp. Table 3 illustrates the same example shown in Sec- tion 2.1 with the alternative lookup table, where The lookup table has signi®cant bits, so the maximum represents the round-to-nearest value of to sig- truncation error ulp. Similarly, the maximum ni®cant bits. rounding error for the ®rst multiplication ulp, and the maximum rounding error for the second multiplica- Table 3: Alternative Lookup Table ( ) tion ulp. Thus, the maximum positive error is less than ulp ( ), and the maximum negative error is also Table entry less than ulp ( ). 3. Optimization Techniques This section describes two optimization techniques for the di- vision algorithm. The ®rst technique uses a slightly different lookup table and allows the two multiplications to use the same rounding mode, whereas the second technique uses an error compensation term to further reduce the Taylor series approximation error. 3.2. Error Compensation 3.1. Alternative Lookup Table The Taylor series approximation error can be further reduced As described in Section 2.3, the rounding modes of the ®rst by adding an error compensation term in the ®rst multiplica- and the second multiplications are different. This may be un- tion. Equation 8 shows that the magnitude of the Taylor se- desirable if the two multiplications need to share the same ries approximation error ( ) increases when either gets multiplier. A simple solution is to use round-to-nearest mode larger or gets smaller. By looking at the ®rst few bits of in the two multiplications as well as in constructing the lookup and , it is possible to identify large and small , and table. Since the error terms can either be positive or negative, then compensate for the approximation error. However, it is the maximum total error becomes the sum of the maximum important to ensure that the approximation error is not over- of each error term. compensated and becomes positive; otherwise this would in- Let be the table entry at with in®nite precision.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us