A method for implementing a divider

By using the combination of data comparison module, shift iteration module and quotient value calculation module in FPGA, a high-precision divider is realized, solving the problems of large resource consumption, long delay and insufficient accuracy of existing dividers, and realizing division and high-precision calculation of any two numbers.

CN119127122BActive Publication Date: 2025-03-14四川思凌科微电子有限公司 +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411612613.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-03-14
Estimated Expiration
2044-11-13

AI Technical Summary

Technical Problem

When existing dividers are implemented in FPGA, they consume a lot of resources, have huge system delays, and cannot divide any two numbers, and the calculation accuracy is insufficient.

Method used

The scaling coefficient is determined through the data comparison module, the shift iteration module is used to perform shift subtraction calculation, and the inverse scaling is performed in conjunction with the quotient value calculation module to realize high-precision calculation of the divider.

Benefits of technology

The division of any two numbers is realized, which reduces the consumption of computing resources and improves the calculation accuracy, with an average error of only 4.85×.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127122B_ABST
    Figure CN119127122B_ABST
Patent Text Reader

Abstract

The invention discloses a method for realizing a divider, belonging to the technical field of programmable chips, and specifically comprising the following steps: firstly, using a data comparison module to compare the sizes of a dividend and a divisor, and determining a scaling factor according to the sizes of the dividend and the divisor, and updating the dividend and the divisor, and transmitting the scaling factor to a shift iteration module; then using the shift iteration module to perform shift subtraction calculation to realize the divider and perform division iteration; finally, using a quotient value calculation module to reversely scale the result of the division performed by the shift iteration module to obtain a real quotient; the invention solves the technical problems of low precision and large required calculation amount of the divider in the prior art, and only requires shift calculation, addition calculation and a small amount of judgment calculation, and does not require any multiplier to obtain the real quotient, which greatly saves calculation resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of programmable chips, and in particular relates to a method for realizing a divider. Background Art

[0002] With the continuous development of FPGA (field programmable gate array) and chips, the requirements for fast and simple implementation of various mathematical operations are getting higher and higher. Among the commonly used mathematical calculations, addition and subtraction consume only a small number of resources in FPGA implementation, followed by multiplication, which consumes more resources. In FPGA, the calculation that consumes the most resources is the divider. The commonly used divider not only consumes a lot of resources, but also has huge system delays. In order to solve this problem, common methods include using cordic (coordinate rotation digital calculation method) to perform phase rotation multiple times to obtain the final division result, and using multiple shift subtractions to convert the division calculation into multiple shift subtractions for calculation. However, these methods have certain requirements and needs, such as only being able to implement division where the numerator is smaller than the denominator, and being unable to implement division of any two numbers. Therefore, it is necessary to consider a fast, high-precision and low-resource divider implementation method.

[0003] In the prior art, the implementation of the divider is mainly composed of a subtractor, a shifter, a comparator, and an adder. There are mainly the following problems:

[0004] 1. There are certain requirements on the size of the dividend and divisor, and it is impossible to implement the division of any two numbers.

[0005] 2. Implementing a divider in a field programmable gate array is expensive and requires more computing resources.

[0006] 3. Insufficient calculation accuracy. Summary of the invention

[0007] The purpose of the present invention is to overcome the problems existing in the prior art that it is impossible to realize the division of any two numbers, the divider requires too much computing resources, and the computing accuracy is limited, thereby proposing a method for implementing a divider to increase the scope of use of the divider and improve the computing accuracy.

[0008] To achieve the above-mentioned purpose, the technical solution adopted by the present invention is as follows:

[0009] A method for implementing a divider is provided, comprising the following steps:

[0010] Step 1: Use the data comparison module to compare the size of the dividend and the divisor, and determine the scaling factor and update the dividend and the divisor according to the size of the dividend and the divisor, and transmit the scaling factor to the shift iteration module;

[0011] Step 2: Use the shift iteration module to perform shift subtraction calculation, thereby realizing a divider and performing division iteration calculation;

[0012] Step 3: Use the quotient calculation module to inversely scale the result of the division performed by the shift iteration module to obtain the true quotient.

[0013] Preferably, when both the dividend and the divisor are greater than 0 in step one, first compare the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. Repeat the comparison of the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. When the dividend is less than the divisor, stop comparing, then exit the scaling step, and record the scaling factor as 0.

[0014] Preferably, when both the dividend and the divisor are less than 0 in step one, take the absolute values ​​of both the dividend and the divisor, and then compare the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value; repeat the comparison of the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. When the dividend is less than the divisor, stop the comparison, then jump out of the scaling step, and record the scaling factor as 0.

[0015] Preferably, when the dividend is greater than 0 and the divisor is less than 0 in step 1, first compare the dividend and the negative divisor. If the dividend is greater than or equal to the negative divisor, the divisor becomes twice the initial value; repeatedly compare the dividend and the negative divisor. If the dividend is greater than or equal to the negative divisor, the divisor becomes twice the initial value. When the dividend is less than the negative divisor, stop comparing and record the number of repeated comparisons.

[0016] Preferably, when the dividend is smaller than the negative divisor in step 1, the scaling step is directly skipped and the scaling factor is recorded as 0.

[0017] Preferably, when the dividend is less than 0 and the divisor is greater than 0 in step 1, first compare the negative dividend and divisor. If the negative dividend is greater than or equal to the divisor, the dividend becomes twice the initial value; repeatedly compare the negative dividend and divisor. If the negative dividend is greater than or equal to the divisor, the dividend becomes twice the initial value. Stop comparing when the negative dividend is less than the divisor, and record the number of repeated comparisons.

[0018] Preferably, when the negative dividend is smaller than the divisor in step one, the scaling step is directly exited and the scaling factor is recorded as 0; when the dividend is equal to 0 in step one, the division result is directly output as 0, and the scaling factor is recorded as 0; when the divisor is equal to 0 in step one, an error is directly reported, and the scaling factor is recorded as 0; when the dividend is smaller than the divisor in step one, the scaling step is exited and the scaling factor is recorded as 0.

[0019] Preferably, the shift iteration module performs the division iterative calculation process as follows: the shift iteration module works as follows: obtain the number of iterations of the divider from the outside, and set the number of iterations to rotate_times; set the intermediate loop parameter t to 1, and set the quotient result to 0; if the quotient result is less than 0, the quotient result becomes (1+t) times the initial value, and then subtract t from the obtained quotient result to obtain a new quotient result, and finally change t to half of the initial value; if the quotient result is greater than 0, the quotient result becomes (1-t) times the initial value, and then add t to the obtained quotient result to obtain a new quotient result, and finally change t to half of the initial value; repeat the operation when the quotient result is greater than 0 rotate_times times, and repeat the operation when the quotient result is less than 0 rotate_times times, and output the quotient result.

[0020] Preferably, the quotient calculation module includes the following steps: quotient_num obtained by the shift iteration module is calculated, and the scaling factor is shift_num, then , ending the process.

[0021] Preferably, the number of iterations rotate_times is any number between 12 and 18.

[0022] Preferably, the division of any two numbers is achieved through two shift and subtraction calculations.

[0023] Compared with the prior art, the technical solution of the present invention has the following advantages / benefits:

[0024] 1. The present invention realizes a divider by performing shift subtraction on the intermediate loop parameter t, which requires shift subtraction calculation, addition calculation and a small amount of judgment calculation. The real quotient can be obtained without any multiplier, thus saving computing resources.

[0025] 2. The present invention uses multi-type discrimination to formulate different calculation schemes and calculation logics for the divisor and dividend conditions that the divider may encounter, thereby reducing the computing resources required for the calculation, making the average error only 4.85× , greatly improving the calculation accuracy.

[0026] 3. The present invention circumvents the limitation on the relationship between the divisor and the dividend in the prior art by performing two shift subtraction calculations, and realizes the division of any two numbers. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0028] Figure 1 It is a flow chart of a method for implementing a divider of the present invention.

[0029] Figure 2 2 is an error simulation diagram of an embodiment of the present invention. DETAILED DESCRIPTION

[0030] In order to make the purpose, technical solutions and advantages of the present invention clearer, the technical solutions in the embodiments of the present invention are clearly and completely described below. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present invention. Therefore, the detailed description of the embodiments of the present invention provided below is not intended to limit the scope of the claimed invention, but merely represents the selected embodiments of the present invention.

[0031] Example 1: Figure 1 As shown, a method for implementing a divider includes the following steps:

[0032] Step 1: Use the data comparison module to compare the size of the dividend and the divisor, and determine the scaling factor and update the dividend and the divisor according to the size of the dividend and the divisor, and transmit the scaling factor to the shift iteration module;

[0033] Step 2: Use the shift iteration module to perform shift subtraction calculation, thereby realizing a divider and performing division iteration calculation;

[0034] Step 3: Use the quotient calculation module to inversely scale the result of the division performed by the shift iteration module to obtain the true quotient.

[0035] In step 1, the relationship between the divisor and the dividend faced by the data comparison module includes the following situations:

[0036] A1: Both the dividend and the divisor are greater than 0. At this time, the dividend and the divisor are compared first. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. Repeat the comparison of the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. When the dividend is less than the divisor, the comparison stops, then the scaling step is exited, and the scaling factor is recorded as 0.

[0037] B1: The dividend is greater than 0, and the divisor is less than 0; first compare the dividend and the negative divisor. If the dividend is greater than or equal to the negative divisor, the divisor becomes twice the initial value; repeatedly compare the dividend and the negative divisor. If the dividend is greater than or equal to the negative divisor, the divisor becomes twice the initial value. When the dividend is less than the negative divisor, stop comparing and record the number of repeated comparisons.

[0038] C1: The dividend is smaller than the negative divisor; in this case, the scaling step is directly skipped and the scaling factor is recorded as 0;

[0039] D1: The dividend is less than 0 and the divisor is greater than 0; first compare the negative dividend and divisor. If the negative dividend is greater than or equal to the divisor, the dividend becomes twice the initial value; repeat the comparison of the negative dividend and divisor. If the negative dividend is greater than or equal to the divisor, the dividend becomes twice the initial value. When the negative dividend is less than the divisor, stop comparing and record the number of repeated comparisons.

[0040] E1: The negative dividend is smaller than the divisor; in this case, the scaling step is directly skipped and the scaling factor is recorded as 0;

[0041] F1: The dividend is equal to 0; in this case, the division result is directly output as 0, and the scaling factor is recorded as 0;

[0042] G1: The divisor is equal to 0; in this case, an error is reported directly, and the scaling factor is recorded as 0

[0043] H1: The dividend is smaller than the divisor. In this case, the scaling step is directly skipped and the scaling factor is recorded as 0.

[0044] I1: If both the dividend and the divisor are less than 0, take the absolute values ​​of both the dividend and the divisor, and then compare the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value; repeat the comparison of the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. When the dividend is less than the divisor, stop the comparison, then jump out of the scaling step, and record the scaling factor as 0.

[0045] The process of step 2 is as follows: obtain the number of iterations of the divider rotate_times from the outside. The selection of the rotate_times parameter is closely related to the accuracy of the final divider. However, when the number of times this parameter is selected is large, it will cause large hardware resource overhead and large delay of the entire system. The usual choice is to rotate_times 12~18 times. And use the iterative shift module to set the intermediate loop parameter t to 1 and the result of the quotient to 0; if the result of the quotient is less than 0, the result of the quotient becomes (1+t) times of the initial value, and then subtract t from the result of the quotient to obtain a new result of the quotient, and finally change t to half of the initial value; if the result of the quotient is greater than 0, the result of the quotient becomes (1-t) times of the initial value, and then add t to the result of the quotient to obtain a new result of the quotient, and finally change t to half of the initial value; repeat the operation when the result of the quotient is greater than 0 rotate_times times, and repeat the operation when the result of the quotient is less than 0 rotate_times times, and output the result of the quotient.

[0046] Step 3 is as follows: Calculate the quotient obtained by the shift iteration module, use the quotient calculation module to set the scaling factor to shift_num, and the quotient result is , then calculate , ending the process.

[0047] The number of iterations rotate_times is any number between 12 and 18.

[0048] Two shift and subtraction calculations can realize the division of any two numbers, solving the technical problems of small usage range and limited usage scenarios in existing dividers.

[0049] Figure 2 The error that can be achieved when the above method is used to divide 100 random numbers (rotate_times is 15 times), from Figure 2 It can be found that the maximum error is less than 6× , the average error is only 4.85× , where error result is the error and number is a number.

[0050] The present invention only requires shifting, addition and a small amount of judgment, and does not require any multipliers, thus saving resources greatly.

[0051] Embodiment 2: This embodiment is a method for implementing a divider.

[0052] First, define the dividend as dividend_num and the divisor as divisor_num.

[0053] when: , , perform the following steps:

[0054] a1: compare the size of dividend_num and divisor_num;

[0055] a2: If it appears ,

[0056] Then ;

[0057] a3: Repeat steps a1 and a2 until , and record the number of times a1 and a2 are repeated rotate_times;

[0058] In particular, if step a2 appears directly , then let .

[0059] when: , , perform the following steps:

[0060] a1: Get The absolute value of

[0061] a2: Compare the dividend_num and divisor_num after taking the absolute value;

[0062] a3: If it appears ,

[0063] Then ;

[0064] a4: Repeat steps a2 and a3 until , and record the number of times a2 and a3 are repeated rotate_times;

[0065] In particular, if step a3 appears directly , then let .

[0066] when When , directly jump out of the scaling step and record the scaling factor shift_num=0.

[0067] when , , perform the following steps:

[0068] b1: compare the size of dividend_num and -divisor_num;

[0069] b2: If it appears ,

[0070] Then ;

[0071] B3: Repeat steps B1 and B2 until , directly jump out of the scaling step, and record the number of times b1 and b2 steps are repeated rotate_times;

[0072] Special, if step b2 appears directly , then let .

[0073] when When , directly jump out of the scaling step and record the scaling factor shift_num=0.

[0074] when , , perform the following steps:

[0075] c1: compare the size of -dividend_num and divisor_num;

[0076] c2: If ,

[0077] Then ;

[0078] C3: Repeat steps C1 and C2 until , and record the number of times c1 and c2 steps are repeated rotate_times;

[0079] Special, if it appears directly , then let .

[0080] when , then directly jump out of the scaling step and record the scaling factor shift_num=0.

[0081] When dividend_num=0, the division result is directly output as 0, and the scaling factor shift_num=0 is recorded.

[0082] When divisor_num=0, an error is reported directly and the scaling factor shift_num=0 is recorded.

[0083] The divider is then implemented using a shift-and-subtract calculation.

[0084] The number of iterations of the divider rotate_times is obtained from the outside. The selection of the rotate_times parameter is closely related to the accuracy of the final divider. However, when the number of times this parameter is selected is large, it will cause large hardware resource overhead and large delay of the entire system. The rotate_times used in this solution is 15 times.

[0085] First, initialize the middle loop parameter t=1, and initialize the quotient result quotient_num=0.

[0086] Determine whether dividend_num is less than 0

[0087] If dividend_num<0, then the following calculation is performed:

[0088]

[0089] Subtract t from the resulting quotient:

[0090]

[0091] Finally, t is shifted.

[0092] make ,

[0093] If dividend_num>0, then the following calculation is performed

[0094]

[0095] Then update the result of the quotient:

[0096]

[0097] Finally, shift t:

[0098] make ,

[0099] Finally, repeat all steps of the two branches in 3 rotate_times times and output quotient_num.

[0100] Will obtain Shift the bits to get the final true quotient result:

[0101] .

[0102] The above are only preferred embodiments of the present invention. It should be noted that the above preferred embodiments should not be regarded as limiting the present invention, and the protection scope of the present invention should be based on the scope defined by the claims. For ordinary technicians in this technical field, several improvements and modifications can be made without departing from the spirit and scope of the present invention, and these improvements and modifications should also be regarded as the protection scope of the present invention.

Claims

1. A method for implementing a divider, characterized in that: The following steps are involved: Step 1: Use the data comparison module to compare the size of the dividend and the divisor, and determine the scaling factor and update the dividend and the divisor according to the size of the dividend and the divisor, and transmit the scaling factor to the shift iteration module; Step 2: Use the shift iteration module to complete the shift subtraction calculation, and then implement the divider and perform the division iteration calculation; Step 3: Use the quotient calculation module to inversely scale the result of the division performed by the shift iteration module to obtain the true quotient; The shift iteration module performs the division iteration calculation process as follows: obtain the iteration number of the divider from the outside, set the iteration number to rotate_times; set the intermediate loop parameter t to 1, and set the quotient result to 0; Then determine whether dividend_num is less than 0, If dividend_num<0, then the following calculation is performed: Subtract t from the resulting quotient: Finally, t is shifted. make , If dividend_num>0, then the following calculation is performed Then update the result of the quotient: Finally, shift t: make , Finally, repeat all the steps of the above two branches rotate_times times and output quotient_num; Will obtain To shift; dividend_num is the dividend, divisor_num is the divisor, and quotient_num is the quotient.

2. The method for implementing a divider according to claim 1, wherein: When both the dividend and the divisor are greater than 0 in step 1, the dividend and the divisor are first compared. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. Repeat the comparison of the dividend and the divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. When the dividend is less than the divisor, the comparison is stopped, and then the scaling step is jumped out, and the scaling factor is recorded as 0. When the dividend and the divisor are both less than 0 in step 1, the absolute values ​​of the dividend and the divisor are taken, and then the dividend and the divisor are compared again. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. Repeatedly compare the dividend and divisor. If the dividend is greater than or equal to the divisor, the divisor becomes twice the initial value. When the dividend is less than the divisor, stop comparing, then jump out of the scaling step, and record the scaling factor as 0.

3. The method for implementing a divider according to claim 1, wherein: When the dividend is greater than 0 and the divisor is less than 0 in step 1, the dividend and the negative divisor are first compared. If the dividend is greater than or equal to the negative divisor, the divisor becomes twice the initial value; Repeatedly compare the dividend and the negative divisor. If the dividend is greater than or equal to the negative divisor, the divisor becomes twice the initial value. When the dividend is less than the negative divisor, stop comparing and record the number of repeated comparisons.

4. The method for implementing a divider according to claim 1, wherein: When the dividend is smaller than the negative divisor in step 1, the scaling step is directly skipped and the scaling factor is recorded as 0.

5. The method for implementing a divider according to claim 1, wherein: When the dividend is less than 0 and the divisor is greater than 0 in step 1, the negative dividend and the divisor are first compared. If the negative dividend is greater than or equal to the divisor, the dividend becomes twice the initial value. Repeatedly compare the negative dividend and divisor. If the negative dividend is greater than or equal to the divisor, the dividend becomes twice the initial value. When the negative dividend is less than the divisor, stop comparing and record the number of repeated comparisons.

6. The method for implementing a divider according to claim 1, characterized in that: When a negative dividend is smaller than the divisor in step one, the scaling step is directly exited and the scaling factor is recorded as 0; when the dividend is equal to 0 in step one, the division result is directly output as 0, and the scaling factor is recorded as 0; when the divisor is equal to 0 in step one, an error is directly reported, and the scaling factor is recorded as 0; when the dividend is smaller than the divisor in step one, the scaling step is exited and the scaling factor is recorded as 0.

7. The method for implementing a divider according to claim 1, characterized in that: The quotient value calculation module calculates the result of the quotient obtained by the shift iteration module, and the scaling factor is set to shift_num, then the result of the quotient is the result of the quotient obtained by the shift iteration module. times.

8. The method for implementing a divider according to claim 7, characterized in that: The number of iterations rotate_times is any number between 12 and 18.

Citation Information

Patent Citations

  • Division operation method and device

    CN102063284A

  • Division operation device for privacy calculation, data processing system and method

    CN113467752A