Floating point multiply-accumulate circuit and method and electronic equipment
By introducing a transmission circuit into the floating point multiplication and accumulation circuit, the sign bits, order codes and mantissa of the multiplication operation result are transmitted in advance, and the problem of long multiplication and accumulation operation time in the prior art is solved and the operation efficiency is improved.
Patent Information
- Application Number
- CN202411040325.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-11-29
AI Technical Summary
In the prior art, the multiplier and adder are connected in series to cause the multiplication and accumulation calculation time to be longer and the efficiency is poor.
A floating point multiplication and accumulation circuit is designed. Through the transmission circuit, the sign bits, order codes and mantissa of the multiplication operation result are transmitted to the adder in advance, reducing the wait time of the adder, and directly decomposing the operands to be accumulated in the adder. Avoid decomposition of product results and save operation time.
It effectively reduces the multiplication and accumulation calculation time and improves the multiplication and accumulation calculation efficiency.
Smart Images

Figure CN119045774A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a floating-point multiplication-accumulation circuit, method and electronic equipment. Background Art
[0002] A floating-point multiply-accumulator is a hardware circuit used to perform floating-point multiply-accumulate (FMA) operations. FMA operations can perform multiplication and addition operations at the same time and are often used in high-performance computing, graphics processing, neural networks, and other fields. FMA operations can greatly improve computing speed and power efficiency, so floating-point multiply-accumulators are an extremely important component of modern computer architectures.
[0003] In some exemplary techniques, a multiplier and an adder are combined to implement the multiplication and accumulation function. First, the multiplier receives two floating point numbers as input and outputs their product. Then, the adder adds each obtained product to the value in the accumulator until the operation is completed.
[0004] In the prior art, the multiplier and the adder are connected in series, and the adder needs to wait for the multiplier to complete the multiplication result before transmitting the product result to the adder. The multiplication and accumulation operation time is long and the multiplication and accumulation operation efficiency is poor. Summary of the invention
[0005] The present invention provides a floating-point multiplication-accumulation circuit, method and electronic device, which are used to solve the defects of long multiplication-accumulation operation time and poor multiplication-accumulation operation efficiency in the prior art, and achieve the technical effect of saving multiplication-accumulation operation time and improving multiplication-accumulation operation efficiency.
[0006] The present invention provides a floating-point multiplication-accumulation circuit, comprising: a floating-point multiplier, a floating-point adder and a transmission circuit; the floating-point multiplier is connected to the transmission circuit, the floating-point multiplier receives a first operand and a second operand, the floating-point multiplier is used to perform a multiplication operation on the first operand and the second operand, obtain a first sign bit, a first exponent and a first mantissa corresponding to a first product result of the first operand and the second operand, and output the first sign bit, the first exponent and the first mantissa to the transmission circuit; the transmission circuit is connected to the floating-point multiplier, the transmission circuit is used to transmit the first sign bit, the first exponent and the first mantissa to the floating-point adder; the floating-point adder obtains an operand to be accumulated, the floating-point adder is used to decompose the operand to be accumulated into a second sign bit, a second exponent and a second mantissa, and calculate a multiplication-accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent and the second mantissa.
[0007] According to a floating-point multiplication-accumulation circuit provided by the present invention, the floating-point multiplier includes: a first processing module and a first operation module; the first processing module is connected to the first operation module, the first processing module receives the first operand and the second operand, the first processing module is used to pre-process the first operand and the second operand to obtain the first sign bit, the third mantissa corresponding to the first operand, the fourth mantissa corresponding to the second operand, and the first intermediate order code corresponding to the first product result; the first processing module is also used to transmit the third mantissa, the fourth mantissa, the first intermediate order code and the first sign bit to the first operation module; the first operation module is connected to the transmission circuit, the first operation module is used to perform multiplication operation on the third mantissa and the fourth mantissa to obtain a first intermediate mantissa, and perform rounding operation on the first intermediate order code and the first intermediate mantissa to obtain the first order code and the first mantissa; the first operation module is also used to output the first sign bit, the first order code and the first mantissa to the transmission circuit.
[0008] According to a floating-point multiplication-accumulation circuit provided by the present invention, the first processing module includes: a decomposition unit, an XOR unit and an exponent processing unit; the decomposition unit is connected to the first operation module, the decomposition unit receives the first operand and the second operand, and the decomposition unit is used to decompose the first operand and the second operand respectively to obtain a third sign bit, a third exponent and the third mantissa corresponding to the first operand, and a fourth sign bit, a fourth exponent and the fourth mantissa corresponding to the second operand; the decomposition unit is also used to transmit the third mantissa and the fourth mantissa to the first operation module; the XOR unit is connected to the decomposition unit and the first operation module, the XOR unit is used to perform an XOR operation on the third sign bit and the fourth sign bit to obtain the first sign bit, and output the first sign bit to the first operation module; the exponent processing unit is connected to the decomposition unit and the first operation module, the exponent processing unit is used to calculate the sum of the third exponent and the fourth exponent to obtain the first intermediate exponent, and output the first intermediate exponent to the first operation module.
[0009] According to a floating-point multiplication-accumulation circuit provided by the present invention, the first operation module includes: a partial product generation unit, a partial product addition unit, a first rounding unit and a transmission unit; the partial product generation unit is connected to the first processing module, and the partial product generation module is used to perform bit-by-bit multiplication calculation on the third mantissa and the fourth mantissa to obtain multiple partial products; the number of the multiple partial products is consistent with the number of bits of the third mantissa and the fourth mantissa; the partial product addition unit is connected to the partial product generation unit, and the partial product addition unit is used to calculate the sum of the multiple partial products to obtain a first intermediate mantissa; the first rounding unit is connected to the first processing module and the partial product addition unit, and the first rounding unit is used to round the first intermediate order code and the first intermediate mantissa to obtain the first order code and the first mantissa; the transmission unit is connected to the first processing unit, the first rounding unit and the transmission circuit, and the transmission unit is used to obtain the first sign bit, the first order code and the first mantissa, and output the first sign bit, the first order code and the first mantissa to the transmission circuit.
[0010] According to a floating-point multiplication-accumulation circuit provided by the present invention, the floating-point multiplier also includes: a first result processing module; the first result processing module is connected to the first operation module, and the first result processing module is used to splice the first sign bit, the first exponent and the first mantissa to obtain the first product result.
[0011] According to a floating-point multiplication and accumulation circuit provided by the present invention, the floating-point adder includes: a second processing module, a mantissa processing module, a second operation module, a second result processing module and an accumulator; the accumulator is connected to the second result processing module and the second processing module, and is used to obtain the operand to be accumulated, and transmit the operand to be accumulated to the second processing module; the second processing module is connected to the transmission circuit, and the second processing module is used to decompose the operand to be accumulated into the second sign bit, the second exponent and the second mantissa; the second processing module is also used to perform an XOR operation on the first sign bit and the second sign bit to obtain the fifth sign bit; the second processing module is also used to calculate the offset between the first exponent and the second exponent, and align the first exponent and the second exponent based on the offset to obtain the aligned exponent; the mantissa processing module is connected to the second processing module, and the mantissa processing module is used to obtain the first mantissa, the second mantissa, the aligned exponent and the fifth sign bit, and aligning the first mantissa and the second mantissa to obtain the fifth mantissa and the sixth mantissa; wherein the mantissa processing includes: splicing the protection bit, the rounding bit and the sticky bit for the first mantissa and the second mantissa respectively; shifting the mantissa corresponding to the smaller exponent of the first exponent and the second exponent to the right by the number of bits corresponding to the offset; the second operation module is connected to the mantissa processing module, and the second operation module is used to obtain the fifth mantissa, the sixth mantissa, the aligned exponent and the fifth sign bit, and perform addition and subtraction operations on the fifth mantissa and the sixth mantissa to obtain the seventh mantissa; the second result processing module is connected to the second operation module, and the second result processing module is used to obtain the seventh mantissa, the aligned exponent and the fifth sign bit, and splicing the seventh mantissa, the aligned exponent and the fifth sign bit to obtain the multiplication and accumulation result.
[0012] According to a floating-point multiplication-accumulation circuit provided by the present invention, the second processing module also includes a selector; the selector is connected to the transmission circuit, and the selector is used to determine whether the current operation is a multiplication-accumulation operation. If it is a multiplication-accumulation operation, the first sign bit, the first exponent and the first mantissa are selected.
[0013] According to a floating-point multiplication-accumulation circuit provided by the present invention, the floating-point multiplication-accumulation circuit further includes: at least one register.
[0014] The present invention also provides a floating-point multiplication and accumulation method, which is applied to a floating-point multiplication and accumulation circuit, wherein the floating-point multiplication and accumulation circuit comprises a floating-point multiplier, a floating-point adder and a transmission circuit; the floating-point multiplication and accumulation method comprises: the floating-point multiplier receives a first operand and a second operand; the floating-point multiplier performs a multiplication operation on the first operand and the second operand to obtain a first sign bit, a first exponent and a first mantissa corresponding to a first product result of the first operand and the second operand, and outputs the first sign bit, the first exponent and the first mantissa to the transmission circuit; the transmission circuit transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder; the floating-point adder obtains an operand to be accumulated; the floating-point adder decomposes the operand to be accumulated into a second sign bit, a second exponent and a second mantissa, and calculates a multiplication and accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent and the second mantissa.
[0015] The present invention also provides an electronic device, comprising any one of the floating-point multiplication-accumulation circuits described above.
[0016] In the floating-point multiplication and accumulation circuit, method and electronic device provided by the present invention, a floating-point multiplier performs a multiplication operation based on receiving a first operand and a second operand, obtains a first sign bit, a first exponent and a first mantissa corresponding to a first product result of the first operand and the second operand, and outputs the first sign bit, the first exponent and the first mantissa to a transmission circuit; the transmission circuit transmits the first sign bit, the first exponent and the first mantissa to a floating-point adder; the floating-point adder obtains an operand to be accumulated, the floating-point adder decomposes the operand to be accumulated into a second sign bit, a second exponent and a second mantissa, and calculates a multiplication and accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent and the second mantissa. According to the scheme of the present invention, on the one hand, before obtaining the first product result of the first operand and the second operand, the floating-point multiplier transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder through the transmission circuit, and the floating-point adder can calculate the multiplication-accumulation result without waiting for the floating-point multiplier to calculate the first product result, thereby reducing the waiting time of the floating-point adder; on the other hand, the transmission circuit directly transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder, and the floating-point adder only needs to decompose the operand to be accumulated, and the floating-point adder does not need to decompose the first product result, thereby saving the operation time of the floating-point adder. Therefore, according to the scheme of the present invention, the operation time of the multiplication-accumulation is saved, and the operation efficiency of the multiplication-accumulation is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 This is one of the structural schematic diagrams of the floating-point multiplication-accumulation circuit provided by the present invention.
[0019] Figure 2 This is the second structural schematic diagram of the floating-point multiplication and accumulation circuit provided by the present invention.
[0020] Figure 3 This is the third structural schematic diagram of the floating-point multiplication and accumulation circuit provided by the present invention.
[0021] Figure 4 This is the fourth structural schematic diagram of the floating-point multiplication and accumulation circuit provided by the present invention.
[0022] Figure 5 This is the fifth structural schematic diagram of the floating-point multiplication and accumulation circuit provided by the present invention.
[0023] Figure 6 This is the sixth structural schematic diagram of the floating-point multiplication and accumulation circuit provided by the present invention.
[0024] Figure 7 It is a flow chart of the floating-point multiplication and accumulation method provided by the present invention.
[0025] Figure 8 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0027] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.
[0028] The terms "first", "second", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise indicated. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, for example, they can be implemented in an order other than those given in the diagrams or descriptions of the embodiments of this application.
[0029] In addition, the terms "including" and "having" and any variations thereof are intended to cover but not exclude inclusion, for example, a product or device comprising a series of components is not necessarily limited to those components explicitly listed, but may include other components not explicitly listed or inherent to these products or devices. The term "module" as used in this application refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or combination of hardware and / or software code that can perform the functions associated with the element.
[0030] The term "Multiply Accumulate (MAC)" used in the embodiments of the present application refers to a special operation in a digital signal processor or some microprocessors. The hardware circuit unit that implements this operation is called a "multiply accumulator". This operation is to add the product of the multiplication and the value of the accumulator a, and then store them in the accumulator. The multiply-accumulate operation can be expressed as . Where b and c are the multiplier and multiplicand. In practical applications, many complex operations (such as convolution, dot product, matrix, digital filter, polynomial evaluation, etc.) can be decomposed into multiple multiplication and accumulation operations, thereby simplifying complex operations and improving the efficiency of operations.
[0031] A floating-point multiply-accumulate (FMA) is a hardware circuit used to perform floating-point multiply-accumulate (FMA) operations. FMA operations can perform multiplication and addition operations at the same time and are often used in high-performance computing, graphics processing, neural networks, and other fields. FMA operations can greatly improve computing speed and power efficiency, so floating-point multiply-accumulates are an extremely important component of modern computer architectures.
[0032] The importance of floating-point multipliers and accumulators lies in their ability to quickly process a large number of complex mathematical operations, such as scientific computing, simulation, and optimization problems commonly found in geophysics, astronomy, computational fluid dynamics, finance, and other fields. In addition, floating-point multipliers and accumulators are also widely used in core operations such as matrix multiplication and convolution operations in deep learning neural networks to accelerate model training and prediction.
[0033] In some exemplary techniques, a multiplier and an adder are combined to implement the multiplication and accumulation function. First, the multiplier receives two floating point numbers as input and outputs their product. Then, the adder adds each obtained product to the value in the accumulator until the operation is completed.
[0034] In the prior art, the multiplier and the adder are connected in series, and the adder needs to wait for the multiplier to complete the multiplication result before transmitting the product result to the adder. The multiplication and accumulation operation time is long and the multiplication and accumulation operation efficiency is poor.
[0035] Based on the above technical problems, the technical concept of the present invention is: how to construct a floating-point multiplication-accumulation circuit that can reduce the waiting time of the adder, thereby reducing the multiplication-accumulation operation time, and further improving the multiplication-accumulation operation efficiency.
[0036] The following specific embodiments are used to describe in detail the technical solution of the present application and how the technical solution of the present application solves the above technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. Figure 1-Figure 6 The floating-point multiply-accumulate circuit of the present invention is described.
[0037] Figure 1 FIG. 1 is one of the structural diagrams of the floating-point multiplication-accumulation circuit provided by the present invention. Figure 1 As shown, the floating-point multiplication-accumulation circuit includes: a floating-point multiplier 10 , a floating-point adder 20 and a transmission circuit 30 .
[0038] Among them, the floating-point multiplier 10 is connected to the transmission circuit 30, and the floating-point multiplier 10 receives the first operand op1 and the second operand op2. The floating-point multiplier 10 is used to perform a multiplication operation on the first operand op1 and the second operand op2, and obtain the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum corresponding to the first product result Mul result of the first operand op1 and the second operand op2, and output the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0039] The transmission circuit 30 is connected to the floating-point multiplier 20 , and is used to transmit the first sign bit sign1 , the first exponent mul_exp and the first mantissa mul_sum to the floating-point adder 20 .
[0040] Among them, the floating-point adder 20 obtains the operand to be accumulated op3, and the floating-point adder 20 is used to decompose the operand to be accumulated op3 into the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add, and calculate the multiplication and accumulation result add_result based on the first sign bit sign1, the first order code mul_exp, the first mantissa mul_sum, the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add.
[0041] Specifically, the first operand op1 and the second operand op2 refer to the multiplier and the multiplicand corresponding to the floating-point multiplier 10. As an example, the first operand op1 and the second operand op2 may be single-precision floating-point numbers.
[0042] In practical applications, after the floating-point multiplier 10 receives the first operand op1 and the second operand op2, first, the first operand op1 and the second operand op2 are decomposed according to the sign bit, the exponent and the mantissa, respectively, to obtain the third sign bit op1_sign_mul, the third exponent op1_exp_mul and the third mantissa op1_fract_mul corresponding to the first operand op1, and the fourth sign bit op2_sign_mul, the fourth exponent op2_exp_mul and the fourth mantissa op2_fract_mul corresponding to the second operand op2.
[0043] Further, the floating-point multiplier 10 adds the third order code op1_exp_mul and the fourth order code op2_exp_mul to obtain the first intermediate order code out_exp_q. The floating-point multiplier 10 performs an XOR operation on the third sign bit op1_sign_mul and the fourth sign bit op2_sign_mul to obtain the first sign bit sign1.
[0044] Further, the floating-point multiplier 10 performs bit-by-bit multiplication calculation on the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to obtain a plurality of partial products; the floating-point multiplier 10 calculates the sum of the plurality of partial products to obtain a first intermediate mantissa sum.
[0045] Furthermore, the floating-point multiplier 10 rounds the first intermediate exponent out_exp_q and the first intermediate mantissa sum to obtain the first exponent mul_exp and the first mantissa mul_sum. Furthermore, the floating-point multiplier 10 transmits the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0046] Afterwards, the floating-point multiplier 10 may perform concatenation processing on the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum to obtain a first product result Mul result.
[0047] Correspondingly, after receiving the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum, the transmission circuit 30 transmits the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20 .
[0048] In this embodiment, the transmission circuit 30 can be constructed based on the signal bypass technology. Through the transmission circuit 30, the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum can be transmitted to the floating-point adder 20 without waiting for the floating-point multiplier 10 to calculate the first product result Mul result, thereby improving the operational efficiency of the floating-point multiplication and accumulation.
[0049] Correspondingly, the floating point adder 20 receives the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum transmitted by the transmission circuit 30, and obtains the operand op3 to be accumulated. It can be understood that the operand op3 to be accumulated can be the multiplication and accumulation result add_result calculated by the floating point adder 20 last time.
[0050] Specifically, the floating-point adder 20 decomposes the operand op3 to be accumulated according to the sign bit, the exponent and the mantissa to obtain the second sign bit op3_sign_add, the second exponent op3_exp_add and the second mantissa op3_fract_add. It can be understood that the floating-point adder 20 only needs to decompose the operand op3 to be accumulated, saving the time of decomposing the multiplication and accumulation result add_result.
[0051] Further, the floating point adder 20 performs an XOR operation on the first sign bit sign1 and the second sign bit op3_sign_add to obtain the fifth sign bit sign2. Further, the floating point adder 20 calculates the offset between the first order code mul_exp and the second order code op3_exp_add, and aligns the first order code mul_exp and the second order code op3_exp_add based on the offset to obtain the aligned order code exp.
[0052] Furthermore, the floating-point adder 20 splices the guard bit (Guard), the rounding bit (Round) and the paste bit (paste bit) for the first mantissa mul_sum and the second mantissa op3_fract_add respectively; the mantissa corresponding to the smaller one of the first order code mul_exp and the second order code op3_exp_add is moved rightward by the number of bits corresponding to the offset, and the first mantissa mul_sum and the second mantissa op3_fract_add are aligned to obtain the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add.
[0053] Further, the floating point adder 20 performs addition and subtraction operations on the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add to obtain the seventh mantissa result_raw. Further, the floating point adder 20 concatenates the seventh mantissa result_raw, the aligned exponent exp and the fifth sign bit sign2 to obtain the multiplication and accumulation result add_result.
[0054] Combined with the above description, on the one hand, before the floating-point multiplier 10 obtains the first product result Mul result of the first operand op1 and the second operand op2, the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum are transmitted to the floating-point adder 20 through the transmission circuit 30, and the floating-point adder 20 can calculate the multiplication and accumulation result add_result without waiting for the floating-point multiplier 10 to calculate the first product result Mul result, thereby reducing the waiting time of the floating-point adder 10; on the other hand, the transmission circuit 30 directly transmits the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20, and the floating-point adder 20 only needs to decompose the operand to be accumulated op3, and the floating-point adder 20 does not need to decompose the first product result mul_sum, thereby saving the operation time of the floating-point adder 20. Therefore, the scheme of this embodiment saves the operation time of multiplication and accumulation and improves the operation efficiency of multiplication and accumulation.
[0055] As an example, for the specific structure of the floating-point multiplier 10, in a possible implementation, Figure 2 FIG. 2 is a second structural diagram of a floating-point multiplication-accumulation circuit provided by the present invention. Figure 2 As shown, the floating-point multiplier 10 comprises: a first processing module 101 and a first operation module 102 .
[0056] The first processing module 101 is connected to the first operation module 102. The first processing module 101 receives the first operand op1 and the second operand op2. The first processing module 101 is used to pre-process the first operand op1 and the second operand op2 to obtain a first sign bit sign1, a third mantissa op1_fract_mul corresponding to the first operand op1, a fourth mantissa op2_fract_mul corresponding to the second operand op2, and a first intermediate order out_exp_q corresponding to the first product result Mul result; the first processing module 101 is also used to transmit the third mantissa op1_fract_mul, the fourth mantissa op2_fract_mul, the first intermediate order out_exp_q, and the first sign bit sign1 to the first operation module 102.
[0057] Among them, the first operation module 102 is connected to the transmission circuit 30, and the first operation module 102 is used to perform a multiplication operation on the third mantissa op1_fract_mul and the fourth mantissa op2_fract_mul to obtain a first intermediate mantissa sum, and to round the first intermediate exponent out_exp_q and the first intermediate mantissa sum to obtain a first exponent mul_exp and a first mantissa mul_sum; the first operation module 102 is also used to output a first sign bit sign1, a first exponent mul_exp and a first mantissa mul_sum to the transmission circuit 30.
[0058] As an example, the first operand op1 and the second operand op2 may be single-precision floating-point numbers, both of which have a bit width of [31:0]. Specifically, after the first processing module 101 receives the first operand op1 and the second operand op2, the first processing module 101 decomposes the first operand op1 and the second operand op2 according to the sign bit, the exponent, and the mantissa; op1
[31] and op
[31] are the sign bits of the first operand op1 and the second operand op2, respectively; op1[30:23] and op2[30:23] are the exponent parts of the first operand op1 and the second operand op2, respectively; op1[22:0] and op2[22:0] are the mantissa parts of the first operand op1 and the second operand op2, respectively. op1
[31] and op
[31] are used as the third sign bit op1_sign_mul and the fourth sign bit op2_sign_mul, respectively. op1[30:23] and op2[30:23] are used as the third order code op1_exp_mul and the fourth order code op2_exp_mul respectively. op1[22:0] and op2[22:0] are both padded with an implicit bit to obtain the third mantissa op1_fract_mul and the fourth mantissa op2_fract_mul.
[0059] Further, the first processing module 101 adds the third order code op1_exp_mul and the fourth order code op2_exp_mul to obtain the first intermediate order code out_exp_q. The first processing module 101 performs an XOR operation on the third sign bit op1_sign_mul and the fourth sign bit op2_sign_mul to obtain the first sign bit sign1. Further, the first processing module 101 transmits the third mantissa op1_fract_mul, the fourth mantissa op2_fract_mul, the first intermediate order code out_exp_q and the first sign bit sign1 to the first operation module 102.
[0060] Correspondingly, the first operation module 102 performs bit-by-bit multiplication on the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to obtain a plurality of partial products; the first operation module 102 calculates the sum of the plurality of partial products to obtain a first intermediate mantissa sum.
[0061] Furthermore, the first operation module 102 rounds the first intermediate order out_exp_q and the first intermediate mantissa sum to obtain the first order mul_exp and the first mantissa mul_sum. Furthermore, the first operation module 102 transmits the first sign bit sign1, the first order mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0062] Correspondingly, after receiving the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum, the transmission circuit 30 transmits the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20 .
[0063] In this embodiment, the transmission circuit 30 can transmit the first product result Mul result to the floating-point adder 20 without waiting for the floating-point multiplier 10 to calculate the first product result, thereby improving the operation efficiency of the floating-point multiplication and accumulation.
[0064] Correspondingly, the floating-point adder 20 obtains the operand to be accumulated op3, the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum. The floating-point adder 20 decomposes the operand to be accumulated op3 into the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add, and calculates the multiplication and accumulation result add_result based on the first sign bit sign1, the first order code mul_exp, the first mantissa mul_sum, the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add.
[0065] Specifically, for the specific structure of the first processing module 101, as an example, in one example, Figure 3 FIG. 3 is a schematic diagram of the structure of the floating-point multiplication-accumulation circuit provided by the present invention. Figure 3 As shown, the first processing module 101 includes: a decomposition unit 1011 , an XOR unit 1012 and an order processing unit 1013 .
[0066] The decomposition unit 1011 is connected to the first operation module 102, and the decomposition unit 1011 receives the first operand op1 and the second operand op2. The decomposition unit 1011 is used to decompose the first operand op1 and the second operand op2 respectively to obtain the third sign bit op1_sign_mul, the third order code op1_exp_mul and the third mantissa op1_fract_mul corresponding to the first operand op1, and the fourth sign bit op2_sign_mul, the fourth order code op2_exp_mul and the fourth mantissa op2_fract_mul corresponding to the second operand op2; the decomposition unit 1011 is also used to transmit the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to the first operation module 30.
[0067] The XOR unit 1012 is connected to the decomposition unit 1011 and the first operation module 102 , and is used to perform an XOR operation on the third sign bit op1_sign_mul and the fourth sign bit op2_sign_mul to obtain the first sign bit sign1 , and output the first sign bit sign1 to the first operation module 102 .
[0068] The order processing unit 1013 is connected to the decomposition unit 1011 and the first operation module 102 , and is used for calculating the sum of the third order op1_exp_mul and the fourth order op2_exp_mul to obtain the first intermediate order out_exp_q, and outputting the first intermediate order out_exp_q to the first operation module 102 .
[0069] As an example, the first operand op1 and the second operand op2 may be single-precision floating-point numbers, both of which have a bit width of [31:0]. Specifically, after the decomposition unit 1011 receives the first operand op1 and the second operand op2, the decomposition unit 1011 decomposes the first operand op1 and the second operand op2 according to the sign bit, the exponent, and the mantissa; op1
[31] and op
[31] are the sign bits of the first operand op1 and the second operand op2, respectively; op1[30:23] and op2[30:23] are the exponent parts of the first operand op1 and the second operand op2, respectively; op1[22:0] and op2[22:0] are the mantissa parts of the first operand op1 and the second operand op2, respectively. The decomposition unit 1011 uses op1
[31] and op
[31] as the third sign bit op1_sign_mul and the fourth sign bit op2_sign_mul, respectively. The decomposition unit 1011 uses op1[30:23] and op2[30:23] as the third order code op1_exp_mul and the fourth order code op2_exp_mul respectively. The decomposition unit 1011 fills op1[22:0] and op2[22:0] with an implicit bit to obtain the third mantissa op1_fract_mul and the fourth mantissa op2_fract_mul.
[0070] Further, the exponent processing unit 1013 adds the third exponent op1_exp_mul and the fourth exponent op2_exp_mul to obtain the first intermediate exponent out_exp_q. The XOR unit 1012 performs an XOR operation on the third sign bit op1_sign_mul and the fourth sign bit op2_sign_mul to obtain the first sign bit sign1. Further, the decomposition unit 1011 transmits the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to the first operation module 30. The XOR unit 1012 outputs the first sign bit sign1 to the first operation module 102. The exponent processing unit 1013 outputs the first intermediate exponent out_exp_q to the first operation module 102.
[0071] Correspondingly, the first operation module 102 performs bit-by-bit multiplication on the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to obtain a plurality of partial products; the first operation module 102 calculates the sum of the plurality of partial products to obtain a first intermediate mantissa sum.
[0072] Furthermore, the first operation module 102 rounds the first intermediate order out_exp_q and the first intermediate mantissa sum to obtain the first order mul_exp and the first mantissa mul_sum. Furthermore, the first operation module 102 transmits the first sign bit sign1, the first order mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0073] Correspondingly, after receiving the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum, the transmission circuit 30 transmits the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20 .
[0074] In this embodiment, the transmission circuit 30 can transmit the first product result Mul result to the floating-point adder 20 without waiting for the floating-point multiplier 10 to calculate the first product result, thereby improving the operation efficiency of the floating-point multiplication and accumulation.
[0075] Correspondingly, the floating-point adder 20 obtains the operand to be accumulated op3, the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum. The floating-point adder 20 decomposes the operand to be accumulated op3 into the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add, and calculates the multiplication and accumulation result add_result based on the first sign bit sign1, the first order code mul_exp, the first mantissa mul_sum, the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add.
[0076] Specifically, for the internal structure of the first operation module 102, as an example, in one example, Figure 4 FIG. 4 is a schematic diagram of the structure of the floating-point multiplication-accumulation circuit provided by the present invention. Figure 4 As shown, the first operation module 102 includes: a partial product generating unit 1021 , a partial product adding unit 1022 , a first rounding unit 1023 and a transmission unit 1024 .
[0077] The partial product generation unit 1021 is connected to the first processing module 101 and is used to perform bit-by-bit multiplication on the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to obtain multiple partial products; the number of the multiple partial products is consistent with the number of bits of op1_fract_mul and the fourth mantissa op2_exp_mul.
[0078] The partial product adding unit 1022 is connected to the partial product generating unit 1021, and the partial product adding unit 1022 is used to calculate the sum of multiple partial products to obtain the first intermediate mantissa sum.
[0079] The first rounding unit 1023 is connected to the first processing module 101 and the partial product adding unit 1022, and is used to round the first intermediate exponent out_exp_q and the first intermediate mantissa sum to obtain the first exponent mul_exp and the first mantissa mul_sum; The transmission unit 1024 is connected to the first processing module 101, the first rounding unit 1023 and the transmission circuit 30, and is used to obtain the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum, and output the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0080] In combination with the above description, the first processing module 101 receives the first operand op1 and the second operand op2, and the first processing module 101 pre-processes the first operand op1 and the second operand op2 to obtain the first sign bit sign1, the third mantissa op1_fract_mul corresponding to the first operand op1, the fourth mantissa op2_fract_mul corresponding to the second operand op2, and the first intermediate order out_exp_q corresponding to the first product result Mul result; the first processing module 101 transmits the third mantissa op1_fract_mul, the fourth mantissa op2_fract_mul, the first intermediate order out_exp_q, and the first sign bit sign1 to the first operation module 102.
[0081] Correspondingly, the partial product generating unit 1021 performs bit-by-bit multiplication calculation on the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to obtain a plurality of partial products. As an example, the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul are both 24 bits, and the number of the plurality of partial products is 24. Further, the partial product adding unit 1022 calculates the sum of the plurality of partial products to obtain a first intermediate mantissa sum. Specifically, the bit width of the first intermediate mantissa sum may be [47:0].
[0082] Furthermore, the first rounding unit 1023 rounds the first intermediate order out_exp_q and the first intermediate mantissa sum to obtain the first order mul_exp and the first mantissa mul_sum. Furthermore, the transmission unit 1024 transmits the first sign bit sign1, the first order mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0083] Correspondingly, after receiving the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum, the transmission circuit 30 transmits the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20 .
[0084] In this embodiment, the transmission circuit 30 can transmit the first product result Mul result to the floating-point adder 20 without waiting for the floating-point multiplier 10 to calculate the first product result, thereby improving the operation efficiency of the floating-point multiplication and accumulation.
[0085] Correspondingly, the floating-point adder 20 obtains the operand to be accumulated op3, the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum. The floating-point adder 20 decomposes the operand to be accumulated op3 into the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add, and calculates the multiplication and accumulation result add_result based on the first sign bit sign1, the first order code mul_exp, the first mantissa mul_sum, the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add.
[0086] In this embodiment, on the one hand, before obtaining the first multiplication result Mul result of the first operand op1 and the second operand op2, the first operation module 102 transmits the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20 through the transmission circuit 30, and the floating-point adder 20 can calculate the multiplication-accumulation result add_result without waiting for the floating-point multiplier 10 to calculate the first multiplication result Mul result, thereby reducing the waiting time of the floating-point adder 10; on the other hand, the transmission circuit 30 directly transmits the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20, and the floating-point adder 20 only needs to decompose the operand to be accumulated op3, and the floating-point adder 20 does not need to decompose the first multiplication result mul_sum, thereby saving the operation time of the floating-point adder 20. Therefore, the operation time of the multiplication-accumulation is saved, and the operation efficiency of the multiplication-accumulation is improved.
[0087] In addition, in a possible implementation, Figure 5 FIG. 5 is a structural diagram of a floating-point multiplication-accumulation circuit provided by the present invention. Figure 5 As shown, the floating-point multiplier 10 further includes: a first result processing module 103 .
[0088] The first result processing module 103 is connected to the first operation module 102, and is used for performing concatenation processing on the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum to obtain a first product result Mul result.
[0089] In practical applications, the first operation module 102 can simultaneously transmit the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the transmission circuit 30 and the first result processing module 103. The first result processing module 103 performs splicing processing on the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to obtain the first product result Mul result. The transmission circuit 30 transmits the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20, and the floating-point adder 20 can calculate the multiplication-accumulation result add_result without waiting for the floating-point multiplier 10 to calculate the first product result Mul result, thereby reducing the waiting time of the floating-point adder 10. This embodiment saves the operation time of multiplication-accumulation and improves the operation efficiency of multiplication-accumulation.
[0090] In addition, as for the internal structure of the floating-point adder 20, as an example, in a possible implementation, Figure 6 FIG. 6 is a sixth structural diagram of a floating-point multiplication-accumulation circuit provided by the present invention. Figure 6 As shown, the floating-point adder 20 includes: a second processing module 201 , a mantissa processing module 202 , a second operation module 203 , a second result processing module 204 and an accumulator 205 .
[0091] The accumulator 205 is connected to the second result processing module 204 and the second processing module 201 , and is used to obtain the operand op3 to be accumulated, and transmit the operand op3 to be accumulated to the second processing module 201 .
[0092] Among them, the second processing module 201 is connected to the transmission circuit 30, and the second processing module 201 is used to decompose the operand to be accumulated op3 into the second sign bit op3_sign_add, the second order code op3_exp_add and the second mantissa op3_fract_add; the second processing module 201 is also used to perform an XOR operation on the first sign bit sign1 and the second sign bit op3_sign_add to obtain the fifth sign bit sign2; the second processing module 201 is also used to calculate the offset between the first order code mul_exp and the second order code op3_exp_add, and align the first order code mul_exp and the second order code op3_exp_add based on the offset to obtain the aligned order code exp.
[0093] The mantissa processing module 202 is connected to the second processing module 201, and the mantissa processing module 201 is used to obtain the first mantissa mul_sum, the second mantissa op3_fract_add, the aligned exponent exp and the fifth sign bit sign2, and perform alignment processing on the first mantissa mul_sum and the second mantissa op3_fract_add to obtain the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add; wherein the mantissa processing includes: splicing the guard bit (Guard), the rounding bit (Round) and the pasting bit (paste bit) of the first mantissa mul_sum and the second mantissa op3_fract_add respectively; and moving the mantissa corresponding to the smaller exponent of the first exponent mul_exp and the second exponent op3_exp_add to the right by the number of bits corresponding to the offset.
[0094] The second operation module 203 is connected to the mantissa processing module 202, and is used to obtain the fifth mantissa mul_mant_add, the sixth mantissa op3_mant_add, the aligned exponent exp and the fifth sign bit sign2, and perform addition and subtraction operations on the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add to obtain the seventh mantissa result_raw.
[0095] Among them, the second result processing module 204 is connected to the second operation module 203, and the second result processing module 204 is used to obtain the seventh mantissa result_raw, the aligned exponent exp and the fifth sign bit sign2, and concatenate the seventh mantissa result_raw, the aligned exponent exp and the fifth sign bit sign2 to obtain the multiplication and accumulation result add_result.
[0096] In combination with the above description, the floating-point multiplier 10 receives the first operand op1 and the second operand op2, performs a multiplication operation on the first operand op1 and the second operand op2, obtains the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum corresponding to the first product result Mul result of the first operand op1 and the second operand op2, and outputs the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the transmission circuit 30. The transmission circuit 30 transmits the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20.
[0097] In this embodiment, the transmission circuit 30 can transmit the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum to the floating-point adder 20 without waiting for the floating-point multiplier 10 to calculate the first product result Mul result, thereby improving the operational efficiency of the floating-point multiplication and accumulation.
[0098] Correspondingly, the second processing module 201 receives the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum transmitted by the transmission circuit 30, and obtains the operand to be accumulated op3 transmitted by the accumulator 205. It can be understood that the operand to be accumulated op3 can be the multiplication and accumulation result add_result calculated by the second result processing module 204 last time.
[0099] As an example, the operand op3 to be accumulated can be a floating point number, and the bit width of the operand op3 to be accumulated is [31:0]. Specifically, the second processing module 201 decomposes the operand op3 to be accumulated according to the sign bit, the exponent and the mantissa, op3
[31] is the sign bit of the operand op3 to be accumulated; op3[30:23] is the exponent part of the operand op3 to be accumulated; op3[22:0] is the mantissa part of the operand op3 to be accumulated. The second processing module 201 uses op3
[31] and op3[30:23] as the second sign bit op3_sign_add and the second exponent op3_exp_add respectively. The second processing module 201 fills op3[22:0] with an implicit bit to obtain the second mantissa op3_fract_add. It can be understood that the second processing module 201 only needs to decompose the operand op3 to be accumulated, which saves the time of decomposing the multiplication and accumulation result add_result.
[0100] Further, the second processing module 201 performs an XOR operation on the first sign bit sign1 and the second sign bit op3_sign_add to obtain the fifth sign bit sign2. Further, the second processing module 201 calculates the offset between the first order code mul_exp and the second order code op3_exp_add, and aligns the first order code mul_exp and the second order code op3_exp_add based on the offset to obtain the aligned order code exp. As an example, if the first order code mul_exp is larger than the second order code op3_exp_add, the second order code op3_exp_add needs to be increased by the offset so that the sum of the first order code mul_exp and the second order code op3_exp_add and the offset is equal to obtain the aligned order code exp.
[0101] Further, the mantissa processing module 202 splices the guard bit (Guard), the rounding bit (Round) and the sticking bit (sticking bit) for the first mantissa mul_sum and the second mantissa op3_fract_add, respectively, to avoid the loss of calculation accuracy caused by the number of bits shifted out when the mantissa is subsequently right-shifted. Further, the mantissa corresponding to the smaller order code of the first order code mul_exp and the second order code op3_exp_add is shifted right by the number of bits corresponding to the offset, and the first mantissa mul_sum and the second mantissa op3_fract_add are aligned to obtain the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add.
[0102] Further, the second operation module 203 performs addition and subtraction operations on the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add to obtain the seventh mantissa result_raw. Further, the second result processing module 204 concatenates the seventh mantissa result_raw, the aligned exponent exp and the fifth sign bit sign2 to obtain the multiplication and accumulation result add_result.
[0103] In this embodiment, on the one hand, before the floating-point multiplier 10 obtains the first product result Mul result of the first operand op1 and the second operand op2, the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum are transmitted to the floating-point adder 20 through the transmission circuit 30, and the floating-point adder 20 can calculate the multiplication and accumulation result add_result without waiting for the floating-point multiplier 10 to calculate the first product result Mul result, thereby reducing the waiting time of the floating-point adder 10; on the other hand, the transmission circuit 30 directly transmits the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20, and the floating-point adder 20 only needs to decompose the operand to be accumulated op3, and the floating-point adder 20 does not need to decompose the first product result mul_sum, thereby saving the operation time of the floating-point adder 20. Therefore, the scheme of this embodiment saves the operation time of multiplication and accumulation and improves the operation efficiency of multiplication and accumulation.
[0104] In practical applications, considering more application scenarios, the floating-point adder 20 can be applied to other scenarios besides the multiplication and accumulation scenario, for example, it can be applied to the sum of any two floating-point numbers. As an example, in a possible implementation, the second processing module 20 further includes a selector.
[0105] The selector is connected to the transmission circuit 30, and is used to determine whether the current operation is a multiplication-accumulation operation. If it is a multiplication-accumulation operation, the first sign bit, the first exponent and the first mantissa are selected.
[0106] For example, the selector may be a mux selector (Multiplexer). Specifically, the selector is connected to the transmission circuit 30, and can determine whether the current operation is a multiplication-accumulation operation. If the current operation is a multiplication-accumulation operation, the selector selects the first sign bit, the first exponent and the first mantissa, and the floating-point adder 20 performs multiplication-accumulation processing; otherwise, the selector selects other data, and the floating-point adder 20 performs a summation operation of floating-point numbers.
[0107] In addition, in a possible implementation manner, the floating-point multiplication-accumulation circuit further includes: at least one register.
[0108] In practical applications, inserting registers in a longer combinational logic circuit can reduce the delay of a single-stage combinational logic, thereby increasing the clock frequency and improving performance. As an example, multiple registers can be inserted in the floating-point multiplier 10 and the floating-point adder 20 to improve the performance of the floating-point multiplication and accumulation circuit. Figure 5 , a register may be inserted between the first processing module 101 and the first operation module 102, and between the first operation module 102 and the first result processing module 103. Figure 6 A register may be inserted between the second processing module 201 and the mantissa processing module 202 , between the mantissa processing module 202 and the second operation module 203 , and between the second operation module 203 and the second result processing module 204 .
[0109] In the floating-point multiplication and accumulation circuit provided in this embodiment, the floating-point multiplier performs a multiplication operation based on the received first operand and the second operand, obtains a first sign bit, a first exponent and a first mantissa corresponding to a first product result of the first operand and the second operand, and outputs the first sign bit, the first exponent and the first mantissa to the transmission circuit; the transmission circuit transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder; the floating-point adder obtains the operand to be accumulated, the floating-point adder decomposes the operand to be accumulated into a second sign bit, a second exponent and a second mantissa, and calculates the multiplication and accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent and the second mantissa. In the scheme of this embodiment, on the one hand, before the floating-point multiplier obtains the first product result of the first operand and the second operand, it transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder through the transmission circuit, and the floating-point adder can calculate the multiplication-accumulation result without waiting for the floating-point multiplier to calculate the first product result, thereby reducing the waiting time of the floating-point adder; on the other hand, the transmission circuit directly transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder, and the floating-point adder only needs to decompose the operand to be accumulated, and the floating-point adder does not need to decompose the first product result, thereby saving the operation time of the floating-point adder. Therefore, the scheme of this embodiment saves the operation time of multiplication-accumulation and improves the operation efficiency of multiplication-accumulation.
[0110] The floating-point multiplication-accumulation method provided by the present invention is described below. The floating-point multiplication-accumulation method described below and the floating-point multiplication-accumulation circuit described above can be referred to each other.
[0111] Figure 7 FIG. 1 is one of the flow charts of the floating-point multiplication and accumulation method provided by the present invention, such as Figure 7 As shown, the method includes the following: step 701 to step 707.
[0112] Step 701: A floating-point multiplier receives a first operand and a second operand.
[0113] Step 702: The floating-point multiplier performs a multiplication operation on the first operand and the second operand to obtain a first sign bit, a first exponent, and a first mantissa corresponding to a first product result of the first operand and the second operand.
[0114] Step 703: The floating-point multiplier outputs a first sign bit, a first exponent, and a first mantissa to a transmission circuit.
[0115] Step 704: The transmission circuit transmits the first sign bit, the first exponent, and the first mantissa to the floating-point adder.
[0116] Step 705: The floating-point adder obtains the operand to be accumulated.
[0117] Step 706: The floating-point adder decomposes the operand to be accumulated into a second sign bit, a second exponent, and a second mantissa.
[0118] Step 707: The floating-point adder calculates a multiplication-accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent, and the second mantissa.
[0119] Specifically, the first operand op1 and the second operand op2 refer to the multiplier and the multiplicand corresponding to the floating-point multiplier 10. As an example, the first operand op1 and the second operand op2 may be single-precision floating-point numbers.
[0120] In practical applications, after the floating-point multiplier 10 receives the first operand op1 and the second operand op2, first, the first operand op1 and the second operand op2 are decomposed according to the sign bit, the exponent and the mantissa, respectively, to obtain the third sign bit op1_sign_mul, the third exponent op1_exp_mul and the third mantissa op1_fract_mul corresponding to the first operand op1, and the fourth sign bit op2_sign_mul, the fourth exponent op2_exp_mul and the fourth mantissa op2_fract_mul corresponding to the second operand op2.
[0121] Further, the floating-point multiplier 10 adds the third order code op1_exp_mul and the fourth order code op2_exp_mul to obtain the first intermediate order code out_exp_q. The floating-point multiplier 10 performs an XOR operation on the third sign bit op1_sign_mul and the fourth sign bit op2_sign_mul to obtain the first sign bit sign1.
[0122] Further, the floating-point multiplier 10 performs bit-by-bit multiplication calculation on the third mantissa op1_fract_mul and the fourth mantissa op2_exp_mul to obtain a plurality of partial products; the floating-point multiplier 10 calculates the sum of the plurality of partial products to obtain a first intermediate mantissa sum.
[0123] Furthermore, the floating-point multiplier 10 rounds the first intermediate exponent out_exp_q and the first intermediate mantissa sum to obtain the first exponent mul_exp and the first mantissa mul_sum. Furthermore, the floating-point multiplier 10 transmits the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0124] Afterwards, the floating-point multiplier 10 may perform concatenation processing on the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum to obtain a first product result Mul result.
[0125] Correspondingly, after receiving the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum, the transmission circuit 30 transmits the first sign bit sign1 , the first order code mul_exp and the first mantissa mul_sum to the floating-point adder 20 .
[0126] In this embodiment, the transmission circuit 30 can be constructed based on the signal bypass technology. Through the transmission circuit 30, the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum can be transmitted to the floating-point adder 20 without waiting for the floating-point multiplier 10 to calculate the first product result Mul result, thereby improving the operational efficiency of the floating-point multiplication and accumulation.
[0127] Correspondingly, the floating point adder 20 receives the first sign bit sign1, the first exponent mul_exp and the first mantissa mul_sum transmitted by the transmission circuit 30, and obtains the operand op3 to be accumulated. It can be understood that the operand op3 to be accumulated can be the multiplication and accumulation result add_result calculated by the floating point adder 20 last time.
[0128] Specifically, the floating-point adder 20 decomposes the operand op3 to be accumulated according to the sign bit, the exponent and the mantissa to obtain the second sign bit op3_sign_add, the second exponent op3_exp_add and the second mantissa op3_fract_add. It can be understood that the floating-point adder 20 only needs to decompose the operand op3 to be accumulated, saving the time of decomposing the multiplication and accumulation result add_result.
[0129] Further, the floating point adder 20 performs an XOR operation on the first sign bit sign1 and the second sign bit op3_sign_add to obtain the fifth sign bit sign2. Further, the floating point adder 20 calculates the offset between the first order code mul_exp and the second order code op3_exp_add, and aligns the first order code mul_exp and the second order code op3_exp_add based on the offset to obtain the aligned order code exp.
[0130] Furthermore, the floating-point adder 20 splices the guard bit (Guard), the rounding bit (Round) and the paste bit (paste bit) for the first mantissa mul_sum and the second mantissa op3_fract_add respectively; the mantissa corresponding to the smaller one of the first order code mul_exp and the second order code op3_exp_add is moved rightward by the number of bits corresponding to the offset, and the first mantissa mul_sum and the second mantissa op3_fract_add are aligned to obtain the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add.
[0131] Further, the floating point adder 20 performs addition and subtraction operations on the fifth mantissa mul_mant_add and the sixth mantissa op3_mant_add to obtain the seventh mantissa result_raw. Further, the floating point adder 20 concatenates the seventh mantissa result_raw, the aligned exponent exp and the fifth sign bit sign2 to obtain the multiplication and accumulation result add_result.
[0132] In the floating-point multiplication and accumulation method provided in this embodiment, the floating-point multiplier performs a multiplication operation based on the received first operand and the second operand, obtains a first sign bit, a first exponent and a first mantissa corresponding to a first product result of the first operand and the second operand, and outputs the first sign bit, the first exponent and the first mantissa to a transmission circuit; the transmission circuit transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder; the floating-point adder obtains the operand to be accumulated, the floating-point adder decomposes the operand to be accumulated into a second sign bit, a second exponent and a second mantissa, and calculates the multiplication and accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent and the second mantissa. In the scheme of this embodiment, on the one hand, before the floating-point multiplier obtains the first product result of the first operand and the second operand, it transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder through the transmission circuit, and the floating-point adder can calculate the multiplication-accumulation result without waiting for the floating-point multiplier to calculate the first product result, thereby reducing the waiting time of the floating-point adder; on the other hand, the transmission circuit directly transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder, and the floating-point adder only needs to decompose the operand to be accumulated, and the floating-point adder does not need to decompose the first product result, thereby saving the operation time of the floating-point adder. Therefore, the scheme of this embodiment saves the operation time of multiplication-accumulation and improves the operation efficiency of multiplication-accumulation.
[0133] In some embodiments, the present invention further provides an electronic device, the electronic device comprising a floating-point multiplication and accumulation circuit as shown in any of the above embodiments. As an example, Figure 8 It is a schematic diagram of the physical structure of an electronic device, such as Figure 8As shown, the electronic device may include: a floating-point multiplier 10 , a floating-point adder 20 and a transmission circuit 30 .
[0134] Among them, the floating-point multiplier 10 is connected to the transmission circuit 30, and the floating-point multiplier 10 receives the first operand op1 and the second operand op2. The floating-point multiplier 10 is used to perform a multiplication operation on the first operand op1 and the second operand op2, and obtain the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum corresponding to the first product result Mul result of the first operand op1 and the second operand op2, and output the first sign bit sign1, the first order code mul_exp and the first mantissa mul_sum to the transmission circuit 30.
[0135] The transmission circuit 30 is connected to the floating-point multiplier 20 , and is used for transmitting the first sign bit sign1 , the first exponent mul_exp and the first mantissa mul_sum to the floating-point adder 20 .
[0136] Among them, the floating-point adder 20 obtains the operand to be accumulated op3, and the floating-point adder 20 is used to decompose the operand to be accumulated op3 into the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add, and calculate the multiplication and accumulation result add_result based on the first sign bit sign1, the first order code mul_exp, the first mantissa mul_sum, the second sign bit op3_sign_add, the second order code op1_exp_add and the second mantissa op1_fract_add.
[0137] In the electronic device provided by the present embodiment, a floating-point multiplier performs a multiplication operation based on receiving a first operand and a second operand, obtains a first sign bit, a first exponent, and a first mantissa corresponding to a first product result of the first operand and the second operand, and outputs the first sign bit, the first exponent, and the first mantissa to a transmission circuit; the transmission circuit transmits the first sign bit, the first exponent, and the first mantissa to a floating-point adder; the floating-point adder obtains an operand to be accumulated, the floating-point adder decomposes the operand to be accumulated into a second sign bit, a second exponent, and a second mantissa, and calculates a multiplication and accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent, and the second mantissa. In the scheme of this embodiment, on the one hand, before the floating-point multiplier obtains the first product result of the first operand and the second operand, it transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder through the transmission circuit, and the floating-point adder can calculate the multiplication-accumulation result without waiting for the floating-point multiplier to calculate the first product result, thereby reducing the waiting time of the floating-point adder; on the other hand, the transmission circuit directly transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder, and the floating-point adder only needs to decompose the operand to be accumulated, and the floating-point adder does not need to decompose the first product result, thereby saving the operation time of the floating-point adder. Therefore, the scheme of this embodiment saves the operation time of multiplication-accumulation and improves the operation efficiency of multiplication-accumulation.
[0138] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0139] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0140] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A floating-point multiplication-accumulation circuit, characterized in that: include: Floating-point multipliers, floating-point adders, and transmission circuits; The floating-point multiplier receives a first operand and a second operand, the floating-point multiplier is connected to the transmission circuit, and is used to perform a multiplication operation on the first operand and the second operand to obtain a first sign bit, a first exponent, and a first mantissa corresponding to a first product result of the first operand and the second operand, and output the first sign bit, the first exponent, and the first mantissa to the transmission circuit; The transmission circuit is connected to the floating-point multiplier, and the transmission circuit is used to transmit the first sign bit, the first exponent and the first mantissa to the floating-point adder; The floating-point adder obtains an operand to be accumulated, and is used to decompose the operand to be accumulated into a second sign bit, a second exponent, and a second mantissa, and based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent, and the second mantissa, calculate the sum of the first product result and the operand to be accumulated to obtain a multiplication-accumulation result.
2. The floating-point multiplication-accumulation circuit according to claim 1, characterized in that: The floating-point multiplier comprises: a first processing module and a first operation module; The first processing module is connected to the first operation module, the first processing module receives the first operand and the second operand, and the first processing module is used to pre-process the first operand and the second operand to obtain the first sign bit, the third mantissa corresponding to the first operand, the fourth mantissa corresponding to the second operand, and the first intermediate order code corresponding to the first product result; the first processing module is also used to transmit the third mantissa, the fourth mantissa, the first intermediate order code and the first sign bit to the first operation module; The first operation module is connected to the transmission circuit, and the first operation module is used to perform multiplication operation on the third mantissa and the fourth mantissa to obtain a first intermediate mantissa, and to round the first intermediate exponent and the first intermediate mantissa to obtain the first exponent and the first mantissa; the first operation module is also used to output the first sign bit, the first exponent and the first mantissa to the transmission circuit.
3. The floating-point multiplication-accumulation circuit according to claim 2, characterized in that: The first processing module includes: a decomposition unit, an XOR unit and an order code processing unit; The decomposition unit is connected to the first operation module, the decomposition unit receives the first operand and the second operand, and is used to decompose the first operand and the second operand respectively to obtain a third sign bit, a third exponent, and the third mantissa corresponding to the first operand, and a fourth sign bit, a fourth exponent, and the fourth mantissa corresponding to the second operand; the decomposition unit is also used to transmit the third mantissa and the fourth mantissa to the first operation module; The XOR unit is connected to the decomposition unit and the first operation module, and the XOR unit is used to perform an XOR operation on the third sign bit and the fourth sign bit to obtain the first sign bit, and output the first sign bit to the first operation module; The rank processing unit is connected to the decomposition unit and the first operation module, and is used for calculating the sum of the third rank and the fourth rank to obtain a first intermediate rank, and outputting the first intermediate rank to the first operation module.
4. The floating-point multiplication-accumulation circuit according to claim 2, characterized in that: The first operation module includes: a partial product generating unit, a partial product adding unit, a first rounding unit and a transmission unit; The partial product generation unit is connected to the first processing module, and the partial product generation module is used to perform bit-by-bit multiplication calculation on the third mantissa and the fourth mantissa to obtain a plurality of partial products; the number of the plurality of partial products is consistent with the number of bits of the third mantissa and the fourth mantissa; The partial product adding unit is connected to the partial product generating unit, and the partial product adding unit is used to calculate the sum of the plurality of partial products to obtain a first intermediate mantissa; The first rounding unit is connected to the first processing module and the partial product adding unit, and is used for performing rounding operation on the first intermediate exponent and the first intermediate mantissa to obtain the first exponent and the first mantissa; The transmission unit is connected to the first processing unit, the first rounding unit and the transmission circuit, and is used to obtain the first sign bit, the first exponent and the first mantissa, and output the first sign bit, the first exponent and the first mantissa to the transmission circuit.
5. The floating-point multiplication-accumulation circuit according to claim 2, characterized in that: The floating-point multiplier further comprises: a first result processing module; The first result processing module is connected to the first operation module, and is used for performing concatenation processing on the first sign bit, the first exponent and the first mantissa to obtain the first product result.
6. The floating-point multiplication-accumulation circuit according to claim 1, characterized in that: The floating-point adder comprises: a second processing module, a mantissa processing module, a second operation module, a second result processing module and an accumulator; The accumulator is connected to the second result processing module and the second processing module, and is used to obtain the operand to be accumulated, and transmit the operand to be accumulated to the second processing module; The second processing module is connected to the transmission circuit, and the second processing module is used to decompose the operand to be accumulated into the second sign bit, the second exponent and the second mantissa; the second processing module is also used to perform an XOR operation on the first sign bit and the second sign bit to obtain the fifth sign bit; the second processing module is also used to calculate the offset between the first exponent and the second exponent, and align the first exponent and the second exponent based on the offset to obtain the aligned exponent; The mantissa processing module is connected to the second processing module, and is used to obtain the first mantissa, the second mantissa, the aligned exponent, and the fifth sign bit, and perform alignment processing on the first mantissa and the second mantissa to obtain the fifth mantissa and the sixth mantissa; wherein the mantissa processing includes: splicing the protection bit, the rounding bit, and the pasting bit of the first mantissa and the second mantissa respectively; shifting the mantissa corresponding to the smaller exponent of the first exponent and the second exponent to the right by the number of bits corresponding to the offset; The second operation module is connected to the mantissa processing module, and the second operation module is used to obtain the fifth mantissa, the sixth mantissa, the aligned exponent and the fifth sign bit, and perform addition and subtraction operations on the fifth mantissa and the sixth mantissa to obtain a seventh mantissa; The second result processing module is connected to the second operation module, and the second result processing module is used to obtain the seventh mantissa, the aligned exponent and the fifth sign bit, and concatenate the seventh mantissa, the aligned exponent and the fifth sign bit to obtain the multiplication and accumulation result.
7. The floating-point multiplication-accumulation circuit according to claim 6, characterized in that: The second processing module also includes a selector; The selector is connected to the transmission circuit, and is used to determine whether the current operation is a multiplication-accumulation operation. If it is a multiplication-accumulation operation, the first sign bit, the first exponent and the first mantissa are selected.
8. The floating-point multiplication-accumulation circuit according to any one of claims 1 to 7, characterized in that: The floating-point multiplication-accumulation circuit further includes: at least one register.
9. A floating-point multiplication and accumulation method, characterized in that: Applied to a floating-point multiplication-accumulation circuit, the floating-point multiplication-accumulation circuit includes a floating-point multiplier, a floating-point adder and a transmission circuit; the floating-point multiplication-accumulation method includes: The floating point multiplier receives a first operand and a second operand; The floating-point multiplier performs a multiplication operation on the first operand and the second operand to obtain a first sign bit, a first exponent, and a first mantissa corresponding to a first product result of the first operand and the second operand, and outputs the first sign bit, the first exponent, and the first mantissa to the transmission circuit; The transmission circuit transmits the first sign bit, the first exponent and the first mantissa to the floating-point adder; The floating point adder obtains the operand to be accumulated; The floating-point adder decomposes the operand to be accumulated into a second sign bit, a second exponent, and a second mantissa, and calculates a multiplication-accumulation result based on the first sign bit, the first exponent, the first mantissa, the second sign bit, the second exponent, and the second mantissa.
10. An electronic device, characterized in that: include: A floating-point multiplication-accumulation circuit as claimed in any one of claims 1 to 8.
