The invention relates to computing devices and, more particularly, to techniques for performing arithmetic operations within computing devices.
Commercial applications and databases typically store numerical data in decimal format. Currently, however, microprocessors do not provide instructions or hardware support for decimal floating-point arithmetic. Consequently, decimal numbers are often read into computers, converted to binary numbers, and then processed using binary floating-point arithmetic. Results are then converted back to decimal before being output or stored. Besides being time-consuming, this process is error-prone, since most decimal numbers cannot be exactly represented as binary numbers. Thus, if binary floating-point arithmetic is used to process decimal data, unexpected results may occur after a few computations.
In addition, most existing decimal dividers are for fixed-point (typically integer) decimal data types. As a result, scaling has to be done when working with numbers of different magnitudes. The process of scaling is also time-consuming and error-prone, and designs for fixed-point decimal dividers cannot be directly applied to floating-point decimal dividers.
In many commercial applications, including financial analysis, banking, tax calculation, currency conversion, insurance, and accounting, the errors introduced by converting between decimal and binary numbers are unacceptable and may violate legal accuracy requirements. Therefore, these applications often use software to perform decimal floating-point arithmetic. Although this approach eliminates errors resulting from conversion between binary and decimal numbers, it leads to long execution times for numerically intensive commercial applications, since software implementations of decimal floating-point operations are typically 100 to 1,000 times slower than equivalent binary floating-point operations in hardware.
In general, the invention is directed to efficient hardware-based techniques for performing decimal floating-point division. More specifically, when performing decimal floating-point division, a processing unit described herein uses an accurate piecewise linear approximation to obtain an initial estimate of a divisor's reciprocal. The piecewise linear approximation employs operand modification and decimal encoding to reduce the memory requirements. The initial estimate of the divisor's reciprocal is then improved using a modified form of Newton-Raphson iteration that is appropriate for decimal data. The processing unit multiplies the divisor's reciprocal by the dividend to produce a preliminary quotient. The preliminary quotient is rounded using an efficient rounding scheme to produce the final decimal floating-point quotient.
In one embodiment, a method comprises receiving a decimal floating-point dividend and a decimal floating-point divisor with a decimal floating-point divider; and performing Newton-Raphson iterations with the decimal floating-point divider to output a decimal floating-point quotient.
In another embodiment, a method comprises receiving a decimal dividend and a decimal divisor with a decimal floating-point divider, accessing a lookup table to retrieve a decimal coefficient using a portion of the divisor as an index into the lookup table, and computing an initial approximation of the divisor's reciprocal based on the coefficient. The method further comprises iteratively computing an improved estimate of the divisor's reciprocal with the decimal floating-point divider, multiplying the dividend by the improved approximation of the divisor's reciprocal to produce a preliminary decimal quotient, computing a biased decimal quotient from the preliminary decimal quotient, and outputting a decimal quotient based on the biased decimal quotient.
In another embodiment, a processing unit comprises a decimal floating-point divider that performs Newton-Raphson iterations to output a decimal floating-point quotient.
In another embodiment, a decimal floating-point divider comprises inputs to receive a decimal floating-point dividend and a decimal floating-point divisor. The divider further comprises a nine's complement block and a decimal multiplier, wherein the nine's complement block and the decimal multiplier compute an initial approximation of the divisor's reciprocal, and wherein the decimal multiplier further (a) performs Newton-Raphson iterations to compute an improved approximation of the divisor's reciprocal based on the initial approximation, and (b) multiplies the dividend by the improved approximation to produce a preliminary decimal quotient, and (c) performs an adjustment on the preliminary decimal quotient to produce a biased decimal quotient, and (d) multiplies the divisor by the biased decimal quotient to generate signals for rounding and correction. The decimal floating-point divider further comprises a processing unit to output a decimal floating-point quotient based on the biased decimal quotient.
The techniques may provide one or more advantages. For example, the hardware-based techniques employed by the processing unit may provide a much faster computation time than conventional software packages, which typically must emulate decimal arithmetic. In addition, performing the division as decimal division instead of converting from decimal to binary form may avoid errors introduced by such conversions.
Moreover, the disclosed techniques employ Newton-Raphson iteration, which approximately doubles the number of accurate digits each iteration, compared to conventional decimal dividers that use digit recurrence algorithms and only produce one decimal digit each iteration. As a result, the described processing unit may achieve accurate decimal division in relatively few iterations.
As another example, compared to conventional piecewise linear approximations that require the use of a decimal multiply-accumulate unit and two coefficients read from memory, some embodiments of the invention may only require the use of a decimal multiplier and a single coefficient read from memory. Further, the same decimal multiplier may be used to perform the Newton-Raphson iteration, final multiplication, and rounding, thereby conserving chip area.
In addition, the techniques provide a divider for floating-point decimal data types. The invention may thus avoid the scaling problems associated with fixed-point dividers. A preferred embodiment of the invention is designed to be compliant with a draft of the revised version of the IEEE 754 Standard for Floating Point Arithmetic.
The details of one or more embodiments of the invention are set forth in the accompanying drawings and the description below. Other features, objects, and advantages of the invention will be apparent from the description and drawings, and from the claims.
As illustrated in
Initially, divider 12 uses an accurate piecewise linear approximation to obtain an initial estimate of a divisor's reciprocal. As described in detail below, divider 12 utilizes conversion modules (CMs) 28A-28B (collectively, “conversion modules 28”) and lookup module 30 to generate a coefficient in BCD form for use in calculating the initial estimate. Divider 12 then utilizes fixed-point decimal multiplier 36 (“decimal multiplier 36”), 9's complement block 38, barrel shifter 42 and reciprocal register 46 to compute the initial estimate of a divisor's reciprocal using a piecewise linear approximation.
Divider 12 utilizes these components to refine the estimate of the divisor's reciprocal using a modified form of Newton-Raphson iteration. In the embodiment shown, decimal multiplier 36 receives input operands from eight different sources and outputs results to four sub-blocks for further processing.
Decimal multiplier 36 may be a high-speed sequential or parallel decimal multiplier. For example, decimal multiplier 36 may be a sequential decimal fixed-point multiplier that uses carry-save addition to accumulate the partial products, leading to a short critical path delay. In certain embodiments, decimal multiplier 36 may perform multiplication in (nmult+6) cycles, where nmult is the number of significant digits in the multiplier operand. Decimal multiplier 36 may also make use of fast generation of multiplicand multiples, decimal (3:2) counters and (4:2) compressors, and a simplified decimal carry-propagate adder to produce the correct quotient. In addition, early exit may provide the opportunity to finish the multiplication in less time when the multiplier operand is short, reducing the time needed to perform the initial reciprocal approximation and early Newton-Raphson iterations.
Divider 12 further contains general processing unit 13 that includes coefficient comparator (“CC” in
Rounding/correction unit 48 rounds the quotient. Data post-processing unit 45 combines the sign, exponent, and coefficient to output the quotient Q in IEEE-754R decimal format.
Processing unit 10 may be a microprocessor or coprocessor for use within a laptop computer, general-purpose computer or high-end computing system. Alternatively, processing unit 10 may be a microcontroller, application specific integrated circuit (ASIC) or other component. Moreover, processing unit 10 may be implemented as a single integrated circuit in which divider 12 constitutes only a portion of the implemented functionality. Alternatively, divider 12 may be implemented in one or more stand-alone integrated circuits. Components of processing unit 10 and divider 12 may be implemented as discrete combinational and sequential logic, logic arrays, microcode, firmware or combinations thereof.
Initially, divider 12 computes an approximation of the divisor's reciprocal, 1/X≈R0 (50). The accuracy of this initial approximation will affect the number of Newton-Raphson iterations needed to obtain a correct quotient having a desired accuracy. Next, divider 12 applies Newton-Raphson iterations to refine the approximation of the divisor's reciprocal (52). Newton-Raphson iteration is an iterative method used to approximate the root of a non-linear function. Divider 12 uses a modified version of the first-order Newton-Raphson division algorithm to approximate 1/X given the initial reciprocal approximation R0. Divider 12 performs m Newton-Raphson iterations to produce an improved reciprocal approximation, Rm.
In the third operation, decimal multiplier 36 multiplies Rm and the dividend Y to produce a preliminary quotient Q′ (54). In the fourth operation, incrementer 40 performs an adjustment (e.g., an addition) to the preliminary quotient Q′ to obtain a biased quotient Q″, and multiplies Q″ with the divisor to generate a trial dividend which is used to produce required signals for rounding/correction logic unit 48 (56). In the fifth operation, divider 12 adjusts and rounds the biased quotient Q″ to obtain the correct quotient, Q (58). Although shown sequentially in
In practice, divider 12 inputs the value of XM into conversion module (CM) 28A, which converts XM from a binary coded decimal (BCD) format to a densely-packed decimal (DPD) encoded version (60). The converted XM is input into lookup module 30 to obtain coefficient C′=1/(XM+5×10−k−1)2 truncated to 2k digits (2 integer digits and 2k−2 fraction digits) (62). Lookup module 30 is indexed by the k most significant digits of the divisor's significand in DPD format and outputs C′ in DPD format. Conversion module 28B converts C′ from DPD to BCD using two-level logic (64). In addition, CM 28A converts XL to its nine's complement, and then concatenates XM with
Simple conversion logic, which takes roughly two gate delays, may be used for these conversions. One reason for this conversion is to reduce the size of lookup module 30. Since DPD represents 3 decimal digits using just 10 bits, this approach reduces the size of the table lookup to roughly 2p×2p, where p=┌(k*10)/3┐. For example, with k=3 the size of the memory lookup is reduced from 12 Kbytes to only 2.5 Kbytes. C′ is output to decimal multiplier 36 for processing.
Decimal multiplier 36 (
The initial approximation is based on a piecewise first order Taylor series expansion, which approximates a function f(X) close to the point A as:
f(X)≈f(A)+f(A)×(X−A). (eq. 1)
To obtain the initial approximation, divider 12 divides the n-digit divisor, X=[0,Xn−1Xn−2 . . . X0], into a k-digit more significant part, XM=[0.Xn−1Xn−2 . . . Xn−k], and an (n−k)-digit less significant part XL=[Xn−k−1Xn−k−2 . . . X0]10−k. Using XM as the input to a table lookup divides the original input interval [0.1, 1) into subintervals of size 10−k. On the subinterval [XM, XM+10−k), a standard piecewise Taylor series expansion of f(X)=1/X about the subinterval midpoint A=XM+5×10−k−1 has the form:
Since (2×XM−X=XM−XL) and (10−k−XL) corresponds to the ten's complement of XL, Equation (2) can be rewritten as:
where
The approximation error, εapprox, from this method is upper-bounded by the second-order term of the Taylor series expansion at A, which gives:
Since 0.1≦XM<1 and 0≦XL<10−k, εapprox is bounded by
When computed with infinite precision, εapprox≦0, such that R0≦1/X, since the piecewise linear Taylor series expansion of 1/X always under-approximates 1/X.
In practice, divider 12 uses the nine's complement of the most significant digits of XL instead of the ten's complement of XL, stores only the most significant digits of C′ in table lookup module 30, and truncates the product C′×X′. Nine's complement block 38 may obtain the nine's complement of XL from XL using only simple two-level logic. Since the absolute value of the approximation error in the initial estimate is less than 10−k+3/4, the goal is to limit the overall error in the initial estimate to less than 10−2k+3, so that the initial approximation is still accurate to at least (2k−3) fraction digits. A second goal is to ensure that the error in the initial approximation is less than zero, since this simplifies the Newton-Raphson iteration and final rounding. For the initial approximation, only the 2k most significant digits of X′ and C′ are used and R0 is truncated to 2k−1 digits. Thus, the value actually computed by divider 12 for the initial approximation is
where εC′, εX′, and εtrunc correspond to the errors due to truncating C′, X′, and R0, respectively. Consequently,
εR0=X′×εC′+C′×εX′+εC′×εC′+εtrunc+εapprox. (eq. 8)
Since 0.1≦X′<1.0, 1.0<C′<100, and 1<R0<10, we have −10−2k+2<εC′≦0, 10−2k<εX′<0, −10−2k+2<εtrunc≦0, which gives the bounds:
1.0×(−10−2k+2)+100×(−10−2k)+(−10−2k+2)+(−2.5×10−2k+2)<εR0<0−0.55×10−2k+3<εR0<0. (eq. 9)
Thus, if the k most significant digits of X are used to access a table lookup, where each entry contains 2k digits, the initial approximation is accurate to more than 2k−3 fraction digits.
The invention uses a modified (e.g., optimized) version of the first-order Newton-Raphson division algorithm to approximate 1/X given the initial reciprocal approximation R0. In the modified version described herein, the Newton-Raphson iteration consists of two general operations. Decimal multiplier 36 and nine's complement block 38 performs the first operation of the Newton-Raphson iteration, approximating V≈(2−X×Ri) by taking the nine's complement of the 2G+2 most significant fraction digits of X×Ri and setting the integer digit to one (70), where G is the number of accurate digits of Ri. Divider 12 then inputs the approximated value of V back into decimal multiplier 36, which performs the second operation of the Newton-Raphson iteration, multiplying Ri by V to obtain Ri+1, where Ri×V is truncated to 2G+1 fraction digits (72). Barrel shifter 42 shifts Ri to reduce the latency of multiplication. Reciprocal register 46 stores temporary results generated by each of the iterations. Although shown sequentially for ease of illustration, the operations may be performed in pipelined fashion.
The first order Newton-Raphson iterative equation for division is:
Ri+1=Ri×(2−X×Ri). (eq. 10)
Since Ri=1/X+εRi, where εRi is the error in iteration i, Equation (10) can be rewritten as:
Since Ri<1/X, then X×Ri<1 and X×Ri≈1, which allows 2−X×Ri to be approximated by taking the nine's complement of the fraction digits of X×Ri and setting the integer digit to one. Full precision multiplications are also avoided, which results in the new iterative equation:
where εm1 is the error due to truncating X×Ri and taking its nine's complement to get V≈2−X×Ri and εm2 is the error due to truncating Ri×V. Equation (12) can then be rewritten as:
The error in the initial reciprocal approximation R0 is bounded by −0.55×10−G<εR0<0, where G=2k−3. Truncating X×R0 to 2G+2 fraction digits and taking its nine's complement results in an error εm1, which is bounded by −10−2G−2≦εm1<0. Similarly, truncating X×V to 2G+1 fraction digits results in an error εm2 that is bounded by −10−2G−1≦εm1≦0. In Equation (13), if εRi<0 then εRi×εm1>0, εm1/X<0, −X×εR
Since εR
Each of the Newton-Raphson iterations more than doubles the number of accurate digits in the reciprocal approximation. By truncating the result of each multiplication and taking the nine's compliment of X×Ri, it is guaranteed that Ri+1<1/X, which simplifies computing 2−X×Ri and the final rounding. Newton-Raphson iteration continues for m iterations to obtain an improved reciprocal approximation Rm, where |εRm|<10−n−2 (74). In practice, an iteration counter may be used, where i is initialized to zero, and the counter exits once i=m.
Once the final Newton-Raphson iteration is performed (
Finally, divider 12 rounds Q″ to produce the final quotient Q (84). Specifically, divider 12 selects a rounding mode from RNE, RNA, RPI, RMI, RTZ, RNT, and RAZ and provides the selected rounding mode to rounding/correction unit 48. Rounding/correction unit 48 outputs a signal to incrementer/decrementer 40 to select the correctly rounded quotient. Data post-processing unit 45 combines the sign, exponent, and coefficient to generate the quotient Q in IEEE-754R decimal format. TABLE 1 lists the abbreviations of the rounding modes supported by the rounding scheme described herein. The techniques described also support the RNT and RAZ rounding modes, which are considered useful in some financial applications.
Rounding/correction unit 48 receives the rounding mode input, and uses decimal multiplier 36 to determine the sign of the remainder, N, and if the remainder N is zero, where the value of the remainder is:
N=|Y|−|Q′|×|X|. (eq. 14)
The rounding direction is determined using the sign of the remainder, whether the remainder is zero, and additional information.
As discussed, the dividend is normalized to 0.1<Y<1.0 and it is assumed that the dividend is less than or equal to the divisor, which gives 0.1<Q≦1. Decimal multiplier 36 obtains preliminary quotient Q′ by multiplying the dividend by the divisor's reciprocal approximation. A small error between the correct quotient, Q, and the preliminary quotient, Q′, may cause Q and Q′ to round in different directions. For example, if Q=0.19+10−10, and Q′=0.19−10−10, when the rounding mode is round toward zero and the rounded quotient has n=7 digits, then Q rounds to 0.19, but Q′ rounds to 0.1899999. To correctly round the quotient, incrementer/decrementer 40 first adjusts Q′ to obtain the (n+1)-digit quotient, Q″, by truncating Q′ to (n+1) digits and then adding 10−(n+1) to the result (80). This technique is similar to that used in some binary division schemes. The error then becomes:
−10(n+1)≦Q−Q″≦10−(n+1). (eq. 15)
Rounding/correction unit 48 uses Q″ instead of Q′ to determine both the sign of the remainder and whether the remainder is equal to zero. The nth fraction digit of Q″ is called its least significant digit (LSD) and the (n+1)th fraction digit of Q″ is called its guard digit (GD). With decimal division, the maximum difference between Y=Q×X and Q″×X is bounded by:
−10−(n+1)×(1−10−n)≦δ=Q×X−Q″×X<10−(n+1)×(1−10−n). (eq. 16)
As a result, the maximum absolute difference between Y and X×Q″ is less than 10−(n+1). Consequently, rounding/correction unit 48 compares the LSD of Y and the corresponding digit of Q″×X to determine the sign of the remainder. If the LSD of Y is not equal to the nth fraction digit of Q″×X, the remainder is positive. Otherwise, the remainder is negative or zero. This is because Y only has n digits but Q″×X has 2n+1 digits. The remainder is zero if all of the digits right of the nth digit in Q″×X are zero, since this means that Q″ is the exact quotient.
By observing the LSD and GD of Q″, and the sign and equality with zero of the remainder, the correctly rounded quotient is selected as one of Q″T, Q″T+10−n, or Q″T−10−n, where Q″T corresponds to Q″ truncated to n digits. An action table, shown in TABLE 2, is used to determine the correct quotient.
In TABLE 2, LSB corresponds to the Least Significant Bit of the LSD of Q. GD corresponds to the guard digit of Q, X indicates that it does not matter what the value is, and (+/−) below each rounding mode corresponds to the sign of Q″. Based on the LSB, GD, remainder, rounding mode, and sign of Q″, the correctly rounded quotient is selected as one of Q″T, Q″T+10−n, or Q″T−10−n. In TABLE 2, Q″T+ denotes Q″T+10−n and Q″T− denotes Q″T−10−n. For example, if LSB is 0, GD is 5, remainder is 0, the rounding mode is RNA, and the sign of the Q″ is negative in the RNA mode, the correct quotient is equal to Q″T−10−n.
Simulation Results
A 64-bit decimal floating-point divider embodiment of the invention was modeled, using the Newton-Raphson division algorithm described herein, in structural Verilog. In particular, a 0.11 micron CMOS standard cell library was used to synthesize certain embodiments of the invention. Under nominal operating conditions and a supply voltage of 1.2 Volts, the synthesized embodiment had a critical path delay of 0.75 ns, which occurred in the decimal barrel shifter. When implemented using a table lookup with k=3 and a sequential fixed-point multiplier that processes one digit per cycle, the divider took 163 cycles to implemented 64-bit (16-digit) decimal floating-point division.
The number of digits used to access the table lookup, k, influences the memory size and the number of Newton-Raphson iterations required.
The number of cycles needed to execute the Newton-Raphson floating-point division algorithm described herein depends on the latency of multiplication, the size of the initial table lookup, and the quotient's precision.
Various embodiments of the invention have been described. These and other embodiments are within the scope of the following claims.
This application claims the benefit of U.S. Provisional Application Ser. No. 60/612,586, filed Sep. 23, 2004, the entire content of which is incorporated herein by reference.
Number | Name | Date | Kind |
---|---|---|---|
3591786 | Nelson | Jul 1971 | A |
4635220 | Yabe et al. | Jan 1987 | A |
4692891 | Yamaoka et al. | Sep 1987 | A |
4817048 | Rawlinson et al. | Mar 1989 | A |
4999801 | Katsuno | Mar 1991 | A |
5515308 | Karp et al. | May 1996 | A |
5587940 | Ferguson | Dec 1996 | A |
6067617 | Webb et al. | May 2000 | A |
6769006 | Krouglov et al. | Jul 2004 | B2 |
7127483 | Beaumont-Smith et al. | Oct 2006 | B2 |
20020143840 | Krouglov et al. | Oct 2002 | A1 |
20040167956 | Vihriala | Aug 2004 | A1 |
Number | Date | Country | |
---|---|---|---|
20060064454 A1 | Mar 2006 | US |
Number | Date | Country | |
---|---|---|---|
60612586 | Sep 2004 | US |