Operation method, device and equipment of floating point divider and storage medium
By initializing and shifting the floating-point division algorithm and dynamically adjusting the quotient and remainder, the problems of low computational efficiency and insufficient accuracy of traditional algorithms are solved, and more efficient and flexible audio and video processing is achieved.
Patent Information
- Application Number
- CN202410869661.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-09-24
AI Technical Summary
The traditional floating-point division algorithm has low computational efficiency and cannot achieve full precision in audio and video algorithm processing, and the fixed calculation process cannot be optimized and adjusted according to specific application scenarios.
Initialization is performed by obtaining the divisor, remainder, and quotient, the bit width difference is calculated, and when the difference is greater than zero, shift processing is performed, and the quotient and remainder are dynamically adjusted until the preset quotient bit width threshold is met.
It improves computing efficiency and accuracy, enables flexible adjustment according to application scenarios, and improves the performance of audio and video algorithm processing.
Smart Images

Figure CN118689446A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computers, and in particular to an operation method, device, equipment and storage medium of a floating-point divider. Background Art
[0002] In audio and video algorithm processing, floating-point division is a common operation, especially in algorithms with feedback, which require high-precision division to avoid error accumulation. However, in traditional processors, division instructions are usually implemented using tables or approximate algorithms, resulting in the quotient only being able to maintain accuracy within a certain range and being unable to achieve full-precision results. This limitation may reduce the effectiveness of the algorithm in actual systems.
[0003] Moreover, the program of the traditional floating-point division algorithm is fixed, and the same steps are followed in each calculation process. This fixed calculation process limits the flexibility and adaptability of the algorithm, and it cannot be optimized and adjusted according to specific application scenarios. In audio and video algorithm processing, dynamic adjustments may be required based on different signal characteristics and processing requirements. The traditional fixed calculation process cannot meet this requirement, resulting in low calculation efficiency. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide an operation method, device, equipment and storage medium of a floating-point divider, which can improve the calculation efficiency and calculation accuracy.
[0005] In order to solve the above technical problems, the present invention provides an operation method of a floating-point divider, comprising:
[0006] Obtain a first divisor, a first remainder, and a first quotient, perform initialization processing on the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, and calculate a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialized remainder;
[0007] Obtaining a first difference between the first remainder bit width and the first divisor bit width, and when detecting that the first difference is greater than zero, performing shift processing on the first initialization quotient and the first initialization remainder respectively to obtain a first shift quotient and a first shift remainder;
[0008] Based on the first divisor, the first shift remainder is updated to obtain a first updated remainder, a first state of the first updated remainder is acquired, and based on the first state, the first shift quotient is shifted to obtain a second shift quotient;
[0009] The quotient bit width of the second shifted quotient is calculated, and when it is detected that the quotient bit width satisfies a preset quotient bit width threshold, the second shifted quotient is used as a calculation result, and the second shifted quotient is output.
[0010] In a possible implementation manner, initializing the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient specifically includes:
[0011] Detect whether the first divisor is a value of 0, and when the first divisor is not a value of 0,
[0012] Obtain a first dividend, and initialize the value of the first remainder to the value of the first dividend to obtain a first initialized remainder;
[0013] And the value of the first quotient is initialized to 0 to obtain a first initialized quotient.
[0014] In a possible implementation manner, calculating a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialization remainder specifically includes:
[0015] Perform binary conversion on the first divisor to obtain a first divisor binary value, perform bit detection on the first divisor binary value to obtain a first divisor bit number, and determine a first divisor bit width corresponding to the first divisor based on the first divisor bit number;
[0016] The first initialization remainder is converted into binary to obtain a first remainder binary value, the first remainder binary value is detected to obtain a first remainder bit number, and based on the first remainder bit number, a first remainder bit width corresponding to the first initialization remainder is determined.
[0017] In a possible implementation, when it is detected that the first difference is greater than zero, performing shift processing on the first initialization quotient and the first initialization remainder respectively to obtain a first shift quotient and a first shift remainder, specifically including:
[0018] When it is detected that the first difference is greater than zero, performing binary conversion on the first quotient to obtain a first quotient binary value;
[0019] Based on the first difference value, left-shift the first quotient binary value to obtain a first shift quotient;
[0020] The first remainder binary value corresponding to the first remainder is obtained, and based on the first difference, the first remainder binary value is left-shifted to obtain a first shift remainder.
[0021] In a possible implementation manner, updating the first shift remainder based on the first divisor to obtain a first updated remainder specifically includes:
[0022] performing a subtraction operation on the first shift remainder and the first divisor to obtain a second difference;
[0023] The second difference is updated to the first shift remainder, and the updated first shift remainder is used as the first updated remainder.
[0024] In a possible implementation manner, obtaining the first state of the first updated remainder specifically includes:
[0025] detecting a first relationship between the first update remainder and a value of 0, and when the first relationship is that the first update remainder is greater than the value of 0, determining that the first state of the first update remainder is greater than the value of 0;
[0026] When the first relationship is that the first updated remainder is equal to the value 0, determining that the first state of the first updated remainder is equal to the value 0;
[0027] When the first relationship is that the first updated remainder is equal to the value 0, it is determined that the first state of the first updated remainder is less than the value 0.
[0028] In a possible implementation manner, performing shift processing on the first shift quotient based on the first state to obtain a second shift quotient specifically includes:
[0029] When the first state is greater than a value of 0, the first shift quotient is left-shifted to obtain a second shift quotient, and a target bit width position corresponding to the second shift quotient is set to 1;
[0030] When the first state is equal to a value of 0, determining a first shift quotient bit width corresponding to the first shift quotient, subtracting the first shift quotient bit width from a preset quotient bit width threshold to determine a first bit width difference, and left-shifting the first shift quotient based on the first bit width difference to obtain a second shift quotient;
[0031] When the first state is less than the value 0, the first updated remainder is updated based on the first divisor to obtain a second updated remainder; the first shift quotient is left-shifted to obtain a second shift quotient, and the target bit width position corresponding to the second shift quotient is set to 0.
[0032] The present invention also provides a floating point divider operation device, comprising: an initialization module, a first shift processing module, a second shift processing module and a quotient width detection module;
[0033] The initialization module is used to obtain a first divisor, a first remainder and a first quotient, perform initialization processing on the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, and calculate a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialized remainder;
[0034] The first shift processing module is used to obtain a first difference between the first remainder bit width and the first divisor bit width, and when it is detected that the first difference is greater than zero, perform shift processing on the first initialization quotient and the first initialization remainder respectively to obtain a first shift quotient and a first shift remainder;
[0035] The second shift processing module is used to update the first shift remainder based on the first divisor to obtain a first updated remainder, obtain a first state of the first updated remainder, and shift the first shift quotient based on the first state to obtain a second shift quotient;
[0036] The quotient bit width detection module is used to calculate the quotient bit width of the second shifted quotient, and when it is detected that the quotient bit width meets a preset quotient bit width threshold, take the second shifted quotient as a calculation result and output the second shifted quotient.
[0037] In a possible implementation, the initialization module is used to perform initialization processing on the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, specifically including:
[0038] Detect whether the first divisor is a value of 0, and when the first divisor is not a value of 0,
[0039] Obtain a first dividend, and initialize the value of the first remainder to the value of the first dividend to obtain a first initialized remainder;
[0040] And the value of the first quotient is initialized to 0 to obtain a first initialized quotient.
[0041] In a possible implementation, the initialization module is used to calculate a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialization remainder, specifically including:
[0042] Perform binary conversion on the first divisor to obtain a first divisor binary value, perform bit detection on the first divisor binary value to obtain a first divisor bit number, and determine a first divisor bit width corresponding to the first divisor based on the first divisor bit number;
[0043] The first initialization remainder is converted into binary to obtain a first remainder binary value, the first remainder binary value is detected to obtain a first remainder bit number, and the first remainder bit width corresponding to the first initialization remainder is determined based on the first remainder bit number. In a possible implementation, the first shift processing module is used to perform shift processing on the first initialization quotient and the first initialization remainder respectively when it is detected that the first difference is greater than zero to obtain a first shift quotient and a first shift remainder, specifically including:
[0044] When it is detected that the first difference is greater than zero, performing binary conversion on the first quotient to obtain a first quotient binary value;
[0045] Based on the first difference value, left-shift the first quotient binary value to obtain a first shift quotient;
[0046] The first remainder binary value corresponding to the first remainder is obtained, and based on the first difference, the first remainder binary value is left-shifted to obtain a first shift remainder.
[0047] In a possible implementation, the second shift processing module is configured to update the first shift remainder based on the first divisor to obtain a first updated remainder, specifically including:
[0048] performing a subtraction operation on the first shift remainder and the first divisor to obtain a second difference;
[0049] The second difference is updated to the first shift remainder, and the updated first shift remainder is used as the first updated remainder.
[0050] In a possible implementation manner, the second shift processing module is used to obtain the first state of the first updated remainder, specifically including:
[0051] detecting a first relationship between the first update remainder and a value of 0, and when the first relationship is that the first update remainder is greater than the value of 0, determining that the first state of the first update remainder is greater than the value of 0;
[0052] When the first relationship is that the first updated remainder is equal to the value 0, determining that the first state of the first updated remainder is equal to the value 0;
[0053] When the first relationship is that the first updated remainder is equal to the value 0, it is determined that the first state of the first updated remainder is less than the value 0.
[0054] In a possible implementation manner, the second shift processing module is configured to perform shift processing on the first shift quotient based on the first state to obtain a second shift quotient, specifically including:
[0055] When the first state is greater than a value of 0, the first shift quotient is left-shifted to obtain a second shift quotient, and a target bit width position corresponding to the second shift quotient is set to 1;
[0056] When the first state is equal to a value of 0, determining a first shift quotient bit width corresponding to the first shift quotient, subtracting the first shift quotient bit width from a preset quotient bit width threshold to determine a first bit width difference, and left-shifting the first shift quotient based on the first bit width difference to obtain a second shift quotient;
[0057] When the first state is less than the value 0, the first updated remainder is updated based on the first divisor to obtain a second updated remainder; the first shift quotient is left-shifted to obtain a second shift quotient, and the target bit width position corresponding to the second shift quotient is set to 0.
[0058] The present invention also provides a terminal device, comprising a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the operation method of the floating-point divider as described in any one of the above when executing the computer program.
[0059] The present invention also provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute the floating-point divider operation method as described in any one of the above.
[0060] Compared with the prior art, the floating-point divider operation method, device, equipment and storage medium of the embodiment of the present invention have the following beneficial effects:
[0061] By obtaining a first divisor, a first remainder and a first quotient, initializing the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, the number of iterations required can be effectively reduced by the initialization process; and subsequently calculating the first divisor bit width corresponding to the first divisor and the first remainder bit width corresponding to the first initialized remainder; obtaining a first difference between the first remainder bit width and the first divisor bit width, and when it is detected that the first difference is greater than zero, shifting the first initialized quotient and the first initialized remainder respectively to obtain a first shifted quotient and a first shifted remainder; based on the first divisor number, update the first shift remainder to obtain a first updated remainder, and obtain a first state of the first updated remainder, and shift the first shift quotient based on the first state to obtain a second shift quotient; it is possible to dynamically adjust the quotient and the remainder based on the shift processing, and flexibly adjust the calculation strategy according to the actual situation during the operation, so as to speed up the operation; calculate the quotient bit width of the second shift quotient, and when it is detected that the quotient bit width meets the preset quotient bit width threshold, use the second shift quotient as the operation result, and output the second shift quotient, so as to ensure that the bit width of the quotient finally outputted can be determined according to the preset quotient bit width threshold, so as to improve the calculation accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 It is a flow chart of an embodiment of a floating-point divider operation method provided by the present invention;
[0063] Figure 2 It is a structural schematic diagram of an embodiment of a floating-point divider operation device provided by the present invention;
[0064] Figure 3 It is a structural schematic diagram of a terminal device provided by the present invention;
[0065] Figure 4 It is a flow chart of another embodiment of a floating-point divider operation method provided by the present invention. DETAILED DESCRIPTION
[0066] The following will be combined with the accompanying drawings in the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0067] For a hearing aid, it is necessary to perform fine processing and adjustment on the input sound signal to adapt to the user's hearing needs. In this process, it involves filtering, equalizing, denoising and other operations on the sound signal, which may require complex mathematical operations, including division operations. Based on this, an operation method of a floating-point divider is provided in an embodiment of the present invention. While improving the calculation efficiency of the floating-point divider, the accuracy of its operation is improved, so that the use of a floating-point divider can provide higher accuracy, flexibility and performance in the audio and video algorithm processing process of the hearing aid, thereby improving the user's hearing experience.
[0068] Example 1, see Figure 1 , Figure 1 FIG. 1 is a flow chart of an embodiment of a floating-point divider operation method provided by the present invention. Figure 1 As shown, the method includes steps 101 to 104, which are specifically as follows:
[0069] Step 101: obtain a first divisor, a first remainder and a first quotient, initialize the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, and calculate a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialized remainder.
[0070] In one embodiment, when a floating-point divider is used in an audio or video algorithm, obtaining data such as the dividend, divisor, quotient and remainder of the floating-point divider usually needs to be done through software; generally, these data are stored in the memory in the form of floating-point numbers, and then passed to the floating-point divider for calculation through appropriate instructions or function calls.
[0071] Therefore, when obtaining the first divisor, the first remainder and the first quotient of the floating-point divider, the first target data acquisition instruction is called through the floating-point divider, and the first target data acquisition instruction is sent to the target database, so that after receiving the first target data acquisition instruction, the target database responds to the first target data acquisition instruction, and extracts the first divisor, the first remainder and the first quotient, and sends the first divisor, the first remainder and the first quotient to the floating-point divider for subsequent calculation and processing.
[0072] In one embodiment, in addition to obtaining the first divisor, the first remainder and the first quotient of the floating-point divider, the first dividend of the floating-point divider is obtained based on the same operation as above.
[0073] In one embodiment, after a floating-point divider obtains the first divisor and the first remainder, the first remainder and the first quotient are initialized to obtain a first initialized remainder and a first initialized quotient, wherein the initialization process includes: detecting whether the first divisor is a value of 0, and when the first divisor is not a value of 0, obtaining a first dividend, initializing the value of the first remainder to the value of the first dividend to obtain a first initialized remainder; and initializing the value of the first quotient to 0 to obtain a first initialized quotient.
[0074] Specifically, when using a floating-point divider to perform division operations, it is very important to determine whether the divisor is zero; if the divisor is zero, the division operation cannot be performed; therefore, when the first divisor is a value of 0, the current floating-point divider operation is exited.
[0075] Specifically, by comparing the obtained value of the first dividend with the value of the first remainder, if they are different, the value of the first remainder is updated based on the value of the first dividend to obtain the first initialized remainder.
[0076] Specifically, by detecting whether the value of the first quotient is 0, if the value of the first quotient is not 0, the value of the first quotient is updated to 0 to obtain a first initialization quotient.
[0077] In one embodiment, when calculating the first divisor bit width corresponding to the first divisor, the first divisor is converted into binary to obtain a first divisor binary value, the first divisor binary value is detected to obtain the number of first divisor bits, and based on the first divisor bit number, the first divisor bit width corresponding to the first divisor is determined.
[0078] In one embodiment, when calculating the first remainder bit width corresponding to the first initialization remainder, the first remainder binary value is obtained by performing binary conversion on the first initialization remainder binary value, the number of bits of the first remainder is detected to obtain the number of bits of the first remainder, and based on the number of bits of the first remainder, the first remainder bit width corresponding to the first initialization remainder is determined.
[0079] Step 102: Obtain a first difference between the first remainder bit width and the first divisor bit width, and when it is detected that the first difference is greater than zero, perform shift processing on the first initialization quotient and the first initialization remainder to obtain a first shift quotient and a first shift remainder.
[0080] In one embodiment, a subtraction operation is performed on the first remainder bit width and the first divisor bit width to obtain a first difference.
[0081] Specifically, the first divisor bit width is set as the minuend, and the first remainder bit width is set as the subtrahend, so that the first difference is obtained by subtracting the first remainder bit width from the first divisor bit width.
[0082] In one embodiment, when it is detected that the first difference is greater than zero, the first quotient is converted into a binary value to obtain a first quotient binary value; based on the first difference, the first quotient binary value is left-shifted to obtain a first shifted quotient.
[0083] Specifically, based on the first difference value, the first quotient binary value is left-shifted by the first difference value bit, and based on data obtained after the left shift, a first shift quotient is determined.
[0084] In one embodiment, when it is detected that the first difference is greater than zero, the first remainder binary value corresponding to the first remainder is obtained, and based on the first difference, the first remainder binary value is left-shifted to obtain a first shift remainder.
[0085] Specifically, based on the first difference, the first remainder binary value is left-shifted by the first difference bit, and based on data obtained after the left shift, a first shift remainder is determined.
[0086] In one embodiment, when it is detected that the first difference is not greater than zero, the first initialization quotient and the first initialization remainder are not shifted, and the first initialization remainder is directly used as the first shift remainder and the first initialization quotient is used as the first shift quotient.
[0087] In the traditional divider algorithm, each time the quotient of the divider outputs a bit value of 1, a subtraction operation is involved. However, when the output bit is 0, no subtraction operation is performed, and only continuous shift operations are performed. Based on this, in this embodiment, by comparing the first remainder bit width with the first divisor bit width, if the remainder bit width is smaller than the divisor, then the remainder must be smaller than the divisor. Therefore, the quotient and the remainder are directly shifted to the left by the number of bits smaller than the bit width. The number of consecutive 0s in the output quotient can be determined based on the first difference, and then the shift operation can be directly performed. Compared with the prior art, the efficiency of data calculation can be improved by detecting bit by bit.
[0088] Step 103: Based on the first divisor, update the first shift remainder to obtain a first updated remainder, obtain a first state of the first updated remainder, and shift the first shift quotient based on the first state to obtain a second shift quotient.
[0089] In one embodiment, a subtraction operation is performed on the first shift remainder and the first divisor to obtain a second difference.
[0090] Specifically, the first shift remainder is set as a minuend, and the first divisor is set as a subtrahend, so that the first shift remainder is subtracted from the first divisor to obtain a second difference.
[0091] In one embodiment, the second difference is updated to the first shift remainder, and the updated first shift remainder is used as the first updated remainder.
[0092] Specifically, the value of the first shift remainder is directly updated to a value corresponding to the second difference to obtain a first updated remainder, wherein the value of the first updated remainder is the same as the value of the second difference.
[0093] In one embodiment, when acquiring the first state of the first updated remainder, the first state of the first updated remainder is determined based on the first relationship by detecting a first relationship between the first updated remainder and a value of 0.
[0094] Specifically, when the first relationship is that the first updated remainder is greater than the value 0, it is determined that the first state of the first updated remainder is greater than the value 0.
[0095] Specifically, when the first relationship is that the first updated remainder is equal to the value 0, it is determined that the first state of the first updated remainder is equal to the value 0.
[0096] Specifically, when the first relationship is that the first updated remainder is equal to the value 0, it is determined that the first state of the first updated remainder is less than the value 0.
[0097] In one embodiment, when the first state is greater than a value of 0, the first shift quotient is left-shifted to obtain a second shift quotient, and a target bit width position corresponding to the second shift quotient is set to 1.
[0098] Specifically, when the first shift quotient is left-shifted, the first shift quotient is first converted into a binary value to obtain a first shift quotient binary value, and the first shift quotient binary value is left-shifted by one bit to obtain a current first shift quotient binary value, and based on the current first shift quotient binary value, the second shift quotient is determined, and at the same time, it is detected whether the target bit width position of the current first shift quotient binary value is 1, if not, the target bit width position is set to 1.
[0099] Preferably, the target bit width position is the least significant bit in the current first shift quotient binary value; after the shift process, the binary value of the shift quotient may include an integer part and a decimal part; the least significant bit usually represents the binary position to the right of the decimal point.
[0100] In one embodiment, when the first state is equal to a value of 0, a first shift quotient bit width corresponding to the first shift quotient is determined, the first shift quotient bit width is subtracted from a preset quotient bit width threshold to determine a first bit width difference, and the first shift quotient is left-shifted based on the first bit width difference to obtain a second shift quotient.
[0101] Specifically, after determining the first shift quotient bit width corresponding to the first shift quotient, the first shift bit width is compared with a preset quotient bit width threshold; if the first shift bit width is less than the preset quotient bit width threshold, the preset quotient bit width threshold is set as the minuend, and the first shift quotient bit width is set as the subtrahend, so that the preset quotient bit width threshold is subtracted from the first shift quotient bit width to obtain the first bit width difference.
[0102] Specifically, the first shift quotient is converted into a binary value to obtain a first shift quotient binary value, and the first shift quotient binary value is shifted left by the first width difference bit to obtain a current first shift quotient binary value, and a second shift quotient is determined based on the current first shift quotient binary value.
[0103] In one embodiment, when the first state is less than the value 0, the first updated remainder is updated based on the first divisor to obtain a second updated remainder; the first shift quotient is left-shifted to obtain a second shift quotient, and the target bit width position corresponding to the second shift quotient is set to 0.
[0104] Specifically, based on the first divisor, when the first updated remainder is updated, a first addition value is obtained by adding the first divisor and the first updated remainder, and the first addition value is updated to the first updated remainder, and the first updated remainder obtained after the update is used as the second updated remainder.
[0105] Specifically, the first divisor is set as a first addend, and the first updated remainder is set as a second addend, so that the first divisor and the first updated remainder are added to obtain a first added value.
[0106] Specifically, when the first shift quotient is left-shifted, the first shift quotient is first converted into a binary value to obtain a first shift quotient binary value, and the first shift quotient binary value is left-shifted by one bit to obtain a current first shift quotient binary value, and based on the current first shift quotient binary value, the second shift quotient is determined, and at the same time, it is detected whether the target bit width position of the current first shift quotient binary value is 0, if not, the target bit width position is set to 0.
[0107] Step 104: Calculate the quotient bit width of the second shifted quotient, and when it is detected that the quotient bit width meets a preset quotient bit width threshold, use the second shifted quotient as a calculation result and output the second shifted quotient.
[0108] In one embodiment, the second shift quotient is converted into binary to obtain a second shift quotient binary value, the second shift quotient binary value is detected to obtain the number of second shift quotient bits, and based on the number of second shift quotient bits, a second shift quotient bit width corresponding to the second shift quotient is determined.
[0109] In one embodiment, the second mobile quotient bit width is compared with the preset quotient bit width threshold. If the second mobile quotient bit width is not less than the preset quotient bit width threshold, it is determined that the quotient bit width meets the preset quotient bit width threshold. Otherwise, it is determined that the quotient bit width does not meet the preset quotient bit width threshold.
[0110] In one embodiment, when it is determined that the quotient bit width satisfies a preset quotient bit width threshold, the floating point number form of the second shifted quotient is directly used as the operation result, and the floating point number form of the second shifted quotient is output.
[0111] In one embodiment, when it is determined that the quotient bit width does not meet the preset quotient bit width threshold, the second updated remainder is updated to the first initialization remainder, and the process returns to step 101 to recalculate the first remainder bit width corresponding to the first initialization remainder, so as to perform the operations of steps 202 to 204 based on the recalculated first remainder bit width until it is determined that the quotient bit width meets the preset quotient bit width threshold. Figure 4 As shown, Figure 4 It is another flow chart of the operation method of a floating-point divider provided by the present invention.
[0112] Example 2, see Figure 2 , Figure 2 FIG. 1 is a schematic diagram of a structure of an embodiment of a floating-point divider computing device provided by the present invention. Figure 2 As shown, the device includes an initialization module 201, a first shift processing module 202, a second shift processing module 203 and a quotient width detection module 204, which are specifically as follows:
[0113] The initialization module 201 is used to obtain a first divisor, a first remainder and a first quotient, initialize the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, and calculate a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialized remainder.
[0114] The first shift processing module 202 is used to obtain a first difference between the first remainder bit width and the first divisor bit width, and when it is detected that the first difference is greater than zero, the first initialization quotient and the first initialization remainder are shifted to obtain a first shift quotient and a first shift remainder.
[0115] The second shift processing module 203 is used to update the first shift remainder based on the first divisor to obtain a first updated remainder, obtain a first state of the first updated remainder, and shift the first shift quotient based on the first state to obtain a second shift quotient.
[0116] The quotient bit width detection module 204 is used to calculate the quotient bit width of the second shifted quotient, and when it is detected that the quotient bit width meets a preset quotient bit width threshold, the second shifted quotient is used as a calculation result and outputted.
[0117] In one embodiment, the initialization module 201 is used to initialize the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, specifically including: detecting whether the first divisor is a value of 0, and when the first divisor is not a value of 0, obtaining a first dividend, initializing the value of the first remainder to the value of the first dividend to obtain a first initialized remainder; and initializing the value of the first quotient to 0 to obtain a first initialized quotient.
[0118] In one embodiment, the initialization module 201 is used to calculate the first divisor bit width corresponding to the first divisor and the first remainder bit width corresponding to the first initialization remainder, specifically including: performing binary conversion on the first divisor to obtain a first divisor binary value, performing bit detection on the first divisor binary value to obtain the first divisor bit number, and determining the first divisor bit width corresponding to the first divisor based on the first divisor bit number; performing binary conversion on the first initialization remainder to obtain a first remainder binary value, performing bit detection on the first remainder binary value to obtain the first remainder bit number, and determining the first remainder bit width corresponding to the first initialization remainder based on the first remainder bit number.
[0119] In one embodiment, the first shift processing module 202 is used to perform shift processing on the first initialization quotient and the first initialization remainder respectively to obtain a first shift quotient and a first shift remainder when it is detected that the first difference is greater than zero, specifically including: when it is detected that the first difference is greater than zero, performing binary conversion on the first quotient to obtain a first quotient binary value; based on the first difference, performing left shift processing on the first quotient binary value to obtain a first shift quotient; obtaining the first remainder binary value corresponding to the first remainder, and based on the first difference, performing left shift processing on the first remainder binary value to obtain a first shift remainder.
[0120] In one embodiment, the second shift processing module 203 is used to update the first shift remainder based on the first divisor to obtain a first updated remainder, specifically including: subtracting the first shift remainder and the first divisor to obtain a second difference; updating the second difference to the first shift remainder, and using the updated first shift remainder as the first updated remainder.
[0121] In one embodiment, the second shift processing module 203 is used to obtain the first state of the first update remainder, specifically including: detecting a first relationship between the first update remainder and a value of 0, and when the first relationship is that the first update remainder is greater than the value of 0, determining that the first state of the first update remainder is greater than the value of 0; when the first relationship is that the first update remainder is equal to the value of 0, determining that the first state of the first update remainder is equal to the value of 0; when the first relationship is that the first update remainder is equal to the value of 0, determining that the first state of the first update remainder is less than the value of 0.
[0122] In one embodiment, the second shift processing module 203 is used to perform shift processing on the first shift quotient based on the first state to obtain a second shift quotient, specifically including: when the first state is greater than a value of 0, performing left shift processing on the first shift quotient to obtain a second shift quotient, and setting the target bit width position corresponding to the second shift quotient to 1; when the first state is equal to a value of 0, determining the first shift quotient bit width corresponding to the first shift quotient, subtracting the first shift quotient bit width from a preset quotient bit width threshold to determine the first bit width difference, and performing left shift processing on the first shift quotient based on the first bit width difference to obtain a second shift quotient; when the first state is less than a value of 0, updating the first updated remainder based on the first divisor to obtain a second updated remainder; and performing left shift processing on the first shift quotient to obtain a second shift quotient, and setting the target bit width position corresponding to the second shift quotient to 0.
[0123] The above floating-point divider operation device can implement the floating-point divider operation method of the above method embodiment. The options in the above method embodiment are also applicable to this embodiment and will not be described in detail here.
[0124] Figure 3 A schematic diagram of the structure of a terminal device. Figure 3 As shown, the terminal device 3 of this embodiment includes: at least one processor 301 ( Figure 3 Only one is shown in the figure) a processor, a memory 302, and a computer program 303 stored in the memory 302 and executable on at least one processor 301, and when the processor 301 executes the computer program 303, the steps in any of the above method embodiments are implemented.
[0125] The terminal device 3 may be a computing device such as a smart phone, a laptop, a tablet computer, and a desktop computer. The terminal device may include but is not limited to a processor 301 and a memory 302. Those skilled in the art will appreciate that Figure 3 It is only an example of the terminal device 3 and does not constitute a limitation on the terminal device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0126] The processor 301 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0127] In some embodiments, the memory 302 may be an internal storage unit of the terminal device 3, such as a hard disk or memory of the terminal device 3. In other embodiments, the memory 302 may also be an external storage device of the terminal device 3, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the terminal device 3. Further, the memory 302 may also include both an internal storage unit of the terminal device 3 and an external storage device. The memory 302 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as program codes of a computer program, etc. The memory 302 may also be used to temporarily store data that has been output or is to be output.
[0128] In addition, an embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in any of the above method embodiments are implemented.
[0129] In several embodiments provided in the present application, it is understood that each box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and a module, a program segment or a part of a code includes one or more executable instructions for realizing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes also be executed in the opposite order, depending on the functions involved.
[0130] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a terminal device to execute all or part of the steps of each embodiment method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0131] In summary, the present invention provides an operation method, device, equipment and storage medium of a floating-point divider, which obtains a first initialized remainder and a first initialized quotient by initializing a first remainder and a first quotient, and calculates a first divisor bit width corresponding to the first divisor, and a first remainder bit width corresponding to the first initialized remainder; when a first difference between the obtained first remainder bit width and the first divisor bit width is greater than zero, the first quotient and the first remainder are shifted to obtain a first shifted quotient and a first shifted remainder; based on the first divisor, the first shifted remainder is updated to obtain a first updated remainder, and based on the first state of the first updated remainder, the first shifted quotient is shifted to obtain a second shifted quotient; the quotient bit width of the second shifted quotient is calculated, and when it is detected that the quotient bit width meets a preset quotient bit width threshold, the second shifted quotient is output; compared with the prior art, the technical solution of the present invention can improve calculation efficiency and calculation accuracy.
[0132] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and substitutions can be made without departing from the technical principles of the present invention. These improvements and substitutions should also be regarded as the scope of protection of the present invention.
Claims
1. A floating point divider operation method, characterized in that: include: Obtain a first divisor, a first remainder, and a first quotient, perform initialization processing on the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, and calculate a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialized remainder; Obtaining a first difference between the first remainder bit width and the first divisor bit width, and when detecting that the first difference is greater than zero, performing shift processing on the first initialization quotient and the first initialization remainder respectively to obtain a first shift quotient and a first shift remainder; Based on the first divisor, the first shift remainder is updated to obtain a first updated remainder, a first state of the first updated remainder is acquired, and based on the first state, the first shift quotient is shifted to obtain a second shift quotient; The quotient bit width of the second shifted quotient is calculated, and when it is detected that the quotient bit width satisfies a preset quotient bit width threshold, the second shifted quotient is used as a calculation result, and the second shifted quotient is output.
2. The floating point divider operation method according to claim 1, wherein: Initializing the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient specifically includes: Detect whether the first divisor is a value of 0, and when the first divisor is not a value of 0, Obtain a first dividend, and initialize the value of the first remainder to the value of the first dividend to obtain a first initialized remainder; And the value of the first quotient is initialized to 0 to obtain a first initialized quotient.
3. The floating point divider operation method according to claim 1, wherein: Calculating a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialization remainder specifically includes: Perform binary conversion on the first divisor to obtain a first divisor binary value, perform bit detection on the first divisor binary value to obtain a first divisor bit number, and determine a first divisor bit width corresponding to the first divisor based on the first divisor bit number; The first initialization remainder is converted into binary to obtain a first remainder binary value, the first remainder binary value is detected to obtain a first remainder bit number, and based on the first remainder bit number, a first remainder bit width corresponding to the first initialization remainder is determined.
4. The floating point divider operation method as claimed in claim 3, characterized in that: When it is detected that the first difference is greater than zero, the first initialization quotient and the first initialization remainder are shifted to obtain a first shift quotient and a first shift remainder, specifically including: When it is detected that the first difference is greater than zero, performing binary conversion on the first quotient to obtain a first quotient binary value; Based on the first difference value, left-shift the first quotient binary value to obtain a first shift quotient; The first remainder binary value corresponding to the first remainder is obtained, and based on the first difference, the first remainder binary value is left-shifted to obtain a first shift remainder.
5. The floating point divider operation method according to claim 1, wherein: Based on the first divisor, updating the first shift remainder to obtain a first updated remainder specifically includes: performing a subtraction operation on the first shift remainder and the first divisor to obtain a second difference; The second difference is updated to the first shift remainder, and the updated first shift remainder is used as the first updated remainder.
6. The floating point divider operation method as claimed in claim 1, characterized in that: Obtaining a first state of the first update remainder specifically includes: detecting a first relationship between the first update remainder and a value of 0, and when the first relationship is that the first update remainder is greater than the value of 0, determining that the first state of the first update remainder is greater than the value of 0; When the first relationship is that the first updated remainder is equal to the value 0, determining that the first state of the first updated remainder is equal to the value 0; When the first relationship is that the first updated remainder is equal to the value 0, it is determined that the first state of the first updated remainder is less than the value 0.
7. The floating point divider operation method according to claim 6, wherein: Performing a shift process on the first shift quotient based on the first state to obtain a second shift quotient specifically includes: When the first state is greater than a value of 0, the first shift quotient is left-shifted to obtain a second shift quotient, and a target bit width position corresponding to the second shift quotient is set to 1; When the first state is equal to a value of 0, determining a first shift quotient bit width corresponding to the first shift quotient, subtracting the first shift quotient bit width from a preset quotient bit width threshold to determine a first bit width difference, and left-shifting the first shift quotient based on the first bit width difference to obtain a second shift quotient; When the first state is less than the value 0, the first updated remainder is updated based on the first divisor to obtain a second updated remainder; the first shift quotient is left-shifted to obtain a second shift quotient, and the target bit width position corresponding to the second shift quotient is set to 0.
8. A floating point divider computing device, characterized in that: include: An initialization module, a first shift processing module, a second shift processing module and a quotient width detection module; The initialization module is used to obtain a first divisor, a first remainder and a first quotient, perform initialization processing on the first remainder and the first quotient to obtain a first initialized remainder and a first initialized quotient, and calculate a first divisor bit width corresponding to the first divisor and a first remainder bit width corresponding to the first initialized remainder; The first shift processing module is used to obtain a first difference between the first remainder bit width and the first divisor bit width, and when it is detected that the first difference is greater than zero, perform shift processing on the first initialization quotient and the first initialization remainder to obtain a first shift quotient and a first shift remainder; The second shift processing module is used to update the first shift remainder based on the first divisor to obtain a first updated remainder, obtain a first state of the first updated remainder, and shift the first shift quotient based on the first state to obtain a second shift quotient; The quotient bit width detection module is used to calculate the quotient bit width of the second shifted quotient, and when it is detected that the quotient bit width meets a preset quotient bit width threshold, take the second shifted quotient as a calculation result and output the second shifted quotient.
9. A terminal device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein the processor implements the operation method of the floating-point divider as claimed in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the floating-point divider operation method according to any one of claims 1 to 7.
Citation Information
Cited By
Calculation method and device for motor position control
CN119853542A
