CN112181357A - Division operation method, device, electronic equipment and medium - Google Patents

Division operation method, device, electronic equipment and medium Download PDF

Info

Publication number
CN112181357A
CN112181357A CN202010908236.0A CN202010908236A CN112181357A CN 112181357 A CN112181357 A CN 112181357A CN 202010908236 A CN202010908236 A CN 202010908236A CN 112181357 A CN112181357 A CN 112181357A
Authority
CN
China
Prior art keywords
iteration
error
division
value
iteration value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010908236.0A
Other languages
Chinese (zh)
Inventor
吴锋
张立勇
钟万勰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Dalian University of Technology
Original Assignee
Dalian University of Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Dalian University of Technology filed Critical Dalian University of Technology
Priority to CN202010908236.0A priority Critical patent/CN112181357A/en
Priority to PCT/CN2020/117978 priority patent/WO2022047873A1/en
Publication of CN112181357A publication Critical patent/CN112181357A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/38Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
    • G06F7/48Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
    • G06F7/483Computations with numbers represented by a non-linear combination of denominational numbers, e.g. rational numbers, logarithmic number system or floating-point numbers
    • G06F7/487Multiplying; Dividing
    • G06F7/4873Dividing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/38Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
    • G06F7/48Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
    • G06F7/499Denomination or exception handling, e.g. rounding or overflow
    • G06F7/49942Significance control
    • G06F7/49947Rounding

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Mathematics (AREA)
  • Computing Systems (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Nonlinear Science (AREA)
  • Complex Calculations (AREA)

Abstract

The application discloses a division operation method, a division operation device, electronic equipment and a medium. The division operation method in the application comprises the following steps: obtaining a division parameter to be subjected to division operation, and obtaining a first iteration value; performing error analysis processing according to the first iteration value, and determining rounding operation required by the division parameter in the current iteration; continuing iterative processing according to the parameters after the rounding operation to obtain a second iterative value; if the second iteration value does not meet the precision requirement, the second iteration value is used as the first iteration value to repeatedly execute the steps until the second iteration value meets the precision requirement, and the second iteration value is output, so that the efficiency of the function iteration algorithm can be improved.

Description

Division operation method, device, electronic equipment and medium
Technical Field
The present application relates to the field of computing technologies, and in particular, to a method and an apparatus for division operation, an electronic device, and a medium.
Background
Division operation is one of the basic operations in a processor (including DSP and embedded chips) and is a very important functional component. In computer graphics, computer vision, visualization, geographic information systems, grid generation techniques and scientific computing, very high precision division operations (beyond that provided by computer hardware) are often required, at which point software is required to simulate floating-point division operations. Compared with floating-point addition, subtraction and multiplication, division operation is more complex and takes longer, so that the design of a calculation scheme of high-performance division is very important. At present, there are five main methods for division: a function iteration algorithm, a numerical loop algorithm, a very large radix algorithm, a table look-up method, and a variable computation period method. Of all these algorithms, the numerical loop algorithm and the function iteration method are the two most commonly used algorithms. The convergence rate of the digital loop algorithm is linear, while the convergence rate of the function iteration algorithm is quadratic.
Function iterative algorithms are widely used in the design of divisions in modern general-purpose processors. Obtaining the division parameter to be divided often requires providing an initial approximate value of a quotient, and then gradually approaches to an accurate quotient through a certain iterative format. A mature function iterative algorithm generally needs to give an initial approximation and an iterative format to perform iterative operation until an iterative result meets the accuracy requirement. However, when processing with a large amount of data is involved, the existing iterative algorithm has a serious problem of wasting computing resources, and the computational efficiency of the iterative algorithm needs to be improved urgently.
Disclosure of Invention
The application provides a division operation method, a division operation device, electronic equipment and a medium.
In a first aspect, a method of division operation is provided, including:
obtaining a division parameter to be subjected to division operation, and obtaining a first iteration value;
performing error analysis processing according to the first iteration value, and determining rounding operation required by the division parameter in the current iteration;
continuing iterative processing according to the division parameter after the rounding operation to obtain a second iterative value;
if the second iteration value does not meet the precision requirement, the second iteration value is used as the first iteration value to repeatedly execute the steps until the second iteration value meets the precision requirement, and the second iteration value is output.
In an optional implementation manner, the performing, according to the first iteration value, an error analysis process to determine a rounding operation that needs to be performed on the division parameter in the current iteration includes:
acquiring a first error of the first iteration value and a second error of the second iteration value;
and determining the rounding operation required to be carried out on the division parameter in the iteration according to the first error and the second error.
In an optional implementation, the determining, according to the first error and the second error, a rounding operation that needs to be performed on the division parameter in the current iteration includes:
determining a precision of a rounding operation of the first iteration value based on the precision of the first error; and determining the precision of the rounding operation of the divisor and/or dividend of the division operation according to the precision of the second error.
In an optional implementation, the determining, according to the first error and the second error, a rounding operation that needs to be performed on the division parameter in the current iteration includes:
and determining the rounding operation required to be carried out on the first iteration value and the divisor according to the index of the first error.
In an alternative embodiment, the first error is:
Figure BDA0002662305380000021
wherein xnIs the first iteration value, a is the divisor, NnIs a positive integer, EnRepresents a constant;
the determining, according to the exponent of the first error, a rounding operation required for the first iteration value and the divisor, includes:
determining the xnThe rounding operation to be performed is to round NnThe numbers after +1 bit are truncated;
determining that said a requires rounding by Nn+1The numbers after +1 bit are truncated.
In an optional embodiment, the method further comprises:
obtaining intermediate numbersAccording to
Figure BDA0002662305380000022
The above-mentioned
Figure BDA0002662305380000023
Is said xnObtained after the rounding operation is carried out, the
Figure BDA0002662305380000024
Obtaining the a after the rounding operation is carried out on the a;
e is to benIn Nn+1The number after +1 bit is truncated to obtain intermediate data after the rounding operation
Figure BDA0002662305380000031
The step of continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value includes:
according to the intermediate data after the rounding operation
Figure BDA0002662305380000032
And said
Figure BDA0002662305380000033
Calculating a second iteration value xn+1
In an alternative embodiment, the first error is:
Figure BDA0002662305380000034
wherein xnIs the first iteration value, a is the divisor, NnIs a positive integer, EnRepresents a constant;
the method further comprises the following steps:
determining a rounding operation required for the first error according to the exponent of the first error;
the step of continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value comprises:
according to the rounding operationCalculating a second iteration value x of the first error after the rounding operation, the first iteration value after the rounding operation, the divisor after the rounding operation, and other intermediate parameters after the rounding operationn+1
In a second aspect, there is provided a division operation apparatus, including:
the acquisition module is used for acquiring a division parameter to be subjected to division operation and acquiring a first iteration value;
the processing module is used for carrying out error analysis processing according to the first iteration value and determining rounding operation required by the division parameter in the current iteration;
the processing module is further configured to continue iterative processing according to the parameter after the rounding operation to obtain a second iterative value;
the processing module is further configured to, if the second iteration value does not meet the accuracy requirement, repeatedly execute the above steps with the second iteration value as the first iteration value;
and the output module is used for outputting the second iteration value until the second iteration value meets the precision requirement.
In a third aspect, an electronic device is provided, comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps as in the first aspect and any one of its possible implementations.
In a fourth aspect, there is provided a computer storage medium storing one or more instructions adapted to be loaded by a processor and to perform the steps of the first aspect and any possible implementation thereof.
The method comprises the steps of obtaining a division parameter to be subjected to division operation, obtaining a first iteration value, carrying out error analysis processing according to the first iteration value, determining rounding operation required by the division parameter in the current iteration, continuing iteration processing according to the parameter after the rounding operation, obtaining a second iteration value, and if the second iteration value does not meet the precision requirement, repeatedly executing the steps by taking the second iteration value as the first iteration value until the second iteration value meets the precision requirement, and outputting the second iteration value. Based on an error analysis theory, under the premise of ensuring the precision, invalid numbers beyond the error are rounded, so that numerical values of short word length and equal precision are substituted into an iteration rule for calculation, the waste of calculation resources can be greatly reduced, and the operation efficiency of a function iteration algorithm is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments or the background art of the present application, the drawings required to be used in the embodiments or the background art of the present application will be described below.
Fig. 1 is a schematic flowchart of a division operation method according to an embodiment of the present disclosure;
FIG. 2 is a schematic flow chart of another division method according to an embodiment of the present disclosure;
FIG. 3 is a diagram illustrating numerical values after a rounding operation in a Newton-Raphson algorithm process according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a division operation apparatus according to an embodiment of the present disclosure;
fig. 5 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the technical solutions of the present application better understood, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The terms "first," "second," and the like in the description and claims of the present application and in the above-described drawings are used for distinguishing between different objects and not for describing a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
The embodiments of the present application will be described below with reference to the drawings.
Referring to fig. 1, fig. 1 is a schematic flow chart of a division operation method according to an embodiment of the present application. The method can comprise the following steps:
101. obtaining a division parameter to be subjected to division operation, and obtaining a first iteration value.
The execution subject of the embodiments of the present application may be a division operation apparatus, and may be an electronic device, which in a specific implementation is a terminal, and may also be referred to as a terminal device, including but not limited to other portable devices such as a mobile phone, a laptop computer, or a tablet computer having a touch-sensitive surface (e.g., a touch screen display and/or a touch pad). It should also be understood that in some embodiments, the device is not a portable communication device, but is a desktop computer. In an alternative embodiment, the division operation method may be executed by a corresponding hardware module, such as a chip or a divider, or may alternatively be executed based on a software program.
In the embodiment of the application, the division operation is implemented by using a function iteration algorithm, and the main theoretical basis is an error analysis theory of the function iteration algorithm. In this embodiment of the application, the division parameter to be subjected to division operation may be from any application scenario that needs to be subjected to division operation, and may include one or more of a dividend, a divisor, each iteration value, and an error, and may be determined according to a used algorithm, which is not limited herein. The division operation method in the embodiment of the present application may be performed in the case of obtaining a specific division parameter. In the embodiment of the present application, assuming that the dividend is b and the divisor is a, the quotient is calculated by using a function iteration method, and the iteration format (1) is:
xn+1=f(a,b,xn);
wherein xnThe approximate quotient after the nth iteration is also referred to as the iteration value in each iteration.
The first iteration value may be any iteration value in an iteration process, including an initial iteration value x0
102. And carrying out error analysis processing according to the first iteration value, and determining the rounding operation required by the division parameter in the current iteration.
Specifically, in each iteration, the error of the iterative approximation value may be calculated based on the error analysis theory of the iteration format (1) used, and then, according to the error analysis theory, on the premise of ensuring the accuracy, the rounding operation may be performed on the invalid number beyond the error. The specific iterative format has a specific error analysis theory, and is not limited herein.
In an alternative embodiment, the step 102 includes:
acquiring a first error of the first iteration value and a second error of the second iteration value;
and determining the rounding operation required to be carried out on the division parameter in the current iteration according to the first error and the second error.
The above rounding operation may be understood as an operation of retaining the bits after the decimal point in any form. In the process of calculating the quotient, the quotient at each step is approximate, and the precision of the quotient can be given according to an error analysis theory. With approximate quotient xnFor example, 0.123456789012345, the approximate quotient decimal point is followed by a 15 digit number. Iterative algorithm in functionThe error of the approximation quotient can be calculated for each iteration. Suppose that the error of the approximation quotient 0.123456789012345 isnAnd 0.01, all the numbers after the 3 rd digit after the approximate quotient decimal point are practically useless and belong to invalid numbers, and if all the numbers participate in calculation, the calculation resources are wasted. The invalid numbers are cut off to obtain approximate quotient
Figure BDA0002662305380000064
Can be combined with
Figure BDA0002662305380000063
And (4) substituting the approximate quotient into an iterative format (1) of the algorithm for calculation.
The first error is any value that measures the accuracy of the first iteration value, such as an absolute difference, a relative error, and the like between the first iteration value and a true value, and is not limited herein. The second error is any value that measures the accuracy of the second iteration value, such as the absolute difference, relative error, etc. of the second iteration value and the true value, and is not limited herein.
Since the accuracy of 0.12 and the accuracy of 0.123456789012345 are the same, the next iteration value x is not affectedn+1The accuracy of (2). But it is clear that the calculation with 0.12 is much simpler than the calculation with 0.123456789012345. Meanwhile, according to the error analysis theory, the error can be measured at xn+1Before being calculated, its accuracy is known (for ease of explanation, assume xn+1Has an error ofn+10.0001). Then according ton+1It can be seen that, for example, other values (e.g., a and b) required in the iterative format may be used in the actual calculation, and the rounding operation may be performed without loss of accuracy. Due to the fact that
Figure BDA0002662305380000061
And
Figure BDA0002662305380000062
is longer than a, b and xnThe word length of the method is short, and the calculation is simpler and quicker.
The division parameter may include one or more of a dividend b, a divisor a, each iteration value, and an error, and may be determined according to an algorithm used, which is not limited herein. The division operation method in the embodiment of the present application may be performed in the case of obtaining a specific division parameter.
In one embodiment, an initial iteration value x is set0The following steps may be performed:
1) obtaining x according to the error analysis theory of the adopted function iterative algorithmnError of (2)nAnd xn+1Error of (2)n+1,n=0,1,…;
2) According to the error, the iteration parameter (such as x) related to the iteration format is determined on the premise of ensuring the precisionnA and b, etc.) to obtain a short word length value (corresponding to the value of the word length)
Figure BDA0002662305380000071
And
Figure BDA0002662305380000072
)。
optionally, the determining, according to the first error and the second error, a rounding operation that needs to be performed on the division parameter in the current iteration includes:
determining a precision of a rounding operation of the first iteration value based on the precision of the first error; and determining the precision of rounding operations of the divisor, the dividend and other iteration parameters related to the iteration format of the division operation according to the precision of the second error.
In particular, the first iteration value x may be setnIs set to be in error with the firstnWith the same precision, a, b, and other iteration parameters involved in the iteration format are set to the second errorn+1With the same precision, to perform the iterative operation.
103. And continuing iterative processing according to the parameters after the rounding operation to obtain a second iterative value.
According to the error analysis theory, under the premise of ensuring the precision, invalid numbers beyond the error are rounded, and the obtained parameters after the rounding operation are substituted into the iteration rule for calculation, so that the calculation complexity is simplified, and the calculation efficiency is improved.
104. If the second iteration value does not meet the precision requirement, the second iteration value is used as the first iteration value to repeatedly execute the steps until the second iteration value meets the precision requirement, and the second iteration value is output.
In the embodiment of the application, for a function iteration algorithm capable of giving error analysis, iteration is sequentially circulated according to an iteration format (1), and a more accurate approximate quotient can be obtained in each iteration. The error and the precision of the iteration result of each step can be judged according to the error analysis result, so that whether the iteration is finished or not is judged. The basic iterative algorithm is not described in detail here.
See fig. 2 for a flow diagram of a division method. The iterative algorithm steps in fig. 2 include: 21. substituting the initial value into an iteration rule; 22. carrying out iterative calculation to obtain an approximate value; 23. calculating an error; ending under the condition that the judgment error is accepted; if the error is judged not to be accepted, executing 24, and according to the error, eliminating invalid numbers in the relevant numerical values; 25. and substituting the rounded numerical value into an iteration rule. Multiple iterations may be performed through the above steps.
In each iteration, the division operation method in the embodiment of the application calculates the error of the iteration approximate value based on the error analysis theory of the adopted iteration format, and then performs rounding operation on invalid numbers beyond the error according to the error analysis theory on the premise of ensuring the precision, so that the numerical values of short word length and equal precision are substituted into the iteration rule for calculation, the calculation complexity can be simplified, and the calculation efficiency is improved.
To further describe the application of the division operation method in the embodiment of the present application, the following description is made in detail in conjunction with different iterative algorithms (formats).
In one embodiment, the rounding operations required for the first iteration value and the divisor may be determined based on the exponent of the first error.
The division operation method can be applied to different iterative algorithms, and because of different iterative rules, the error calculation may also be different, and further, the rounding operation on the related data in the calculation may also be different.
In an alternative embodiment, the first error is:
Figure BDA0002662305380000081
wherein xnIs the first iteration value, a is the divisor, NnIs a positive integer, EnRepresents a constant;
n is aboven+1The method is an index corresponding to an error in the (n + 1) th iteration, and the rounding operation required for determining the first iteration value and the divisor according to the index of the first error comprises the following steps:
determining the above xnThe rounding operation to be performed is to round NnThe numbers after +1 bit are truncated;
determining the rounding operation required for a is to round Nn+1The numbers after +1 bit are truncated.
Specifically, the application can be further illustrated by taking a Newton-Rapshon algorithm as an example. Let a be the divisor, b be the dividend, and the quotient be Q. The Newton-Rapshon algorithm is used to calculate x 1 ÷ a and then the quotient Q is calculated b × x in one multiplication. The Newton-Rapshon algorithm is a function iteration algorithm, and an initial value x needs to be provided during calculation0Then, the following iterative format is used for calculation:
xn+1=xn×(2-a×xn);
definition of xnHas an error ofn=1-a×xnThen the above formula can be expressed as:
xn+1=xn×(1+n);
xn+1error of (2)n+1Can be expressed as:
Figure BDA0002662305380000082
as can be seen from the above equation, the Newton-Rapshon algorithm converges secondarily. If the initial iteration value x0Choose good, then initial error0It is small and the number of iterations is small. In the current method for improving the Newton-Rapshon algorithm, the initial iteration value x is mostly aimed at0The selection of (2) is improved. According to the method, the Newton-Rapshon algorithm is improved by using the error analysis result, the calculation amount can be reduced, and the calculation efficiency of the division is improved.
In the process of carrying out division operation by adopting a Newton-Rapshon algorithm, because errors generated by each iteration are different, the iteration precision gradually becomes better along with the increase of the iteration times. While in the initial few iterations, xnIs not good, so xnIt is not necessary to store all the numbers, but only the number corresponding to the precision, and thus the multiplication a × x is calculatednIn time, all numbers do not need to be calculated, and invalid numbers exceeding the error can be discarded, thereby reducing the calculation amount. The details will be described below. Assuming that the reciprocal x of a is 1 ÷ a, a is represented as: a is Ax 2MWherein | A | is more than or equal to 1 and less than or equal to 2, and M is an integer. If | a ≦ 1, a ═ a. Since the reciprocal of a is actually equal to a ═ A-1×2-MThus, without loss of generality, discussion can be made only with respect to 1 ≦ a ≦ 2. An initial approximation of 0 ≦ x may be provided at this time0Less than or equal to 1, and the specific calculation steps are as follows:
1) according to the initial iteration value x0Calculating an initial error0And it is expressed as follows according to a scientific counting method:
Figure BDA00026623053800000912
wherein-N0Is that0Index of (1), N0Is a positive integer.
2) Iterate by n-0, 1, …. x is the number ofnHas an error ofnAn index of-NnThus x will benIn NnThe numbers after +1 are truncated, representing this step as:
Figure BDA0002662305380000091
where Roundoff () represents a rounding operation. After rounding off
Figure BDA0002662305380000092
Is still the error of
Figure BDA0002662305380000093
Of the order of (d), and therefore does not affect the accuracy of the next iteration, but does so
Figure BDA0002662305380000094
Word length is greater than xnThe word length of (2) is much smaller, and the data processing amount is simplified. The rounding method of the rounding operation may be the rounding method provided in IEEE745 standard, and may also use "quasi-round 1 in" method, "constant one" method, etc., which is not limited in the embodiments of the present application.
Further optionally, the method further comprises:
obtaining intermediate data
Figure BDA0002662305380000095
Above is xnObtained after the rounding operation, the
Figure BDA0002662305380000096
The rounding operation is carried out for the a;
e is to benIn Nn+1The numbers after +1 bit are truncated to obtain intermediate data after the rounding operation
Figure BDA0002662305380000097
The above-mentioned continuing the iterative process according to the parameter after the rounding operation, and obtaining the second iterative value includes:
according to the intermediate data after the rounding operation
Figure BDA0002662305380000098
And the above
Figure BDA0002662305380000099
Calculating a second iteration value xn+1
In the Newton-Raphson algorithm, a second iteration value x is obtainedn+1Intermediate data may be first calculated from the divisor and the previous iteration value, including the divisor after each rounding operation described above
Figure BDA00026623053800000910
And the iteration value
Figure BDA00026623053800000911
A corresponding rounding operation may still be used in the calculation of the intermediate data. Continuing by way of example, the following steps may be seen:
3) according to the error analysis theory of the Newton-Raphson algorithm, the error of each iteration is reduced according to the square, so that xn+1Must be twice the last error index, so there is Nn+1=2Nn. But in calculating xn+1When it is needed to use
Figure BDA0002662305380000101
Wherein
Figure BDA0002662305380000102
The word length of (a) is very short, while a retains all the exact digits, which are very long. Because of xn+1It is still not accurate and therefore it is not necessary to use the exact a, and a can be rounded to fit N in an+1The numbers after +1 are truncated to give
Figure BDA0002662305380000103
4) By using
Figure BDA0002662305380000104
And
Figure BDA0002662305380000105
computing
Figure BDA0002662305380000106
According to
Figure BDA0002662305380000107
And enCan calculate
Figure BDA0002662305380000108
But enIs obtained by multiplication. In general, subtraction has little effect on the word length of the result during calculation, and multiplication often results in a significant increase in word length. Because of xn+1With a precision of
Figure BDA0002662305380000109
So that e can be controlled with guaranteed accuracynA rounding operation is performed, so that:
Figure BDA00026623053800001010
5) finally calculate xn+1
Figure BDA00026623053800001011
If xn+1And returning to 2) to continue calculating when n is equal to n + 1.
The division operation method in the embodiment of the application is suitable for a Newton-Raphson algorithm, and the rounding operation combined with the characteristics of the algorithm can reduce the data calculation amount without influencing the accuracy and improve the processing efficiency.
In an alternative embodiment, the application is further described by taking the Markstein algorithm as an example.
Optionally, the first error is:
Figure BDA00026623053800001012
wherein xnIs the first iteration value, a is the divisor, NnIs a positive integer, EnRepresents a constant;
the method further comprises the following steps:
determining a rounding operation required for the first error according to the exponent of the first error;
the above-mentioned continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value includes:
calculating a second iteration value x based on the first error after the rounding operation and the first iteration value after the rounding operationn+1
Similar to the application of the Newton-Raphson algorithm, the above steps may correspond to the Markstein algorithm, the iterative format of which is as follows:
xn+1=xn+xn×n,n+1=1-a×xn+1
the method is used for a Markstein algorithm, and the specific calculation steps are as follows:
1) according to the initial iteration value x0Calculating an initial error0And it is expressed as follows according to a scientific counting method:
Figure BDA0002662305380000111
wherein-N0Is that0Index of (1), N0Is a positive integer. According to N0X is to be0In N0The numbers after +1 are truncated, representing this step as:
Figure BDA0002662305380000112
2) according to the formula n ═ n0,1, … iterate. Firstly, tonA rounding operation is performed. The Markstein algorithm is second order convergent, so xn+1Has an error of
Figure BDA0002662305380000113
Magnitude. To ensure to be pairednAfter rounding operation, the calculation x is not influencedn+1To a precision ofnRetention of 2NnA bit significant digit whose rounding operation is expressed as:
Figure BDA0002662305380000114
3) computing
Figure BDA0002662305380000115
And to enA rounding operation is performed. For the same reason, to ensure xn+1Has an error of
Figure BDA0002662305380000116
Magnitude, pair enThe rounding operation is performed by reserving 2NnBit significant digits, rounded by operations represented as
Figure BDA0002662305380000117
4) Computing
Figure BDA0002662305380000118
And to xn+1Performing rounding operations
Figure BDA0002662305380000119
5) The rounding operation is performed on a next. The purpose of rounding a is to calculate xn+2According to the quadratic convergence property of the algorithm, xn+2Has an error of
Figure BDA00026623053800001110
Magnitude. Therefore, to ensure that the calculation of x is not affected after the rounding operation is performed on an+2With a retained 4NnBit significant digits, rounded by operations represented as
Figure BDA00026623053800001111
6) Computing
Figure BDA00026623053800001112
Error of (2)
Figure BDA00026623053800001113
wherein-Nn+1Is thatn+1Is used as an index of (1). If it is judged that
Figure BDA00026623053800001114
And returning to 2) to continue calculating when n is equal to n + 1.
The above two embodiments of the iterative algorithm were tested experimentally. The experiment is carried out in a epsilon [1,2 ]]Any 100000 points are taken, the reciprocal of the 100000 points is calculated, 0.5 is taken as an initial value, and each point is iterated for 6 times. Meanwhile, the traditional Newton-Raphson algorithm and Markstein are adopted for calculation. The calculation result shows that the prior Newton-Raphson algorithm calculates 100000 points, and the average error after 6 iterations is 0.45 multiplied by 10-16Standard deviation of 0.66X 10-16. The prior Markstein algorithm calculates 100000 points, and the average error after 6 iterations is 0.45 multiplied by 10-16Standard deviation of 0.65X 10-16. The average error of the Newton-Raphson algorithm adopted in the embodiment of the application is 0.52 multiplied by 10-16Standard deviation of 0.72X 10-16(ii) a The average error of the Markstein algorithm adopted in the embodiment of the application is 0.37 multiplied by 10-16Standard deviation of 0.56X 10-16The error magnitude is not different, the difference of specific errors is small, and even the error of the Markstein algorithm in the embodiment of the application is smaller in the same iteration times.
Again taking a 1.477134351152927 as an example, see a Newton-Raphson algorithm as shown in fig. 3The numerical values after the rounding operation in the process are shown schematically. Wherein, when the Newton-Raphson function iterative algorithm based on the error theory is adopted to calculate 1/1.477134351152927, the rounded correlation value (is
Figure BDA0002662305380000121
And
Figure BDA0002662305380000122
)。
Figure BDA0002662305380000123
and
Figure BDA0002662305380000124
the expressions of (c) are described with reference to the corresponding formulas in the previous embodiments, respectively. All values are represented in 32-bit binary, the first row giving the name of the value, the second row giving the exponent of the value, and the remaining rows giving the mantissa of the value. Invalid numbers in the mantissa are rounded and labeled 0. Taking column 2 as an example, column 2 gives
Figure BDA0002662305380000125
32 bit binary representation of a value, where line 2 is-1, representing
Figure BDA0002662305380000126
And rows 3 to 32 represent
Figure BDA0002662305380000127
Only 3, 4 rows have numbers, and the remaining 5 to 30 rows are all 0.
Figure BDA0002662305380000128
Is to x0The mantissa of the value obtained after the rounding operation only retains two digits.
As can be seen from fig. 3, when the method in the embodiment of the present application is used to calculate 1a, the word length of the value used in each iteration is different. By rounded iteration value
Figure BDA0002662305380000129
For example, the initial value (x)0) Has only 2 bits, second step (x)1) It is 4 bits and is incremented sequentially until the last step, there are 32 bits. Similarly, in operation
Figure BDA00026623053800001210
And
Figure BDA00026623053800001211
as well as so. However, in a general iterative algorithm, all iteration steps are calculated by 32 bits, so that compared with the current function iteration calculation method, the division calculation method in the embodiment of the application avoids unnecessary calculation, and greatly improves the calculation efficiency.
The embodiment of the application is based on an error analysis theory, and invalid numbers beyond errors can be rounded off on the premise of keeping the precision in each step of iteration process of an iterative algorithm, so that numerical values of short word length and equal precision are substituted into an iteration format for calculation, the calculation complexity is simplified, particularly the calculation complexity of multiplication in the iteration process is improved, and the calculation efficiency is improved. The method can be applied to any function iteration method with a given error analysis, and the iteration method in the two embodiments is only a part of examples and does not limit the scope of the embodiments of the present application. That is, for any function iteration method capable of providing error analysis, the division operation method in the embodiment of the present application may be used to round the relevant numerical values in the iteration process according to the error and precision requirements, so as to substitute the numerical values with short word length and equal precision into the iteration format for calculation, thereby greatly simplifying the complexity of calculation and improving the calculation efficiency, which is not described in detail in the embodiment of the present application.
The method provided by the embodiment of the application can be used for not only a division calculation part in a microprocessor, but also an algorithm design which needs high precision and adopts software to simulate division operation, can be applied to various application scenes containing iterative algorithms, such as floating point number division operation, greatly simplifies the calculation complexity and the calculation resource waste, and improves the calculation efficiency. The application scenario of the method is not limited in the embodiment of the application.
Based on the description of the division operation method embodiment, the embodiment of the application also discloses a division operation device. Referring to fig. 4, the division operation apparatus 400 includes:
an obtaining module 410, configured to obtain a division parameter to be subjected to division operation, and obtain a first iteration value;
a processing module 420, configured to perform error analysis processing according to the first iteration value, and determine a rounding operation that needs to be performed on the division parameter in the current iteration;
the processing module 420 is further configured to continue iterative processing according to the parameter after the rounding operation to obtain a second iterative value;
the processing module 420 is further configured to, if the second iteration value does not meet the accuracy requirement, repeatedly execute the above steps with the second iteration value as the first iteration value;
an output module 430, configured to output the second iteration value until the second iteration value meets the accuracy requirement.
According to an embodiment of the present application, each step involved in the method of the embodiment shown in fig. 1 may be performed by each module in the division operation apparatus 400 shown in fig. 4, and is not described herein again.
The division operation apparatus 400 in the embodiment of the present application may acquire a division parameter to be divided, acquire a first iteration value, perform error analysis processing according to the first iteration value, determine a rounding operation that needs to be performed on the division parameter in the current iteration, continue iteration processing according to the parameter after the rounding operation, acquire a second iteration value, and if the second iteration value does not satisfy a precision requirement, repeat the above steps with the second iteration value as the first iteration value until the second iteration value satisfies the precision requirement, and output the second iteration value. Based on an error analysis theory, under the premise of ensuring the precision, invalid numbers beyond the error are rounded, so that numerical values of short word length and equal precision are substituted into an iteration rule for calculation, the waste of calculation resources can be greatly reduced, and the operation efficiency of a function iteration algorithm is improved.
Based on the description of the method embodiment and the device embodiment, the embodiment of the application further provides an electronic device. Referring to fig. 5, the electronic device 500 includes at least a processor 501, an input device 502, an output device 503, and a computer storage medium 504. The processor 501, the input device 502, the output device 503, and the computer storage medium 504 in the terminal may be connected by a bus or other means.
A computer storage medium 504 may be stored in the memory of the terminal, the computer storage medium 504 being used for storing a computer program comprising program instructions, and the processor 501 being used for executing the program instructions stored by the computer storage medium 504. The processor 501 (or CPU) is a computing core and a control core of the terminal, and is adapted to implement one or more instructions, and specifically, adapted to load and execute the one or more instructions so as to implement a corresponding method flow or a corresponding function; in one embodiment, the processor 501 described above in the embodiments of the present application may be used to perform a series of processes, including the method in the embodiment shown in fig. 1, and the like.
An embodiment of the present application further provides a computer storage medium (Memory), where the computer storage medium is a Memory device in a terminal and is used to store programs and data. It is understood that the computer storage medium herein may include a built-in storage medium in the terminal, and may also include an extended storage medium supported by the terminal. The computer storage medium provides a storage space that stores an operating system of the terminal. Also stored in this memory space are one or more instructions, which may be one or more computer programs (including program code), suitable for loading and execution by processor 501. The computer storage medium may be a high-speed RAM memory, or may be a non-volatile memory (non-volatile memory), such as at least one disk memory; and optionally at least one computer storage medium located remotely from the processor.
In one embodiment, one or more instructions stored in a computer storage medium may be loaded and executed by processor 501 to perform the corresponding steps in the above embodiments; in particular implementations, one or more instructions in the computer storage medium may be loaded by processor 501 and executed to perform any step of the method in fig. 1, which is not described herein again.
According to the embodiment of the application, the complexity of the function iteration algorithm for processing the division problem, especially the calculation complexity of multiplication in the iteration process, can be simplified, and therefore the calculation efficiency is improved. Compared with a general function iteration algorithm, the method adds a rounding operation step with adaptability and is easy to implement. The division component in the processor 501 and the software modules which need high-precision division operation (exceeding the precision provided by computer hardware) such as computer graphics, computer vision, visualization, geographic information systems, grid generation technology, scientific calculation and the like can have high application value, and are not described herein again.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and modules may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the division of the module is only one logical division, and other divisions may be possible in actual implementation, for example, a plurality of modules or components may be combined or integrated into another system, or some features may be omitted, or not performed. The shown or discussed mutual coupling, direct coupling or communication connection may be an indirect coupling or communication connection of devices or modules through some interfaces, and may be in an electrical, mechanical or other form.
Modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The procedures or functions according to the embodiments of the present application are wholly or partially generated when the computer program instructions are loaded and executed on a computer. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored on or transmitted over a computer-readable storage medium. The computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wire (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)), or wirelessly (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that includes one or more of the available media. The usable medium may be a read-only memory (ROM), or a Random Access Memory (RAM), or a magnetic medium, such as a floppy disk, a hard disk, a magnetic tape, a magnetic disk, or an optical medium, such as a Digital Versatile Disk (DVD), or a semiconductor medium, such as a Solid State Disk (SSD).

Claims (10)

1. A method of division, comprising:
obtaining a division parameter to be subjected to division operation, and obtaining a first iteration value;
performing error analysis processing according to the first iteration value, and determining rounding operation required by the division parameter in the current iteration;
continuing iterative processing according to the division parameter after the rounding operation to obtain a second iterative value;
if the second iteration value does not meet the precision requirement, the second iteration value is used as the first iteration value to repeatedly execute the steps until the second iteration value meets the precision requirement, and the second iteration value is output.
2. The method of dividing operation according to claim 1, wherein said performing error analysis processing according to the first iteration value to determine a rounding operation required to be performed on the division parameter in the current iteration comprises:
acquiring a first error of the first iteration value and a second error of the second iteration value;
and determining the rounding operation required to be carried out on the division parameter in the iteration according to the first error and the second error.
3. The method of claim 2, wherein determining the rounding required to perform the division parameter in the current iteration based on the first error and the second error comprises:
determining a precision of a rounding operation of the first iteration value based on the precision of the first error; and determining the precision of the rounding operation of the divisor and/or dividend of the division operation according to the precision of the second error.
4. The method of claim 2, wherein determining the rounding required to perform the division parameter in the current iteration based on the first error and the second error comprises:
and determining the rounding operation required to be carried out on the first iteration value and the divisor according to the index of the first error.
5. The method of division as claimed in claim 4, wherein the first error is:
Figure FDA0002662305370000021
wherein xnIs the first iteration value, a is the divisor, NnIs a positive integer, EnRepresents a constant;
the determining, according to the exponent of the first error, a rounding operation required for the first iteration value and the divisor, includes:
determining the xnThe rounding operation to be performed is to round NnThe numbers after +1 bit are truncated;
determining that said a requires rounding by Nn+1The numbers after +1 bit are truncated.
6. The method of claim 5, further comprising:
obtaining intermediate data
Figure FDA0002662305370000022
The above-mentioned
Figure FDA0002662305370000023
Is said xnObtained after the rounding operation is carried out, the
Figure FDA0002662305370000024
Obtaining the a after the rounding operation is carried out on the a;
e is to benIn Nn+1The number after +1 bit is truncated to obtain intermediate data after the rounding operation
Figure FDA0002662305370000025
The step of continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value includes:
according to the intermediate data after the rounding operation
Figure FDA0002662305370000026
And said
Figure FDA0002662305370000027
Calculating a second iteration value xn+1
7. The method of division as claimed in claim 4, wherein the first error is:
Figure FDA0002662305370000028
wherein xnIs the first iteration value, a is the divisor, NnIs a positive integer, EnRepresents a constant;
the method further comprises the following steps:
determining a rounding operation required for the first error according to the exponent of the first error;
the step of continuing iterative processing according to the parameter after the rounding operation to obtain a second iterative value comprises:
calculating a second iteration value x based on the first error after the rounding operation, the first iteration value after the rounding operation, the divisor after the rounding operation, and other intermediate parameters after the rounding operationn+1
8. A division operation apparatus, comprising:
the acquisition module is used for acquiring a division parameter to be subjected to division operation and acquiring a first iteration value;
the processing module is used for carrying out error analysis processing according to the first iteration value and determining rounding operation required by the division parameter in the current iteration;
the processing module is further configured to continue iterative processing according to the parameter after the rounding operation to obtain a second iterative value;
the processing module is further configured to, if the second iteration value does not meet the accuracy requirement, repeatedly execute the above steps with the second iteration value as the first iteration value;
and the output module is used for outputting the second iteration value until the second iteration value meets the precision requirement.
9. An electronic device, comprising a memory and a processor, the memory storing a computer program that, when executed by the processor, causes the processor to perform the steps of the method of division as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, in which a computer program is stored which, when executed by a processor, causes the processor to carry out the steps of the method of division as claimed in any one of claims 1 to 7.
CN202010908236.0A 2020-09-02 2020-09-02 Division operation method, device, electronic equipment and medium Pending CN112181357A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202010908236.0A CN112181357A (en) 2020-09-02 2020-09-02 Division operation method, device, electronic equipment and medium
PCT/CN2020/117978 WO2022047873A1 (en) 2020-09-02 2020-09-27 Division operation method and apparatus, electronic device, and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010908236.0A CN112181357A (en) 2020-09-02 2020-09-02 Division operation method, device, electronic equipment and medium

Publications (1)

Publication Number Publication Date
CN112181357A true CN112181357A (en) 2021-01-05

Family

ID=73925562

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010908236.0A Pending CN112181357A (en) 2020-09-02 2020-09-02 Division operation method, device, electronic equipment and medium

Country Status (2)

Country Link
CN (1) CN112181357A (en)
WO (1) WO2022047873A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120011185A1 (en) * 2010-07-06 2012-01-12 Silminds, Llc. Rounding unit for decimal floating-point division
CN105389157A (en) * 2015-10-29 2016-03-09 中国人民解放军国防科学技术大学 Goldschmidt algorithm-based floating-point divider
CN106250098A (en) * 2015-06-12 2016-12-21 Arm 有限公司 For controlling the device and method rounded off when performing floating-point operation
CN109298848A (en) * 2018-08-29 2019-02-01 中科亿海微电子科技(苏州)有限公司 The subduplicate circuit of double mode floating-point division
CN111104092A (en) * 2019-12-06 2020-05-05 北京多思安全芯片科技有限公司 Fast divider and division operation method

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB2540215B (en) * 2015-07-10 2020-09-09 Advanced Risc Mach Ltd An apparatus and method for performing division
CN105955706B (en) * 2016-06-16 2018-06-26 武汉芯泰科技有限公司 A kind of divider and division operation method
CN111399803B (en) * 2019-01-03 2022-07-15 北京小米松果电子有限公司 Division operation method, device, storage medium and electronic equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120011185A1 (en) * 2010-07-06 2012-01-12 Silminds, Llc. Rounding unit for decimal floating-point division
CN106250098A (en) * 2015-06-12 2016-12-21 Arm 有限公司 For controlling the device and method rounded off when performing floating-point operation
CN105389157A (en) * 2015-10-29 2016-03-09 中国人民解放军国防科学技术大学 Goldschmidt algorithm-based floating-point divider
CN109298848A (en) * 2018-08-29 2019-02-01 中科亿海微电子科技(苏州)有限公司 The subduplicate circuit of double mode floating-point division
CN111104092A (en) * 2019-12-06 2020-05-05 北京多思安全芯片科技有限公司 Fast divider and division operation method

Also Published As

Publication number Publication date
WO2022047873A1 (en) 2022-03-10

Similar Documents

Publication Publication Date Title
US6138135A (en) Propagating NaNs during high precision calculations using lesser precision hardware
US20160313976A1 (en) High performance division and root computation unit
US8914431B2 (en) Range check based lookup tables
US9996345B2 (en) Variable length execution pipeline
De Dinechin et al. Multiplicative square root algorithms for FPGAs
US9983850B2 (en) Shared hardware integer/floating point divider and square root logic unit and associated methods
CN103914276A (en) Fixed point division circuit utilizing floating point architecture
Isupov Using floating-point intervals for non-modular computations in residue number system
US6182100B1 (en) Method and system for performing a logarithmic estimation within a data processing system
CN114296682A (en) Floating point number processing device, floating point number processing method, electronic equipment, storage medium and chip
CN114139693A (en) Data processing method, medium, and electronic device for neural network model
Chen High‐order Taylor series approximation for efficient computation of elementary functions
CN112835551A (en) Data processing method for processing unit, electronic device, and computer-readable storage medium
US9612800B2 (en) Implementing a square root operation in a computer system
CN112181357A (en) Division operation method, device, electronic equipment and medium
US10459689B2 (en) Calculation of a number of iterations
CN116166217A (en) System and method for performing floating point operations
Bajger et al. Low-error, high-speed approximation of the sigmoid function for large FPGA implementations
US8407274B2 (en) Machine division
CN115469829B (en) Arithmetic device and exponent arithmetic method based on arithmetic circuit
US9311272B1 (en) System and method for faster division
US9454345B1 (en) Apparatus for faster division
Fu et al. Low latency divider using ensemble of moving average curves
CN118302744A (en) Floating point logarithmic system scaling system for machine learning
JP4192547B2 (en) Calculation method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination