Root mean square calculation method and device based on hardware implementation and electronic equipment

By using a hardware iterative calculation method and updating the parameters mask, root, and reder, the problem of not being able to perform root mean square calculation on hardware was solved, thus achieving efficient root mean square calculation.

CN119357543BActive Publication Date: 2026-04-28XIAN WEIHE ZHILIAN TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
XIAN WEIHE ZHILIAN TECHNOLOGY CO LTD
Filing Date
2024-12-26
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

The root mean square (RMS) calculation cannot be implemented in hardware using existing technologies.

Method used

By acquiring the data X to be calculated and the input bit width, the output bit width is determined, and the root mean square calculation is implemented in hardware using an iterative calculation method, including updating and judging the parameters mask, root, and reder, until the number of iterations reaches the output bit width.

Benefits of technology

It implements the function of root mean square calculation in hardware, reducing computational complexity and hardware area loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357543B_ABST
    Figure CN119357543B_ABST
Patent Text Reader

Abstract

The application relates to a hardware-based root mean square calculation method and device and electronic equipment, the method comprising: acquiring to-be-calculated data and an input bit width; determining an output bit width and the value of a first parameter according to the input bit width, and presetting the initial values of a second parameter and a third parameter as 0; judging whether the current iteration number is less than the output bit width; in the case that the current iteration number is determined to be less than the output bit width, performing first-round updating on the second parameter, the third parameter and the to-be-calculated data X obtained through last iteration calculation, and determining a fourth parameter based on the second parameter after the first-round updating; judging whether the fourth parameter is less than or equal to the third parameter after the first-round updating; according to the judgment result, determining the second parameter, the third parameter and the to-be-calculated data participating in next iteration calculation, and performing iteration calculation again until the current iteration number reaches the value of the output bit width, and obtaining a root mean square calculation result. In this way, the root mean square calculation can be realized based on hardware.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of wireless communication technology, and in particular to a hardware-based root mean square (RMS) calculation method, apparatus, and electronic device. Background Technology

[0002] With the development of 5G technology, the amount of data that user equipment (UE) needs to process is increasing. In order to ensure that UE has higher throughput and faster processing speed, most of the data processing cannot be directly achieved through digital signal processing (DSP) or central processing unit (CPU), so hardware is required.

[0003] However, while conventional calculations such as addition, subtraction, multiplication, and division can usually be implemented in hardware, the root mean square (RMS) calculation cannot be implemented in hardware. Therefore, how to implement the RMS calculation in hardware has become a technical problem that urgently needs to be solved. Summary of the Invention

[0004] This application provides a hardware-based root mean square (RMS) calculation method, apparatus, and electronic device to solve the problem in related technologies that conventional calculations such as addition, subtraction, multiplication, and division can usually be implemented in hardware, but RMS calculation cannot be implemented in hardware.

[0005] In a first aspect, embodiments of this application provide a hardware-based root mean square (RMS) calculation method, the method comprising:

[0006] Obtain the data to be calculated X and the input bit width The input bit width The input bit width is the fixed-point representation of the data X to be calculated in the hardware, where the value of the data X to be calculated is less than or equal to the input bit width. Maximum supported value;

[0007] According to the input bit width Determine the output bit width ;

[0008] According to the input bit width Determine the value of the first parameter mask, and preset the initial values ​​of the second parameter root and the third parameter reder to 0;

[0009] Determine if the current iteration number is less than the output bit width. The value;

[0010] If the current iteration number is determined to be less than the output bit width Given the value of the second parameter root obtained from the previous iteration, the third parameter reder obtained from the previous iteration, and the data to be calculated X obtained from the previous iteration are updated in the first round. Based on the value of the second parameter root after the first round of updates, the value of the fourth parameter divi is determined.

[0011] Determine whether the value of the fourth parameter, divi, is less than or equal to the value of the third parameter, reder, after the first round of updates;

[0012] Based on the judgment result, the second parameter root, the third parameter reder, and the data to be calculated X are determined for the next iteration calculation, and the iteration calculation is performed again until the current iteration number reaches the specified output bit width. The value of the second parameter root is used to determine the root mean square calculation result of the data X to be calculated.

[0013] Optionally, determining the second parameter root, the third parameter reder, and the data X to be calculated based on the judgment result includes:

[0014] If the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates, a second round of updates is performed on the values ​​of the third parameter reder and the second parameter root after the first round of updates. The data to be calculated X after the first round of updates is used as the data to be calculated X in the next iteration, the value of the third parameter reder after the second round of updates is used as the third parameter reder in the next iteration, and the value of the second parameter root after the second round of updates is used as the second parameter root in the next iteration.

[0015] If the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of updates, the data to be calculated X after the first round of updates will be used as the data to be calculated in the next iteration, the value of the third parameter reder after the first round of updates will be used as the third parameter reder after the next iteration, and the value of the second parameter root after the first round of updates will be used as the second parameter root after the next iteration.

[0016] Optionally, the step of performing a second round of updates on the value of the third parameter reder and the value of the second parameter root after the first round of updates includes:

[0017] Calculate the difference between the value of the third parameter `reder` after the first round of updates and the value of the fourth parameter `divi`, and determine the difference as the value of the third parameter `reder` after the second round of updates; and,

[0018] Increment the value of the second parameter root after the first round of updates by one to obtain the value of the second parameter root after the second round of updates.

[0019] Optionally, the first round of updating the second parameter root obtained from the previous iteration, the third parameter reder obtained from the previous iteration, and the data to be calculated X obtained from the previous iteration includes:

[0020] The second parameter root, calculated in the previous iteration, is shifted one position to the left to obtain the value of the second parameter root after the first round of updates;

[0021] The third parameter `reder` obtained from the previous iteration is shifted left by one bit, and a bitwise OR operation is performed between the shifted value and the target value to obtain the updated value of the third parameter `reder` for the first round. The target value is the data to be calculated X obtained from the previous iteration, shifted right by the input bit width. The value obtained by subtracting 2 digits;

[0022] The data X to be calculated obtained in the previous iteration is shifted two bits to the left, and the shifted value is bitwise ANDed with the first parameter mask to obtain the value of the data X to be calculated after the first round of updates.

[0023] Optionally, determining the value of the fourth parameter divi based on the value of the second parameter root after the first round of updates includes:

[0024] The value of the second parameter root after the first round of updates is shifted one position to the left, and the shifted value is incremented by one to obtain the value of the fourth parameter divi.

[0025] Optionally, the step of adjusting according to the input bit width Determine the output bit width ,include:

[0026] According to the formula calculate;

[0027] in, This indicates the output bit width. This indicates the input bit width. This indicates the floor function.

[0028] Optionally, the step of adjusting according to the input bit width Determine the value of the first parameter mask, including:

[0029] Left-shift the input bit width by the value 1 The corresponding digits are then shifted left and the value is reduced by one to obtain the value of the first parameter mask. Secondly, embodiments of this application also provide a hardware-based root mean square (RMS) calculation device, the device comprising:

[0030] The acquisition module is used to acquire the data to be calculated X and the input bit width. The input bit width The input bit width is the fixed-point representation of the data X to be calculated in the hardware, where the value of the data X to be calculated is less than or equal to the input bit width. Maximum supported value;

[0031] The first determining module is used to determine the input bit width. Determine the output bit width ;

[0032] The second determining module is used to determine the input bit width. Determine the value of the first parameter mask, and preset the initial values ​​of the second parameter root and the third parameter reder to 0;

[0033] The first judgment module is used to determine whether the current iteration number is less than the output bit width. The value;

[0034] The update module is used to determine if the current iteration number is less than the output bit width. Given the value of the second parameter root obtained from the previous iteration, the third parameter reder obtained from the previous iteration, and the data to be calculated X obtained from the previous iteration are updated in the first round. Based on the value of the second parameter root after the first round of updates, the value of the fourth parameter divi is determined.

[0035] The second judgment module is used to determine whether the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of update;

[0036] The loop module is used to determine the second parameter root, the third parameter reder, and the data to be calculated X for the next iteration based on the judgment result, and then perform iterative calculation again until the current iteration number reaches the specified output bit width. The value of the second parameter root is used to determine the root mean square calculation result of the data X to be calculated.

[0037] Thirdly, embodiments of this application also provide an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;

[0038] Memory, used to store computer programs;

[0039] When a processor executes a program stored in memory, it implements the hardware-based root mean square calculation method described in the first aspect.

[0040] Fourthly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the hardware-based root mean square calculation method as described in the first aspect.

[0041] Compared with the prior art, the technical solution provided in this application embodiment has the following advantages: The method provided in this application embodiment obtains the data to be calculated X and the input bit width. The input bit width The input bit width is the fixed-point representation of the data X to be calculated in the hardware, where the value of the data X to be calculated is less than or equal to the input bit width. The maximum supported value; based on the input bit width Determine the output bit width According to the input bit width First, determine the value of the first parameter `mask`, and preset the initial values ​​of the second parameter `root` and the third parameter `reder` to 0; then, determine whether the current iteration number is less than the output bit width. The value; when the current iteration number is less than the output bit width Given the given values, the second parameter `root`, the third parameter `reder`, and the data to be calculated `X` obtained from the previous iteration are updated in the first round. Based on the updated value of the second parameter `root`, the value of the fourth parameter `divi` is determined. It is then determined whether the value of the fourth parameter `divi` is less than or equal to the updated value of the third parameter `reder`. Based on the determination result, the second parameter `root`, the third parameter `reder`, and the data to be calculated `X` are determined for the next iteration, and the iteration is performed again until the current iteration count reaches the specified output bit width. The value of the second parameter root is used to determine the root mean square result of the data X to be calculated. This method allows for calculation based on the hardware input bit width. Determine the output bit width Then, based on the input bit width and output bit width The algorithm iteratively calculates the data X to be calculated, the second parameter root, and the third parameter reder, thereby obtaining the final calculation result of the second parameter root, which is the root mean square calculation result of the data X to be calculated. This solves the problem that root mean square calculation cannot be implemented in hardware in related technologies. Attached Figure Description

[0042] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0043] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0044] Figure 1 A flowchart illustrating a hardware-based root mean square (RMS) calculation method provided in this application embodiment;

[0045] Figure 2 A flowchart illustrating another hardware-based root mean square (RMS) calculation method provided in this application embodiment;

[0046] Figure 3 A schematic diagram of a hardware-based root mean square (RMS) calculation device provided in an embodiment of this application;

[0047] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0048] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0049] See Figure 1 , Figure 1 This is a flowchart illustrating a hardware-based root mean square (RMS) calculation method provided in an embodiment of this application. Figure 1 As shown, the hardware-based root mean square (RMS) calculation method may include the following steps:

[0050] Step S102: Obtain the data to be calculated X and the input bit width. , where the input bit width The input bit width is the fixed-point representation of the data X to be calculated within the hardware. The value of the data X to be calculated is less than or equal to the input bit width. The maximum supported value.

[0051] Specifically, the aforementioned data X to be calculated represents the data for which root mean square (RMS) calculation is required. This data X can be represented in hardware as a binary fixed-point data, which can be pre-converted from any base of fixed-point or floating-point data. The aforementioned input bit width... This represents the bit width occupied by the data X to be calculated in fixed-point form within the hardware; this input bit width... It is determined based on the inherent properties of the hardware, such as its type and specifications. Since the leftmost bit of binary fixed-point data is the most significant bit in the hardware, typically representing the sign of the data, the actual data bit width is equal to the input bit width. Subtract one bit width, meaning the value of the data X to be calculated should be less than or equal to the input bit width. -1 bits later, the data bits are all binary values ​​of 1.

[0052] When obtaining data X to be calculated, non-binary fixed-point data can be converted to binary fixed-point data before acquisition. For example, for a certain floating-point data, the following formula can be used to convert the floating-point data to decimal fixed-point data: d'x=x*2^(length_in-1), where d'x refers to the decimal fixed-point representation of the value x, x is a certain floating-point number, and length_in represents the input bit width. After obtaining the decimal fixed-point data, it can be converted back to binary fixed-point data.

[0053] It should be noted that the letter X here represents the data to be calculated in this application. Of course, other letters can also be used to represent the data to be calculated, which does not constitute a limitation on this application. In this application, the input bit width is used. Of course, other English terms can also be used to represent the input bit width, which does not constitute a limitation of this application. Step S104: According to the input bit width Determine the output bit width .

[0054] After determining the input bit width Then, based on the input bit width Determine the output bit width The output bit width here This refers to the data output bit width that minimizes both hardware area and power consumption without affecting the accuracy of the root mean square (RMS) calculation. This output bit width... and input bit width The relationships between them can be derived from human experience or experimental data; this application does not impose specific limitations. It should be noted that... The term "output bit width" is used in this application. Of course, other English terms can also be used to represent the output bit width, which does not constitute a limitation of this application.

[0055] Step S106: Based on the input bit width Determine the value of the first parameter mask, and preset the initial values ​​of the second parameter root and the third parameter reder to 0.

[0056] The first parameter `mask`, the second parameter `root`, and the third parameter `reder` are parameters required in the hardware-based root mean square (RMS) calculation process. Therefore, their initial values ​​need to be determined before iterative calculation. The value of the first parameter `mask` does not change during iterative calculation; its value can be determined based on the input bit width. The obtained value is actually a mask used for bitwise AND operations with the data to be calculated, X, to prevent overflow of X. The values ​​of the second parameter `root` and the third parameter `reder` change with each iteration, and their initial values ​​are both 0. The fourth parameter `divi` is determined by the second parameter `root` in each iteration. The role of the fourth parameter `divi` is to work with the third parameter `reder` to determine the validity of the current second parameter `root`.

[0057] It should be noted that in this application, mask, root, and reder refer to the first, second, and third parameters, respectively. Of course, other English terms can also be used to represent the first, second, and third parameters, which does not constitute a limitation on this application.

[0058] Step S108: Determine if the current iteration number is less than the output bit width. The value.

[0059] During the iterative calculation process, it is necessary to determine whether the current iteration number is less than the output bit width before each iteration. The value, if the current iteration number is greater than or equal to the output bit width If the value is less than the output bit width, it indicates that the root mean square (RMS) calculation result has been obtained, and the iteration calculation can be stopped; if the current iteration number is less than the output bit width... If the value is not specified, it indicates that the root mean square calculation result has not yet been obtained and iterative calculation needs to be continued.

[0060] Step S110: Determine if the current iteration number is less than the output bit width. Given the given values, the first round of updates is performed on the second parameter root obtained from the previous iteration, the third parameter reder obtained from the previous iteration, and the data to be calculated X obtained from the previous iteration. Based on the value of the second parameter root after the first round of updates, the value of the fourth parameter divi is determined.

[0061] In each iteration, the second parameter `root`, the third parameter `reder`, and the data to be calculated `X` obtained from the previous iteration need to be updated in the first round. Based on the updated value of the second parameter `root`, the value of the fourth parameter `divi` is determined. For example, in the first iteration, the initial values ​​of the second parameter `root`, the third parameter `reder`, and the data to be calculated are updated in the first round; in the second iteration, the second parameter `root`, the third parameter `reder`, and the data to be calculated `X` are updated in the first round; in the third iteration, the second parameter `root`, the third parameter `reder`, and the data to be calculated `X` are updated in the second round, and so on. It should be noted that `divi` here represents the fourth parameter in this application. Of course, other English terms can be used to represent the fourth parameter, which does not constitute a limitation of this application.

[0062] Step S112: Determine whether the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates.

[0063] In each iteration, it is necessary to determine whether the value of the fourth parameter, divi, is less than or equal to the value of the third parameter, reder, after the first round of updates. If the value of the fourth parameter, divi, is less than or equal to the value of the third parameter, reder, after the first round of updates, a second round of updates is required for both the third parameter, reder, and the second parameter, root, after the first round of updates. After completing the second round of updates, the next iteration begins. If the value of the fourth parameter, divi, is greater than the value of the third parameter, reder, after the first round of updates, a second round of updates is not required for both the third parameter, reder, and the next iteration begins directly.

[0064] Step S114: Based on the judgment result, determine the second parameter root, the third parameter reder, and the data to be calculated X for the next iteration calculation, and perform iterative calculation again until the current iteration number reaches the output bit width. The value of the root mean square is used to determine the root mean square result of the data X to be calculated.

[0065] In this step, based on the results of the judgment between the fourth parameter divi and the value of the third parameter reder after the first round of updates, the second parameter root, the third parameter reder, and the data X to be calculated for the next iteration are determined, and the iteration loop is performed again until the current iteration count reaches the output bit width. The value. This ensures that the number of iterations reaches the output bit width. The corresponding numerical values, thus the number of bits in the calculation result (binary fixed-point data) and the output bit width This ensures a match, and the second parameter `root`, the third parameter `reder`, and the data to be calculated `X` can be adjusted in each iteration so that the value of the second parameter `root` obtained in the last iteration is the root mean square result of the initial data to be calculated. In this embodiment, the input bit width can be based on the hardware. Determine the output bit width Then, based on the input bit width and output bit width The algorithm iteratively calculates the data X to be calculated, the second parameter root, and the third parameter reder, thereby obtaining the final calculation result of the second parameter root, which is the root mean square calculation result of the data X to be calculated. This solves the problem that root mean square calculation cannot be implemented in hardware in related technologies.

[0066] In an optional embodiment, step S114 above, determining the second parameter root, the third parameter reder, and the data to be calculated X for the next iteration calculation based on the judgment result, includes:

[0067] If the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates, perform a second round of updates on the values ​​of the third parameter reder and the second parameter root after the first round of updates. Use the data X to be calculated after the first round of updates as the data X to be calculated in the next iteration, use the value of the third parameter reder after the second round of updates as the third parameter reder in the next iteration, and use the value of the second parameter root after the second round of updates as the second parameter root in the next iteration.

[0068] If the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of updates, the data to be calculated X after the first round of updates will be used as the data to be calculated in the next iteration, the value of the third parameter reder after the first round of updates will be used as the third parameter reder after the next iteration, and the value of the second parameter root after the first round of updates will be used as the second parameter root after the next iteration.

[0069] Specifically, if the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates, a second round of updates can be performed on the values ​​of the third parameter reder and the second parameter root after the first round of updates. The data to be calculated X after the first round of updates will be used as the data to be calculated in the next iteration, the value of the third parameter reder after the second round of updates will be used as the third parameter reder after the next iteration, and the value of the second parameter root after the second round of updates will be used as the second parameter root after the next iteration. If the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of updates, a second round of updates is not required. The data to be calculated X after the first round of updates will be used directly as the data to be calculated in the next iteration, the value of the third parameter reder after the first round of updates will be used as the third parameter reder after the next iteration, and the value of the second parameter root after the first round of updates will be used as the second parameter root after the next iteration.

[0070] Using the above method, based on the value of the fourth parameter divi and the value of the third parameter reder after the first round of updates, it can be determined whether a second round of updates is needed for the values ​​of the third parameter reder and the second parameter root after the first round of updates, thereby accurately determining the values ​​of each parameter participating in the next iteration calculation.

[0071] In an optional embodiment, the above steps, including updating the value of the third parameter reder and the value of the second parameter root after the first round of updates, in a second round, include:

[0072] Calculate the difference between the value of the third parameter `reder` and the value of the fourth parameter `divi` after the first round of updates, and determine the value of the third parameter `reder` after the second round of updates; and,

[0073] Increment the value of the second parameter root after the first round of updates by one to obtain the value of the second parameter root after the second round of updates.

[0074] Specifically, when updating the value of the third parameter reder after the first round of updates, the difference between the value of the third parameter reder after the first round of updates and the value of the fourth parameter divi after the first round of updates can be calculated, and then the difference between the two can be used as the value of the third parameter reder after the second round of updates.

[0075] When updating the value of the second parameter root after the first round of updates, you can increment the value of the second parameter root after the first round of updates by one to obtain the value of the second parameter root after the second round of updates.

[0076] Using the above method, when the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates, a second round of updates can be performed on the second parameter root and the third parameter reder to determine the values ​​of each parameter participating in the next iteration calculation.

[0077] In an optional embodiment, step 110 above, which involves updating the second parameter root obtained in the previous iteration, the third parameter reder obtained in the previous iteration, and the data to be calculated X obtained in the previous iteration, includes:

[0078] The second parameter root, calculated in the previous iteration, is shifted one position to the left to obtain the value of the second parameter root after the first round of updates;

[0079] The third parameter `reder` obtained from the previous iteration is shifted left by one bit, and a bitwise OR operation is performed between the shifted value and the target value to obtain the updated value of the third parameter `reder` for the first round. The target value is the data to be calculated from the previous iteration, X, shifted right by the input bit width. The value obtained by subtracting 2 digits;

[0080] The data X to be calculated obtained in the previous iteration is shifted two bits to the left, and the shifted value is bitwise ANDed with the first parameter mask to obtain the value of the data X to be calculated after the first round of updates.

[0081] Specifically, when updating the second parameter root obtained from the previous iteration in the first round, the second parameter root obtained from the previous iteration can be shifted left by one bit to obtain the value of the second parameter root after the first round of updates.

[0082] When updating the third parameter `reder` obtained from the previous iteration, the value can be shifted left by one bit, and then a bitwise OR operation can be performed between the shifted value and the target value to obtain the updated value of the third parameter `reder`. The target value is the data to be calculated from the previous iteration, multiplied by the input bit width. The value obtained by subtracting 2 digits.

[0083] When updating the data X to be calculated in the previous iteration for the first time, the data X to be calculated in the previous iteration can be shifted left by two bits, and the shifted value can be bitwise ANDed with the first parameter mask to obtain the value of the data X to be calculated after the first round of updates.

[0084] Using the above method, the second parameter root, the third parameter reder, and the data X to be calculated from the previous iteration can be updated in the first round to determine the fourth parameter divi and make subsequent judgments.

[0085] In an optional embodiment, step 110 above, determining the value of the fourth parameter divi based on the value of the second parameter root after the first round of updates, includes:

[0086] The value of the second parameter root after the first round of updates is shifted one position to the left, and the shifted value is incremented by one to obtain the value of the fourth parameter divi.

[0087] Specifically, when determining the value of the fourth parameter divi, the value of the second parameter root after the first round of updates can be shifted left by one bit, and the shifted value can be incremented by one to obtain the value of the fourth parameter divi. This facilitates subsequent judgments based on the value of the fourth parameter divi and the value of the third parameter reder after the first round of updates.

[0088] In an optional embodiment, step 104 above, based on the input bit width Determine the output bit width ,include:

[0089] According to the formula calculate;

[0090] in, Indicates the output bit width. Indicates the input bit width. This indicates the floor function.

[0091] For example, suppose the input bit width is determined If the bit width is 22 bits, the output bit width can be calculated using the formula above. .

[0092] Using the above method, the input bit width can be determined. Accurately determine the output bit width. .

[0093] In an alternative embodiment, based on the input bit width Determine the value of the first parameter mask, including:

[0094] Left shift input bit width of logarithmic 1 The corresponding digits are then shifted left and the value is decreased by one to obtain the value of the first parameter, mask. In other words, based on the input bit width... When determining the value of the first parameter mask, the binary fixed-point number 1 can be shifted left. After adding one bit, subtract one from the result. This way, you can accurately obtain the first parameter, mask.

[0095] In an optional embodiment, the implementation flow of the hardware-based root mean square calculation method provided in this application is as follows: Figure 2 As shown, all the calculations here are implemented specifically for the hardware characteristics. Specifically, after preparing the data X to be calculated and the input bit width... Output bit width After setting the initial values ​​for the first parameter `mask`, the second parameter `root`, and the third parameter `reder`, the iterative calculation begins. The conditions for the iterative calculation are related to the number of iterations `i`, and the total number of iterations requires a total output bit width. The corresponding number of times.

[0096] After entering the iteration, the second parameter `root` can be shifted left by one bit to obtain the second parameter `root` after the first round of updates; the data to be calculated `X` can be shifted left by two bits and then bitwise ANDed with the first parameter `mask` to obtain the data to be calculated `X` after the first round of updates; the third parameter `reder` can be shifted left by one bit, followed by shifting the data to be calculated `X` to the right. -2 bits, then right-shift the data X to be calculated. The value after -2 bits is bitwise ORed with the value after shifting the third parameter reder one bit to the left to obtain the third parameter reder after the first round of updates; the second parameter root after the first round of updates can also be shifted one bit to the left and then incremented by 1 to obtain the fourth parameter divi.

[0097] Then, based on the values ​​updated in the first round, the relationship between the fourth parameter `divi` and the third parameter `reder` updated in the first round is determined. If the fourth parameter `divi` is less than or equal to the third parameter `reder` updated in the first round, the difference between the value of the third parameter `reder` updated in the first round and the value of the fourth parameter `divi` is used to update the third parameter `reder` updated in the first round, and the second parameter `root` updated in the first round is incremented by one. Then, the data to be calculated X updated in the first round is used as the data to be calculated X in the next iteration, the third parameter `reder` updated in the second round is used as the third parameter `reder` updated in the second round, and the second parameter `root` updated in the second round is used as the second parameter `root` updated in the second round, and the process proceeds to the next iteration. If the fourth parameter `divi` is greater than the third parameter `reder` updated in the first round, the data to be calculated X updated in the first round is used as the data to be calculated X in the next iteration, the third parameter `reder` updated in the first round is used as the third parameter `reder` updated in the first round, and the second parameter `root` updated in the first round is used as the second parameter `root` updated in the first round, and the process proceeds to the next iteration. The pseudocode corresponding to the computational logic of its iterative calculation process is shown below:

[0098]

[0099]

[0100] To facilitate understanding of the calculation process, an example is provided below. Assume the data to be calculated for the root mean square (RMS) is X=41, and the input bit width is length_in=22. Then, the output bit width is length_out=11. For ease of data representation, all calculated data will be expressed in decimal.

[0101] The calculation begins by left-shifting the value of the first parameter, mask, by 22 bits (resulting in 4194304), then subtracting 1, resulting in 4194303. The initial values ​​of the second parameter, root, and the third parameter, reder, are both 0.

[0102] In the first iteration, since the initial value of the second parameter `root` is 0, shifting 0 left by one bit still leaves 0, meaning `root` is 0 after the first update. The initial value of the third parameter `reder` is 0, and shifting 0 left by one bit still leaves 0. Then, `length_in - 2 = 22 - 2 = 20` is calculated. Next, `x` is shifted right by 20 bits, meaning the binary representation of 41 (00101001) is shifted right by 20 bits, resulting in 0. This 0 is then XORed with the left-shifted `reder`, resulting in 0, so `reder` is 0 after the first update. Shifting `X` left by 2 bits, meaning the binary representation of 41 (00101001) is shifted left by 2 bits, results in the binary representation 10100100, which corresponds to the decimal number 164. Then, a bitwise AND operation is performed between this 164 and the mask value 4194303, resulting in 164. During the `devi` calculation, the root, which has been left-shifted by one bit, is shifted left by another 1 bit, meaning 0 left-shifted by one bit still leaves 0, and then 1 is added, resulting in 1. Since divi = 1 and reder = 0 at this point, divi > reder, which does not conform to the if condition logic. Therefore, the second round of update is not performed, and the loop directly enters the next iteration. Thus, the result of the first iteration is: fourth parameter divi = 1; third parameter reder = 0; second parameter root = 0; data to be calculated X = 164.

[0103] The result of the second iteration is: fourth parameter divi = 1; third parameter reder = 0; second parameter root = 0; data to be calculated X = 656. The specific calculation logic is the same as that of the first iteration, and will not be repeated here.

[0104] The result of the third iteration is: fourth parameter divi=1; third parameter reder=0; second parameter root=0; data to be calculated X=2624.

[0105] The result of the fourth iteration is: fourth parameter divi=1; third parameter reder=0; second parameter root=0; data to be calculated X=10496.

[0106] The result of the 5th iteration is: fourth parameter divi=1; third parameter reder=0; second parameter root=0; data to be calculated X=41984.

[0107] The result of the 6th iteration is: fourth parameter divi=1; third parameter reder=0; second parameter root=0; data to be calculated X=167936.

[0108] The result of the 7th iteration is: fourth parameter divi=1; third parameter reder=0; second parameter root=0; data to be calculated X=671744.

[0109] The result of the 8th iteration is: fourth parameter divi=1; third parameter reder=0; second parameter root=0; data to be calculated X=2686976.

[0110] The result of the 9th iteration is: fourth parameter divi=1; third parameter reder=2; second parameter root=0; data to be calculated X=2359296.

[0111] Because during the 9th iteration, the fourth parameter divi < the third parameter reder, root + 1 results in root = 1.

[0112] The result of the 10th iteration is: fourth parameter divi=5; third parameter reder=6; second parameter root=2; data to be calculated X=1048576.

[0113] Since the 10th iteration satisfies the condition that the fourth parameter divi < the third parameter reder, then root+1=3.

[0114] The result of the 11th iteration is: fourth parameter divi = 13; third parameter reder = 5; second parameter root = 6; data to be calculated X = 0. Since the 11th iteration has been completed, the final output is root = 6.

[0115] Because it is a fixed-point representation, it can only represent up to 6, so the output result is 6, which is the same as the result calculated above.

[0116] The hardware-based root mean square (RMS) calculation method provided in this application can be implemented iteratively using basic operations such as hardware shifting and addition / subtraction. Furthermore, the calculated data does not require fixed-point to floating-point conversion, and the shifting and addition / subtraction operations are simple to implement with minimal area loss, thus enabling hardware-based RMS operations to be performed within a very small area.

[0117] See Figure 3 , Figure 3 This is a schematic diagram of a hardware-based root mean square (RMS) calculation device provided in an embodiment of this application. Figure 3 As shown, the hardware-based root mean square (RMS) calculation device 300 includes:

[0118] Module 302 is used to acquire the data to be calculated X and the input bit width. , where the input bit width The input bit width is the fixed-point representation of the data X to be calculated within the hardware. The value of the data X to be calculated is less than or equal to the input bit width. Maximum supported value;

[0119] The first determining module 304 is used to determine the input bit width. Determine the output bit width ;

[0120] The second determining module 306 is used to determine the input bit width. Determine the value of the first parameter mask, and preset the initial values ​​of the second parameter root and the third parameter reder to 0;

[0121] The first judgment module 308 is used to determine whether the current iteration number is less than the output bit width. The value;

[0122] Update module 310 is used to determine if the current iteration number is less than the output bit width. Given the value of the second parameter root obtained from the previous iteration, the third parameter reder obtained from the previous iteration, and the data to be calculated X obtained from the previous iteration are updated in the first round. Based on the value of the second parameter root after the first round of updates, the value of the fourth parameter divi is determined.

[0123] The second judgment module 312 is used to determine whether the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of update;

[0124] The loop module 314 is used to determine the second parameter root, the third parameter reder, and the data to be calculated X for the next iteration based on the judgment result, and then perform iterative calculation again until the current iteration count reaches the output bit width. The value of the root mean square is used to determine the root mean square result of the data X to be calculated.

[0125] Furthermore, the loop module 314 includes:

[0126] The first determining submodule is used to perform a second round of updates on the values ​​of the third parameter reder and the second parameter root after the first round of updates, when the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates. The data to be calculated X after the first round of updates is used as the data to be calculated X in the next iteration, the value of the third parameter reder after the second round of updates is used as the third parameter reder in the next iteration, and the value of the second parameter root after the second round of updates is used as the second parameter root in the next iteration.

[0127] The second determining submodule is used to determine the following when the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of updates: the data to be calculated after the first round of updates is used as the data to be calculated after the first round of updates, the value of the third parameter reder after the first round of updates is used as the third parameter reder after the first round of updates, and the value of the second parameter root after the first round of updates is used as the second parameter root after the first round of updates.

[0128] Furthermore, the first determining submodule includes:

[0129] The first calculation unit is used to calculate the difference between the value of the third parameter `reder` and the value of the fourth parameter `divi` after the first round of updates, and to determine the difference as the value of the third parameter `reder` after the second round of updates; and...

[0130] The second calculation unit is used to increment the value of the second parameter root after the first round of updates by one, so as to obtain the value of the second parameter root after the second round of updates.

[0131] Furthermore, the update module 310 includes:

[0132] The first left shift submodule is used to shift the second parameter root, calculated in the previous iteration, one position to the left to obtain the value of the second parameter root after the first round of updates;

[0133] The second left-shift submodule is used to shift the third parameter reder obtained from the previous iteration by one bit to the left, and then perform a bitwise OR operation between the shifted value and the target value to obtain the value of the third parameter reder after the first round of updates. The target value is the data to be calculated from the previous iteration multiplied by the right-shifted input bit width. The value obtained by subtracting 2 digits;

[0134] The third left shift submodule is used to shift the data X to be calculated two bits to the left of the previous iteration, and then perform a bitwise AND operation between the shifted value and the first parameter mask to obtain the value of the data X to be calculated after the first round of updates.

[0135] Furthermore, the update module 310 also includes:

[0136] The fourth left-shift submodule is used to shift the value of the second parameter root one position to the left after the first round of updates, and then add one to the shifted value to obtain the value of the fourth parameter divi.

[0137] Furthermore, the first determining module 304 includes:

[0138] The first calculation submodule is used to calculate according to the formula. calculate;

[0139] in, Indicates the output bit width. Indicates the input bit width. This indicates the floor function.

[0140] Furthermore, the second determining module 306 includes:

[0141] The second calculation submodule is used to left-shift the input bit width of the value 1. The corresponding digits are then shifted left and the value is reduced by one to obtain the value of the first parameter, mask.

[0142] It should be noted that the hardware-based root mean square calculation device 300 can implement the steps of the hardware-based root mean square calculation method provided in any of the aforementioned method embodiments, and can achieve the same technical effect, which will not be elaborated here.

[0143] like Figure 4 As shown in the illustration, this application also provides an electronic device, including a processor 411, a communication interface 412, a memory 413, and a communication bus 414, wherein the processor 411, the communication interface 412, and the memory 413 communicate with each other via the communication bus 414.

[0144] Memory 413 is used to store computer programs;

[0145] In one embodiment of this application, when the processor 411 executes the program stored in the memory 413, it implements the steps of the hardware-based root mean square calculation method provided in any of the foregoing method embodiments.

[0146] The electronic device provided in this application embodiment can specifically be a module capable of communication functions or a terminal device containing such a module. The terminal device can be a mobile terminal or a smart terminal. Specifically, a mobile terminal can be at least one of a mobile phone, tablet computer, or laptop computer; a smart terminal can specifically be a smart car, smartwatch, shared bicycle, smart cabinet, or other terminal containing a wireless communication module; and the module can specifically be a wireless communication module, such as any one of a 2G communication module, 3G communication module, 4G communication module, 5G communication module, or NB-IoT communication module.

[0147] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the hardware-based root mean square calculation method provided in any of the foregoing method embodiments.

[0148] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the steps of the hardware-based root mean square calculation method described above.

[0149] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0150] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A hardware-based root mean square (RMS) calculation method, characterized in that, The method includes: Obtain the data to be calculated X and the input bit width The input bit width The input bit width is the fixed-point representation of the data X to be calculated in the hardware, where the value of the data X to be calculated is less than or equal to the input bit width. Maximum supported value; According to the input bit width Determine the output bit width ; According to the input bit width The value of the first parameter mask is determined, and the initial values ​​of the second parameter root and the third parameter reder are preset to 0. The value of the first parameter mask does not change with the number of iterations and is used as a mask to perform a bitwise AND operation with the data to be calculated X. The values ​​of the second parameter root and the third parameter reder change with the iteration calculation. The fourth parameter divi is the value determined by the second parameter root in each iteration. The fourth parameter divi is used to cooperate with the third parameter reder to jointly determine the validity of the second parameter root obtained in the current iteration calculation. Determine if the current iteration number is less than the output bit width. The value; If the current iteration number is determined to be less than the output bit width Given the given values, the second parameter root, the third parameter reder, and the data X to be calculated from the previous iteration are updated in the first round. Based on the value of the second parameter root after the first round of updates, the value of the fourth parameter divi is determined. The value of the fourth parameter divi is obtained by shifting the value of the second parameter root one position to the left after the first round of updates and adding one to the shifted value. Determine whether the value of the fourth parameter, divi, is less than or equal to the value of the third parameter, reder, after the first round of updates; Based on the judgment result, the second parameter root, the third parameter reder, and the data to be calculated X are determined for the next iteration calculation, and the iteration calculation is performed again until the current iteration number reaches the specified output bit width. The value of the second parameter root is determined as the root mean square calculation result of the data X to be calculated. The step of determining the second parameter root, the third parameter reder, and the data X to be calculated in the next iteration based on the judgment result includes: If the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates, a second round of updates is performed on the values ​​of the third parameter reder and the second parameter root after the first round of updates. The data to be calculated X after the first round of updates is used as the data to be calculated X in the next iteration, the value of the third parameter reder after the second round of updates is used as the third parameter reder in the next iteration, and the value of the second parameter root after the second round of updates is used as the second parameter root in the next iteration. If the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of update, the data to be calculated X after the first round of update is used as the data to be calculated X in the next iteration calculation, the value of the third parameter reder after the first round of update is used as the third parameter reder in the next iteration calculation, and the value of the second parameter root after the first round of update is used as the second parameter root in the next iteration calculation. The first round of updating the second parameter root obtained from the previous iteration, the third parameter reder obtained from the previous iteration, and the data X to be calculated obtained from the previous iteration includes: The second parameter root, calculated in the previous iteration, is shifted one position to the left to obtain the value of the second parameter root after the first round of updates; The third parameter `reder` obtained from the previous iteration is shifted left by one bit, and a bitwise OR operation is performed between the shifted value and the target value to obtain the updated value of the third parameter `reder` for the first round. The target value is the data to be calculated X obtained from the previous iteration, shifted right by the input bit width. The value obtained by subtracting 2 digits; The data X to be calculated obtained in the previous iteration is shifted two bits to the left, and the shifted value is bitwise ANDed with the first parameter mask to obtain the value of the data X to be calculated after the first round of updates; The second round of updates to the values ​​of the third parameter `reder` and the second parameter `root` after the first round of updates includes: Calculate the difference between the value of the third parameter `reder` after the first round of updates and the value of the fourth parameter `divi`, and determine the difference as the value of the third parameter `reder` after the second round of updates; and, Increment the value of the second parameter root after the first round of updates by one to obtain the value of the second parameter root after the second round of updates.

2. The method according to claim 1, characterized in that, The input bit width Determine the output bit width ,include: According to the formula calculate; in, This indicates the output bit width. This indicates the input bit width. This indicates the floor function.

3. The method according to claim 1, characterized in that, The input bit width Determine the value of the first parameter mask, including: Left-shift the input bit width by the value 1 The corresponding digits are then shifted to the left and the value of the left-shifted value is reduced by one to obtain the value of the first parameter mask.

4. A hardware-based root mean square (RMS) calculation device, characterized in that, The device includes: The acquisition module is used to acquire the data to be calculated X and the input bit width. The input bit width The input bit width is the fixed-point representation of the data X to be calculated in the hardware, where the value of the data X to be calculated is less than or equal to the input bit width. Maximum supported value; The first determining module is used to determine the input bit width. Determine the output bit width ; The second determining module is used to determine the input bit width. The value of the first parameter mask is determined, and the initial values ​​of the second parameter root and the third parameter reder are preset to 0. The value of the first parameter mask does not change with the number of iterations and is used as a mask to perform a bitwise AND operation with the data to be calculated X. The values ​​of the second parameter root and the third parameter reder change with the iteration calculation. The fourth parameter divi is the value determined by the second parameter root in each iteration. The fourth parameter divi is used to cooperate with the third parameter reder to jointly determine the validity of the second parameter root obtained in the current iteration calculation. The first judgment module is used to determine whether the current iteration number is less than the output bit width. The value; The update module is used to determine if the current iteration number is less than the output bit width. Given the given values, the second parameter root, the third parameter reder, and the data X to be calculated from the previous iteration are updated in the first round. Based on the value of the second parameter root after the first round of updates, the value of the fourth parameter divi is determined. The value of the fourth parameter divi is obtained by shifting the value of the second parameter root one position to the left after the first round of updates and adding one to the shifted value. The second judgment module is used to determine whether the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of update; The loop module is used to determine the second parameter root, the third parameter reder, and the data to be calculated X for the next iteration based on the judgment result, and then perform iterative calculation again until the current iteration number reaches the specified output bit width. The value of the second parameter root is determined as the root mean square calculation result of the data X to be calculated. The loop module includes: The first determining submodule is used to perform a second round of updates on the values ​​of the third parameter reder and the second parameter root after the first round of updates when the value of the fourth parameter divi is less than or equal to the value of the third parameter reder after the first round of updates. The data to be calculated X after the first round of updates is used as the data to be calculated X participating in the next iteration calculation, the value of the third parameter reder after the second round of updates is used as the third parameter reder participating in the next iteration calculation, and the value of the second parameter root after the second round of updates is used as the second parameter root participating in the next iteration calculation. The second determining submodule is used to, when the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of update, use the data to be calculated after the first round of update as the data to be calculated in the next iteration, the value of the third parameter reder after the first round of update as the third parameter reder after the first round of update, and the value of the second parameter root after the first round of update as the second parameter root after the first round of update. The update module includes: The first left shift submodule is used to shift the second parameter root, calculated in the previous iteration, one position to the left to obtain the value of the second parameter root after the first round of updates; The second left-shift submodule is used to shift the third parameter reder obtained from the previous iteration by one bit to the left, and then perform a bitwise OR operation between the shifted value and the target value to obtain the value of the third parameter reder after the first round of updates. The target value is the data to be calculated X right-shifted input bit width obtained from the previous iteration. The value obtained by subtracting 2 digits; The third left shift submodule is used to shift the data X to be calculated two bits to the left of the previous iteration, and perform a bitwise AND operation between the shifted value and the first parameter mask to obtain the value of the data X to be calculated after the first round of updates. The first determining submodule includes: The first calculation unit is used to calculate the difference between the value of the third parameter reder after the first round of updates and the value of the fourth parameter divi, and to determine the difference as the value of the third parameter reder after the second round of updates; and The second calculation unit is used to increment the value of the second parameter root after the first round of updates by one, so as to obtain the value of the second parameter root after the second round of updates.

5. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the hardware-based root mean square calculation method as described in any one of claims 1-3.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the hardware-based root mean square calculation method as described in any one of claims 1-3.

Citation Information

Patent Citations

  • Method for calculating inverse square roots

    KR1020070025195A