Root mean square calculation method and device based on hardware implementation and electronic equipment
Through the iterative calculation methods, the calculation of the average root in the hardware is used to solve the problem of unable to achieve average square root calculation in the hardware in the existing technology, and the efficiency of data processing is improved.
Patent Information
- Application Number
- CN202411938227.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-26
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2044-12-26
AI Technical Summary
The prior art cannot implement root mean square calculation based on hardware, resulting in a lack of efficient calculation methods when processing big data.
By obtaining the width of the data X and the input position, the output bits are determined, and the iterative calculation method is used to update the second -parameter root, the third parameter Reder, and the data X to be calculated, until the number of iteration reaches the value of the output bits, and it is necessary Calculate the calculation result of the data x.
The hardware-based root mean square calculation is implemented, which solves the problem that traditional methods cannot realize the root mean square calculation on hardware, and improves the efficiency and throughput of data processing.
Smart Images

Figure CN119357543A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of wireless communication technology, and in particular to a root mean square calculation method, device and electronic device based on hardware implementation. Background Art
[0002] With the development of the fifth generation mobile communication technology (5G), the amount of data that user equipment (UE) needs to process is increasing. In order to ensure that the user equipment has a higher throughput and faster processing speed, most of the data processing cannot be achieved directly through digital signal processing (DSP) or central processing unit (CPU), so it needs to be achieved with the help of hardware.
[0003] However, in the related technology, conventional calculations such as addition, subtraction, multiplication and division can usually be implemented based on hardware, but the root mean square calculation cannot be implemented based on hardware. Therefore, how to implement the root mean square calculation based on hardware has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The present application provides a root mean square calculation method, device and electronic device based on hardware implementation to solve the problem in the related art that conventional calculations such as addition, subtraction, multiplication and division can usually be implemented based on hardware, but root mean square calculation cannot be implemented based on hardware.
[0005] In a first aspect, an embodiment of the present application provides a root mean square calculation method based on hardware implementation, the method comprising: Get the data to be calculated X and the input bit width , where the input bit width is the bit width occupied by the data to be calculated X in fixed-point form in the hardware, and the value of the data to be calculated X is less than or equal to the input bit width The maximum value supported; According to the input bit width , determine the output bit width ; 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; Determine whether the current number of iterations is less than the output bit width The value of When determining that the current number of iterations is less than the output bit width In the case of the value of, the second parameter root obtained by the previous iteration calculation, the third parameter reder obtained by the previous iteration calculation and the data to be calculated X obtained by the previous iteration calculation are updated for the first round, and the value of the fourth parameter divi is determined based on the value of the second parameter root after the first round of update; 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; According to the judgment result, the second parameter root, the third parameter reder and the data to be calculated X participating in the next iterative calculation are determined, and the iterative calculation is performed again until the current number of iterations reaches the output bit width The value of the second parameter root finally obtained is determined as the root mean square calculation result of the data X to be calculated.
[0006] Optionally, the determining, according to the judgment result, the second parameter root, the third parameter reder and the data to be calculated X to be involved in the next iterative calculation includes: In the case that 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 updating, the value of the third parameter reder after the first round of updating and the value of the second parameter root after the first round of updating are updated in the second round, and the to-be-calculated data X after the first round of updating is used as the to-be-calculated data X participating in the next iterative calculation, the value of the third parameter reder after the second round of updating is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the second round of updating is used as the second parameter root participating in the next iterative calculation; When 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 participating in the next iterative calculation, the value of the third parameter reder after the first round of update is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the first round of update is used as the second parameter root participating in the next iterative calculation.
[0007] Optionally, performing a second round of updating on the value of the third parameter reder after the first round of updating and the value of the second parameter root after the first round of updating includes: Calculating the difference between the value of the third parameter reder after the first round of updating and the value of the fourth parameter divi, and determining the difference as the value of the third parameter reder after the second round of updating; and, The value of the second parameter root after the first round of update is increased by one to obtain the value of the second parameter root after the second round of update.
[0008] Optionally, performing a first round of updating on the second parameter root obtained by the last iterative calculation, the third parameter reder obtained by the last iterative calculation, and the to-be-calculated data X obtained by the last iterative calculation includes: Shift the second parameter root calculated in the previous iteration left by one position to obtain the value of the second parameter root after the first round of update; The third parameter reder obtained by the last iteration is shifted left by one bit, and the left-shifted value is bitwise ORed with the target value to obtain the value of the third parameter reder after the first round of update, wherein the target value is the input bit width of the data to be calculated X right-shifted obtained by the last iteration. -The value obtained after the digit of 2; The data X to be calculated obtained by the previous iterative calculation is shifted left by two bits, and a bitwise AND operation is performed on the left-shifted value and the first parameter mask to obtain the value of the data X to be calculated after the first round of update.
[0009] Optionally, determining the value of the fourth parameter divi based on the value of the second parameter root after the first round of update includes: The value of the second parameter root after the first round of update is shifted left by one bit, and the value after the left shift is increased by one to obtain the value of the fourth parameter divi.
[0010] Optionally, the input bit width , determine the output bit width ,include: According to the formula calculate; in, represents the output bit width, represents the input bit width, Indicates floor operation.
[0011] Optionally, the input bit width , determine the value of the first parameter mask, including: Shift the value 1 left by the input bit width The corresponding digit is shifted to the left, and the left-shifted value is reduced by one to obtain the value of the first parameter mask. In a second aspect, the embodiment of the present application further provides a root mean square calculation device based on hardware implementation, the device comprising: Acquisition module, used to obtain the data to be calculated X and the input bit width , where the input bit width is the bit width occupied by the data to be calculated X in fixed-point form in the hardware, and the value of the data to be calculated X is less than or equal to the input bit width The maximum value supported; The first determining module is used to determine the input bit width according to the , determine the output bit width ; The second determining module is used to determine the input bit width according to the , 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; The first judgment module is used to judge whether the current number of iterations is less than the output bit width The value of An updating module is used to determine that the current number of iterations is less than the output bit width. In the case of the value of, the second parameter root obtained by the previous iteration calculation, the third parameter reder obtained by the previous iteration calculation and the data to be calculated X obtained by the previous iteration calculation are updated for the first round, and the value of the fourth parameter divi is determined based on the value of the second parameter root after the first round of update; A second judgment module is used to judge 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 to participate in the next iterative calculation according to the judgment result, and perform iterative calculation again until the current number of iterations reaches the output bit width The value of the second parameter root finally obtained is determined as the root mean square calculation result of the data X to be calculated.
[0012] In a third aspect, an embodiment of the present application further provides 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 via the communication bus; Memory, used to store computer programs; The processor is used to implement the root mean square calculation method based on hardware implementation described in the first aspect when executing the program stored in the memory.
[0013] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the hardware-based root mean square calculation method as described in the first aspect is implemented.
[0014] The above technical solution provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application obtains the data to be calculated X and the input bit width , where the input bit width is the bit width occupied by the data to be calculated X in fixed-point form in the hardware, and the value of the data to be calculated X is less than or equal to the input bit width The maximum supported value; according to the input bit width , determine the output bit width ; 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; determine whether the current number of iterations is less than the output bit width The value of; when determining that the current number of iterations is less than the output bit width In the case of a value of , the second parameter root obtained by the previous iterative calculation, the third parameter reder obtained by the previous iterative calculation, and the data to be calculated X obtained by the previous iterative calculation are updated for the first round, and the value of the fourth parameter divi is determined based on the value of the second parameter root after the first round of update; it is determined 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; according to the judgment result, the second parameter root, the third parameter reder, and the data to be calculated X participating in the next iterative calculation are determined, and iterative calculation is performed again until the current number of iterations reaches the output bit width The value of the second parameter root finally obtained is determined as the root mean square calculation result of the data to be calculated X. In the above manner, the input bit width of the hardware can be , determine the output bit width , and then according to the input bit width and output bit width , the data to be calculated X, the second parameter root and the third parameter reder are iteratively calculated, thereby obtaining the final calculation result of the second parameter root, that is, the RMS calculation result of the data to be calculated X, which solves the problem in the related art that the RMS calculation cannot be implemented based on hardware. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0016] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0017] Figure 1A schematic diagram of a process flow of a root mean square calculation method based on hardware implementation provided in an embodiment of the present application; Figure 2 A flowchart of another root mean square calculation method based on hardware implementation provided in an embodiment of the present application; Figure 3 A schematic diagram of the structure of a root mean square calculation device based on hardware implementation provided in an embodiment of the present application; Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0019] See also Figure 1 , Figure 1 The following is a flow chart of a root mean square calculation method based on hardware implementation provided in an embodiment of the present application. Figure 1 As shown, the root mean square calculation method based on hardware implementation may include the following steps: Step S102: Obtain the data to be calculated X and the input bit width , where the input bit width is The bit width occupied by the data to be calculated X in fixed-point form in the hardware. The value of the data to be calculated X is less than or equal to the input bit width. The maximum value supported.
[0020] Specifically, the data to be calculated X represents the data that needs to be calculated for RMS. The data to be calculated X can be represented as a binary fixed-point data in hardware, which can be pre-converted from any fixed-point data or floating-point data. Indicates the bit width occupied by the data to be calculated X in fixed-point form in the hardware. The input bit width It is determined based on the hardware's own properties, such as the type and rules of the hardware. Since the leftmost bit of binary fixed-point data in hardware is the highest bit, it generally represents the positive and negative signs of the data, so the actual data bit width is the input bit width Subtract one bit width, that is, the value of the data X to be calculated should be less than or equal to the input bit width -1 bit after which all data bits have a binary value of 1.
[0021] When obtaining the data X to be calculated, the non-binary fixed-point data can be converted into binary fixed-point data before obtaining it. For example, for a certain floating-point data, the following formula can be used to convert the floating-point data into decimal fixed-point data: d'x=x*2^(length_in-1), where d'x is 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 calculating the decimal fixed-point data, the decimal fixed-point data can be converted into binary fixed-point data.
[0022] 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 to this application. In this application, the input bit width is represented by , and of course, other English words can also be used to represent the input bit width, which does not constitute a limitation to this application. Step S104: According to the input bit width , determine the output bit width .
[0023] After determining the input bit width After that, you can use the input bit width , determine the output bit width The output bit width here is It refers to the data output bit width that minimizes the hardware area and power consumption without affecting the RMS calculation accuracy. and input bit width The relationship between can be obtained based on human experience or experimental data, and is not specifically limited in this application. In this application, the output bit width is represented. Of course, other English words can also be used to represent the output bit width, which does not constitute a limitation to this application.
[0024] Step S106: 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.
[0025] The first parameter mask, the second parameter root and the third parameter reder are the relevant parameters needed in the RMS calculation process based on hardware implementation. Therefore, their initial values need to be determined before iterative calculation. Among them, the value of the first parameter mask will not change with iterative calculation. The value of the first parameter mask can be changed according to the input bit width. It is determined that it is actually a mask, which is used to perform a bitwise AND operation with the data to be calculated X to prevent overflow of the data to be calculated X. The values of the second parameter root and the third parameter reder will change with the iterative calculation, and their initial values are both 0. The fourth parameter divi is the value determined by the second parameter root in each iteration. The role of the fourth parameter divi is to cooperate with the third parameter reder to jointly determine the validity of the current second parameter root.
[0026] It should be noted that mask, root and reder here represent the first parameter, the second parameter and the third parameter respectively in this application. Of course, other English words can also be used to represent the first parameter, the second parameter and the third parameter, which does not constitute a limitation to this application.
[0027] Step S108: Determine whether the current number of iterations is less than the output bit width The numerical value of .
[0028] During the loop iterative calculation process, it is necessary to determine whether the current number of iterations is less than the output bit width before each iteration calculation. If the current number of iterations is greater than or equal to the output bit width If the value of , it means that the RMS calculation result has been calculated and the iterative calculation can be stopped; if the current number of iterations is less than the output bit width If the value is less than , it means that the RMS calculation result has not been obtained and iterative calculation needs to be continued.
[0029] Step S110: When it is determined that the current number of iterations is less than the output bit width In the case of a numerical value, the second parameter root obtained by the previous iterative calculation, the third parameter reder obtained by the previous iterative calculation and the data to be calculated X obtained by the previous iterative calculation are updated for the first round, and the value of the fourth parameter divi is determined based on the value of the second parameter root after the first round of update.
[0030] In each iterative calculation, it is necessary to perform a first round of updates on the second parameter root obtained in the previous iterative calculation, the third parameter reder obtained in the previous iterative calculation, and the data to be calculated X obtained in the previous iterative calculation, and determine the value of the fourth parameter divi based on the value of the second parameter root after the first round of update. For example, in the first iterative calculation, the initial value of the second parameter root, the initial value of the third parameter reder, and the data to be calculated are updated in the first round; in the second iterative calculation, the second parameter root obtained in the first iterative calculation, the third parameter reder obtained in the first iterative calculation, and the data to be calculated X obtained in the first iterative calculation are updated in the first round; in the third iterative calculation, the second parameter root obtained in the second iterative calculation, the third parameter reder obtained in the second iterative calculation, and the data to be calculated X obtained in the second iterative calculation are updated in the first round, and so on. It should be noted that divi here represents the fourth parameter in this application. Of course, other English words can also be used to represent the fourth parameter, which does not constitute a limitation to this application.
[0031] 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 update.
[0032] In each iterative calculation, 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 update. If it is determined that 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, it means that it is necessary to perform a second round of update on the value of the third parameter reder after the first round of update and the value of the second parameter root after the first round of update, and enter the next iterative calculation after completing the second round of update; if it is determined that the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of update, it means that it is not necessary to perform a second round of update on the value of the third parameter reder after the first round of update and the value of the second parameter root after the first round of update, and directly enter the next iterative calculation.
[0033] Step S114: According to the judgment result, determine the second parameter root, the third parameter reder and the data to be calculated X to participate in the next iterative calculation, and perform iterative calculation again until the current number of iterations reaches the output bit width The value of the second parameter root finally obtained is determined as the root mean square calculation result of the data to be calculated X.
[0034] In this step, the second parameter root, the third parameter reder and the data to be calculated X that participate in the next iteration calculation can be determined according to the judgment result of the fourth parameter divi and the value of the third parameter reder after the first round of update, and the iteration cycle is performed again until the current iteration number reaches the output bit width In this way, the number of iterations can be guaranteed to reach the output bit width The corresponding value, so the number of bits of the calculation result (binary fixed-point data) and the output bit width In addition, the second parameter root, the third parameter reder and the data to be calculated X can be adjusted in each iteration process so that the value of the second parameter root calculated in the last iteration is the root mean square calculation result of the initial data to be calculated. In this embodiment, the input bit width of the hardware can be used to calculate the second parameter root. , determine the output bit width , and then according to the input bit width and output bit width , the data to be calculated X, the second parameter root and the third parameter reder are iteratively calculated, thereby obtaining the final calculation result of the second parameter root, that is, the RMS calculation result of the data to be calculated X, which solves the problem in the related art that the RMS calculation cannot be implemented based on hardware.
[0035] In an optional embodiment, the above step S114, based on the judgment result, determines the second parameter root, the third parameter reder and the data to be calculated X to participate in the next iterative calculation, including: In the case that 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 updating, the value of the third parameter reder after the first round of updating and the value of the second parameter root after the first round of updating are updated in the second round, and the to-be-calculated data X after the first round of updating is used as the to-be-calculated data X participating in the next iterative calculation, the value of the third parameter reder after the second round of updating is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the second round of updating is used as the second parameter root participating in the next iterative calculation; When 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 participating in the next iterative calculation, the value of the third parameter reder after the first round of update is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the first round of update is used as the second parameter root participating in the next iterative calculation.
[0036] 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 update, the value of the third parameter reder after the first round of update and the value of the second parameter root after the first round of update can be updated for the second round, and the data to be calculated X after the first round of update is used as the data to be calculated X participating in the next iterative calculation, the value of the third parameter reder after the second round of update is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the second round of update is used as the second parameter root participating in the next iterative calculation. If the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of update, there is no need to perform the second round of update, and the data to be calculated X after the first round of update is directly used as the data to be calculated X participating in the next iterative calculation, the value of the third parameter reder after the first round of update is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the first round of update is used as the second parameter root participating in the next iterative calculation.
[0037] Through 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 update, it can be determined whether a second round of update is required for the value of the third parameter reder after the first round of update and the value of the second parameter root after the first round of update, thereby accurately determining the values of each parameter participating in the next iterative calculation.
[0038] In an optional embodiment, the above step of performing a second round of updating on the value of the third parameter reder after the first round of updating and the value of the second parameter root after the first round of updating includes: Calculating the difference between the value of the third parameter reder after the first round of updating and the value of the fourth parameter divi, and determining the difference as the value of the third parameter reder after the second round of updating; and, The value of the second parameter root after the first round of update is increased by one to obtain the value of the second parameter root after the second round of update.
[0039] Specifically, when performing a second round of updating on the value of the third parameter reder after the first round of updating, the difference between the value of the third parameter reder after the first round of updating and the value of the fourth parameter divi 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 updating.
[0040] When performing a second round of updating on the value of the second parameter root after the first round of updating, the value of the second parameter root after the first round of updating may be added by one to obtain the value of the second parameter root after the second round of updating.
[0041] In the above manner, 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 update, the second parameter root and the third parameter reder can be updated for the second round to determine the values of the parameters participating in the next iterative calculation.
[0042] In an optional embodiment, the above step 110, performing a first round of updating on the second parameter root obtained by the previous iterative calculation, the third parameter reder obtained by the previous iterative calculation, and the data to be calculated X obtained by the previous iterative calculation, includes: Shift the second parameter root calculated in the previous iteration left by one position to obtain the value of the second parameter root after the first round of update; Shift the third parameter reder obtained by the previous iteration calculation left by one bit, and perform a bitwise OR operation on the left-shifted value and the target value to obtain the value of the third parameter reder after the first round of update, where the target value is the input bit width of the data to be calculated X right-shifted obtained by the previous iteration calculation -The value obtained after the digit of 2; The data X to be calculated obtained by the previous iteration is shifted left by two bits, and the left-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 update.
[0043] Specifically, when performing the first round of updating on the second parameter root obtained by the previous iterative calculation, the second parameter root obtained by the previous iterative calculation may be shifted left by one position to obtain the value of the second parameter root after the first round of updating.
[0044] When the third parameter reder obtained by the last iteration is updated for the first round, the third parameter reder obtained by the last iteration can be shifted left by one bit, and the value after the left shift is bitwise ORed with the target value to obtain the value of the third parameter reder after the first round of update, wherein the target value is the input bit width of the data to be calculated X right shifted obtained by the last iteration. -2 digits after the value obtained.
[0045] When performing the first round of updating on the data to be calculated X obtained by the previous iterative calculation, the data to be calculated X obtained by the previous iterative calculation can be left-shifted by two bits, and the left-shifted value is bitwise ANDed with the first parameter mask to obtain the value of the data to be calculated X after the first round of updating.
[0046] In the above manner, the second parameter root obtained by the last iterative calculation, the third parameter reder obtained by the last iterative calculation and the to-be-calculated data X obtained by the last iterative calculation can be updated for the first round to determine the fourth parameter divi and perform subsequent judgment.
[0047] In an optional embodiment, the above step 110, determining the value of the fourth parameter divi based on the value of the second parameter root after the first round of update, includes: The value of the second parameter root after the first round of update is shifted left by one position, and the value after the left shift is increased by one to obtain the value of the fourth parameter divi.
[0048] Specifically, when determining the value of the fourth parameter divi, the value of the second parameter root after the first round of update can be shifted left by one place, and the value after left shift can be added by one to obtain the value of the fourth parameter divi, so as to facilitate subsequent judgments based on the value of the fourth parameter divi and the value of the third parameter reder after the first round of update.
[0049] In an optional embodiment, the above step 104, according to the input bit width , determine the output bit width ,include: According to the formula calculate; in, Indicates the output bit width, Indicates the input bit width, Indicates floor operation.
[0050] For example, suppose the input bit width is determined is 22 bits, then the output bit width can be calculated according to the above formula .
[0051] In the above way, according to the input bit width , accurately determine the output bit width .
[0052] In an optional embodiment, according to the input bit width , determine the value of the first parameter mask, including: Shift the value 1 left by the input bit width The corresponding digit is shifted left by one, and the value after left shift is reduced by one to obtain the value of the first parameter mask. , when determining the value of the first parameter mask, you can shift the binary fixed-point number 1 left After the bit is added, subtract 1. In this way, the first parameter mask can be accurately obtained.
[0053] In an optional embodiment, the implementation process of the root mean square calculation method based on hardware implementation provided in the embodiment of the present application is as follows: Figure 2 As shown in the figure, all calculations here are implemented based on the hardware characteristics. Specifically, after preparing the data to be calculated X and the input bit width , output bit width , the value of the first parameter mask, the initial value of the second parameter root and the initial value of the third parameter reder, then it enters the iterative calculation. The iterative calculation condition is related to the number of iterations i. The number of iterative calculations requires a total of iterative output bit width The corresponding number of times.
[0054] 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 update; 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 update; the third parameter reder can be shifted left by one bit, and then the data to be calculated X can be shifted right by one bit. -2 bits, then right shift the data X to be calculated The value after -2 bits is bitwise ORed with the value of the third parameter reder after shifting left by one bit to obtain the third parameter reder after the first round of update; the second parameter root after the first round of update can also be shifted left by one bit and then added with 1 to obtain the fourth parameter divi.
[0055] Then, based on the value after the first round of update, the relationship between the fourth parameter divi and the third parameter reder after the first round of update is determined. If the fourth parameter divi is less than or equal to the third parameter reder after the first round of update, the third parameter reder after the first round of update is updated by using the difference between the value of the third parameter reder after the first round of update and the value of the fourth parameter divi, and the second parameter root after the first round of update is added by one, and then the data to be calculated X after the first round of update is used as the data to be calculated X participating in the next iterative calculation, the third parameter reder after the second round of update is used as the third parameter reder participating in the next iterative calculation, and the second parameter root after the second round of update is used as the second parameter root participating in the next iterative calculation, and the next iterative calculation is entered. If the fourth parameter divi is greater than 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 participating in the next iterative calculation, the third parameter reder after the first round of update is used as the third parameter reder participating in the next iterative calculation, and the second parameter root after the first round of update is used as the second parameter root participating in the next iterative calculation, and the next iterative calculation is entered. The pseudo code corresponding to the calculation logic of its iterative calculation process is as follows:
[0056]
[0057] To facilitate understanding of the calculation process, an example is given here. Assuming that the data to be calculated for RMS is X=41, and the input bit width length_in=22, it can be known that the output bit width length_out=11. To facilitate data representation, all calculation data are expressed in decimal.
[0058] The value of the first parameter mask is 1, shifted left by 22 bits (4194304), and then subtracted by 1 to get 4194303. The initial values of the second parameter root and the third parameter reder are both 0.
[0059] In the first iteration, since the initial value of the second parameter root is 0, it is still 0 after being shifted left by one bit, that is, the root after the first round of update is 0. The initial value of the third parameter reder is 0, and it is still 0 after being shifted left by one bit. Then, length_in-2=22-2=20 is calculated, and then x is shifted right by 20 bits, that is, the binary number 00101001 of 41 is shifted right by 20 bits, and the result is 0. Then, this 0 is XORed with the reder after being shifted left by one bit, and the result is still 0. Therefore, reder after the first round of update is 0. X is shifted left by 2 bits, that is, the binary number 00101001 of 41 is shifted left by 2 bits, and the binary number 10100100 is obtained, and its corresponding decimal number is 164. Then, the bitwise AND operation of 164 and the value of mask 4194303 is performed, and the result is 164. When calculating divi, the root after being shifted left by one bit is first shifted left by 1 bit, that is, 0 is still 0 after being shifted left by one bit, and then 1 is added to obtain the result of 1. Because divi=1, reder=0, so divi>reder, does not meet the if judgment logic, so the second round of update is not performed, and the next for loop is directly entered. Therefore, the result of the first iteration calculation is: the fourth parameter divi=1; the third parameter reder=0; the second parameter root=0; the data to be calculated X=164.
[0060] The result of the second iteration calculation is: the fourth parameter divi = 1; the third parameter reder = 0; the second parameter root = 0; the data to be calculated X = 656. The specific calculation logic is the same as that of the first iteration calculation, and will not be repeated here.
[0061] The result of the third iterative calculation is: the fourth parameter divi=1; the third parameter reder=0; the second parameter root=0; the data to be calculated X=2624.
[0062] The result of the fourth iterative calculation is: the fourth parameter divi=1; the third parameter reder=0; the second parameter root=0; the data to be calculated X=10496.
[0063] The result of the fifth iterative calculation is: the fourth parameter divi=1; the third parameter reder=0; the second parameter root=0; the data to be calculated X=41984.
[0064] The result of the sixth iteration calculation is: the fourth parameter divi=1; the third parameter reder=0; the second parameter root=0; the data to be calculated X=167936.
[0065] The result of the seventh iteration calculation is: the fourth parameter divi=1; the third parameter reder=0; the second parameter root=0; the data to be calculated X=671744.
[0066] The result of the 8th iterative calculation is: the fourth parameter divi=1; the third parameter reder=0; the second parameter root=0; the data to be calculated X=2686976.
[0067] The result of the 9th iterative calculation is: the fourth parameter divi=1; the third parameter reder=2; the second parameter root=0; the data to be calculated X=2359296.
[0068] Because in the 9th iterative calculation, the fourth parameter divi<the third parameter reder, so root+1 gets root=1.
[0069] The result of the 10th iterative calculation is: the fourth parameter divi=5; the third parameter reder=6; the second parameter root=2; the data to be calculated X=1048576.
[0070] Because the 10th iteration satisfies the fourth parameter divi<the third parameter reder, root+1=3.
[0071] The result of the 11th iteration is: the fourth parameter divi = 13; the third parameter reder = 5; the second parameter root = 6; the data to be calculated X = 0. Because the 11th iteration has been completed, the final output root = 6.
[0072] , 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.
[0073] The RMS calculation method based on hardware implementation provided in this application can be implemented through iteration using basic operations such as hardware shift and addition and subtraction operations. In addition, the calculated data does not need to be converted from fixed to floating point, and the shift and addition and subtraction operations are simple to implement, with minimal area loss, so the RMS hardware operation can be implemented with a very small area.
[0074] See also Figure 3 , Figure 3 The schematic diagram of the structure of a root mean square calculation device based on hardware implementation provided in the embodiment of the present application is as follows. Figure 3 As shown, the RMS calculation device 300 based on hardware implementation includes: Acquisition module 302, used to obtain the data to be calculated X and the input bit width , where the input bit width is The bit width occupied by the data to be calculated X in fixed-point form in the hardware. The value of the data to be calculated X is less than or equal to the input bit width. The maximum value supported; The first determination module 304 is used to determine the input bit width according to , determine the output bit width ; The second determination module 306 is used to determine the input bit width according to , 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; The first judgment module 308 is used to judge whether the current number of iterations is less than the output bit width The value of Update module 310, for determining that the current number of iterations is less than the output bit width In the case of the value of, the second parameter root obtained by the previous iteration calculation, the third parameter reder obtained by the previous iteration calculation and the data to be calculated X obtained by the previous iteration calculation are updated for the first round, and the value of the fourth parameter divi is determined based on the value of the second parameter root after the first round of update; The second judgment module 312 is used to judge 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 314 is used to determine the second parameter root, the third parameter reder and the data to be calculated X to participate in the next iteration calculation according to the judgment result, and perform iterative calculation again until the current iteration number reaches the output bit width The value of the second parameter root finally obtained is determined as the root mean square calculation result of the data to be calculated X.
[0075] Furthermore, the loop module 314 includes: a first determining submodule, configured to perform a second round of updating on the value of the third parameter reder after the first round of updating and the value of the second parameter root after the first round of updating, 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 updating, and use the to-be-calculated data X after the first round of updating as the to-be-calculated data X participating in the next iterative calculation, the value of the third parameter reder after the second round of updating as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the second round of updating as the second parameter root participating in the next iterative calculation; The second determination submodule is used to use the to-be-calculated data X after the first round of update as the to-be-calculated data X participating in the next iterative calculation, the value of the third parameter reder after the first round of update as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the first round of update as the second parameter root participating in the next iterative calculation when the value of the fourth parameter divi is greater than the value of the third parameter reder after the first round of update.
[0076] Furthermore, the first determining submodule includes: A first calculation unit is used to calculate the difference between the value of the third parameter reder after the first round of update 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 update; and The second calculation unit is used to add one to the value of the second parameter root after the first round of update to obtain the value of the second parameter root after the second round of update.
[0077] Furthermore, the update module 310 includes: The first left shift submodule is used to left shift the second parameter root calculated in the previous iteration by one position to obtain the value of the second parameter root after the first round of update; The second left shift submodule is used to shift the third parameter reder obtained by the previous iteration calculation to the left by one bit, and perform a bitwise OR operation on the left-shifted value and the target value to obtain the value of the third parameter reder after the first round of update, wherein the target value is the right shift input bit width of the data to be calculated obtained by the previous iteration calculation -The value obtained after the digit of 2; The third left-shift submodule is used to left-shift the data to be calculated X obtained by the previous iterative calculation by two bits, and perform a bitwise AND operation on the left-shifted value and the first parameter mask to obtain the value of the data to be calculated X after the first round of update.
[0078] Furthermore, the updating module 310 further includes: The fourth left-shift submodule is used to left-shift the value of the second parameter root after the first round of update by one position, and add one to the left-shifted value to obtain the value of the fourth parameter divi.
[0079] Further, the first determining module 304 includes: The first calculation submodule is used to calculate the calculate; in, Indicates the output bit width, Indicates the input bit width, Indicates floor operation.
[0080] Further, the second determining module 306 includes: The second calculation submodule is used to shift the value 1 to the left input bit width The corresponding digit is shifted left by one, and the value after left shifting is reduced by one to obtain the value of the first parameter mask.
[0081] 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 effects, which will not be described one by one here.
[0082] like Figure 4 As shown, the embodiment of the present application further 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 through the communication bus 414. Memory 413, used for storing computer programs; In one embodiment of the present application, the processor 411 is used to implement the steps of the hardware-based root mean square calculation method provided by any of the aforementioned method embodiments when executing the program stored in the memory 413.
[0083] The electronic device provided in the embodiment of the present application may specifically be a module capable of realizing a communication function or a terminal device including the module, etc. The terminal device may be a mobile terminal or a smart terminal. The mobile terminal may specifically be at least one of a mobile phone, a tablet computer, a laptop computer, etc.; the smart terminal may specifically be a terminal including a wireless communication module such as a smart car, a smart watch, a shared bicycle, a smart cabinet, etc.; the module may specifically be a wireless communication module, such as any one of a 2G communication module, a 3G communication module, a 4G communication module, a 5G communication module, and a NB-IOT communication module.
[0084] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the root mean square calculation method based on hardware implementation as provided in any of the aforementioned method embodiments are implemented.
[0085] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device performs the steps of the root mean square calculation method based on hardware implementation.
[0086] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0087] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be 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 present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A root mean square calculation method based on hardware implementation, characterized in that: The method comprises: Get the data to be calculated X and the input bit width , where the input bit width is the bit width occupied by the data to be calculated X in fixed-point form in the hardware, and the value of the data to be calculated X is less than or equal to the input bit width The maximum value supported; According to the input bit width , determine the output bit width ; 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; Determine whether the current number of iterations is less than the output bit width The value of When determining that the current number of iterations is less than the output bit width In the case of the value of, the second parameter root obtained by the previous iteration, the third parameter reder obtained by the previous iteration, and the data to be calculated X obtained by the previous iteration are updated for the first round, and the value of the fourth parameter divi is determined based on the value of the second parameter root after the first round of update; 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; According to the judgment result, the second parameter root, the third parameter reder and the data to be calculated X participating in the next iterative calculation are determined, and the iterative calculation is performed again until the current number of iterations reaches the output bit width The value of the second parameter root finally obtained is determined as the root mean square calculation result of the data X to be calculated.
2. The method according to claim 1, characterized in that: The second parameter root, the third parameter reder and the data to be calculated X that are involved in the next iterative calculation are determined according to the judgment result, including: In the case that 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 updating, the value of the third parameter reder after the first round of updating and the value of the second parameter root after the first round of updating are updated in the second round, and the to-be-calculated data X after the first round of updating is used as the to-be-calculated data X participating in the next iterative calculation, the value of the third parameter reder after the second round of updating is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the second round of updating is used as the second parameter root participating in the next iterative calculation; When 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 participating in the next iterative calculation, the value of the third parameter reder after the first round of update is used as the third parameter reder participating in the next iterative calculation, and the value of the second parameter root after the first round of update is used as the second parameter root participating in the next iterative calculation.
3. The method according to claim 2, characterized in that The second round of updating of the value of the third parameter reder after the first round of updating and the value of the second parameter root after the first round of updating includes: Calculating the difference between the value of the third parameter reder after the first round of updating and the value of the fourth parameter divi, and determining the difference as the value of the third parameter reder after the second round of updating; and, The value of the second parameter root after the first round of update is increased by one to obtain the value of the second parameter root after the second round of update.
4. The method according to claim 1, characterized in that The first round of updating of the second parameter root obtained by the last iterative calculation, the third parameter reder obtained by the last iterative calculation, and the to-be-calculated data X obtained by the last iterative calculation includes: Shift the second parameter root calculated in the previous iteration left by one position to obtain the value of the second parameter root after the first round of update; The third parameter reder obtained by the last iteration is shifted left by one bit, and the left-shifted value is bitwise ORed with the target value to obtain the value of the third parameter reder after the first round of update, wherein the target value is the input bit width of the data to be calculated X right-shifted obtained by the last iteration. -The value obtained after the digit of 2; The data X to be calculated obtained by the previous iterative calculation is shifted left by two bits, and a bitwise AND operation is performed on the left-shifted value and the first parameter mask to obtain the value of the data X to be calculated after the first round of update.
5. The method according to claim 4, characterized in that The determining the value of the fourth parameter divi based on the value of the second parameter root after the first round of update includes: The value of the second parameter root after the first round of update is shifted left by one bit, and the value after the left shift is increased by one to obtain the value of the fourth parameter divi.
6. The method according to claim 1, characterized in that According to the input bit width , determine the output bit width ,include: According to the formula calculate; in, represents the output bit width, represents the input bit width, Indicates floor operation.
7. The method according to claim 1, characterized in that According to the input bit width , determine the value of the first parameter mask, including: Shift the value 1 left by the input bit width The corresponding digit is shifted left, and the value after left shifting is reduced by one to obtain the value of the first parameter mask.
8. A root mean square calculation device based on hardware implementation, characterized in that: The device comprises: Acquisition module, used to obtain the data to be calculated X and the input bit width , where the input bit width is the bit width occupied by the data to be calculated X in fixed-point form in the hardware, and the value of the data to be calculated X is less than or equal to the input bit width The maximum value supported; The first determining module is used to determine the input bit width according to the , determine the output bit width ; The second determining module is used to determine the input bit width according to the , 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; The first judgment module is used to judge whether the current number of iterations is less than the output bit width The value of An updating module is used to determine that the current number of iterations is less than the output bit width. In the case of the value of, the second parameter root obtained by the previous iteration, the third parameter reder obtained by the previous iteration, and the data to be calculated X obtained by the previous iteration are updated for the first round, and the value of the fourth parameter divi is determined based on the value of the second parameter root after the first round of update; A second judgment module is used to judge 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 to participate in the next iterative calculation according to the judgment result, and perform iterative calculation again until the current number of iterations reaches the output bit width The value of the second parameter root finally obtained is determined as the root mean square calculation result of the data X to be calculated.
9. 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; The processor is used to implement the hardware-based root mean square calculation method described in any one of claims 1 to 7 when executing the program stored in the memory.
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 root mean square calculation method based on hardware implementation as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Root-mean-square delay spread estimation method and system based on data statistics
CN111064682A
Divider and division processing method
CN113391787A
Large integer bit width division circuit and method for SRT algorithm with cardinal number of 4
CN113467750A
Special function unit (SFU) calculation device and data calculation method
CN117992122A
Method for calculating inverse square roots
KR1020070025195A
Cited By
Division calculation method and device based on hardware implementation
CN120010813A