Background of the Invention
This invention relates to floating point arithmetic units and, more particularly, to an apparatus for computing a sticky bit for the arithmetic unit.
When numeric operands are represented in the form A.sup.x, B.sup.y within a computing system, the exponents x and y must be the same when two numbers are to be added or subtracted. If the exponents differ, the binary representation of the mantissa of the number having the smaller exponent must be shifted by an amount equal to the difference between the two exponents. FIG. 1 is a shift control circuit 10, not necessarily in the prior art, which performs such shifting. Shift control circuit 10 includes subtractors 14 and 18 which receive the operand exponents, designated exp (A) and exp (B), over buses 22 and 26. Subtractor 14 performs the operation exp (A)-exp (B), and subtractor 18 performs the operation exp (B)-exp (A). The resulting data in the form of shift counts from subtractors 14 and 18 are communicated to selection logic 30 over buses 34 and 38. Selection logic 30 determines which exponent is larger (e.g., by determining which shift count is positive or negative) and communicates a selection signal to a multiplexer 42 over a bus 44. Selection logic 30 communicates the positive shift count to a shift circuit 46 over a bus 50. Multiplexer 42 receives the operand mantissa designated mantissa (A) and mantissa (B), over buses 54 and 58, respectively. Multiplexer 42 selects the mantissa to be shifted in response to the selection signal received over bus 44 and communicates the selected mantissa to shift circuit 46 over a bus 62. Shift circuit 46 shifts the selected mantissa by an amount equal to the shift count received over bus 50. The shifted mantissa then is communicated to an ALU over a bus 66.
The number of bits used to represent the mantissa depends upon the precision mode selected in the particular computer. In single precision mode, each mantissa is represented with 24 bits, whereas in double precision mode each mantissa is represented with 53 bits. Since arithmetic operations in both single and double precision mode are processed the same way, only double precision mode shall be discussed herein.
FIG. 2A is a diagram of a double precision mantissa register 70. Mantissa register 70 includes fifty-three storage locations labeled B01-B53. B53 is always 1 if denormal numbers are not supported. The programmer uses these storage locations to store the binary representation of the mantissa for use by multiplexer 42. FIG. 2B is a diagram of a double precision mantissa register 72 which may be used to store the shifted mantissa before it is communicated to the ALU. Mantissa register 72 includes fifty-three storage locations S01-S53 which are used to store the shifted mantissa. Additionally, mantissa register 72 includes three storage locations which are transparent to the programmer. These storage locations comprise a guard bit (G), a round bit (R), and a sticky bit (S) as specified by the standard IEEE 754. The guard and round bits are the first and second bits beyond rounding precision. The sticky bit (S) indicates whether or not a nonzero value in bit positions B01-B53 of mantissa register 70 was shifted out during the mantissa shifting operation. A sticky bit value of "1" indicates that a meaningful portion of the mantissa has been lost and that the result of the mathematical operation may be inaccurate. Thus, calculation and monitoring of the sticky bit is very important to conform to the standard.
One approach used to calculate the sticky bit, not necessarily in the prior art, is shown in FIG. 3. The shift count from selection logic 30 is used to generate a mask 74 which is logically ANDed to the mantissa to be shifted which is stored in register 70. The mask typically contains a "1" in the number of least significant bit positions corresponding to the shift count (e.g., if the shift count equals five, the five least significant bit positions will contain a "1"). The result of the logical AND operation is stored in a register 82. Each storage location in register 82 which contains a "1" indicates that a corresponding nonzero bit in register 70 will be lost after the shifting operation. Thereafter, a logical OR is performed on each bit in register 82 to produce the sticky bit. Thus, if at least one nonzero bit in the mantissa will be lost as a result of the shifting operation (e.g., bits B04 and B03 in register 78), then that event will be indicated by a sticky bit equal to 1. Because of hardware constraints in the calculation of the shift count, the mask pattern cannot be generated until almost all bits of the outputs of subtractors 14 and 18 are available.
A second approach to sticky bit calculation is to logically OR the actual bits that are shifted out beyond the guard and round bit positions as shifting takes place. In this approach, the final sticky bit cannot be computed until all the shifting steps are finished.
With either approach, calculation of the sticky bit ordinarily lies in a critical path in the overall arithmetic sequence, and the arithmetic operation cannot proceed until the sticky bit is available.
Summary of the Invention
The present invention is directed to an arithmetic unit wherein a plurality of electrical signals corresponding to the mantissa is shifted, and a bit signal corresponding to the sticky bit is calculated simultaneously with the calculation of the shift count. Initially, a serial approach to mantissa shifting and sticky bit calculation is employed. A parallel approach to mantissa shifting and sticky bit calculation is adopted when all shift count bits are available. In one embodiment of the present invention, an exclusive OR gate is used to calculate the difference between the least significant bits of the first and second exponents. A shifter/sticky bit calculator immediately acts upon the output of the exclusive OR gate and begins shifting the mantissa and calculating the guard, round, and sticky bits. The more significant bits of the shift count are progressively generated thereafter, and the guard, round and sticky bits are calculated and the mantissa is shifted as the shift count bits become available. As soon as all shift count bits are available, a parallel approach to sticky bit calculation is adopted. Consequently, the shifted mantissa and the guard, round and sticky bits are available at the same time and much earlier than if the sticky bit were calculated according to known methods.
Brief Description of the Drawings
FIG. 1 is a block diagram of a known mantissa shifting circuit.
FIG. 2A is a diagram of a double precision mantissa register.
FIG. 2B is a diagram of a double precision mantissa register including guard, round and sticky bit storage locations.
FIG. 3 is a diagram showing a known method of computing the sticky bit.
FIG. 4 is a block diagram of a particular embodiment of a mantissa shifting circuit according to the present invention.
FIG. 5 is a more detailed block diagram of a particular embodiment of the shifter/sticky bit calculator according to the present invention shown in FIG. 4.
Detailed Description of the Preferred Embodiments
FIG. 4 is a block diagram of a mantissa shifting circuit 90 according to the present invention. Mantissa shifting circuit 90 includes subtractors 94 and 98 which subtract the exponents of two operands to be processed. As with subtractors 14 and 18 shown in FIG. 1, subtractor 94 performs the operation (EXP(A)-EXP(B)) whereas subtractor 98 performs the operation (EXP(B)-EXP(A)). Subtractors 94 and 98 receive the values of the exponents of the two operands over buses 102 and 106. Subtractor 94 communicates with a shifter/sticky bit calculator 114 over a bus 122. Similarly, subtractor 98 communicates with a shifter/sticky bit calculator 134 over a bus 142. Shifter/sticky bit calculator 114 receives the value of mantissa (B) over a bus 143, and shifter/sticky bit calculator 134 receives the value of mantissa (A) over a bus 144. Shifter/sticky bit calculators 114 and 134 shift their associated mantissas and calculate the guard, round, and sticky bits as each output bit of their associated subtractors becomes available.
Subtractors 94 and 98 communicate with selection logic 150 over buses 154 and 156, and the shifted mantissas from shifter/sticky bit calculators 114 and 134 are communicated to a multiplexer 160 over buses 164 and 168. Since it is not known which mantissa actually needs to be shifted at the time shifting is begun, both mantissas are shifted simultaneously. The shifted mantissa to be used in the arithmetic operation is selected by multiplexer 160 in response to signals received from selector 150 over a bus 172.
FIG. 5 is a more detailed block diagram of subtractor 94 and shifter/sticky bit calculator 114. Subtractor 98 and shifter/sticky bit calculator 134 operate in the same way, so a discussion of them shall be omitted. Unlike known subtractors such as subtractors 14 and 18 of FIG. 1, subtractor 94 is constructed to operate with a minimum number of hardware levels and to make each bit of the subtraction result available for use by shifter/sticky bit calculator 114 as soon as possible. For example, the present applicants take advantage of the fact that when any two binary numbers are subtracted, the least significant bit of the result is the same whether the first operand is subtracted from the second or vice versa. Thus, an exclusive OR gate 200 is used as a least significant bit (LSB) subtractor 204. Consequently, only a single level of logic is required to perform the subtraction operation for the least significant bit pair of the exponents, and the result of the subtraction is immediately made available to stage 1 logic 220 in shifter/sticky bit calculator 114 over a line 208.
Since the mantissa is shifted a maximum of one bit position in response to the subtraction of the least significant bit pair of the exponents, only the guard bit must be calculated from the output (SHC1) from LSB subtractor 204. The round and sticky bits are set to zero. Stage 1 logic 220 calculates the guard bit for this stage as the logical AND of SHC1 with the least significant bit (B01) of the unshifted mantissa (B) received on bus 143. The results of the this first shift (SH1(01)-SH1(53)) and guard, round and sticky bit calculation (G1, R1, S1) are communicated to stage 2 logic 224 over a bus 228.
The more significant bit positions of the exponents are processed with a more significant bit (MSB) subtractor 212. Once again, the minimum number of hardware levels is employed for the subtraction of each exponent bit pair. Subtraction of bit pairs 2-3 of the exponents typically requires two logic levels, subtraction of bit pairs 4-6 of the exponents typically requires three logic levels, and subtraction of bit pairs 7-10 of the exponents requires four logic levels.
The second shift count bit (SHC2) becomes available from MSB subtractor 212 at or before the time that stage 1 logic produces its output on bus 228. Stage 2 logic 224 further shifts mantissa (B) by 2 positions if SHC2 is true. Thus, the guard bit G2 is calculated as either the previous guard bit G1, if no shifting is to occur, or bit 2 (SH1(02)) of the previously shifted mantissa (B) appearing on bus 228. The selection is obtained by the logical operation G2=G1*SHC2+SH1(02)*SHC2 where * is a logical AND operation and + is a logical OR operation. The round bit R2 is calculated by the logical operation R2=SHC2*SH1(01). The sticky bit S2 is calculated by the logical operation S2=G1*SHC2. Thus, if SHC2 is true, the guard and round bits are the bit positions 2 and 1, respectively of the output from stage 1 logic 220, and the sticky bit is the previous guard bit. Otherwise, the guard, round and sticky bits are the same as their previous values.
Bit 3 of the shift count (SHC3) is available at or before the time that stage 2 logic produces its output on bus 236, and this bit represents a possible additional shift of four bits of the mantissa appearing on bus 236. Accordingly, stage 3 logic 240 shifts the value of mantissa (B) received on bus 236 by four positions if SHC3 is true.
A general algorithm may be provided for the calculation of the guard, round and sticky bits for this shift and all shifts hereafter. For some integer N>1, the guard bit is calculated for the Nth shift as G(N)=(A*B)+(C*D) wherein A is the value of the guard bit for the (N-1)th shift; B is the inverted value of bit N of the shift count; C is the 2.sup.(N-1) th bit of the (N-1)th shifted binary number (e.g., SH2(4) for N=3); and D is the value of bit N of the shift count.
For some integer M>2, the round bit for an Mth shift is calculated as R(M)=(E*F)+(G*H) wherein E is the value of the round bit for the (M-1)th shift; F is the inverted value of bit M of the shift count; G is the value of the (2.sup.(M-1) -1)th bit of the (M-1)th shifted binary number (e.g., SH2(3) for M=3); and H is the value of bit M of the shift count.
For some integer L>2, the sticky bit for an Lth shift is calculated as S(L)=P+Q*(R+S+T) where P is the value of the sticky bit for the (L-1)th shift; Q is the value of bit L of the shift count; R is the logical OR of the (2.sup.(L-1) -2) least significant bits of the (L-1)th shifted binary number; S is the guard bit for the (L-1)th shift; and T is the round bit for the (L-1)th shift.
The remaining shift count bits (SHC4-SHC10) typically require three or four logical levels to calculate them. As a result, the remaining shift count bits are available at the fourth shift, and a parallel approach to shifting may be adopted at this time. In this embodiment, however, parallel processing is delayed for one more shift (i.e., the fourth shift). After the fourth shift, the parallel approach is adopted.
To implement parallel processing in this embodiment, the mantissa bits from stage 4 logic 244 are grouped together. For example, bits SH4(01)-SH4(13) form one group, bits SH4(14)-SH4(29) form a second group, and bits SH4(30)-SH4(45) form a third group. Let SA equal the logical OR of all bits in the first group, let SB equal the logical OR of all bits of the second group, and let SC equal the logical OR of all bits in the third group. Then let SHBYND equal the logical OR of bits 7-10 of the shift count. A value of one for SHBYND indicates that all bits in the mantissa register have been shifted out, since bits 7-10 of the shift count represent a shift of 64 or more, assuming denormal numbers are not supported. A slight modification of SHBYND is necessary if denormal numbers are supported. Two partial sticky bits are calculated in final logic 248: STK1=(G4+R4)*(SHC5+SHC6)+SHBYND+S2+S3+S4, and STK2=SHC6*SHC5*SC+SHC6*(SB+SA)+SHC5*SA. The final sticky bit then is calculated as S(final)=STK1+STK2.
While the above is a description of a preferred embodiment of the present invention, various modifications may be employed. Consequently, the scope of the invention should not be limited except as described in the claims.