Abstract:
Polynomial circuitry for calculating a polynomial having terms including powers of an input variable, where the input variable has a mantissa and an exponent, and the circuitry has a number of bits of precision, includes multiplier circuitry that calculates a common power of the input variable factored out of terms of the polynomial having powers of the variable greater than 1. The polynomial circuitry further includes, for each respective remaining term of the polynomial that contributes to the number of bits of precision: (1) a coefficient memory loaded with a plurality of instances of a coefficient for the respective term, each instance being shifted by a different number of bits, (2) address circuitry for selecting one of the instances of the coefficient based on the exponent, and (3) circuitry for combining the selected instance of the coefficient with a corresponding power of the input variable to compute the respective term.

Description:
FIELD OF THE INVENTION 
     This invention relates to computing floating-point polynomials in integrated circuit devices such as programmable logic devices (PLDs), and particularly to computing floating-point polynomials using fixed-point resources. 
     BACKGROUND OF THE INVENTION 
     Horner&#39;s rule (also referred to as Horner&#39;s scheme or Horner&#39;s algorithm) is an efficient way of calculating polynomials, useful for both hardware and software. 
     A polynomial can be described as: 
                     p   ⁡     (   x   )       =         ∑     i   =   0     n     ⁢           ⁢       a   i     ⁢     x   i         =       a   0     +       a   1     ⁢   x     +       a   2     ⁢     x   2       +       a   3     ⁢     x   3       +   …   +       a   n     ⁢     x   n                   (   1   )               
For an example where n=5, this can be reformatted using Horner&#39;s rule as:
 
 p ( x )= a   0   +x ( a   1   +x ( a   2   +x ( a   3   +x ( a   4   +a   5   X ))))  (2)
 
This has the advantage of removing the calculations of powers of x. There are still as many addition operations as there are coefficients, and as many multiplication operations as there are terms of x. For this case of n=5, there are five addition operations, and five multiplication operations. For small inputs—i.e., inputs substantially less than 1—the number of terms that need to be calculated is low, because later terms become vanishingly small.
 
     However, even for a small number of terms, substantial resources may be required. For example, applications in which these operations are used frequently call for double-precision arithmetic. In a PLD such as those sold by Altera Corporation under the trademark STRATIX®, this could translate to approximately 8,500 adaptive look-up tables (ALUTs) and 45 18×18 multipliers. 
     SUMMARY OF THE INVENTION 
     The present invention relates to method and circuitry for implementing floating-point polynomial series calculations using fixed-point resources. This reduces the amount of resources required, and also reduces datapath length and therefore latency. Embodiments of the invention are particularly well-suited to applications for which the input range can be kept small. One such class of operations are trigonometric functions, where range reduction can be used to keep the inputs small, as described in copending, commonly-assigned U.S. patent application Ser. No. 12/717,212, filed Mar. 4, 2010, which is hereby incorporated by reference herein in its entirety. The circuitry can be provided in a fixed logic device, or can be configured into a programmable integrated circuit device such as a programmable logic device. 
     According to one aspect of the invention, denormalization operations are performed using the coefficients, instead of using arithmetic and logic resources to calculate and implement the denormalization, and the renormalization requires only a single-bit calculation. The remainder of the calculation can be carried out as a fixed-point calculation, consuming corresponding device area and with corresponding latency, while the results are equivalent to performing the same calculation using double-precision floating-point arithmetic. 
     In accordance with embodiments of the invention, there is provided polynomial circuitry for calculating a polynomial having terms including powers of an input variable, where the input variable is represented by a mantissa and an exponent, and the circuitry has a number of bits of precision. The polynomial circuitry includes (1) a respective coefficient memory loaded with a plurality of respective instances of a coefficient for each respective one of the terms, each respective instance being shifted by a different number of bits, and (2) address circuitry for selecting one of the respective instances of the coefficient based on the exponent. 
     A method of operating such circuitry, and a method of configuring a programmable device as such polynomial circuitry are also provided, and a non-transitory machine-readable data storage medium is provided that is encoded with software for performing the method of configuring such circuitry on a programmable device. 
    
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
       Further features of the invention, its nature and various advantages will be apparent upon consideration of the following detailed description, taken in conjunction with the accompanying drawings, in which like reference characters refer to like parts throughout, and in which: 
         FIG. 1  shows an example of circuitry according to an embodiment of the invention; 
         FIG. 2  is a cross-sectional view of a magnetic data storage medium encoded with a set of machine-executable instructions for performing a method according to the present invention; 
         FIG. 3  is a cross-sectional view of an optically readable data storage medium encoded with a set of machine executable instructions for performing a method according to the present invention; and 
         FIG. 4  is a simplified block diagram of an illustrative system employing a programmable logic device incorporating the present invention. 
     
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
     Circuitry according to the invention implements Horner&#39;s rule for floating-point polynomial calculations by using the coefficients to perform denormalization and performing the remainder of the calculation as a fixed-point calculation. For any particular implementation of a polynomial calculation, each coefficient may be stored in a table as multiple versions of itself, each shifted a different amount. The exponent of the coefficient term could function as the index to the table, selecting the correct shifted version. 
     An embodiment of the invention may be understood by reference to an example of the inverse tangent (tan −1 , ATAN or arctan) function. The inverse tangent function can be computed using the following series: 
                     arctan   ⁡     (   x   )       =     x   -       x   3     3     +       x   5     5     -         x   7     7     ⁢   …               (   3   )               
Using Horner&#39;s rule, this can be expressed as:
 
     
       
         
           
             
               
                 
                   
                     arctan 
                     ⁡ 
                     
                       ( 
                       x 
                       ) 
                     
                   
                   = 
                   
                     x 
                     + 
                     
                       
                         x 
                         3 
                       
                       ⁡ 
                       
                         ( 
                         
                           
                             
                               - 
                               1 
                             
                             3 
                           
                           + 
                           
                             
                               x 
                               2 
                             
                             5 
                           
                           - 
                           
                             
                               
                                 x 
                                 7 
                               
                               7 
                             
                             ⁢ 
                             … 
                           
                         
                         ) 
                       
                     
                   
                 
               
               
                 
                   ( 
                   4 
                   ) 
                 
               
             
           
         
       
     
                     arctan   ⁡     (   x   )       =     x   +     x   ⁡     (     0   +     x   ⁡     (     0   +     x   ⁡     (         -   1     3     +       x   ⁡     (     0   +     x   5       )       ⁢   …       )         )         )                 (   5   )               
This uses two adders and five multipliers, although if equation (4) is limited to two terms it can be implemented using two adders and only three multipliers.
 
     For an inverse tangent calculation, an accurate estimate is required for only a small range. This is also true of most other trigonometric functions. For example, a good tradeoff for a double-precision inverse tangent implementation would require an input range of 0-2 −10  radians. For 52-bit precision as used in double-precision arithmetic, with a 10-bit input range, the second term would be 20 bits (x 3 -x) to the right of the first term, and the third term would be 40 bits (x 5 -x) to the right. The next term would be 60 bits to the right, and therefore can be ignored for this example of 52-bit precision. However, the invention would apply no matter how many terms were used. 
     As the second term is 20 bits to the right, it will have a maximum contribution of 32 bits (52 bits-20 bits) to the final result, and can therefore be well-represented with 36-bit precision. Similarly, as the third term is 40 bits to the right, it will have a maximum contribution of only 12 bits, and can therefore be well-represented by 18 bits. 
     If the input is less than 2 −10 , then the following terms will have even smaller contributions based on their powers. For example, if the input is 2 −12 , the second term will be 24 bits to the right and the third term will be 48 bits to the right. For inputs of 2 −14  or less, even the third term contribution will be more than 56 bits to the right and make a negligible contribution to the result. 
     A full floating-point adder is not required to add together the terms. As long as the input is less than 1, each term will be less than its preceding term, so that swapping of operands is not required, and denormalization can be applied to the smaller term immediately. In fact, the denormalization shift can be applied directly to all of the following terms immediately, as each can be calculated in relation to the first term simultaneously. 
     As noted above, according to embodiments of the invention, the denormalization shifts are not applied as separate operations, but are applied to the coefficients. Therefore, they may be implemented as multiplications by constants. For example, in current PLD (e.g., FPGA) architectures, it is usually more efficient to implement such multiplications in specialized processing blocks (e.g., DSP blocks) that include fixed arithmetic structures with configurable interconnect, rather than in general-purpose programmable logic. 
     Regardless of how the multiplication operations are implemented, in accordance with embodiments of the invention, each coefficient may be represented by a table of shifted coefficients. The exponent of the term to which the coefficient is applied determines the required degree of shifting, and therefore functions as an index into the coefficient table. 
     Examples of the coefficient tables for the inverse tangent example are shown in Tables 1 and 2 (below) for the second and third terms, respectively, of the “inner series” of Equation (4). The value in the first column of each table is the address/index corresponding to the exponent of the value of the input x, expressed in binary form. The value in the second column of each table is the coefficient itself. From each entry to the next, the coefficient, if expressed in binary form, would be shifted by the product of the index and the power of the corresponding term of the series. However, to save space, the shifted coefficient values, which are signed binary numbers, are represented by the equivalent hexadecimal values. Thus, in Table 1, the coefficient values are eight-character hexadecimal values representing 32-bit signed binary values, while in Table 2, the coefficient values are five-character hexadecimal values representing 20-bit signed binary values: 
     
       
         
               
               
             
           
               
                 TABLE 1 
               
               
                   
               
               
                 Index 
                 Coefficient 
               
               
                   
               
             
             
               
                 00000 
                 AAAAAAAA 
               
               
                 00001 
                 EAAAAAAA 
               
               
                 00010 
                 FAAAAAAA 
               
               
                 00011 
                 FEAAAAAA 
               
               
                 00100 
                 FFAAAAAA 
               
               
                 00101 
                 FFEAAAAA 
               
               
                 00110 
                 FFFAAAAA 
               
               
                 00111 
                 FFFEAAAA 
               
               
                 01000 
                 FFFFAAAA 
               
               
                 01001 
                 FFFFEAAA 
               
               
                 01010 
                 FFFFFAAA 
               
               
                 01011 
                 FFFFFEAA 
               
               
                 01100 
                 FFFFFFAA 
               
               
                 01101 
                 FFFFFFEA 
               
               
                 01110 
                 FFFFFFFA 
               
               
                 01111 
                 FFFFFFFE 
               
               
                 10000 
                 FFFFFFFF 
               
               
                 &gt;10000  
                 00000000 
               
               
                   
               
             
          
         
       
     
     
       
         
               
               
             
           
               
                 TABLE 2 
               
               
                   
               
               
                 Index 
                 Coefficient 
               
               
                   
               
             
             
               
                 00000 
                 1999A 
               
               
                 00001 
                 0199A 
               
               
                 00010 
                 0019A 
               
               
                 00011 
                 0001A 
               
               
                 00100 
                 00002 
               
               
                 &gt;00100  
                 00000 
               
               
                   
               
             
          
         
       
     
     In the examples shown, the second term will have 17 possible exponent values including the original unshifted value (32 bits of input range, with each successive shifted value decreasing by 2 bits per bit of reduction of the input power) as shown in Table 1, and the third term will have five possible exponent values including the original unshifted value (18 bits of input range, with each successive shifted value decreasing by 4 bits per bit of reduction of the input power) as shown in Table 2. In other embodiments, these tables may be somewhat larger, to allow at least some small contribution into the least significant bit position of the result. 
       FIG. 1  shows an embodiment of circuitry  100  for implementing Equation (4) according to an embodiment of the invention. 
     The input  111  is in double-precision format, including a 52-bit mantissa  121  (not including an implied leading ‘1’) and an 11-bit exponent  131 . As part of the conversion to fixed-point processing, the mantissa is expanded to 53 bits by converting the implied leading ‘1’ to an actual leading ‘1’. The x 3  term is calculated to 36-bit precision, by multiplying x by itself using a 36×36 bit fixed-point multiplier  101 , and multiplying that result by x using another 36×36 bit fixed-point multiplier  102 . The upper 36 bits of x are used in each multiplication operation. x is inherently aligned with itself for the first fixed-point operation, while x 2  is aligned with x for the second fixed-point operation. 
     To calculate the “inner series” of Equation (4), the upper 18 bits of the x 2  term are multiplied, using fixed point multiplier  103 , with the output of the third term coefficient table  107 . Third term coefficient table  107  is addressed by the input exponent through address circuitry  117 , to select the properly-shifted version of the coefficient, which is provided in an unnormalized fixed-point format. The result of that multiplication, right-shifted by 20 bits, is added to the 36-bit output of the second term coefficient table  108 , which also is provided in an unnormalized fixed-point format, using a 36-bit fixed-point adder  104 . Like third term coefficient table  107 , second term coefficient table  108  is indexed by the input exponent through address circuitry  118  to select the properly-shifted version of the coefficient. 
     That completes the first two terms of the “inner series.” As noted above, in this example, the third and subsequent terms are beyond the 52-bit precision of the system and therefore need not be computed. For systems of different precision, or where different numbers of bits are provided in the inputs or coefficients, it is possible that a different number of terms of the “inner series” may be calculated. 
     The 36-bit inner series result is then multiplied by the x 3  term using a 36×36-bit fixed-point multiplier  105 . The upper 36 bits of that product, right-shifted by 20 bits, is added to the prefixed input mantissa  111  by 53-bit fixed point adder  106 . 
     The mantissa is then normalized. Because the sum of all of the following terms would always be very small—i.e., less than 0.5 10 —only a 1-bit normalization is needed (i.e., a 1-bit shift will be applied where needed). The 1-bit normalization can be carried out using a 52-bit 2:1 multiplexer  109 . 
     As can be seen, this example uses two 36×36 fixed-point multipliers ( 101  and  105 ) and two 18×18 fixed-point multipliers ( 102  and  103 ), as well as one 36-bit fixed-point adder  104 , one 53-bit fixed-point adder  106 , and one 52-bit 2:1 multiplexer, as well as memories for the coefficient tables  107 ,  108 . In all, if this example is implemented in a STRATIX® PLD of the type described above, 188 adaptive look-up tables and 14 18×18 fixed-point multipliers are used. This is much smaller than previously-known hardware implementations of Horner&#39;s method. 
     Specifically, a brute-force double-precision floating-point implantation of Equation (4) would use about 4000 adaptive look-up tables and 27 18×18 fixed-point multipliers. By finding an optimal translation to fixed-point arithmetic, the required resources are greatly reduced when implementing the present invention. The latency also is much smaller, at about 10 clocks, which is less than the latency of a single double-precision floating-point multiplier or adder by itself. 
     Although the example described above in connection with  FIG. 1  involved a polynomial including only odd powers of x (x 3 , x 5 , . . . ), the invention can be used with a polynomial including only even powers of x (x 2 , x 4 , . . . ) or including all powers of x (x 2 , x 3 , x 4 , x 5 , . . . ). More generally, the higher powers would be multiplied out first, and the lower powers would be computed by shifting relative to the higher powers, with that shifting coded into the coefficient tables. Looked at another way, a power of x, up to the largest common power of x greater than 1 (x 3  in the example, but possibly as low as) x 2 ) would be factored out and multiplied first. Only terms in the remaining factored polynomial whose powers of x did not exceed the precision of the system would be retained. Each term would be shifted according to its power of x, with that shifting being coded into the coefficient tables, to provide an intermediate result. That intermediate result would be multiplied by the factored-out common power of x to provide the final result. 
     Thus it is seen that circuitry and methods for performing polynomial calculations have been provided. This invention may have use in hard-wired implementations of polynomial calculations, as well as in software implementations. 
     Another potential use for the present invention may be in programmable devices such as PLDs, as discussed above, where programming software can be provided to allow users to configure a programmable device to perform polynomial calculations, either as an end result or as part of a larger operation. The result would be that fewer logic resources of the programmable device would be consumed. And where the programmable device is provided with a certain number of dedicated blocks for arithmetic functions (to spare the user from having to configure arithmetic functions from general-purpose logic), the number of dedicated blocks needed to be provided (which may be provided at the expense of additional general-purpose logic) can be reduced (or sufficient dedicated blocks for more operations, without further reducing the amount of general-purpose logic, can be provided). 
     Instructions for carrying out a method according to this invention for programming a programmable device to perform polynomial calculations, may be encoded on a machine-readable medium, to be executed by a suitable computer or similar device to implement the method of the invention for programming or configuring PLDs or other programmable devices to perform operations as described above. For example, a personal computer may be equipped with an interface to which a PLD can be connected, and the personal computer can be used by a user to program the PLD using a suitable software tool, such as the QUARTUS® II software available from Altera Corporation, of San Jose, Calif. 
       FIG. 2  presents a cross section of a magnetic data storage medium  800  which can be encoded with a machine executable program that can be carried out by systems such as the aforementioned personal computer, or other computer or similar device. Medium  800  can be a floppy diskette or hard disk, or magnetic tape, having a suitable substrate  801 , which may be conventional, and a suitable coating  802 , which may be conventional, on one or both sides, containing magnetic domains (not visible) whose polarity or orientation can be altered magnetically. Except in the case where it is magnetic tape, medium  800  may also have an opening (not shown) for receiving the spindle of a disk drive or other data storage device. 
     The magnetic domains of coating  802  of medium  800  are polarized or oriented so as to encode, in manner which may be conventional, a machine-executable program, for execution by a programming system such as a personal computer or other computer or similar system, having a socket or peripheral attachment into which the PLD to be programmed may be inserted, to configure appropriate portions of the PLD, including its specialized processing blocks, if any, in accordance with the invention. 
       FIG. 3  shows a cross section of an optically-readable data storage medium  810  which also can be encoded with such a machine-executable program, which can be carried out by systems such as the aforementioned personal computer, or other computer or similar device. Medium  810  can be a conventional compact disk read-only memory (CD-ROM) or digital video disk read-only memory (DVD-ROM) or a rewriteable medium such as a CD-R, CD-RW, DVD-R, DVD-RW, DVD+R, DVD+RW, or DVD-RAM or a magneto-optical disk which is optically readable and magneto-optically rewriteable. Medium  810  preferably has a suitable substrate  811 , which may be conventional, and a suitable coating  812 , which may be conventional, usually on one or both sides of substrate  811 . 
     In the case of a CD-based or DVD-based medium, as is well known, coating  812  is reflective and is impressed with a plurality of pits  813 , arranged on one or more layers, to encode the machine-executable program. The arrangement of pits is read by reflecting laser light off the surface of coating  812 . A protective coating  814 , which preferably is substantially transparent, is provided on top of coating  812 . 
     In the case of magneto-optical disk, as is well known, coating  812  has no pits  813 , but has a plurality of magnetic domains whose polarity or orientation can be changed magnetically when heated above a certain temperature, as by a laser (not shown). The orientation of the domains can be read by measuring the polarization of laser light reflected from coating  812 . The arrangement of the domains encodes the program as described above. 
     A PLD  90  programmed according to the present invention may be used in many kinds of electronic devices. One possible use is in a data processing system  900  shown in  FIG. 5 . Data processing system  900  may include one or more of the following components: a processor  901 ; memory  902 ; I/O circuitry  903 ; and peripheral devices  904 . These components are coupled together by a system bus  905  and are populated on a circuit board  906  which is contained in an end-user system  907 . 
     System  900  can be used in a wide variety of applications, such as computer networking, data networking, instrumentation, video processing, digital signal processing, or any other application where the advantage of using programmable or reprogrammable logic is desirable. PLD  90  can be used to perform a variety of different logic functions. For example, PLD  90  can be configured as a processor or controller that works in cooperation with processor  901 . PLD  90  may also be used as an arbiter for arbitrating access to a shared resources in system  900 . In yet another example, PLD  90  can be configured as an interface between processor  901  and one of the other components in system  900 . It should be noted that system  900  is only exemplary, and that the true scope and spirit of the invention should be indicated by the following claims. 
     Various technologies can be used to implement PLDs  90  as described above and incorporating this invention. 
     It will be understood that the foregoing is only illustrative of the principles of the invention, and that various modifications can be made by those skilled in the art without departing from the scope and spirit of the invention. For example, the various elements of this invention can be provided on a PLD in any desired number and/or arrangement. One skilled in the art will appreciate that the present invention can be practiced by other than the described embodiments, which are presented for purposes of illustration and not of limitation, and the present invention is limited only by the claims that follow.