Floating point variable processing method and device, computer equipment and storage medium

By embedding a coprocessor of floating point computing unit in the main processor, directly obtaining and processing floating point variables, the problem of low floating point data processing efficiency of existing trigonometric function computing units is solved, and more efficient floating point data processing is achieved .

CN119473215APending Publication Date: 2025-02-18SUZHOU WATECH ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411620350.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The existing trigonometric function calculation unit is less efficient when processing floating point data, requires multiple iterations and frequently fetches instructions, resulting in slow operation speed.

Method used

By embedding a coprocessor of floating point computing unit in the main processor, the pending floating point variable is directly obtained using preset floating point instructions and processed in the main processor. The method includes converting the floating point variable into a fixed point variable, performing iterative calculations until the calculation requirements are met, and then reflecting the result and writing back to the floating point register.

Benefits of technology

This greatly shortens the access delay and increases the iterative calculation amount within a unit clock cycle, thereby improving the efficiency of floating-point data processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473215A_ABST
    Figure CN119473215A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the technical field of computer data processing, in particular to a floating point variable processing method and device, computer equipment and a storage medium, and the floating point variable processing method comprises the steps: obtaining a to-be-processed floating point variable from a coprocessor based on a preset floating point instruction, and converting the floating point variable into a fixed point variable; mapping the to-be-processed floating point variable to a corresponding coordinate interval in the preset coordinate space according to the quadrant of the to-be-processed floating point variable in the preset coordinate space, and determining the initial direction rotation amount of the fixed point variable in the rotation branch and the initial plane branch movement amount corresponding to the plane branch; performing iterative calculation on the fixed-point variables based on the initial direction rotation amount and the initial plane branch movement amount until iteration meets calculation requirements, and obtaining each output fixed-point amount; and performing reflection on each output fixed-point quantity based on the coordinate interval, converting the output fixed-point quantity into a target floating-point quantity and writing the target floating-point quantity back to the target module. And the floating point variable processing method with higher efficiency is provided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of computer data processing, and in particular, to a floating-point variable processing method, apparatus, computer equipment and storage medium. Background Art

[0002] The trigonometric function calculation unit is used to implement the sin / cos hardware calculation function of floating points, and is often used in related algorithm applications such as motor control, metering, and signal processing. In terms of hardware implementation, the current general solution is to hang the trigonometric function calculation unit on the AMBA (Advanced Microcontroller Bus Architecture, a communication standard for high-performance embedded microcontrollers) bus or coprocessor interface, and use the cordic algorithm (Coordinate Rotation Digital Computer, coordinate rotation digital calculation method) for multiple iterations to obtain the sin / cos calculation results of the required accuracy. The trigonometric function calculation unit consists of two parts: the function operation control module and the floating-point calculation unit: the function operation control module controls the calculation process of the entire trigonometric function; the floating-point calculation unit completes the addition and subtraction operations of each cordic iteration. The unit supports floating-point absolute value, addition, subtraction, multiplication, division, square root and comparison operations. However, the overall operation speed is relatively low, and instructions are required to fetch data each time. After completing one floating-point cordic iteration operation, the instruction retrieves the data and then performs the next cordic iteration. The speed advantage is not obvious.

[0003] Therefore, there is an urgent need for a method that is more efficient in processing floating-point data when calculating trigonometric functions. Summary of the invention

[0004] The embodiments of the present application provide a floating-point variable processing method, apparatus, computer equipment, and storage medium.

[0005] According to a first aspect of an embodiment of the present application, a floating-point variable processing method is provided, which is applied to a main processor, wherein the main processor is embedded with a coprocessor consisting of at least a floating-point calculation unit, and the method comprises:

[0006] Acquire a floating-point variable to be processed from the coprocessor based on a preset floating-point instruction, and convert the floating-point variable into a fixed-point variable;

[0007] Mapping the floating-point variable to be processed to a corresponding coordinate interval in the preset coordinate space according to the quadrant in which the floating-point variable to be processed is located in the preset coordinate space, and determining the rotation amount of the fixed-point variable in the initial direction of the rotation branch and the initial plane branch movement amount corresponding to the plane branch;

[0008] Iteratively calculating the fixed-point variables based on the initial direction rotation amount and the initial plane branch movement amount until the iteration meets the calculation requirements to obtain each output fixed-point quantity;

[0009] De-mapping each of the output fixed-point quantities is performed based on the coordinate interval, each of the output fixed-point quantities is converted into a target floating-point quantity and written back to the target module.

[0010] In an optional embodiment of the present application, the plane branch includes a first coordinate direction branch and a second coordinate direction branch, and correspondingly, the output fixed-point quantity includes a first output fixed-point quantity and a second output fixed-point quantity; correspondingly, the fixed-point variable is iteratively calculated based on the initial direction rotation amount and the initial plane branch movement amount using the following formula until the iteration meets the calculation requirements to obtain each output fixed-point quantity:

[0011]

[0012] Among them, x i+1 Represents the first output fixed-point quantity of the first coordinate direction branch after the i-th iteration, y i+1 Represents the second output fixed-point quantity of the second coordinate direction branch after the i-th iteration, z i+1 represents the rotation output fixed-point quantity of the rotation branch after the i-th iteration; x i Indicates the first input fixed-point quantity of the first coordinate direction branch at the i-th iteration, y i Indicates the second input fixed-point quantity of the second coordinate direction branch at the i-th iteration, z i represents the rotation input fixed-point quantity of the rotation branch at the i-th iteration; d i Indicates the rotation direction of the rotating branch, arctan2 -i Represents the iteration step size of the rotation branch in the i-th iteration.

[0013] In an optional embodiment of the present application, the first coordinate direction branch is a horizontal branch, and correspondingly, the first output fixed-point quantity is a cosine function value; and / or, the second coordinate direction branch is a longitudinal branch, and correspondingly, the second output fixed-point quantity is a sine function value.

[0014] In an optional embodiment of the present application, the de-mapping of each of the output fixed-point quantities based on the coordinate interval, converting each of the output fixed-point quantities into a target floating-point quantity and writing the converted quantity back to the target module includes:

[0015] De-mapping each of the output fixed-point quantities based on the coordinate interval to obtain each of the output fixed-point quantities corresponding to each of the output fixed-point quantities in the coordinate interval;

[0016] Performing floating point conversion on each of the output fixed-point quantities to obtain corresponding output floating-point quantities;

[0017] A left shift operation is performed on each output floating-point quantity according to a preset leading zero calculation model to obtain the target floating-point quantity, and the target floating-point quantity is written back to the floating-point register.

[0018] In an optional embodiment of the present application, the iterative calculation of the fixed-point variable based on the initial direction rotation amount and the initial plane branch movement amount includes:

[0019] For each plane branch movement amount of each fixed-point variable, a 4:2 carry-preserve adder is used to iteratively calculate the fixed-point variable.

[0020] In an optional embodiment of the present application, a 4:2 carry-save adder is used to iteratively calculate the fixed-point variable according to the following formula:

[0021]

[0022] Among them, xc i+1 represents the carry component output value of the horizontal branch after the i-th iteration, xs i+1 represents the sum component output value of the lateral branch after the i-th iteration, yc i+1 Represents the carry component output value of the longitudinal branch after the i-th iteration, ys i+1 represents the sum component output value of the longitudinal branch after the i-th iteration; xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration; yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component at the i-th iteration, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, Cin i+1 Indicates the carry after the i-th iteration; “-” indicates the inversion logic, Represents the exclusive OR logical operator.

[0023] In an optional embodiment of the present application, xc i ′、xs i ′、yc i ′、ys i ′ and Cin i+1 The expression is as follows:

[0024] yc i '=-d i 2 -i yc i

[0025] ys i '=-d i 2 -i ys i

[0026] xc i '=d i 2 -i xc i

[0027] xs i '=d i 2 -i xs i

[0028] Cin i+1 =2Co i

[0029] Among them, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component in the i-th iteration, Cin i+1 represents the carry after the i-th iteration, Co i represents the carry output value of the first 3:2CSA adder at the i-th iteration, yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration, d i Indicates the rotation direction of the rotating branch.

[0030] According to a second aspect of an embodiment of the present application, there is provided a floating-point variable processing device, which is applied to a main processor, wherein the main processor is embedded with a coprocessor consisting of at least a floating-point calculation unit, and the device comprises:

[0031] A conversion module, configured to obtain a floating-point variable to be processed from the coprocessor based on a preset floating-point instruction, and convert the floating-point variable into a fixed-point variable;

[0032] A first determination module is used to map the floating-point variable to be processed to a corresponding coordinate interval in the preset coordinate space according to the quadrant in which the floating-point variable to be processed is located in the preset coordinate space, and determine the rotation amount of the fixed-point variable in the initial direction of the rotation branch and the initial plane branch movement amount corresponding to the plane branch;

[0033] An iterative calculation module, used for iteratively calculating the fixed-point variables based on the initial direction rotation amount and the initial plane branch movement amount, until the iteration meets the calculation requirements, and obtaining each output fixed-point quantity;

[0034] The second determination module is used to perform inverse mapping on each of the output fixed-point quantities based on the coordinate interval, convert each of the output fixed-point quantities into a target floating-point quantity and write the converted quantity back to a target module.

[0035] According to a third aspect of an embodiment of the present application, a computer device is provided, comprising: a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any of the above methods when executing the computer program.

[0036] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of any of the above methods when executed by a processor.

[0037] The floating-point variable processing method provided in the embodiment of the present application is applied to a main processor, wherein the main processor is embedded with a coprocessor consisting of at least a floating-point calculation unit. During the floating-point variable processing, the floating-point variables to be processed can be directly obtained from the coprocessor based on preset floating-point instructions, and processed in the main processor, thereby avoiding the need to complete one iterative operation before obtaining new data for the next iteration in the traditional solution. The embodiment of the present application can perform parallel acquisition of the floating-point variables to be processed based on preset floating-point instructions, or acquire multiple groups of data at a time, and then perform rapid iterative calculations on the fixed-point variables in the main processor based on the initial direction rotation amount and the initial plane branch movement amount, thereby greatly shortening the access delay and increasing the iterative calculation amount within a unit clock cycle, thereby greatly improving the efficiency of floating-point data processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0039] Figure 1 A schematic diagram of an application scenario of a floating-point variable processing method provided by an embodiment of the present application;

[0040] Figure 2A flowchart of a floating-point variable processing method provided for one embodiment of the present application;

[0041] Figure 3 A flow chart of a floating-point variable processing method provided by an embodiment of the present application;

[0042] Figure 4 A flowchart of a floating-point variable processing method provided for one embodiment of the present application;

[0043] Figure 5 A block diagram of a CSA compression structure provided for one embodiment of the present application;

[0044] Figure 6 A block diagram of a planar branch compression structure provided for an embodiment of the present application;

[0045] Figure 7 A schematic diagram of the structure of a floating-point variable processing device provided in one embodiment of the present application;

[0046] Figure 8 A schematic diagram of the computer device structure provided for one embodiment of the present application. DETAILED DESCRIPTION

[0047] In the process of implementing the present application, the inventors found that there is an urgent need for a more efficient floating-point variable processing method.

[0048] In response to the above problems, the embodiments of the present application provide a floating-point variable processing method, apparatus, computer device and storage medium to improve the efficiency of floating-point variable processing.

[0049] The solutions in the embodiments of the present application can be implemented using various computer languages, for example, the object-oriented programming language Java and the interpreted scripting language JavaScript.

[0050] In order to make the technical solutions and advantages in the embodiments of the present application more clearly understood, the exemplary embodiments of the present application are further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than an exhaustive list of all the embodiments. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.

[0051] The following is a brief description of the application environment of the floating-point variable processing method provided in the embodiment of the present application:

[0052] See also Figure 1, the floating-point variable processing method provided in the embodiment of the present application is applied to a main processor, wherein the main processor is embedded with a coprocessor composed of a floating-point calculation unit, and the floating-point calculation unit is directly embedded in the main processor as a coprocessor. The main processor can be, for example, an ARM core or other device with advanced computing capabilities and an EPCDE interface, which is not specifically limited in the embodiment of the present application. The coprocessor implements the floating-point calculation of m*sin(x) or m*cos(x), and the coefficient m input range is [0,1], and the radian x input range is [-1,1]. The coprocessor includes a state machine control unit, radian preprocessing, cordic iteration, multiplication processing, and result post-processing parts, which are embedded in the ARM core through the EPCDE interface, run at the same clock frequency as the ARM core, and use floating-point instructions to access the coprocessor.

[0053] The main processor includes an instruction fetch unit, an external processing unit, a data processing unit, and a custom datapath, wherein the instruction fetch unit is used to fetch execution instructions from the cache of the ARM core, the external processing unit is used to process and control some instructions in the coprocessor, the data processing unit is used to process data on the pipeline in the ARM core, and the custom datapath is used to process data on the pipeline in the coprocessor. The coprocessor at least includes: a state machine control unit, a radian preprocessing unit, an iterative calculation unit, a multiplication processing unit, and a post-processing unit; the state machine control unit is used to control the entire trigonometric function according to different iteration precisions. The calculation process of the number, the radian pre-processing unit is used for the conversion of floating-point variables to fixed-point and quadrant mapping, the iterative calculation unit is used to complete the compression calculation using 4:2CSA, the multiplication processing unit is used for coefficient multiplication operation, the post-processing unit is used for quadrant inverse mapping, and the conversion of fixed-point results to floating points, wherein the main processor accesses the coprocessor through a floating-point instruction, the floating-point instruction refers to a VCX floating-point instruction (ARM comes with it, including three types of VCX1 / 2 / 3, corresponding to different access types respectively), and the EPCDE interface refers to the data interface between the ARM core and the coprocessor, which is used for data interaction between the two.

[0054] Please also see Figure 2 and Figure 3 The following embodiments take the above-mentioned main processor as the execution subject, and apply the floating-point variable processing method provided in the embodiment of the present application to the above-mentioned main processor to process the floating-point variable as an example for specific description. The floating-point variable processing method provided in the embodiment of the present application includes the following steps 201 to 204:

[0055] Step 201: acquiring a floating-point variable to be processed from the coprocessor based on a preset floating-point instruction, and converting the floating-point variable into a fixed-point variable;

[0056] After receiving the preset floating-point instruction, the main processor reads the floating-point variable to be processed from the state machine control unit in the coprocessor through the EPCDE interface, and calls the data processing unit to complete the conversion of the floating-point variable to a fixed-point variable, for example, converting it to a fixed-point variable of (q1.31), where q1.31 refers to 32-bit fixed-point data, 1 sign bit plus 31 decimal places.

[0057] Step 202: Map the floating-point variable to be processed to a corresponding coordinate interval in the preset coordinate space according to the quadrant in which the floating-point variable to be processed is located in the preset coordinate space, and determine the rotation amount of the fixed-point variable in the initial direction of the rotation branch and the initial plane branch movement amount corresponding to the plane branch;

[0058] The preset coordinate space generally includes at least three coordinate directions: x direction, y direction, and z direction. In the embodiment of the present application, the x direction represents the horizontal branch x, the y direction represents the longitudinal branch y, and the z direction represents the rotation branch y in the direction perpendicular to the xy plane. In the embodiment of the present application, the rotation branch z is used to represent the iterative rotation direction di. In the embodiment of the present application, for example, the mapping can be performed according to the quadrant in which the rotation branch z0 (Z0 in the embodiment of the present application is represented by radians) in the floating-point variable to be processed is located in the preset coordinate space. The target coordinate interval of the mapping is [0, π / 2]. The mapping relationship between different quadrants can be, for example, as shown in Table 1 below:

[0059] Table 1

[0060] Target rotation angle Pre-rotation angle Rear target rotation angle [0,π / 2] 0 Z0 [π / 2,π] π / 2 Z0-π / 2 [-π / 2,0] 0 Z0 [-π,-π / 2] -π / 2 Z0+π / 2

[0061] Among them, for example: if the rotation branch z0 is in [0,π / 2], then z0 is not pre-rotated and directly maintains the original radian z0; if the rotation branch z0 is in [π / 2,π], then z0 is pre-rotated by π / 2 and mapped to the radian Z0-π / 2 in the target coordinate interval [0,π / 2]; if the rotation branch z0 is in [-π / 2,0], then z0 is not pre-rotated and directly maintains the original radian z0; if the rotation branch z0 is in [-π,-π / 2], then z0 is pre-rotated by -π / 2 and mapped to the radian Z0+π / 2 in the target coordinate interval [0,π / 2].

[0062] Of course, the above-mentioned target coordinate range, mapping method and specific mapping process in corresponding Table 1 are only used for examples and do not constitute a specific limitation on the mapping process of the embodiment of the present application, and can be flexibly adjusted and set according to actual conditions.

[0063] Step 203, iteratively calculating the fixed-point variables based on the initial direction rotation amount and the initial plane branch movement amount, until the iteration meets the calculation requirements, and obtaining each output fixed-point variable;

[0064] The iterative process can adopt cordic iteration, 4:2CSA (Carry-Save Adder) method for iteration). The iterative method is different for different situations. The embodiments of the present application are not exhaustive here and can be flexibly selected and set according to actual conditions.

[0065] Step 204: De-map each of the output fixed-point quantities based on the coordinate interval, convert each of the output fixed-point quantities into a target floating-point quantity and write it back to the target module.

[0066] After the iteration is completed, the preset coordinate space in step 202 above can be reverse mapped according to the target coordinate interval where the floating-point variable to be processed is located corresponding to the output fixed-point quantity. For example, in the mapping process in step 202, the floating-point variable to be processed is in the target coordinate interval of [π / 2,π]. In the mapping process, z0 is pre-rotated by π / 2. In the reverse mapping of this step, each output fixed-point quantity is pre-rotated by -π / 2. After reverse mapping, the data can be written back after conversion according to the conversion rules between fixed-point data and floating-point data. The target module can be a floating-point register, etc., which is not specifically limited in the embodiment of the present application and can be flexibly set according to actual conditions.

[0067] The floating-point variable processing method provided in the embodiment of the present application is applied to a main processor, wherein the main processor is embedded with a coprocessor consisting of at least a floating-point calculation unit. During the floating-point variable processing, the floating-point variables to be processed can be directly obtained from the coprocessor based on preset floating-point instructions, and processed in the main processor, thereby avoiding the need to complete one iterative operation before obtaining new data for the next iteration in the traditional solution. The embodiment of the present application can perform parallel acquisition of the floating-point variables to be processed based on preset floating-point instructions, or acquire multiple groups of data at a time, and then perform rapid iterative calculations on the fixed-point variables in the main processor based on the initial direction rotation amount and the initial plane branch movement amount, thereby greatly shortening the access delay and increasing the iterative calculation amount within a unit clock cycle, thereby greatly improving the efficiency of floating-point data processing.

[0068] In an optional embodiment of the present application, the first coordinate direction branch is a horizontal branch, and correspondingly, the first output fixed-point quantity is a cosine function value; and / or, the second coordinate direction branch is a longitudinal branch, and correspondingly, the second output fixed-point quantity is a sine function value.

[0069] That is, the above-mentioned initial direction rotation amount is the initial value assigned to the rotation branch z as the initial rotation amount z0, and the iteration bit width of the rotation branch z can be, for example, 20 bits. Similarly, the initial plane branch movement amount is the initial value assigned to the horizontal branch x and the longitudinal branch y, which are the initial horizontal branch movement amount and the initial longitudinal branch movement amount, respectively. The iteration bit width of the horizontal branch x and the longitudinal branch y can be, for example, 34 bits, which is larger than the rotation branch z. During the iteration process, when the iteration accuracy issued by the floating-point instruction is met, the first output fixed-point value xn and the second output fixed-point value yn are taken out, xn corresponds to the cosine function value cos, and yn corresponds to the sine function data sin.

[0070] In the floating-point variable processing process of the embodiment of the present application, the cosine function value is determined by the first output fixed-point quantity of the horizontal branch, and the sine function value is determined by the second output fixed-point quantity of the vertical branch, thereby realizing the calculation of trigonometric functions, which can greatly improve the calculation efficiency of trigonometric functions in the computer processing process.

[0071] In an optional embodiment of the present application, the plane branch includes a first coordinate direction branch and a second coordinate direction branch, and correspondingly, the output fixed-point quantity includes a first output fixed-point quantity and a second output fixed-point quantity; in the above step 203, the fixed-point variable is iteratively calculated based on the initial direction rotation amount and the initial plane branch movement amount until the iteration meets the calculation requirements and each output fixed-point quantity is obtained, the trigonometric function can be iteratively calculated using cordic circular rotation, and its basic iteration formula is as follows:

[0072]

[0073] Among them, x i+1 Represents the first output fixed-point quantity of the first coordinate direction branch after the i-th iteration, y i+1 Represents the second output fixed-point quantity of the second coordinate direction branch after the i-th iteration, z i+1 represents the rotation output fixed-point quantity of the rotation branch after the i-th iteration; x i Indicates the first input fixed-point quantity of the first coordinate direction branch at the i-th iteration, y i Indicates the second input fixed-point quantity of the second coordinate direction branch at the i-th iteration, z i represents the rotation input fixed-point quantity of the rotation branch at the i-th iteration; d i Indicates the rotation direction of the rotating branch, arctan2 -i Represents the iteration step size of the rotation branch in the i-th iteration.

[0074] The above formula can greatly improve the calculation efficiency of trigonometric functions in computer processing.

[0075] In the above formula, the variable x i+1,y i+1 and z i+1 That is, the horizontal coordinate value, vertical coordinate value and angle value of each iteration. The step size of the iteration is arctan2 -i , the z branch provides the rotation direction di, d i The expression is as follows:

[0076]

[0077] If zi is less than 0, di = -1, if zi is greater than or equal to 0, di = 1. After n iterations, the first output fixed-point quantity xn corresponds to the cosine value, and the second output fixed-point quantity yn corresponds to the sin value. At the same time, the coefficient value A will be iterated. The more iterations, the more 1 / A tends to the stable value of 0.607252935.

[0078] See also Figure 4 In an optional embodiment of the present application, the above step 204, the de-mapping of each output fixed-point quantity based on the coordinate interval, converting each output fixed-point quantity into a target floating-point quantity and writing it back to the target module, includes the following steps 401-403:

[0079] Step 401: De-map each of the output fixed-point quantities based on the coordinate interval to obtain each of the output fixed-point quantities corresponding to each of the output fixed-point quantities in the coordinate interval;

[0080] Step 402: performing floating point conversion on each of the output fixed-point quantities to obtain corresponding output floating-point quantities;

[0081] Step 403: perform a left shift operation on each output floating-point quantity according to a preset leading zero calculation model to obtain the target floating-point quantity, and write the target floating-point quantity back to the floating-point register.

[0082] The first output fixed-point quantity xn and the second output fixed-point quantity yn are reversely mapped in the manner exemplified in step 204 to obtain the cos(z0) and sin(z0) values ​​of the quadrant where the fixed-point variable z0 is located; then the fixed-point result (q1.31) (i.e., the data containing the cos(z0) and sin(z0) values) is converted to floating point to obtain each output floating-point quantity. Finally, according to the leading zero calculation, each output floating-point quantity is left-shifted, and the converted floating-point result value is written back to the floating-point register: for example, firstly, the left-shifted value is calculated according to the leading zero algorithm, and the decimal place of the fixed-point data is left-shifted to obtain the mantissa of the floating-point data; then, the left-shifted value is subtracted from the exponent base value of the single-precision data to obtain the exponent of the floating-point data; finally, the sign bit of the fixed-point data is given to the sign bit of the floating-point data to form a single-precision floating-point number (e.g., 1-bit sign bit, 8-bit exponent bit, 23-bit mantissa bit).

[0083] After performing iterative calculations, the embodiments of the present application convert the obtained fixed-point results into target floating-point quantities through processes such as inverse mapping and floating-point conversion, thereby ensuring that the results written back into the floating-point registers are consistent with the data types of the floating-point variables to be processed initially obtained, thereby facilitating the convenience and efficiency of subsequent processing.

[0084] In an optional embodiment of the present application, the above step 203, the iterative calculation of the fixed-point variable based on the initial direction rotation amount and the initial plane branch movement amount, includes the following steps:

[0085] For the plane branch movement amount of each fixed-point variable, a 4:2 carry-preserve adder is used to iteratively calculate the fixed-point variable.

[0086] The 4:2CSA (Carry-Save Adder) method is used for iteration. Compared with the addition and subtraction calculations in the cordic iterative algorithm, the number of iterations in one clock cycle can be increased, thereby greatly improving the floating-point variable processing efficiency.

[0087] See also Figure 5 and Figure 6 , the iterative calculation of the transverse branch x and the longitudinal branch y can be calculated using 4:2CSA, such as Figure 5 As shown, the 4:2CSA structure is composed of two 3:2CSAs, including a structure with 5 input quantities and 3 output quantities, wherein the 5 input quantities include A / B / C / D as four input numbers and the carry output Ci of the previous level, and the 3 output quantities include: the carry output Co of the current level and the addition result outputs Carry and Sum of the current level.

[0088] The expression of 4:2CSA is as follows:

[0089]

[0090] Among them, ABCD represents 4 of the 5 inputs in the 4:2CSA adder expression, Ci represents the carry output of the previous stage, Co represents the carry output of the current stage, Carry and Sum represent the addition result output of the current stage; "-" represents the inversion logic, Represents the exclusive OR logical operator.

[0091] Applying 4:2CSA to the transverse branch x and the longitudinal branch y, the input variables of the transverse branch x and the longitudinal branch y are divided into the following two parts:

[0092] x i =xc i +xs i

[0093] yi =yc i +ys i

[0094] Then, the cordic iteration formula of the horizontal branch x and the vertical branch y is converted into the following formula. In an optional embodiment of the present application, the plane branch movement amount of the fixed-point variable can be iteratively calculated using a 4:2 carry-preserve adder according to the following formula:

[0095] In an optional embodiment of the present application, a 4:2 carry-save adder is used to iteratively calculate the fixed-point variable for the plane branch movement amount of the fixed-point variable according to the following formula:

[0096]

[0097] Among them, xc i+1 represents the carry component output value of the horizontal branch after the i-th iteration, xs i+1 represents the sum component output value of the lateral branch after the i-th iteration, yc i+1 Represents the carry component output value of the longitudinal branch after the i-th iteration, ys i+1 represents the sum component output value of the longitudinal branch after the i-th iteration; xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration; yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component at the i-th iteration, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, Cin i+1 Indicates the carry after the i-th iteration; “-” indicates the negation logic, for example, the negation of 0 is 1, and the negation of 1 is 0; Represents the exclusive OR logical operator, for example:

[0098] 0 is XORed with 0, the result is 0;

[0099] 1 is XORed with 0, the result is 1;

[0100] 0 is XORed with 1, the result is 1;

[0101] 1 is XORed with 1, the result is 0.

[0102] In an optional embodiment of the present application, xc i ′、xs i ′、yc i ′、ys i ′ and Cin i+1 The expression is as follows:

[0103] yc i '=-d i 2 -i yc i

[0104] ys i '=-d i 2 -i ys i

[0105] xc i '=d i 2 -i xc i

[0106] xs i '=d i 2 -i xs i

[0107] Cin i+1 =2Co i

[0108] Among them, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component in the i-th iteration, Cin i+1 represents the carry after the i-th iteration, Co i represents the carry output value of the first 3:2CSA adder at the i-th iteration, yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration, d i Indicates the rotation direction of the rotating branch.

[0109] The structure of the transverse branch x and the longitudinal branch y iterated once is as follows Figure 6 As shown, after the shift operation, the 4:2CSA operation is performed to obtain the second iteration xc, xs, yc and ys. At the same time, according to the timing of the iteration, multiple iterations can be performed in one clock cycle. The z branch needs to be operated in advance to provide the rotation direction di for the xy branch iteration. After the shift operation, the 4:2CSA operation is performed to obtain the second iteration xc, xs, yc and ys.

[0110] It should be understood that, although the various steps in the flow chart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the figure may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0111] See also Figure 7 An embodiment of the present application provides a floating-point variable processing device 700, which is applied to a main processor, wherein the main processor is embedded with a coprocessor composed of a floating-point calculation unit, wherein the coprocessor at least includes: a state machine control unit, a radian preprocessing unit, an iterative calculation unit, a multiplication processing unit, and a post-processing unit, wherein the main processor accesses the coprocessor through a floating-point instruction, and the device 700 includes:

[0112] A conversion module 710, configured to obtain a floating-point variable to be processed from the coprocessor based on a preset floating-point instruction, and convert the floating-point variable into a fixed-point variable;

[0113] A first determination module 720 is used to map the floating-point variable to be processed to a corresponding coordinate interval in the preset coordinate space according to the quadrant in which the floating-point variable to be processed is located in the preset coordinate space, and determine the rotation amount of the fixed-point variable in the initial direction of the rotation branch and the initial plane branch movement amount corresponding to the plane branch;

[0114] An iterative calculation module 730, configured to iteratively calculate the fixed-point variables based on the initial direction rotation amount and the initial plane branch movement amount, until the iteration meets the calculation requirements, thereby obtaining each output fixed-point variable;

[0115] The second determination module 740 is used to perform inverse mapping on each of the output fixed-point quantities based on the coordinate interval, convert each of the output fixed-point quantities into a target floating-point quantity and write it back to the target module.

[0116] In an optional embodiment of the present application, the plane branch includes a first coordinate direction branch and a second coordinate direction branch, and correspondingly, the output fixed-point quantity includes a first output fixed-point quantity and a second output fixed-point quantity; the first determination module 730 is specifically used to iteratively calculate the fixed-point variable based on the initial direction rotation amount and the initial plane branch movement amount using the following formula until the iteration meets the calculation requirements to obtain each output fixed-point quantity:

[0117]

[0118] Among them, x i+1 Represents the first output fixed-point quantity of the first coordinate direction branch after the i-th iteration, y i+1 Represents the second output fixed-point quantity of the second coordinate direction branch after the i-th iteration, z i+1 represents the rotation output fixed-point quantity of the rotation branch after the i-th iteration; x i Indicates the first input fixed-point quantity of the first coordinate direction branch at the i-th iteration, y i Indicates the second input fixed-point quantity of the second coordinate direction branch at the i-th iteration, z i represents the rotation input fixed-point quantity of the rotation branch at the i-th iteration; d i Indicates the rotation direction of the rotating branch, arctan2 -i Represents the iteration step size of the rotation branch in the i-th iteration.

[0119] In an optional embodiment of the present application, the first coordinate direction branch is a horizontal branch, and correspondingly, the first output fixed-point quantity is a cosine function value; and / or, the second coordinate direction branch is a longitudinal branch, and correspondingly, the second output fixed-point quantity is a sine function value.

[0120] In an optional embodiment of the present application, the second determination module 740 is specifically used to perform a reverse mapping on each of the output fixed-point quantities based on the coordinate interval to obtain each of the output fixed-point quantities corresponding to the output fixed-point quantities in the coordinate interval; perform a floating-point conversion on each of the output fixed-point quantities to obtain corresponding output floating-point quantities; perform a left shift operation on each of the output floating-point quantities according to a preset leading zero calculation model to obtain the target floating-point quantity, and write the target floating-point quantity back to the floating-point register.

[0121] In an optional embodiment of the present application, the first determination module 730 is specifically configured to iteratively calculate the fixed-point variables using a 4:2 carry-save adder for each plane branch movement amount of each fixed-point variable.

[0122] In an optional embodiment of the present application, the first determination module 730 is specifically configured to perform iterative calculation on the fixed-point variable using a 4:2 carry-save adder according to the following formula:

[0123]

[0124] Among them, xc i+1 represents the carry component output value of the horizontal branch after the i-th iteration, xs i+1 represents the sum component output value of the lateral branch after the i-th iteration, yc i+1 Represents the carry component output value of the longitudinal branch after the i-th iteration, ys i+1 represents the sum component output value of the longitudinal branch after the i-th iteration; xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration; yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component at the i-th iteration, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, Cin i+1 Indicates the carry after the i-th iteration; “-” indicates the inversion logic, Represents the exclusive OR logical operator.

[0125] In an optional embodiment of the present application, xc i ′、xs i ′、yc i ′、ys i ′ and Cin i+1 The expression is as follows:

[0126] yc i '=-d i 2 -i yc i

[0127] ys i '=-d i 2 -i ys i

[0128] xc i '=di 2 -i xc i

[0129] xs i '=d i 2 -i xs i

[0130] Cin i+1 =2Co i

[0131] Among them, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component in the i-th iteration, Cin i+1 represents the carry after the i-th iteration, Co i represents the carry output value of the first 3:2CSA adder at the i-th iteration, yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration, d i Indicates the rotation direction of the rotating branch.

[0132] For the specific definition of the floating-point variable processing device 700, please refer to the definition of the floating-point variable processing method above, which will not be repeated here. Each module in the floating-point variable processing device 700 can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0133] In one embodiment, a computer device is provided, the internal structure diagram of which can be as follows: Figure 8As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a floating-point variable processing method as described above is implemented. It includes: a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, any step in the floating-point variable processing method as described above is implemented.

[0134] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, any step in the above floating-point variable processing method can be implemented.

[0135] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0136] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0137] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1A function specified in one or more boxes.

[0138] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0139] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0140] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A floating point variable processing method, characterized in that: Applied to a main processor, the main processor being embedded with a coprocessor consisting of at least a floating point calculation unit, the method comprising: Acquire a floating-point variable to be processed from the coprocessor based on a preset floating-point instruction, and convert the floating-point variable into a fixed-point variable; Mapping the floating-point variable to be processed to a corresponding coordinate interval in the preset coordinate space according to the quadrant in which the floating-point variable to be processed is located in the preset coordinate space, and determining the rotation amount of the fixed-point variable in the initial direction of the rotation branch and the initial plane branch movement amount corresponding to the plane branch; Iteratively calculating the fixed-point variables based on the initial direction rotation amount and the initial plane branch movement amount until the iteration meets the calculation requirements to obtain each output fixed-point quantity; De-mapping each of the output fixed-point quantities is performed based on the coordinate interval, each of the output fixed-point quantities is converted into a target floating-point quantity and written back to the target module.

2. The floating-point variable processing method according to claim 1, characterized in that: The plane branch includes a first coordinate direction branch and a second coordinate direction branch. Correspondingly, the output fixed-point quantity includes a first output fixed-point quantity and a second output fixed-point quantity. Correspondingly, the fixed-point variable is iteratively calculated based on the initial direction rotation amount and the initial plane branch movement amount using the following formula until the iteration meets the calculation requirements to obtain each output fixed-point quantity: Among them, x i+1 Represents the first output fixed-point quantity of the first coordinate direction branch after the i-th iteration, y i+1 Represents the second output fixed-point quantity of the second coordinate direction branch after the i-th iteration, z i+1 represents the rotation output fixed-point quantity of the rotation branch after the i-th iteration; x i Indicates the first input fixed-point quantity of the first coordinate direction branch at the i-th iteration, y i Indicates the second input fixed-point quantity of the second coordinate direction branch at the i-th iteration, z i represents the rotation input fixed-point quantity of the rotation branch at the i-th iteration; d i Indicates the rotation direction of the rotating branch, arctan2 -i Represents the iteration step size of the rotation branch in the i-th iteration.

3. The floating-point variable processing method according to claim 2, characterized in that: The first coordinate direction branch is a horizontal branch, and correspondingly, the first output fixed-point quantity is a cosine function value; and / or, the second coordinate direction branch is a vertical branch, and correspondingly, the second output fixed-point quantity is a sine function value.

4. The floating-point variable processing method according to claim 1, characterized in that: The method of performing reverse mapping on each of the output fixed-point quantities based on the coordinate interval, converting each of the output fixed-point quantities into a target floating-point quantity and writing the converted quantity back to the target module comprises: De-mapping each of the output fixed-point quantities based on the coordinate interval to obtain each of the output fixed-point quantities corresponding to each of the output fixed-point quantities in the coordinate interval; Performing floating point conversion on each of the output fixed-point quantities to obtain corresponding output floating-point quantities; A left shift operation is performed on each output floating-point quantity according to a preset leading zero calculation model to obtain the target floating-point quantity, and the target floating-point quantity is written back to the floating-point register.

5. The floating-point variable processing method according to claim 1, characterized in that: The iterative calculation of the fixed-point variable based on the initial direction rotation amount and the initial plane branch movement amount includes: For each plane branch movement amount of each fixed-point variable, a 4:2 carry-preserve adder is used to iteratively calculate the fixed-point variable.

6. The floating-point variable processing method according to claim 3, characterized in that: The fixed-point variable is iteratively calculated using a 4:2 carry-save adder according to the following formula: Among them, xc i+1 represents the carry component output value of the horizontal branch after the i-th iteration, xs i+1 represents the sum component output value of the lateral branch after the i-th iteration, yc i+1 Represents the carry component output value of the longitudinal branch after the i-th iteration, ys i+1 represents the sum component output value of the longitudinal branch after the i-th iteration; xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration; yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component at the i-th iteration, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, Cin i+1 Indicates the carry after the i-th iteration; "-" indicates the inversion logic, and "⊕" indicates the exclusive OR logic operator.

7. The floating-point variable processing method according to claim 6, characterized in that: xc i ′、xs i ′、yc i ′、ys i ′ and Cin i+1 The expression is as follows: yc i '=-d i 2 -i yc i yes i '=-d i 2 -i yes i xc i '=d i 2 -i xc i xs i '=d i 2 -i xs i Eating i+1 =2Co i Among them, yc i ′ represents the shift amount of the carry component of the longitudinal branch at the i-th iteration, ys i ′ represents the displacement of the longitudinal branch and component at the i-th iteration, xc i ′ represents the shift amount of the carry component of the horizontal branch at the i-th iteration, xs i ′ represents the displacement of the lateral branch and component in the i-th iteration, Cin i+1 represents the carry after the i-th iteration, Co i represents the carry output value of the first 3:2CSA adder at the i-th iteration, yc i Indicates the carry component input value of the longitudinal branch at the i-th iteration, ys i represents the sum component input value of the longitudinal branch at the i-th iteration, xc i represents the carry component input value of the horizontal branch at the i-th iteration, xs i represents the sum component input value of the lateral branch at the i-th iteration, d i Indicates the rotation direction of the rotating branch.

8. A floating point variable processing device, characterized in that: Applied to a main processor, the main processor is embedded with a coprocessor consisting of at least a floating point calculation unit, the device comprises: A conversion module, configured to obtain a floating-point variable to be processed from the coprocessor based on a preset floating-point instruction, and convert the floating-point variable into a fixed-point variable; A first determination module is used to map the floating-point variable to be processed to a corresponding coordinate interval in the preset coordinate space according to the quadrant in which the floating-point variable to be processed is located in the preset coordinate space, and determine the rotation amount of the fixed-point variable in the initial direction of the rotation branch and the initial plane branch movement amount corresponding to the plane branch; An iterative calculation module, used for iteratively calculating the fixed-point variables based on the initial direction rotation amount and the initial plane branch movement amount, until the iteration meets the calculation requirements, and obtaining each output fixed-point quantity; The second determination module is used to perform inverse mapping on each of the output fixed-point quantities based on the coordinate interval, convert each of the output fixed-point quantities into a target floating-point quantity and write the converted quantity back to a target module.

9. A computer device comprising: The method comprises a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the steps of the method according to any one of claims 1 to 7 when executing the computer program.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.