A resource reuse type transcendental function operation implementation method
By using a resource-reuse-based transcendental function operation method, the problems of high hardware resource consumption and long computation time are solved, achieving efficient and accurate transcendental function operation, which is suitable for data-intensive and real-time applications.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-21
- Publication Date
- 2026-03-24
AI Technical Summary
Existing technologies for implementing transcendental function operations suffer from high hardware resource consumption, long computation time, and insufficient accuracy, making them particularly difficult to meet the requirements of data-intensive and real-time applications.
A resource-reuse-based transcendental function operation method is adopted, including preprocessing, table lookup, calculation, and postprocessing steps. By reusing hardware resources such as adders/subtractors and multipliers, the operation of trigonometric functions, exponential functions, and logarithmic functions is realized, and the operation of hyperbolic functions is realized by adding floating-point adders/subtractors and multipliers.
It achieves efficient resource utilization for transcendental function operations with an error of less than 2ulp, meeting design accuracy requirements, and reaches a frequency of 270MHz under SMIC 40nm process, making it suitable for data-intensive and real-time applications.
Smart Images

Figure CN115658008B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of transcendental function operation technology, and particularly relates to a resource-reusable transcendental function operation implementation method. Background Technology
[0002] Today, transcendental functions have an increasingly wide range of applications, including image and speech processing, scientific computing, digital signal processing, and real-time motor control, which involve a large number of trigonometric functions, inverse trigonometric functions, exponential functions, and logarithmic operations.
[0003] These functions are mathematically distinct from algebraic functions, as they cannot be obtained through a finite number of linear operations on variables, and are therefore called transcendental functions.
[0004] Performing transcendental function calculations using general-purpose multiplication and addition units to execute corresponding software algorithms requires a long computation time and consumes significant computational resources. Therefore, designing dedicated hardware units for implementing transcendental functions is crucial for data-intensive and real-time applications. For example, TI's TMX320 series DSP chips include a dedicated fast computation unit for implementing transcendental functions.
[0005] The main methods for implementing transcendental functions in hardware include series convergence, lookup table methods, and the CORDIC (Coordinate Rotation Digital Computer) algorithm. Different hardware architectures are required for series convergence of different transcendental functions, and achieving high precision necessitates the superposition of many series, which consumes significant hardware resources. Using lookup tables requires storing large amounts of data, also resulting in high hardware consumption. The CORDIC algorithm has the advantage of small circuit area, requiring only shift registers and adders / subtractors for computation. However, its disadvantage is its slow convergence speed; typically, only one significant digit is added per iteration. For single-precision floating-point operations, the CORDIC algorithm requires a considerable number of clock cycles to achieve the required precision. Summary of the Invention
[0006] The purpose of this invention is to provide a method for implementing resource-reusable transcendental function operations to solve the aforementioned technical problems.
[0007] To solve the above-mentioned technical problems, the specific technical solution of the resource reuse type transcendental function operation implementation method of the present invention is as follows:
[0008] A method for implementing resource-reusable transcendental function operations includes a preprocessing step, a table lookup step, a calculation step, and a postprocessing step.
[0009] The preprocessing step performs corresponding data processing according to the type of the operation function and feeds the processed data into the other three steps for operation.
[0010] The table lookup step searches for the corresponding table based on the type of the operation function, obtains the polynomial coefficients, and sends them to the calculation step.
[0011] The calculation step performs a finite number of multiplications and additions on the preprocessed data and the coefficients given after looking up the table, and sends the results to the post-processing step.
[0012] The post-processing step performs corresponding data post-processing according to the type of the operation function, obtains the result, and outputs it.
[0013] Furthermore, trigonometric functions, exponential functions with base e, and logarithmic operations are all implemented using second-order polynomials based on table lookup steps.
[0014] Further, it includes input compression, the input compression step comprising:
[0015] Compress the inputs of the sine and cosine functions to [0, 0.5);
[0016] Compress the input range of the arctangent function to [0, 1);
[0017] Exponential function e x According to the formula Let y = e x x∈(-∞,+∞) transforms into y=2 x For operations x∈[0,1), the floating-point number a×2i is equal to the exponent value of a in its floating-point representation +i;
[0018] The input range of the logarithmic function is compressed to [1, 2).
[0019] Furthermore, the inputs to the preprocessing step are floating-point input values `input` and `mode`. Based on the `mode` value, the input data is processed accordingly: trigonometric functions convert the input number to a fixed-point number, and then trigonometric identities transform the input to the specified range [0, 0.5). Finally, the high 7 bits and low 16 bits of `sin_data_qn` are output to the lookup table step and the calculation step; the exponential function first converts the input to a fixed-point number and then processes it through the first multiplier. The multiplication is performed, and the high 7 bits and low 16 bits of the 8-bit integer part exp_int and the fractional part exp_data_qn are output to the post-processing step, the table lookup step, and the calculation step, respectively. The logarithmic function takes the exponent number exp of the floating-point input, performs exp*ln2 multiplication, and outputs the result ln_add directly to the post-processing step. The high 7 bits and low 16 bits of the 23-bit mantissa ln_data_qn of the floating-point input are output to the table lookup step and the calculation step, respectively.
[0020] Furthermore, the multipliers for the preprocessing steps of logarithmic and exponential functions are shared.
[0021] Furthermore, the table lookup step includes: after receiving the address from the preprocessing module, searching for and outputting the binomial y = ax from the pre-generated sine and cosine function tables, arctangent function tables, exponential function tables, and logarithmic function tables. 2 The quadratic coefficient a, linear coefficient b, and zero-order coefficient c of +bx+c are then used to select the fitting parameters corresponding to the currently specified operation from five outputs based on the mode code, and output them to the calculation steps.
[0022] Furthermore, the calculation steps are performed sequentially in a fixed-point calculation manner as follows: the multiplier first performs the operation a×x, the adder / subtractor obtains the result (a×x)±b, the multiplier obtains the result of the operation (a×x+b)×x, the adder obtains the result (a×x+b)×x+c, and finally, when truncating the data, the adder performs a rounding operation to improve the accuracy, and then the rounded data is output to the post-processing steps.
[0023] Furthermore, the post-processing step includes: receiving the sign bit, the calculation result of the preprocessing step, and the fixed-point calculation result of the calculation step, and then performing the final corresponding processing on the received data according to the mode code: the trigonometric function converts the fixed-point result into a floating-point number and combines it with the sign bit before outputting it; the exponential function converts the fixed-point result into a floating-point number, adds the integer part of the exponent given by the preprocessing module to the exponent part, and combines it with the sign bit before outputting it; the logarithmic function adds the fixed-point result to exp*ln2 given by the preprocessing module, converts it into a floating-point number, and combines it with the sign bit before outputting it.
[0024] The resource-reuse-based transcendental function operation implementation method of the present invention has the following advantages: By reusing hardware resources such as adders / subtractors and multipliers, the present invention can implement the sine function y = sin(πx), the cosine function y = cos(πx), and the arctangent function. Exponential function y = e x The device calculates the logarithmic function y = ln(x). Furthermore, by adding a floating-point adder / subtractor and a floating-point multiplier, it can also perform calculations of hyperbolic functions y = sinh(x), y = cosh(x), and y = atanh(x). The error of each function implemented by the device is less than 2ulp, meeting the design accuracy requirements. In terms of performance, under SMIC 40nm process technology, the frequency of this 4-cycle transcendental function calculation method can reach 270MHz. Attached Figure Description
[0025] Figure 1This is a schematic diagram of the implementation method of transcendental function operation of the present invention;
[0026] Figure 2 This is a schematic diagram of the preprocessing steps of the present invention;
[0027] Figure 3 This is a schematic diagram of the table lookup steps of the present invention;
[0028] Figure 4 This is a schematic diagram of the calculation steps of the present invention;
[0029] Figure 5 This is a schematic diagram of the post-processing steps of the present invention. Detailed Implementation
[0030] To better understand the purpose, structure, and function of this invention, the following detailed description of a resource reuse-type transcendental function operation implementation method of this invention is provided in conjunction with the accompanying drawings.
[0031] like Figure 1 As shown, the present invention provides a resource-reuse-type transcendental function operation implementation method, including a preprocessing step, a table lookup step, a calculation step, and a post-processing step. The preprocessing step performs corresponding data processing based on the type of the operation function and sends the processed data to the other three steps for calculation. The table lookup step searches for the corresponding table based on the type of the operation function, obtains the polynomial coefficients, and sends them to the calculation step. The calculation step performs a finite number of multiplications and additions on the preprocessed data and the coefficients obtained from the table lookup, and sends the results to the post-processing step. The post-processing step performs corresponding data post-processing based on the type of the operation function, obtains the results, and outputs them.
[0032] Trigonometric functions, exponential functions with base e, and logarithmic operations are all implemented using second-order polynomials based on table lookup steps.
[0033] Based on the periodicity of the sine and cosine functions, we can compress the inputs of y = sin(πx) and y = cos(πx) to the range [-1, 1). Furthermore, the sine function is symmetric about the origin, while the cosine function is symmetric about y, thus further compressing the input range to [0, 1). Simultaneously, the graph of the sine function in the range [0, 1] is symmetric about the line x = 0.5, and the graph of the cosine function in the range [0, 1] is symmetric about the point (0, 0.5), ultimately compressing the computational input to [0, 0.5).
[0034] In practical applications, the input of the arctangent function is not large, generally between -1 and 1. Based on the odd function property of the arctangent function, we compress the input range to [0, 1).
[0035] For the exponential function ex According to the formula (where i is) The integer part, d is From the decimal part, we can see that we can express y = e x x∈(-∞,+∞) transforms into y=2 x Operations on x∈[0,1). According to the IEEE 754 floating-point representation, the floating-point number a×2i is equal to the exponent value of a in its floating-point representation +i.
[0036] For the logarithmic function ln(x), according to the formula (where exp is the exponent of the floating-point number x and man is the mantissa) It can be seen that we can compress the input range of y = ln(x), x∈(0,+∞) to [1,2).
[0037] The hardware architecture diagram of the entire transcendental function computation device is as follows: Figure 1 As shown, the system is divided into four modules based on their respective functions: a preprocessing module (Pre), a table lookup module (Lut), a calculation module (Calu), and a postprocessing module (Post). These modules respectively complete four steps: input preprocessing, looking up the fitting parameter table, calculating the function value based on the fitting parameters, and output processing. In terms of specific computational structure design, the resource-reuse transcendental function operation method of this invention adopts a fixed-point algorithm, which consumes fewer resources compared to floating-point arithmetic devices.
[0038] The hardware architecture of the preprocessing module is as follows: Figure 2 As shown, the system includes a floating-point to fixed-point conversion module, a subtractor, a first multiplier, an inverter, a first selector, a second selector, a third selector, a fourth selector, and a selection logic module. The floating-point to fixed-point conversion module outputs a fixed-point number to the first selector, the second selector, the inverter, and the selection logic module. The selection logic module determines the output of the first selector (a fixed-point number or its inverted form) based on the characteristics of the fixed-point number. The subtractor subtracts 127 from the exponent (exp) of the floating-point number to be logarithmically processed to obtain the true exponent (IEEE standard floating-point exponent definition) and outputs the result to the second selector. Because the multipliers required for the logarithmic and exponential function preprocessing stages can be shared, the second and third selectors select the appropriate multipliers for the first multiplier based on the function type of the operation. The fourth selector then outputs the corresponding computation address to the lookup table module and the number to be computed to the computation module, based on the function type of the operation. Meanwhile, other outputs of the preprocessing module, such as the integer part of the exponential function, the addend of the logarithmic function, and the sign bit of the floating-point input, are connected to the postprocessing module.
[0039] The inputs for the preprocessing step are floating-point input values `input` and `mode`. The preprocessing step performs corresponding processing on the input data based on the `mode` value: trigonometric functions convert the input number to a fixed-point number, then transform it to the specified range [0, 0.5) using trigonometric identities, and finally output the high 7 bits and low 16 bits of `sin_data_qn` to the lookup table step and the calculation step; the exponential function first converts the input to a fixed-point number and then processes it through the first multiplier. The multiplication is performed, and the high 7 bits and low 16 bits of the 8-bit integer part exp_int and the fractional part exp_data_qn are output to the post-processing step, the table lookup step, and the calculation step, respectively. The logarithmic function takes the exponent of the floating-point input exp, performs exp*ln2 multiplication, and outputs the result ln_add directly to the post-processing step. The high 7 bits and low 16 bits of the 23-bit mantissa ln_data_qn of the floating-point input are output to the table lookup step and the calculation step, respectively. The multipliers needed for the logarithmic and exponential function preprocessing steps can be shared.
[0040] The hardware architecture of the table lookup module is as follows: Figure 3 As shown, this includes four pre-generated lookup tables (sine and cosine function table, arctangent function table, exponential function table, and logarithmic function table) and a fifth selector. The lookup steps include: after receiving the address from the preprocessing module, searching for and outputting the binomial y = ax from the four pre-generated tables. 2 The coefficients of the quadratic term *a*, the linear term *b*, and the zero-order term *c* are calculated for +bx+c. Then, based on the mode code, the fitting parameters corresponding to the currently specified operation are selected from five outputs and output to the computation steps.
[0041] The hardware architecture of the computing module is as follows: Figure 4 As shown, the calculation includes a sixth selector, an adder / subtractor, a second multiplier, a third multiplier, a first adder, and a second adder. The calculation steps are performed sequentially using fixed-point computation: the sixth selector outputs the corresponding result to the adder / subtractor based on the function type; the second multiplier first performs the operation a×x; the adder / subtractor obtains the result (a×z)±b (since the coefficients of the quadratic terms in the sine and cosine function fitting coefficients are all less than zero, while the coefficients of the quadratic terms in other functions are all greater than zero, subtraction is performed when performing sine function operations, and addition is performed when performing other function operations); the third multiplier obtains the result (a×x+b)×z; and the first adder obtains the result (a×x+b)×x+c. This is then summed with the result of calculating each term individually, resulting in ax. 2 Compared to +bx+c, this saves one multiplication operation. Finally, when truncating the data, a second adder performs rounding to improve precision before outputting the rounded data to the post-processing step.
[0042] The hardware architecture of the post-processing module is as follows: Figure 5As shown, the system includes a seventh selector, an eighth selector, a fixed-point to floating-point conversion module, a third adder, a fourth adder, and a symbolic processing logic module. The seventh selector outputs the corresponding result to the fixed-point to floating-point conversion module based on the function type of the operation. The fixed-point to floating-point conversion module converts the calculation result output by the calculation module (if it's a logarithmic function operation, the result is first added to exp*ln2 using the third adder) into a floating-point number, and outputs the resulting floating-point number to the symbolic processing logic or the fourth adder (for exponential function operations). The fourth adder is used to add ln_add (equivalent to multiplying by 2) to the exponent of the floating-point number obtained from the exponential function operation. i The symbol processing logic module and the fourth adder output the result to the eighth selector, which outputs the corresponding floating-point result according to the function type of the operation, thus obtaining the operation result.
[0043] The post-processing steps include: receiving the sign bit, calculation result, and fixed-point calculation result from the preprocessing step; then, based on the mode code, performing the final processing on the received data: the trigonometric function converts the fixed-point result into a floating-point number and combines it with the sign bit before outputting; the exponential function converts the fixed-point result into a floating-point number, adds the integer part of the exponent provided by the preprocessing module to the exponent part, and combines it with the sign bit before outputting; and the logarithmic function adds the fixed-point result to exp*ln2 provided by the preprocessing module, converts it into a floating-point number, and combines it with the sign bit before outputting.
[0044] The resource-reuse-type transcendental function operation implementation method of the present invention can directly implement trigonometric functions (sine and cosine functions, arctangent functions) and exponential functions e. x And operations with the logarithmic function ln(x). For example, when implementing trigonometric function operations, the steps are as follows: First, the preprocessing step converts the input fixed-point number to a floating-point number, then performs range conversion according to the properties of trigonometric functions, selecting the data itself or its inverted form for operation and table lookup. The table lookup step looks up the table based on the address output by the preprocessing module, obtains the coefficients, and outputs them to the calculation module. The calculation step performs a finite number of fixed-point multiplications and additions on the number to be calculated and the coefficients, and outputs the fixed-point results to the post-processing module. The post-processing step converts the obtained fixed-point number to a floating-point number and then performs symbolic logic processing to obtain the final floating-point operation result.
[0045] In addition, this device can be connected to floating-point arithmetic hardware to perform hyperbolic function operations. For hyperbolic functions, after performing the aforementioned exponential or logarithmic operations using this device, the corresponding floating-point addition / subtraction / multiplication is performed to obtain the corresponding calculation result.
[0046] According to the formula When calculating hyperbolic sine and cosine functions, one can first use a transcendental function calculation device to calculate e. x With e -xThen perform another floating-point addition / subtraction, and finally perform a floating-point multiplication with the constant 0.5 to obtain the final result.
[0047] According to the formula To calculate the hyperbolic arctangent function, you first need to perform floating-point addition / subtraction of 1+x and 1-x, then use the transcendental function calculation device to calculate ln(1+x) and ln(1-x), then perform floating-point addition / subtraction on the result, and finally perform floating-point multiplication with the constant 0.5 to obtain the final result.
[0048] In summary, by reusing hardware resources such as adders / subtractors and multipliers, the resource-reuse transcendental function operation implementation method of this invention can realize the sine function y = sin(πx), the cosine function y = cos(πx), and the arctangent function. Exponential function y = e x The device is used to calculate the logarithmic function y = ln(x). Furthermore, by adding a floating-point adder / subtractor and a floating-point multiplier, it can also perform calculations of hyperbolic functions y = sinh(x), y = cosh(x), and y = atanh(x). Verification shows that the error of this transcendental function calculation method for each function is less than 2ulp, meeting the design accuracy requirements. In terms of performance, using SMIC's 40nm process, the frequency of this 4-cycle transcendental function calculation method can reach 270MHz.
[0049] It is understood that the present invention has been described through some embodiments, and those skilled in the art will recognize that various changes or equivalent substitutions can be made to these features and embodiments without departing from the spirit and scope of the invention. Furthermore, under the teachings of the present invention, these features and embodiments can be modified to adapt to specific situations and materials without departing from the spirit and scope of the invention. Therefore, the present invention is not limited to the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of this application are within the protection scope of the present invention.
Claims
1. A method for implementing resource-reuse-type transcendental function arithmetic, applied to a resource-reuse-type transcendental function arithmetic device, characterized in that, The resource-reuse transcendental function arithmetic device is divided into four modules: a preprocessing module, a table lookup module, a calculation module, and a post-processing module. These modules respectively complete the preprocessing, table lookup, calculation, and post-processing steps. The preprocessing module includes a floating-point to fixed-point converter, a subtractor, a first multiplier, an inverter, a first selector, a second selector, a third selector, a fourth selector, and a selection logic module. The floating-point to fixed-point converter outputs a fixed-point number to the first selector, the second selector, the inverter, and the selection logic module. The selection logic module determines the output of the first selector based on the characteristics of the fixed-point number. The subtractor is used to subtract 127 from the exponent exp of the floating-point number to be logarithmically operated on to obtain the actual exponent, and outputs the result to the second selector. The second and third selectors select the corresponding multipliers according to the function type of the operation and send them to the first multiplier for operation. The fourth selector then outputs the corresponding calculation address to the lookup table module and the number to be calculated to the calculation module according to the function type of the operation. The other outputs of the preprocessing module are connected to the postprocessing module. The resource reuse type transcendental function operation implementation method includes a preprocessing step, a lookup table step, a calculation step, and a postprocessing step. The preprocessing step performs corresponding data processing according to the type of the operation function and feeds the processed data into the other three steps for operation. The inputs for the preprocessing step are floating-point input values `input` and `mode`. Based on the `mode` value, the input data is processed accordingly: trigonometric functions convert the input numbers to fixed-point numbers, and then trigonometric identities are used to transform the input to a specified range. Finally, the high 7 bits and low 16 bits of sin_data_qn are output to the lookup table step and the calculation step; the exponential function first converts the input to a fixed-point number and then performs the calculation using the first multiplier. The multiplication is performed, and then the high 7 bits and low 16 bits of the 8-bit integer part exp_int and the fractional part exp_data_qn are output to the post-processing step, the table lookup step, and the calculation step, respectively; the logarithmic function takes the exponent of the floating-point input exp and then performs... The multiplication is performed and the result ln_add is directly output to the post-processing step. The high 7 bits and low 16 bits of the 23-bit mantissa ln_data_qn of the floating-point input are output to the table lookup step and the calculation step, respectively. The first multiplier is shared in the preprocessing steps for logarithmic and exponential functions; The table lookup step searches for the corresponding table based on the type of the operation function, obtains the polynomial coefficients, and sends them to the calculation step. The calculation step performs a finite number of multiplications and additions on the preprocessed data and the coefficients given after looking up the table, and sends the results to the post-processing step. The post-processing step performs corresponding data post-processing according to the type of the operation function, obtains the result, and outputs it.
2. The method for implementing resource reuse-type transcendental function operations according to claim 1, characterized in that, Trigonometric functions, exponential functions with base e, and logarithmic operations are all implemented using second-order polynomials based on table lookup steps.
3. The method for implementing resource reuse-type transcendental function operations according to claim 1, characterized in that, This includes input compression, the input compression steps of which include: Compress the inputs of sine and cosine functions to ; Compress the input range of the arctangent function to ; Exponential function According to the formula ,Will Transform into In the operation, the floating-point number a × 2i is equal to the exponent value of a in its floating-point representation + i; The input range of the logarithmic function is compressed to .
4. The method for implementing resource reuse-type transcendental function operations according to claim 3, characterized in that, The table lookup step includes: after receiving the address from the preprocessing module, searching for and outputting the binomial from the pre-generated sine and cosine function tables, arctangent function tables, exponential function tables, and logarithmic function tables. The quadratic coefficient a, the linear coefficient b, and the zero-order coefficient c are obtained; then, according to the mode code, the fitting parameters corresponding to the currently specified operation are selected from the five outputs and output to the calculation steps.
5. The method for implementing resource reuse-type transcendental function operations according to claim 3, characterized in that, The calculation steps are performed sequentially using a fixed-point calculation method: the multiplier first performs... The arithmetic operators and adders / subtractors are obtained. ) As a result, the multiplier obtains The result of the operation, the adder obtains As a result, when finally extracting the data, an adder is used to perform rounding to improve accuracy, and then the rounded data is output to the post-processing step.
6. The method for implementing resource reuse-type transcendental function operations according to claim 3, characterized in that, The post-processing steps include: receiving the sign bit from the preprocessing step, the calculation result from the preprocessing step, and the fixed-point calculation result from the calculation step; then, the post-processing step performs the final corresponding processing on the received data according to the mode code: the trigonometric function converts the fixed-point result into a floating-point number and combines it with the sign bit before outputting; the exponential function converts the fixed-point result into a floating-point number, adds the integer part of the exponent provided by the preprocessing module to the exponent part, and combines it with the sign bit before outputting; the logarithmic function combines the fixed-point result with the integer part of the exponent provided by the preprocessing module... After addition, the numbers are converted to floating-point numbers and then combined with the sign bit before being output.
Citation Information
Patent Citations
Resource reuse type transcendental function operation implementation device
CN115617307A