Reciprocal operation solving method and system
Technical Field
The present application relates to the field of digital circuit technologies, and in particular, to a reciprocal operation solution method and system.
Background
Digital circuits are circuits that use digital signals to perform arithmetic and logical operations on digital quantities. The reciprocal operation is an operation frequently encountered in digital circuits, and belongs to division operation.
In the implementation of a digital circuit, a general division operation occupies a very large amount of hardware resources, and thus, the division operation circuit is also an operation unit that needs to be avoided as much as possible in the implementation of the digital circuit. However, in some applications where the use of reciprocal operations is unavoidable, we often do not need to obtain a very precise value, but only an approximation thereof. For example, in an AGC (automatic Gain Control) circuit of a digital circuit, it is not necessary to obtain a very precise Gain, and the final Gain G = Vref/Vest is: the reference level amplitude is divided by the actual detected estimated level amplitude, and if one divider circuit is used, the area cost of the divider circuit alone may be greater than the entire automatic gain control logic, thus increasing circuit cost.
Disclosure of Invention
In view of this, the present application provides a reciprocal operation solving method and system, so as to overcome the problems of large hardware resource occupation and high circuit cost of division operation in the prior art.
In order to achieve the above object, the present application provides the following technical solutions:
a method of solving reciprocal operations, comprising:
decomposing a denominator in a function to be solved into an exponential part and a decimal part meeting a first preset condition by a separation circuit;
approximating, by an inverse approximation circuit, an inverse of the fractional part with a piecewise function that meets a second preset condition;
and multiplying the piecewise function and the exponential part by utilizing a multiplication circuit to calculate an approximate value of the function to be solved.
Preferably, the decomposing, by the separation circuit, the denominator in the function to be solved into an exponential part and a fractional part meeting a first preset condition includes:
moving the decimal point of the binary data corresponding to the denominator to the left or to the right until the moved data meets the first preset condition, and recording the data as a decimal part;
the number of bits of the decimal point movement is noted to obtain the exponent portion.
Preferably, the first preset condition is not less than 0.5 and less than 1, or equal to 0.
Preferably, the approximating, by an inverse approximation circuit, the inverse of the fractional part by a piecewise function meeting a second preset condition includes:
and according to a linear approximation principle, approximately representing the reciprocal of the fractional part by using a piecewise function meeting a second preset condition.
A system for solving reciprocal operations, comprising: a separation circuit, a reciprocal approximation circuit, and a multiplication circuit, wherein,
the separation circuit is used for decomposing a denominator in a function to be solved into an exponential part and a decimal part meeting a first preset condition;
the reciprocal approximation circuit is used for approximating the reciprocal of the decimal part by a piecewise function meeting a second preset condition;
the multiplication circuit is used for utilizing the piecewise function to multiply with the exponential part to calculate the approximate value of the function to be solved.
Preferably, the separation circuit includes: a mobile module and a recording module, wherein,
the moving module is used for moving the decimal point of the binary data corresponding to the denominator to the left or to the right until the moved data meet the first preset condition;
and the recording module is used for recording the moved data meeting the first preset condition as a decimal part and recording the number of bits moved by the decimal point to obtain an exponential part.
Preferably, the first preset condition is not less than 0.5 and less than 1, or equal to 0.
Preferably, the reciprocal approximation circuit is specifically configured to approximate the reciprocal of the fractional part by using a piecewise function meeting a second preset condition according to a linear approximation principle.
According to the technical scheme, the application provides a reciprocal operation solving method and a reciprocal operation solving system, wherein the solving method comprises the following steps: decomposing a denominator in a function to be solved into an exponential part and a decimal part meeting a first preset condition by a separation circuit; approximating, by an inverse approximation circuit, an inverse of the fractional part with a piecewise function that meets a second preset condition; and utilizing a multiplication circuit to multiply the piecewise function and the exponential part to calculate an approximate value of the function to be solved. The solving method converts reciprocal operation in the digital circuit into simple multiplication operation, avoids the use of a division circuit in the digital circuit, and reduces the circuit cost.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flowchart of a method for solving reciprocal operations according to an embodiment of the present application;
FIG. 2 is a data storage format of an 8-bit integer 28 according to an embodiment of the present disclosure;
FIG. 3 is a graph showing the comparison between the 1/f accurate value and the approximate value provided in the first embodiment of the present application;
FIG. 4 is a diagram illustrating an error evaluation between the 1/f accurate value and the approximate value provided in the first embodiment of the present application;
fig. 5 is a schematic structural diagram of a system for solving reciprocal operations according to a second embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, 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 invention.
In order to solve the problems of large hardware resource occupation and high circuit cost of division operation in the prior art, the application provides a reciprocal operation solving method and a reciprocal operation solving system, and the specific scheme is as follows:
example one
A solution method for reciprocal operation is provided in an embodiment of the present application, as shown in fig. 1, fig. 1 is a flowchart of the solution method for reciprocal operation provided in the embodiment of the present application. The method comprises the following steps:
s101: decomposing a denominator in a function to be solved into an exponential part and a decimal part meeting a first preset condition by a separation circuit;
in this application, the splitting circuit decomposing the denominator in the function to be solved into an exponential part and a fractional part meeting a first preset condition may include:
moving the decimal point of the binary data corresponding to the denominator to the left or to the right until the moved data meets a first preset condition, and recording the data as a decimal part;
the number of bits of the decimal point shift is noted to obtain the exponent portion.
In the present application, the first preset condition is not less than 0.5 and less than 1, or equal to 0.
Specifically, the denominator value of the reciprocal is first decomposed into a fractional part f and an exponential part n:
Value=f×2 n (1)
wherein f is more than or equal to 0.5 and less than 1 or f =0;
it should be noted that the reciprocal operation can be expressed as a function f (x) =1/x, i.e., the reciprocal of the denominator x (the variable value is the denominator x here). The denominator is broken down into a fractional part and an exponential part by a circuit.
Since data is stored in binary in the circuit, it is reasonable to decompose the value into a fractional part and an exponential part, and since any one data exists in binary form in the digital circuit, it is also very natural to decompose this data into two pieces, represented as an integer part and a fractional part, respectively. The exponent part n is easy to determine, just by how many bits the decimal point needs to be moved to the left or right, and the fraction part still uses the original data structure, but the position of the decimal point is changed.
Specifically, taking an 8-bit integer 28 as an example, as shown in fig. 2, fig. 2 is a data storage format of the 8-bit integer 28 according to an embodiment of the present application. Among the binary numbers, MSB (Most Significant Bit) is the highest weighted Bit, similar to the leftmost digit in a decimal number. Typically, the MSB is located at the leftmost side of the binary number, and the LSB (Least Significant Bit) is located at the rightmost side of the binary number. If MSB =1, the data is a negative value, and if MSB =0, the data is a non-negative value.
To get a qualified fraction, the fraction point needs to be shifted 5 bits to the left, so n =5; the decimal point has moved to the left of the largest non-zero bit, resulting in a fractional part of 0.875, so the value can be decomposed to 0.875 × 2 5 。
The reciprocal value 1/value =2 of the value -5 X (1/0.875). The power of 2 can be completed by simple shift operation, so that the reciprocal of a number value is mainly the reciprocal of a fraction part after decomposition of reciprocal denominator, that is, the reciprocal of any number can be solved as the reciprocal of a number between 0.5 and 1. This can be approximated by a simple piecewise function, where accuracy allows, thereby greatly simplifying the implementation of the circuit.
S102: the reciprocal of the fractional part is approximately expressed by a reciprocal approximation circuit by utilizing a piecewise function which meets a second preset condition;
in the application, the reciprocal approximation circuit approximates the reciprocal of the fractional part by using a piecewise function meeting a second preset condition according to a linear approximation principle.
In the present application, to simplify the implementation of the circuit, the approximation is done by a simple piecewise function, where accuracy allows.
The function is: y is 1 =1/f,0.50≤f<1
A piecewise function may be used:
to approximate, wherein, y 2 Is a function y 1 The piecewise approximation function of. x is a number between 0.50 and 1, a, b, c, d are constants selected by the piecewise function;
specifically, the selection criteria of the constants are the following two:
the piecewise function obtained by using the set of constants can be better approximated as the function y 1 ;
The set of constants is to be as simple as possible in circuit implementation if condition 1) is satisfied.
For example, we choose x =0.75, a = -2.5, b = -3.25, c = -1.5, d = -2.5 to approximate a value of 1/f. Fig. 3 is a graph showing a comparison relationship between an accurate value and an approximate value of 1/f provided in an embodiment of the present application, where two curves respectively show the accurate value and the approximate value of 1/f, a solid line is the accurate value of 1/f in an interval of [0.5,1.0 ], and a dotted line is the approximate value obtained by approximation using a two-stage linear function. FIG. 4 shows that the error between the 1/f exact value and the approximate value provided in the first embodiment of the present application has been converted to a dB value, and it can be seen that the error between the reciprocal and the true value obtained by the piecewise approximation method is within 0.5 dB (within 6%), which is sufficient for many applications that do not require exact values.
S103: and multiplying the piecewise function and the exponential part by using a multiplication circuit to calculate an approximate value of the function to be solved.
The inverse of the data value, i.e. the function to be solved:
multiplication operation is common in circuit design, and all places needing division operation can be converted into multiplication operation and reciprocal operation to be completed.
It should be noted that, in the present application, two segments of the approximation function in the reciprocal approximation calculation may be selected, but not limited to two-segment function approximation; the approximation function in the reciprocal approximation calculation can be a linear function or other functions; the coefficients a, b, c and d of the first-order approximation function selected in the reciprocal approximation calculation can be selected from the values in the present example, but are not limited to the values in the present example, and for different applications, constant values meeting the application precision requirement are selected, and once the constant values are selected, the values are determined; the circuit simplification method in the application is suitable for all rational numbers and is not limited to integers; the present application may be used, but is not limited to, in digital circuits, as well as in software programs.
Example two
On the basis of the first embodiment, the second embodiment of the present application provides a reciprocal solution system, as shown in fig. 5, fig. 5 is a schematic structural diagram of the reciprocal solution system provided in the second embodiment of the present application, and the system includes: a separation circuit 201, a reciprocal approximation circuit 202, and a multiplication circuit 203, wherein,
the separation circuit 201 is used for decomposing a denominator in a function to be solved into an exponential part and a decimal part meeting a first preset condition;
in the present application, the separation circuit may include: a mobile module and a recording module, wherein,
the moving module is used for moving the decimal point of the binary data corresponding to the denominator to the left or to the right until the moved data meet a first preset condition;
and the recording module is used for recording the moved data meeting the first preset condition as a decimal part and recording the number of the moved bits of the decimal point to obtain an exponential part.
Specifically, the first preset condition is not less than 0.5 and less than 1, or equal to 0.
A reciprocal approximation circuit 202 for approximating the reciprocal of the fractional part decomposed by the separation circuit 201 by using a piecewise function conforming to a second preset condition;
the multiplication circuit 203 is configured to multiply the piecewise function obtained by the reciprocal approximation circuit 202 by the exponential part obtained by decomposition by the separation circuit 201, and calculate an approximation value of the function to be solved.
The reciprocal approximation circuit 202 is specifically configured to approximate the reciprocal of the fractional part by using a piecewise function conforming to a second preset condition according to a linear approximation principle.
The same or similar parts as the first embodiment can be referred to each other, and are not described in detail in this embodiment.
According to the technical scheme, the method and the system for solving the reciprocal operation are provided, the reciprocal operation and the division operation in the digital circuit are converted into simple multiplication operation, the division circuit in the digital circuit is avoided, and therefore the circuit cost is reduced.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising one of 8230; \8230;" 8230; "does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.