Design method of fixed-point and floating-point adder
By designing the shared mantissa adder module and pre-shifter in the neural network adder, compatible calculations of fixed-point and floating-point numbers are realized, which solves the problems of difficult format conversion, large module area and high delay in the existing technology, and significantly reduces the power consumption. consumption and delay to meet the complex application requirements of neural networks.
Patent Information
- Application Number
- CN202410832420.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2024-03-18
- Filing Date
- 2024-06-26
- Publication Date
- 2024-10-01
AI Technical Summary
Existing neural network adders are difficult to be compatible with fixed-point and floating-point calculations, resulting in difficult format conversion, large module area, high power consumption, and long delays.
Design a fixed-floating-point adder, which distinguishes the input data type through the shared mantissa addition module, performs low-bit and mantissa calculations in the fixed-point and floating-point processing modules respectively, and uses the pre-shifter for normalization processing to reduce logic resources and Delay.
It realizes compatible calculation of fixed-point numbers and floating-point numbers, reduces the area and power consumption of the adder, improves the calculation speed, and meets the complex application requirements of neural networks.
Smart Images

Figure CN118732990A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of neural network processing elements, and in particular to a fixed-point and floating-point adder design method. Background Art
[0002] With the rapid development of artificial intelligence, AI training and reasoning are computationally intensive tasks that require powerful high-performance computing solutions. NPU (Neural Network Processing Unit) is a special design for neural network calculations to process complex algorithms and massive amounts of data. It is widely used to accelerate artificial intelligence tasks, especially deep learning algorithms and machine learning algorithms. In the training and reasoning calculations of neural networks, the requirements for data accuracy are diverse, and both floating-point and fixed-point computing capabilities are crucial for NPUs. The adder is the core computing unit of NPU. Its performance directly affects the processing power of NPU. It can be divided into fixed-point adders and floating-point adders according to the data format. Fixed-point numbers include fixed-point integers and fixed-point decimals. The decimal point position of fixed-point numbers is fixed, and the data range that can be represented is limited. In addition, there is no problem of mantissa alignment during the calculation process of fixed-point numbers, and the calculation is simple. Floating-point numbers consist of exponents and mantissas. Compared with fixed-point numbers, floating-point numbers have a larger dynamic range of data representation and higher data accuracy. Therefore, their circuit scale is larger and more logic resources are consumed.
[0003] Classic neural networks include convolutional neural networks and recurrent neural networks, which are usually composed of convolutional layers, activation function layers, pooling layers, fully connected layers, and softmax layers. When neural networks use adders for calculations, sometimes fixed-point calculations are required, and sometimes floating-point calculations are required. For example, the convolutional layer is usually at the front of the neural network, and is more suitable for fixed-point calculations due to memory and bandwidth limitations; the activation function layer is more suitable for floating-point calculations because it is a nonlinear operation with higher precision. The fully connected layer has a higher computational density and is more suitable for floating-point calculations, which can guarantee a certain degree of precision.
[0004] However, the adders used in neural networks still have the following problems: 1) It is difficult to be compatible with both fixed-point and floating-point data formats at the same time, and format conversion is required, which cannot directly meet the application of neural networks; 2) The adder module area required by the neural network is large, resulting in increased power consumption; 3) The delay of the adder during operation is too high, for example: the delay of the serial carry adder gate circuit is too large; the power consumption and delay of the carry lookahead adder will also increase when the number of recursions increases; the shifter inside the adder needs to wait for the calculation result before shifting, which also makes the delay higher. Summary of the invention
[0005] The technical problem to be solved by the present invention is: how to design a fixed-point and floating-point adder that is compatible with the fixed-point and floating-point calculations required by a neural network, while effectively reducing latency and power consumption.
[0006] In view of the above technical problems, a fixed-point floating-point adder design method is proposed; it is implemented by the following technical solutions: A fixed-point floating-point adder design method comprises the following steps: S1, setting a shared mantissa addition module at the input end of the fixed-point and floating-point adder, using the shared mantissa addition module to receive input data at the input end, performing fixed-point and floating-point distinction on the input data, and distinguishing the data type of the input data; wherein the data type includes fixed-point numbers and floating-point numbers, the fixed-point number includes a sign bit and a value bit, and the floating-point number includes a sign bit, an exponent, and a mantissa; S2. When the input data is a fixed-point number, the numerical bit of the fixed-point number is calculated in the shared mantissa addition module of step S1 to obtain a low-bit calculation result; a fixed-point number processing module is set to retain the highest carry in the low-bit calculation result, and the retained carry is transmitted to a given point number processing module, and the fixed-point number addition calculation result is obtained according to the sign bit of the fixed-point number and the retained carry; S3, when the input data is a floating-point number, the mantissa of the floating-point number is calculated in the shared mantissa addition module of step S1 to obtain a floating-point mantissa addition calculation result; a floating-point number processing module is set to perform order processing on the exponent of the floating-point number; a pre-shifter is set in the floating-point number processing module, and the floating-point mantissa addition calculation result is normalized by the pre-shifter to obtain a normalized processing result; the floating-point number addition calculation result is obtained according to the sign bit of the floating-point number, the exponent after order processing and the normalized processing result; S4, transmitting the fixed-point number addition calculation result in step S2 or the floating-point number addition calculation result in step S3 to the output module, and outputting it through the output end of the fixed-point and floating-point adder.
[0007] By sharing the mantissa addition module, preliminary processing of floating-point numbers and fixed-point numbers is performed simultaneously to complete the mantissa addition calculation of floating-point numbers and the low-bit calculation of fixed-point numbers. This form of module sharing and reuse reduces the logic resources required for the adder, saves area and power consumption, and is also compatible with both fixed-point and floating-point formats, which can meet the use requirements of neural networks. In addition, a pre-shifter is also provided in the floating-point processing module for fast normalization processing, which further speeds up the calculation speed and reduces latency.
[0008] Preferably, in step S1, the shared mantissa addition module includes multiple groups of carry-lookahead adders, and each group of carry-lookahead adders is sequentially connected in a serial carry manner. Multiple groups of carry-lookahead adders are serially connected to reduce power consumption and area.
[0009] Preferably, any group of carry-lookahead adders is composed of multiple 1-bit full adders in a carry-lookahead manner within the group. Multiple 1-bit full adders carry-lookahead within the group, which improves the calculation speed and effectively reduces the delay.
[0010] Preferably, in step S3, when normalization is performed, if the result of floating-point mantissa addition calculation is a non-normal number, left normalization is performed; if the result of floating-point mantissa addition calculation overflows, right normalization is performed. Normalization is performed to ensure the effective accuracy of the data and reduce calculation errors.
[0011] Preferably, in step S3, the floating-point mantissa addition calculation result is rounded to the nearest value according to the IEEE-754 standard after being normalized. The precision of the floating-point number represented by the fixed floating-point adder is limited, and when the fixed floating-point adder outputs to the outside, the precision of the floating-point number represented by the receiving device is also limited, so the calculation result of the floating-point number must be rounded, and the nearest rounding can round the calculation result to the nearest representable value, close to the real mathematical result, and can reduce rounding errors.
[0012] Preferably, in step S3, after obtaining the normalized processing result, it is also necessary to perform floating point overflow processing on the normalized processing result, and the floating point overflow processing includes positive overflow processing and negative overflow processing; the maximum positive normalized number is used as the result of the positive overflow processing, and the minimum negative normalized number is used as the result of the negative overflow processing. Floating point overflow means that the calculation result exceeds the actual representable range, and the overflowed part will also destroy the stability and accuracy of the calculation, so overflow processing is required to ensure the accuracy of the calculation.
[0013] Preferably, in step S3, parallel logic is used between the pre-shifter and the shared mantissa addition module. The pre-shifter can prejudge in parallel how to perform subsequent normalization processing without waiting for the shared mantissa addition module to finish calculation, thereby effectively reducing calculation delay.
[0014] Preferably, the mantissa of the floating-point number includes an operand. When normalization is performed in step S3, the pre-shifter calculates the number of leading 0 / 1s according to the operand, and determines in advance the number of bits that need to be left-shifted during normalization based on the number of leading 0 / 1s. The leading 0 / 1 refers to the value of the highest bit of the mantissa after normalization. The number of leading 0 / 1s can be quickly determined based on the operand, so that the pre-shifter can make a pre-judgment in advance and speed up the calculation.
[0015] Preferably, in step S3, when the pre-shifter is used for normalization processing, the pre-shifter uses a carry generation function, a carry transfer function and an annihilation function. Using these three functions can quickly calculate the operations required by the pre-shifter during normalization processing, improve calculation efficiency and reduce calculation delay.
[0016] Compared with the prior art, the present invention has the following beneficial effects: The fixed-point and floating-point adder of the present invention is compatible with fixed-point number calculation and floating-point number calculation. Compared with the existing adders that can only perform fixed-point number calculation or floating-point number calculation, the solution of the present invention has stronger performance and can better meet the complex application requirements of neural networks. In addition, the solution of the present invention reuses a shared mantissa processing module, which reduces the area of the adder and greatly reduces power consumption. Moreover, the present invention also uses a pre-shifter to make a judgment on the normalization processing in advance, eliminating the link of waiting for the calculation to be completed for the normalization processing, effectively reducing the delay and improving the calculation speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic diagram of a fixed-point and floating-point adder; Figure 2 It is a structural diagram of a set of 4-bit carry-lookahead adders; Figure 3 It is a connection diagram between multiple groups of 4-bit carry-lookahead adders; Figure 4 The figure is a schematic diagram of the operation principle of a pre-shifter. DETAILED DESCRIPTION
[0018] The technical solutions in the embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings in the embodiments of the present invention. Example
[0019] like Figure 1 As shown, it is a schematic diagram of a fixed-point and floating-point adder, which is compatible with data in both fixed-point and floating-point formats. It uses a shared mantissa addition module to process fixed-point and floating-point numbers at the same time, and then sends their respective processing results to the corresponding processing modules to finally complete the addition calculation.
[0020] A fixed-point floating-point adder design method specifically comprises the following steps: S1. A shared mantissa addition module is set at the input end of the fixed-point and floating-point adders. The shared mantissa addition module includes multiple groups of carry-lookahead adders. The specific number of carry-lookahead adders needs to be set according to the actual data to be processed. For example, if 20-bit data needs to be processed, 5 groups of 4-bit carry-lookahead adders are used; for another example, if 16-bit data needs to be processed, 4 groups of 4-bit carry-lookahead adders are used. The shared mantissa addition module is used to receive input data at the input end. The input data may contain fixed-point numbers or floating-point numbers. The fixed-point number includes a sign bit and a value bit, and the floating-point number includes a sign bit, an exponent, and a mantissa. The exponent can also be called an exponent bit, and the mantissa can also be called a mantissa bit. The different information contained in the two types of data can be used to distinguish between fixed-point numbers and floating-point numbers.
[0021] It should be noted that the carry-lookahead adder used in this embodiment is based on the operation logic of the traditional carry-lookahead adder, and the addition calculation process is modified. Taking the traditional carry-lookahead adder with an input operand width of N as an example, the input operand width is set to X. n and Y n , n∈[N,1], then the carry generation function can be expressed as (1-1): G n-1 =X n-1 *Y n-1 , n∈[N,1], * represents multiplication operation; the carry transfer function is expressed as (1-2): P n-1 =X n-1 ⊕Y n-1 , n∈[N, 1], ⊕ represents an exclusive-or operation; the carry from the lower bit and the carry from the highest bit are represented as (1-3): ; The carry lookahead flag is represented by (1-4): C n =G n-1 +P n-1 *C n-1 , n∈[N,1]; the output of the carry-lookahead adder is (1-5): S n-1 =X n-1 ⊕Y n-1 ⊕C n-1 As the bit width of the traditional carry-lookahead adder gradually increases, the circuit will become more complex, and the area and power consumption will be larger. Therefore, the carry-lookahead adder used in this embodiment is improved.
[0022] like Figure 2 As shown in FIG. 1 , it is a schematic diagram of the structure of a set of 4-bit carry-lookahead adders, such as Figure 3 As shown in FIG. 1 , it is a connection diagram between multiple groups of 4-bit carry-lookahead adders. Figure 2 and Figure 3 As shown, taking the processing of 16-bit fixed-point numbers and 16-bit floating-point numbers as an example, the mantissa of a 16-bit floating-point number is 10 bits, the hidden bit is 1 bit, and the sign bit is 1 bit, so the shared mantissa addition module needs to process 12 bits. In the three groups of carry-lookahead adders of the shared mantissa addition module of this embodiment, an addition module design of "carry-lookahead within the group, serial carry between groups" is adopted, that is, multiple 1-bit full adders within the group are connected in parallel, and the carry-lookahead method is adopted to ensure the calculation speed within the group; different groups are connected in series to ensure the orderliness of the calculation. There are 3 groups of carry-lookahead adders, covering the 12-bit low bits of the 16-bit fixed-point number, and each group has 4 bits, and a 4-bit carry-lookahead design is adopted within the group. Among them, C represents carry, P represents the "forward propagation" signal, G is the "generate" signal related to P, S represents summation, and X and Y both represent operands.
[0023] From (1-4), we can deduce that the carry of each bit of any set of 4-bit carry-lookahead adders can be expressed by the following formula: (1-6) Substituting (1-6) into (1-5) we can get the calculation result of any set of 4-bit carry-lookahead adders: (1-7) From (1-7), it can be seen that the calculation result of any group of carry-lookahead adders is only related to the input operand and the carry, and has nothing to do with the calculation result of the low bit. Therefore, when performing low-bit calculation on the fixed-point number in the shared mantissa addition module, it is only necessary to retain and transmit the highest-bit carry from the result of the low-bit calculation, which will not cause any erroneous effect on the final result of the fixed-point number. The shared mantissa addition module can also calculate the mantissa of the floating-point number. The two formats of numbers are reused in one module, which saves the area and power consumption of the adder while ensuring accuracy. After the shared mantissa addition module completes the calculation, it will send the fixed-point number or floating-point number to the corresponding subsequent module for processing, effectively reducing latency.
[0024] In the three groups of 4-bit carry-lookahead adders used, the carry and calculation results of each group of 4-bit carry-lookahead adders follow (1-6) and (1-7). The delay from C0 to C4 of the first group of 4-bit carry-lookahead adders is 4 levels of gate circuits; the delay from C4 to C8 of the second group of 4-bit carry-lookahead adders is 2 levels of gate circuits, plus the delay from C0 to C4, a total of 6 levels; the delay from C8 to C4 of the third group of 4-bit carry-lookahead adders is 2 levels of gate circuits, plus the delay from C0 to C4, a total of 6 levels; 12 The delay is 2 levels of gate circuits, plus the delay from C0 to C8, a total of 8 levels, so the delay of the 12-bit "intra-group carry lookahead, inter-group serial carry" addition module is 8 levels of gate circuits.
[0025] S2. If the input data is a fixed-point number, the low-bit calculation can be performed on the numerical bit of the fixed-point number in the shared mantissa addition module to obtain the low-bit calculation result. Then set the fixed-point number processing module. For the addition calculation of the fixed-point number, after the input data passes through the shared mantissa addition module to obtain the low-bit addition calculation result, the carry of the highest bit in the calculation result will be retained and passed to the fixed-point number processing module for high-bit addition. The high-bit addition module accepts the carry from the low bit and combines it with the corresponding sign bit to obtain the final fixed-point number addition calculation result.
[0026] For fixed-point numbers, their numerical bits are divided into fixed-point integers and fixed-point decimals. For fixed-point decimals, the mantissa of the fixed-point number is the numerical part after the decimal point. The position of the decimal point is fixed and known, so there is no need to process the mantissa. Simply add them together without any additional calculation. Fixed-point numbers can be divided into low bits and high bits. The low bits contain the main part of the numerical bits. After the shared mantissa addition module completes the low-bit calculation, the subsequent high-bit calculation can also be processed quickly.
[0027] S3. If the input data is a floating-point number, the mantissa of the floating-point number can be calculated in the shared mantissa addition module to obtain the floating-point mantissa addition calculation result. The shared mantissa addition module can be reused, thereby reducing the logic resources required for the adder, saving area and power consumption. Then set the floating-point number processing module to perform order processing on the exponent of the floating-point number. Since the exponents of different floating-point numbers may vary greatly, direct addition calculation may cause serious numerical underflow or numerical overflow, so order processing is required to make it calculated on the same order of magnitude to ensure the effectiveness of the calculation.
[0028] It should be noted that a floating-point number consists of a sign bit, an exponent, and a mantissa. When representing a floating-point number, the position of the decimal point is unknown and not fixed, and needs to be determined with the help of the exponent. During the addition calculation of floating-point numbers, it is necessary to ensure that the decimal point position is aligned before the correct mantissa calculation can be performed.
[0029] In the representation of floating-point numbers, the mantissa is the part after the decimal point, which usually needs to be normalized. In the addition calculation of two or more floating-point numbers, the addition of the mantissas may result in a result that exceeds the normalized range. For example, if the result of adding two mantissas is 2.101, then this result needs to be normalized back to between 1 and 2, that is, the decimal point needs to be shifted right by one place to get 1.1010. This right shift process needs to be completed by a shifter or pre-shifter. In this right shift process, the "leading 0 / 1" refers to the value of the highest bit of the normalized mantissa. If the highest bit is 0, it means that the mantissa can continue to move to the right, that is, the decimal point moves to the left, until the highest bit becomes 1. At this time, the number of bits moved is the number of bits that need to be shifted left.
[0030] In addition, when normalizing the result of the mantissa addition calculation, if the result of the mantissa addition calculation overflows, it needs to be normalized to the right, that is, the mantissa is shifted 1 bit to the right; if the calculation result is a non-standard number, it needs to be normalized to the left. Floating-point overflow means that the calculation result exceeds the actual range that can be represented. The overflow part will also destroy the stability and accuracy of the calculation, so in order to protect the accuracy of the calculation, overflow processing must be performed. The left normalization adopts a pre-shifter design, which directly calculates the number of leading 0 / 1 through the input operand, and predicts the number of bits that need to be shifted in advance, without waiting for the mantissa addition calculation to be completed. Then, the calculation result after normalization is rounded. The rounding method adopted in this scheme is the nearest rounding in the IEEE-754 standard.
[0031] Then, the result of the addition of the mantissa after rounding is combined with the exponent to perform floating-point overflow processing. The floating-point overflow processing method adopted in this scheme is that the result of the positive overflow is the maximum positive specification number that can be represented in the floating-point format, and the result of the negative overflow is the minimum negative specification number that can be represented in the floating-point format. The precision of the floating-point number represented inside the fixed floating-point adder is limited, and when the fixed floating-point adder outputs to the outside, the precision of the floating-point number represented in the receiving device is also limited. Therefore, the calculation result of the floating-point number must be rounded, and the nearest rounding can round the calculation result to the closest representable value, which is close to the real mathematical result and can reduce rounding errors.
[0032] like Figure 4 As shown, it is an operation principle diagram of a pre-shifter used in the present invention, which is provided in the floating point number processing module, and is a traditional serial logic shifter modified into a parallel logic, so as to be connected in parallel with the shared mantissa addition module. The pre-shifter does not need to wait for the mantissa addition calculation result to be completed, and directly predicts the number of leading 0 / 1 according to the operands contained in the input data, so as to determine how many bits need to be shifted left, and prepare for normalization processing in advance.
[0033] In this pre-shifter, three functions are needed to predict the number of leading 0 / 1s, among which the carry generation function uses (1-1), the carry transfer function uses (1-2), and the definition of the annihilation function is expressed by the following formula: (Indicates X n +Y n NOT operation) (1-8) When the pre-shifter is running, it is necessary to calculate the leading 0 and the leading 1. Assuming that the first 0 in the carry transfer function appears at the nth position, it can be obtained from the following formula: (1-9) (1) Calculation of leading 0s If G -n=0, then m=n; if G -n =1, the value of m can be obtained from the following formula: (1-10) Among them, n, m∈[N,1].
[0034] The number of leading zeros is m or m-1, depending on whether the carry from the mth position is 0 or 1. If C m If it is 0, the number of leading 0s is m, otherwise it is m-1.
[0035] (2) Leading 1 calculation If A -n =0, then m=n; if A -n =1, the value of m can be obtained from the following formula: (1-11) Among them, n, m∈[N,1].
[0036] The number of leading 1s is m-1 or m, depending on whether the carry from the mth position is 0 or 1. If C m If it is 0, the number of leading 0s is m-1, otherwise it is m.
[0037] Using the result of the leading 0 / 1 prediction of the pre-shifter, the exponent of the floating-point number is adjusted after the exponent of the floating-point number is aligned. At the same time, the floating-point mantissa calculation result is rounded to the nearest integer. After the normalization process is completed, the floating-point number addition calculation result can be obtained based on the sign bit of the floating-point number, the exponent after the alignment process, and the normalization process result.
[0038] S4. If the input data is a fixed-point number, the fixed-point number addition calculation result is transmitted to the output module and then output through the output end of the fixed-point and floating-point adder; if the input data is a floating-point number, the floating-point number addition calculation result is transmitted to the output module and then output through the output end of the fixed-point and floating-point adder.
[0039] In addition, on the basis of being able to meet the actual delay requirements, a CRC check can be added to the output module to check whether the calculation result is correct, so as to further ensure the calculation accuracy of the fixed-point and floating-point adders.
[0040] Specific application examples:
[0041] A low-latency 16-bit fixed-point and floating-point adder includes a shared mantissa addition module, a fixed-point number processing module and a floating-point number processing module. It can process 16-bit floating-point numbers and 16-bit fixed-point numbers. The floating-point number complies with the IEEE-754 standard, and the mantissa of the floating-point number occupies 12 bits. The fixed-point and floating-point adder uses a set of hardware logic computing resources, namely a shared mantissa addition module. The shared mantissa addition module is composed of three groups of 4-bit carry-lookahead adders in series, and each group of carry-lookahead adders is composed of four 1-bit full adders in parallel.
[0042] The shared mantissa addition module receives an input data from the fixed-point and floating-point adder input terminal, and distinguishes the fixed-point and floating-point numbers according to the control logic used for the input data, and finds that the input data is a floating-point number. The floating-point number contains a sign bit, an exponent, and a mantissa. The exponent and mantissa are collectively referred to as the value bits of the floating-point number. The value bits contain the corresponding operands X0~X 11 and Y0~Y 11 .
[0043] In each group of carry-lookahead adders, there are 4 1-bit full adders connected in parallel. When the 4 1-bit full adders are connected, C represents the carry, P represents the "forward propagation" signal, G represents the "generate" signal related to P, S represents the sum, X and Y represent the operands, and then according to (1-4): C n =G n-1 +P n-1 *C n-1 , n∈[N, 1] is carried forward, and then (1-6) Substitute into (1-5): S n-1 =X n-1 ⊕Y n-1 ⊕C n-1 In the above example, we can obtain the calculation results of each group of carry-lookahead adders (1-7): .
[0044] The three groups of carry-lookahead adders are connected in series. The delay of the first group of 4-bit carry-lookahead adders from C0 to C4 is 4 levels of gate circuits. The delay of the second group of 4-bit carry-lookahead adders from C4 to C8 is 2 levels of gate circuits, plus the delay from C0 to C4, a total of 6 levels. The delay of the third group of 4-bit carry-lookahead adders from C8 to C 12 The delay is 2 levels of gate circuits, plus the delay from C0 to C8, a total of 8 levels, making the delay of the 12-bit "intra-group carry lookahead, inter-group serial carry" addition module 8 levels of gate circuits.
[0045] According to the above calculation process, the mantissa addition of the floating-point number is completed to obtain the floating-point mantissa addition calculation result, and the floating-point mantissa addition calculation result is sent to the floating-point number processing module; In the floating-point processing module, a pre-shifter is also provided, which is connected in parallel with the shared mantissa addition module. When the shared mantissa addition module needs to perform left normalization during the floating-point mantissa calculation, the pre-shifter is used to directly predict the number of leading 0 / 1. When predicting, three functions are needed, among which the carry generation function adopts (1-1): G n-1 =X n-1 *Y n-1 , n∈[N,1]; carry transfer function is (1-2): P n-1 =X n-1 ⊕Y n-1 , n∈[N,1]; annihilation function uses (1-8): .
[0046] The pre-shifter needs to calculate the leading 0 and leading 1 when predicting. Assume that the first 0 in the carry transfer function is at the nth position, which can be obtained from the following formula: (1-9) (1) Calculation of leading 0s If G -n =0, then m=n; if G -n =1, then the value of m is obtained from the following formula: (1-10) Among them, n, m∈[N,1].
[0047] The number of leading zeros is m or m-1, depending on whether the carry from the mth position is 0 or 1. If C m If it is 0, the number of leading 0s is m, otherwise it is m-1.
[0048] (2) Leading 1 calculation If A -n =0, then m=n; if A -n =1, the value of m is obtained from the following formula: (1-11) Among them, n, m∈[N,1].
[0049] The number of leading 1s is m-1 or m, depending on whether the carry from the mth position is 0 or 1. If C m If it is 0, the number of leading 0s is m-1, otherwise it is m.
[0050] After the left normalization, the calculation result of the left normalization is rounded according to the IEEE-754 standard, that is, rounded to the nearest. During the rounding, it is found that there is still a positive overflow of the floating point number, and positive overflow processing is required, so the maximum positive normal number is used as the calculation result of the positive overflow processing. At the same time, the exponent of the floating point number is compared, and the exponent addition and subtraction calculation is performed, and the result of the exponent addition and subtraction, the sign bit of the floating point number, and the calculation result of the positive overflow processing are used as the floating point number addition calculation result and input into the output module.
[0051] The output module receives the floating point addition calculation result and outputs the result to the outside through the output end of the fixed floating point adder.
[0052] Then, the fixed-point adder receives the input data again, and distinguishes the fixed-point and floating-point values according to the control logic used for the input data, and finds that the input data is a fixed-point number. The fixed-point number contains a sign bit and a value bit, and the value bit also contains the operands X0~X 11 and Y0~Y 11 .
[0053] In the shared mantissa addition module, three groups of carry-lookahead adders are used to calculate the 12-bit low bits of the fixed-point number. The calculation process is the same as the mantissa addition calculation process of the floating-point number mentioned above. Then, the highest bit of the low-bit calculation result is retained and sent to the fixed-point number processing module. In the fixed-point number processing module, the remaining 4 bits of the high bits of the fixed-point number are added, and the result of the high-bit addition and the sign bit of the fixed-point number are input into the output module as the fixed-point number addition calculation result.
[0054] The output module receives the result of the fixed-point addition calculation and outputs the result to the outside through the output end of the fixed-point and floating-point adder.
[0055] The fixed-point floating-point adder receives the next input data again, referring to the above calculation process, until all the data is received and processed.
[0056] In summary, the fixed-point and floating-point adder used in the present invention is compatible with fixed-point number calculations and floating-point number calculations, and meets the complex application requirements of neural networks; in addition, the solution of the present invention reuses a shared mantissa processing module, which reduces the area of the adder and greatly reduces power consumption; moreover, the present invention also uses a pre-shifter to make a judgment on the normalization processing in advance, eliminating the step of waiting for the mantissa calculation to be completed for the normalization processing, effectively reducing the delay, improving the calculation speed, and having significant progress.
[0057] The above embodiments are only for illustrating the technical idea of the present invention, and cannot be used to limit the protection scope of the present invention. Any changes made on the basis of the technical solution in accordance with the technical idea proposed by the present invention shall fall within the protection scope of the present invention.
Claims
1. A fixed-point and floating-point adder design method, It is characterized in that The steps include: S1, setting a shared mantissa addition module at the input end of the fixed-point and floating-point adder, using the shared mantissa addition module to receive input data at the input end, performing fixed-point and floating-point distinction on the input data, and distinguishing the data type of the input data; wherein the data type includes fixed-point numbers and floating-point numbers, the fixed-point number includes a sign bit and a value bit, and the floating-point number includes a sign bit, an exponent, and a mantissa; S2. When the input data is a fixed-point number, the low-bit calculation is performed on the numerical bit of the fixed-point number in the shared mantissa addition module of step S1 to obtain a low-bit calculation result; a fixed-point number processing module is set to retain the highest-bit carry in the low-bit calculation result, and the retained carry is transmitted to the fixed-point number processing module, and the fixed-point number addition calculation result is obtained according to the sign bit of the fixed-point number and the retained carry; S3, when the input data is a floating-point number, the mantissa of the floating-point number is calculated in the shared mantissa addition module of step S1 to obtain a floating-point mantissa addition calculation result; a floating-point number processing module is set to perform order processing on the exponent of the floating-point number; a pre-shifter is set in the floating-point number processing module, and the floating-point mantissa addition calculation result is normalized by the pre-shifter to obtain a normalized processing result; the floating-point number addition calculation result is obtained according to the sign bit of the floating-point number, the exponent after order processing and the normalized processing result; S4, transmitting the fixed-point number addition calculation result in step S2 or the floating-point number addition calculation result in step S3 to the output module, and outputting it through the output end of the fixed-point and floating-point adder.
2. A fixed-point and floating-point adder design method according to claim 1, It is characterized in that In step S1, the shared mantissa addition module includes a plurality of groups of carry-lookahead adders, and each group of carry-lookahead adders are sequentially connected in a serial carry manner.
3. A fixed-point and floating-point adder design method according to claim 2, It is characterized in that Any group of carry-lookahead adders is composed of multiple 1-bit full adders in a carry-lookahead manner within the group.
4. A fixed-point and floating-point adder design method according to claim 1, It is characterized in that In step S3, when performing normalization processing, if the result of floating-point mantissa addition calculation is a non-normal number, then left normalization processing is performed; if the result of floating-point mantissa addition calculation overflows, then right normalization processing is performed.
5. A fixed-point and floating-point adder design method according to claim 1, It is characterized in that In step S3, the floating-point mantissa addition calculation result is normalized and then rounded to the nearest integer according to the IEEE-754 standard.
6. A fixed-point and floating-point adder design method according to claim 1, It is characterized in that In step S3, after obtaining the normalized processing result, it is also necessary to perform floating point overflow processing on the normalized processing result; the floating point overflow processing includes positive overflow processing and negative overflow processing; The maximum positive normal number is used as the result of positive overflow processing, and the minimum negative normal number is used as the result of negative overflow processing.
7. A fixed-point and floating-point adder design method according to claim 1, It is characterized in that In step S3, parallel logic is used between the pre-shifter and the shared mantissa addition module.
8. A fixed-point and floating-point adder design method according to claim 1, It is characterized in that The mantissa of the floating point number includes the operand; when normalization is performed in step S3, the pre-shifter calculates the number of leading 0 / 1s according to the operand, and determines in advance the number of bits required to be left-shifted during normalization based on the number of leading 0 / 1s.
9. A fixed-point and floating-point adder design method according to claim 1, It is characterized in that In step S3, when the pre-shifter is used to perform normalization processing, the pre-shifter uses a carry generation function, a carry transfer function and an annihilation function.
