This application is based upon and claims the benefit of priority of the prior Japanese Patent Application No. 2012-183419, filed on Aug. 22, 2012, the entire contents of which are incorporated herein by reference.
The embodiments discussed herein are directed to a multiplying device and a multiplying method.
There has been known a floating-point multiplying device having a multiplying circuit for multiplying mantissa parts of normalized floating-point numbers (for example, refer to Patent Document 1). A first zero detecting circuit detects the number of zeros consecutive in a highest place side of a fixed point number being a multiplicand. A second zero detecting circuit detects the number of zeros consecutive in a highest place side of a fixed-point number being a multiplier. A first left-shifting circuit left-shifts the multiplicand by the number of the zeros detected by the first zero detecting circuit to supply the resultant to the multiplying circuit. A second left-shifting circuit left-shifts the multiplier by the number of the zeros detected by the second zero detecting circuit to supply the resultant to the multiplying circuit. An adder adds the numbers of the zeros detected by the first and second zero detecting circuits. A right-shifting circuit right-shifts a result of multiplication that the multiplying circuit performs on the multiplicand and the multiplier which are left-shifted by the first and second left-shifting circuits, by a number indicated by a result of the addition of the adder.
In Patent Document 1, the right-shifting circuit requires a digit width twice as high as format precision at the maximum, which increases both a resource amount and a delay time.
A multiplying device includes: a counting circuit which counts the number of zeros consecutive in higher places of a mantissa part of a floating-point number being a multiplier; a shift amount arithmetic circuit which calculates a shift amount based on a digit number of fixed precision of the mantissa part and a count value counted by the counting circuit; a shifting circuit which left-shifts a mantissa part of a floating-point number being a multiplicand by the shift amount; a digit number arithmetic circuit which calculates a digit number of the mantissa part of the multiplier by subtracting the count value from the digit number of the fixed precision of the mantissa part; a multiplying circuit which outputs an intermediate product on a digit-by-digit basis of the mantissa part of the multiplier based on the mantissa part of the multiplicand left-shifted by the shifting circuit and the mantissa part of the multiplier; an adding circuit which adds an exponent part of the floating-point number being the multiplicand and an exponent part of the floating-point number being the multiplier to output an addition value; and a control circuit which outputs the intermediate product output by the multiplying circuit as a mantissa part of a floating-point number being a product and outputs the value output by the adding circuit as an exponent part of the floating-point number being the product, when the number of times the multiplying circuit outputs the intermediate product is the digit number calculated by the digit number arithmetic circuit.
The object and advantages of the invention will be realized and attained by means of the elements and combinations particularly pointed out in the claims.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory and are not restrictive of the invention.
“001100” being a mantissa part of a shifted multiplicand is a number resulting from left-shift of the mantissa part “000110” of the multiplicand by “1” being the shift amount LSA. A digit number DC of the mantissa part of the multiplier is expressed by m−LZC2=6−4=2. “0” being an exponent part of a product is a value resulting from addition of the exponent part “0” of the multiplicand and the exponent part “0” of the multiplier.
Next, the mantissa part “001100” of the shifted multiplicand is multiplied by the least significant digit “1” of the mantissa part “000011” of the multiplier and the resultant is right-shifted by one digit, whereby a partial product “00110.0” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “1” from “2”.
Next, the mantissa part “001100” of the shifted multiplicand is multiplied by the second least significant digit “1” of the mantissa part “000011” of the multiplier, whereby a partial product “001100” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “0” from “1”.
When the digit number DC of the mantissa part of the multiplier becomes “0”, the partial product “00110.0” relevant to the least significant digit and the partial product “001100” relevant to the second least significant digit are added, so that an intermediate product “001210.0” is obtained. An exponent part of the product is left “0”.
Next, “001210” whose fixed precision is six digits out of the intermediate product “001210.0” is output as an output OUT4 of the product. The output OUT4 of the product has a mantissa part “001210” and an exponent part “0”. Consequently, a highly precise product free of digit cancellation is obtained. Further, since a shifting circuit or a register with m×2=6×2=12 digits as in
“111000” being a mantissa part of a shifted multiplicand is a number resulting from left-shift of the mantissa part “011100” of the multiplicand by “1” being the shift amount LSA. A digit number DC of the mantissa part of the multiplier is expressed by m−LZC2=6−4=2. “0” being an exponent part of a product is a value resulting from addition of the exponent part “0” of the multiplicand and the exponent part “0” of the multiplier.
Next, the mantissa part “111000” of the shifted multiplicand is multiplied by the least significant digit “1” of the mantissa part “000011” of the multiplier and the resultant is right-shifted by one digit, whereby a partial product “11100.0” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “1” from “2”.
Next, the mantissa part “111000” of the shifted multiplicand is multiplied by the second least significant digit “1” of the mantissa part “000011” of the multiplier, whereby a partial product “111000” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “0” from “1”.
When the digit number DC of the mantissa part of the multiplier becomes “0”, the partial product “11100.0” relevant to the least significant digit and the partial product “111000” relevant to the second least significant digit are added, and an intermediate product “122100.0” is obtained. An exponent part of the product is left “0”.
Next, “122100” whose fixed precision is six digits out of the intermediate product “122100.0” is output as the output OUT5 of the product. The output OUT5 of the product has a mantissa part “122100” and an exponent part “0”. Consequently, a highly precise product free of digit cancelation can be obtained.
A mantissa part “110000” of a shifted multiplicand is a number resulting from left-shift of the mantissa part “000011” of the multiplicand by “4” being the shift amount LSA. A digit number DC of the mantissa part of the multiplier is expressed by m−LZC2=6−1=5. “0” being an exponent part of a product is a value resulting from addition of the exponent part “0” of the multiplicand and the exponent part “0” of the multiplier.
Next, the mantissa part “110000” of the shifted multiplicand is multiplied by the least significant digit “0” of the mantissa part “011100” of the multiplier and the resultant is right-shifted by four digits, whereby a partial product “00.0000” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “4” from “5”.
Next, the mantissa part “110000” of the shifted multiplicand is multiplied by the second least significant digit “0” of the mantissa part “011100” of the multiplier and the resultant is right-shifted by three digits, whereby a partial product “000.000” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “3” from “4”.
Next, the mantissa part “110000” of the shifted multiplicand is multiplied by the third least significant digit “1” of the mantissa part “011100” of the multiplier and the resultant is right-shifted by two digits, whereby a partial product “1100.00” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “2” from “3”.
Next, the mantissa part “110000” of the shifted multiplicand is multiplied by the fourth least significant digit “1” of the mantissa part “011100” of the multiplier and the resultant is right-shifted by one digit, whereby a partial product “11000.0” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “1” from “2”.
Next, the mantissa part “110000” of the shifted multiplicand is multiplied by the fifth least significant digit “1” of the mantissa part “011100” of the multiplier, whereby a partial product “110000” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “0” from “1”.
Next, when the digit number DC of the mantissa part of the multiplier becomes “0”, the aforesaid five partial products relevant to the first to fifth least significant digits are added, whereby an intermediate product “122100.0” is obtained. An exponent part of the product is left “0”.
Next, “122100” whose fixed precision is six digits out of the intermediate product “122100.0” is output as an output OUT6 of the product. The output OUT6 of the product has a mantissa part “122100” and an exponent part “0”. Consequently, a highly precise product free of digit cancelation can be obtained.
A mantissa part “999000” of a shifted multiplicand is a number resulting from left-shift of the mantissa part “099900” of the multiplicand by “1” being the shift amount LSA. A digit number DC of the mantissa part of the multiplier is expressed by m−LZC2=6−4=2. “0” being an exponent part of a product is a value resulting from addition of the exponent part “0” of the multiplicand and the exponent part “0” of the multiplier.
Next, the mantissa part “999000” of the shifted multiplicand is multiplied by the least significant digit “9” of the mantissa part “000099” of the multiplier and the resultant is right-shifted by one digit, whereby a partial product “899100.0” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “1” from “2”.
Next, the mantissa part “999000” of the shifted multiplicand is multiplied by the second least significant digit “9” of the mantissa part “000099” of the multiplier, whereby a partial product “8991000” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “0” from “1”.
Next, when the digit number DC of the mantissa part of the multiplier becomes “0”, the partial product “899100.0” relevant to the least significant digit and the partial product “8991000” relevant to the second least significant digit are added, whereby an intermediate product “9890100.0” is obtained. An exponent part of the product is left “0”. Here, an integer part of the intermediate product “9890100.0” has seven digits, which exceeds a digit number m of fixed precision=6, and this is a state of the overflow.
Next, since the seventh least significant digit of the integer part of the intermediate product “9890100.0” is one of “1 to 9”, it is determined that this is an overflow state. In this case, the intermediate product “9890100.0” is right-shifted by one digit to increment the exponent part of the product from “0” to “1”, and an output OUT7 of the product is output. The output OUT7 of the product has a mantissa part “989010” and an exponent part “1”. Consequently, the overflow is prevented and a highly precise product is obtained.
Here, since “2” being the shift amount LSA is larger than “1” being the multiplicand reading zero count value LZC1, it is not possible to left-shift the mantissa part “011111” of the multiplicand by “2” being the shift amount LSA. In this case, the mantissa part “011111” of the multiplicand is left-shifted by “1” being the multiplicand reading zero count value LZC1, whereby a mantissa part “111110” of a shifted multiplicand is obtained. A digit number DC of the mantissa part of the multiplier is expressed by m−LZC2=6−3=3. “1” being an exponent part of a product is expressed by exp1+exp2+LSA−LZC1=0+0+2−1=1 as a result of the correction.
Next, the mantissa part “111110” of the shifted multiplicand is multiplied by the least significant digit “1” of the mantissa part “000111” of the multiplier and the resultant is right-shifted by two digits, whereby a partial product “1111.10” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “2” from “3”.
Next, the mantissa part “111110” of the shifted multiplicand is multiplied by the second least significant digit “1” of the mantissa part “000111” of the multiplier and the resultant is right-shifted by one digit, whereby a partial product “11111.0” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “1” from “2”.
Next, the mantissa part “111110” of the shifted multiplicand is multiplied by the third least significant digit “1” of the mantissa part “000111” of the multiplier, whereby a partial product “111110” of the mantissa parts is obtained. The digit number DC of the mantissa part of the multiplier is decremented to “0” from “1”.
Next, when the digit number DC of the mantissa part of the multiplier becomes “0”, the aforesaid partial products relevant to the first to third least significant digits are added, whereby an intermediate product “123332.1” is obtained. An exponent part of the product is left “1”. In this state, an output OUT8 of the product is output. The output OUT8 of the product has a mantissa part, which has an integer part “123332” and a fractional part “0.1”, and an exponent part “1”. Thereafter, in the mantissa part of the product, for example, the fractional part is rounded off, and the mantissa part “123332” and the exponent part “1” are output. As described above, by correcting the left-shift amount and the exponent part, a highly precise product is obtained.
An exclusive logical sum circuit 901 is a positive-negative sign arithmetic circuit and outputs an exclusive logical sum value of the positive-negative sign sg1 of the multiplicand and the positive-negative sign sg2 of the multiplier as a positive-negative sign sg0. That is, the exclusive logical sum circuit 901 receives the positive-negative sign sg1 of the floating-point number being the multiplicand and the positive-negative sign sg2 of the floating-point number being the multiplier, and when the both positive-negative signs are the same, it outputs the positive-negative sign sg0 of a floating-point number being a product as positive (value “0”), and when the both positive-negative signs are different, it outputs the positive-negative sign sg0 of the floating-point number being the product as negative (value “1”). A register 919 holds the positive-negative sign sg0 and outputs the positive-negative sign sg0 as a positive-negative sign sg of the floating-point number being the product.
An adding circuit 902 adds the exponent part exp1 of the floating-point number being the multiplicand and the exponent part exp2 of the floating-point number being the multiplier to output a resultant value exp0 (=exp1+exp2).
A multiplicand reading zero count circuit 903 counts, as the multiplicand reading zero count value LZC1, the number of zeros consecutive in higher places of the mantissa part sf1 of the floating-point number being the multiplicand. A multiplier reading zero count circuit 904 counts, as the multiplier reading zero count value LZC2, the number of zeros consecutive in higher places of the mantissa part sf2 of the floating-point number being the multiplier.
A subtracting circuit 906 is a shift amount arithmetic circuit and it calculates “15”−LZC2 to output the shift amount LSA. Concretely, the subtracting circuit 906 subtracts the multiplier reading zero count value LZC2 and 1 from a digit number m of fixed precision of the mantissa parts sf1 and sf2 to calculate the shift amount LSA as in the following expression. Here, m is, for example, 16.
A subtracting circuit 908 subtracts the multiplicand reading zero count value LZC1 from the shift amount LSA to output LSA−LZC1 and also outputs a carry-out co. The carry-out co is “1” when LSA−LZC1 is zero or more, and is “0” when LSA−LZC1 is a negative value.
An adding circuit 909 adds the output value “LSA−LZC1” of the subtracting circuit 908 and the value exp0 to output exp0+LSA−LZC1. A selector 910 selects and outputs the value exp0 when the carry-out co is “1”, and selects and outputs the value exp0+LSA−LZC1 when the carry-out co is “0” (for example, the case of
An incrementing circuit 911 increments the output value exp of a register 920 to output the value exp+1. A selector 912 selects and outputs the output value of the selector 910 at the time of the first multiplication for an intermediate product, and selects and outputs the output value of the incrementing circuit 911 at the time of the multiplication for the intermediate product from the second time onward. The value of the register 920 is updated to the output value of the selector 912 according to a correction signal ext or the like output by a control circuit 918, and is output as the exponent part exp of the floating-point number being the product.
An incrementing circuit 913 increments the shift amount LSA to output the digit number DC of the mantissa part sf2 of the multiplier as in the following expression.
As described above, the subtracting circuit 906 and the incrementing circuit 913 are digit number arithmetic circuits, and subtract the multiplier reading zero count value LZC2 from the digit number m of fixed precision of the mantissa part to calculate the digit number DC of the mantissa part of the multiplier.
A decrementing circuit 914 decrements an output value DC0 of a register 921 to output the value DC0−1. A selector 925 selects and outputs the digit number DC of the mantissa part sf2 of the multiplier at the time of the first multiplication for the intermediate product, and selects and outputs the output value of the decrementing circuit 914 at the time of the multiplication for the intermediate product from the second time onward. The value of the register 921 is updated to the output value of the selector 925 to be output as the value DC0 under a later-described condition.
A selector 907 selects and outputs the shift amount LSA when the carry-out co is “1”, and selects and outputs the multiplicand reading zero count value LZC1 when the carry-out co is “0” (for example, the case of
A left-shifting circuit 905 left-shifts the mantissa part sf1 of the multiplicand by the output value of the selector 907 to output a mantissa part sft1 of the multiplicand.
A multiplication loop circuit (multiplying circuit) 915 receives an intermediate product r output by an r register 922, the mantissa part sft1 of the multiplicand, the mantissa part sf2 of the multiplier, and the correction signal ext to output an intermediate product A1 and the least significant digit A2 on a digit-by-digit basis of the mantissa part sf2 of the multiplier.
In
In
The least significant digit A2 of the multiplication loop circuit 915 is input to a g register 923. The g register 923 stores the least significant digit g and outputs the least significant digit g to the rounding circuit 917 and a logical sum (OR) circuit 916.
The logical sum circuit 916 outputs a bit logical sum value of the least significant digit (four bits) g. That is, the logical sum circuit 916 outputs “0” when the least significant digit g is “0”, and outputs “1” when the least significant digit g is any one of “1” to “9”. The output value of the logical sum circuit 916 is input to an s register 924. The s register 924 stores a sticky bit s for rounding and outputs the sticky bit s to the rounding circuit 917.
An integer part of the mantissa part of the intermediate product is stored in the r register 922. A digit in the tenths place of the mantissa part of the intermediate product is stored in the g register 923. The sticky bit in the hundredths place of the mantissa part of the intermediate product is stored in the s register 924.
First, a case where the rounding mode is “0” will be described. In this rounding mode, the rounding circuit 917 performs rounding called bankers' rounding. When the least significant bit of the intermediate product r of the r register 922 is “1” (when the intermediate product is an odd number), and when the digit g in the tenths place of the g register 923 is “5” and the sticky bit s of the s register 924 is “0”, 1 is added to the intermediate product r relevant to the m-th least significant digit, which product is stored in the r register 922, and the resultant is output as the mantissa part sf of the product. For example, “3.5” becomes “4” by the rounding. Further, when the digit g in the tenths place of the g register 923 is “5” and the sticky bit s of the s register 924 is “1”, the rounding circuit 917 adds 1 to the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, and outputs the resultant as the mantissa part sf of the product. For example, “2.51” becomes “3” by the rounding. Further, when the digit g in the tenths place of the g register 923 is any one of “6” to “9”, 1 is added to the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, and the resultant is output as the mantissa part sf of the product. For example, “2.6” becomes “3” by the rounding.
Next, a case where the rounding mode is “1” will be described. In this rounding mode, the rounding circuit 917 performs rounding-down. The rounding circuit 917 outputs the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, as it is as the mantissa part sf.
Next, a case where the rounding mode is “2” will be described. In this rounding mode, the rounding circuit 917 performs the rounding in a +∞ direction. When the positive-negative sign sg is “0” and the digit g in the tenths place of the g register 923 is any one of “1” to “9”, the rounding circuit 917 adds 1 to the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, and outputs the resultant as the mantissa part sf of the product. Further, when the positive-negative sign sg is “0” and the sticky bit s of the s register 924 is “1”, the rounding circuit 917 adds 1 to the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, and outputs the resultant as the mantissa part sf of the product.
Next, a case where the rounding mode is “3” will be described. In this rounding mode, the rounding circuit 917 performs the rounding in a −∞ direction. When the positive-negative sign sg is “1” and the digit g in the tenths place of the g register 923 is any one of “1” to “9”, the rounding circuit 917 adds 1 to the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, and outputs the resultant as the mantissa part sf of the product. Further, when the positive-negative sign sg is “1” and the sticky bit s of the s register 924 is “1”, the rounding circuit 917 adds 1 to the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, and outputs the resultant as the mantissa part sf of the product.
Next, a case where the rounding mode is “4” will be described. In this rounding mode, the rounding circuit 917 performs rounding-off. When the digit g in the tenths place of the g register 923 is any one of “5” to “9”, the rounding circuit 917 adds 1 to the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, and outputs the resultant as the mantissa part sf of the product.
Incidentally, when the rounding is not necessary, the update of the g register 923 and the s register 924 may be skipped, and the rounding circuit 917 may output the intermediate product relevant to the m-th least significant digit, which product is stored in the r register 922, as the mantissa part sf without performing the rounding.
As a result of the above-described processing, the multiplying device outputs the product being the floating-point number including the positive-negative sign sg, the exponent part ext, and the mantissa part sf.
In the cases of
Further, in the case of
Further, in the case of
Further, when the number of times the multiplication loop circuit 915 outputs the intermediate product A1 becomes the digit number DC of the mantissa part sf2 of the multiplier and the digit number of the intermediate product A1 output by the multiplication loop circuit 915 exceeds the digit number m of the fixed precision of the product, the control circuit 918 outputs the value resulting from the right-shift of the intermediate product A1 output by the multiplication loop circuit 915 by one digit, as the mantissa part sf of the floating-point number being the product, and outputs the value to which the value output by the adding circuit 909 is incremented, as the exponent part sf of the floating-point part sf of the floating-point number being the product.
Further, when the number of times the multiplication loop circuit 915 outputs the intermediate product A1 becomes the digit number DC of the mantissa part sf2 of the multiplier and the digit number of the intermediate product output by the multiplication loop circuit 915 exceeds the digit number m of the fixed precision of the product, the rounding circuit 917 rounds the intermediate product output by the multiplication loop circuit 915 and outputs the rounded intermediate product as the mantissa part sf of the floating-point number being the product.
According to this embodiment, it is possible to multiply denormalized fixed-precision floating-point numbers. Further, a highly precise product is obtained without any digit cancelation as occurring in
This embodiment is a fixed-latency multiplying device whose input and output format is a 64-bit decimal floating-point format of IEEE754-2008. The register 1303 holds a count value LC. The decrementing circuit 1302 decrements the count value LC of the register 1303 and outputs LC−1. The digit number m (for example, “16”) of the mantissa parts sf1 and sf2 is input to the selector 1301. The digit number “16” is a count value of fixed latency. The selector 1301 selects and outputs the initial value “16” at the time of the first multiplication for the intermediate product, and selects and outputs the output value of the decrementing circuit 1302 at the time of the multiplication for the intermediate product from the second time onward. The register 1303 holds the output value of the selector 1301. The count value LC of the register 1303 is output to the control circuit 918. The control circuit 918 receives the output value DC0 of the register 921, the most significant digit of the r register 922, and the count value LC of the register 1303 and outputs the correction signal ext and a register update stop signal stp.
As described above, after the count value LC (initial value is “16”) of the fixed latency is counted, the control circuit 918 outputs the positive-negative sign sg, the mantissa part sf, and the exponent part exp of the floating-point number being the product. In the multiplying device of the first embodiment, the time from the input of the multiplicand and the multiplier to the output of the product is variable latency which is variable according to the multiplicand and the multiplier. On the other hand, in the multiplying device of this embodiment, latency is fixed latency, that is, the time from the input of the multiplicand and the multiplier to the output of the product is fixed irrespective of the multiplicand and the multiplier. This facilitates processing of circuits on subsequent stages of the multiplying device.
In the first and second embodiments, the case of a decimal number is described as an example, but it should be noted that the decimal number is not restrictive.
The above-described embodiments only illustrate concrete examples for carrying out the present invention, and the technical scope of the present invention should not be construed in a limited manner by these embodiments. That is, the present invention can be embodied in various forms without departing from its technical idea or its main features.
It is possible to multiply floating-point numbers with a small resource amount and delay time.
All examples and conditional language provided herein are intended for the pedagogical purposes of aiding the reader in understanding the invention and the concepts contributed by the inventor to further the art, and are not to be construed as limitations to such specifically recited examples and conditions, nor does the organization of such examples in the specification relate to a showing of the superiority and inferiority of the invention. Although one or more embodiments of the present invention have been described in detail, it should be understood that the various changes, substitutions, and alterations could be made hereto without departing from the spirit and scope of the invention.
Number | Date | Country | Kind |
---|---|---|---|
2012-183419 | Aug 2012 | JP | national |