Data processing method, medium, electronic device, and program product

By aligning the leading 1s of the divisor and dividend, integer division operations are optimized, solving the problem of excessive loop iterations and improving computational efficiency.

CN115357216BActive Publication Date: 2026-11-20ARM TECH CHINA CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211067568.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-01
Publication Date
2026-11-20
Estimated Expiration
2042-09-01

AI Technical Summary

Technical Problem

The existing integer division operation involves a large number of loops, resulting in a long operation cycle and low computational efficiency.

Method used

By determining the significant digits of the dividend and divisor, and aligning the leading 1 of the divisor with the leading 1 of the dividend, the number of loops is reduced, thus optimizing the division operation process.

Benefits of technology

It effectively reduces the number of loops in the division process, reduces subtraction, shifting and comparison operations, and improves computational efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115357216B_ABST
    Figure CN115357216B_ABST
Patent Text Reader

Abstract

The application relates to the computer technical field and discloses a data processing method, a medium, an electronic device and a program product. The data processing method comprises the following steps: obtaining a first dividend and a first divisor to be subjected to a division operation; determining the position of a leading 1 in the first dividend, and setting the position of the leading 1 of the first divisor to be aligned with the position of the leading 1 of the first dividend; and performing a subtraction operation, a comparison operation of a difference value and zero and a shift operation on the first dividend and the first divisor in sequence to obtain a division operation result of the first dividend and the first divisor. The data processing method can effectively reduce the number of cycles in the division operation process while ensuring the correctness of the division operation, that is, the number of subtraction, shift and comparison operations in the cycle process is reduced, and the calculation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a data processing method, medium, electronic device, and program product. Background Technology

[0002] Integer division is one of the most basic arithmetic functions in computers and has extremely wide applications. Integer division can be implemented in hardware, such as using a divider; it can also be implemented in software, such as using operators like Softmax and normalization in deep learning models.

[0003] Integer division can be divided into division with and without restoring the remainder. Regardless of the method, the quotient is calculated bit by bit in a loop during the division process. The number of loops depends on the default number of significant bits in the quotient. For example, if the default number of significant bits in the quotient is 32 bits, the conventional algorithm requires 32 loops; and each loop must perform at least one subtraction, shift, and comparison operation. Therefore, the existing division process suffers from a long computation cycle, significantly limiting the performance of the divider and reducing computational efficiency. Summary of the Invention

[0004] This application provides a data processing method, a medium, an electronic device, and a program product.

[0005] In a first aspect, embodiments of this application provide a data processing method applied to an electronic device, comprising: acquiring a first dividend and a first divisor to be divided; determining the position of the leading 1 in the first dividend and setting the position of the leading 1 in the first divisor to be aligned with the position of the leading 1 in the first dividend; sequentially performing a subtraction operation, a difference-to-zero comparison operation, and a shift operation on the first dividend and the first divisor to obtain the division result of the first dividend and the first divisor.

[0006] In the embodiments of this application, the leading 1 refers to the position of the first "1" in the binary number.

[0007] For example, if the first dividend is 1010, then the leading 1 of the first dividend is in the first position; if the first divisor is 0011, then the leading 1 of the first divisor is in the third position.

[0008] In this embodiment of the application, by setting the position of the leading 1 of the first divisor to be aligned with the position of the leading 1 of the first dividend, the number of loops in the division operation can be effectively reduced while ensuring the correctness of the division operation. That is, the subtraction, shifting and comparison operations in the loop process are reduced, thereby improving the calculation efficiency.

[0009] In one possible implementation, determining the position of the leading 1 in the first dividend and setting the position of the leading 1 in the first divisor to be aligned with the position of the leading 1 in the first dividend includes: calculating the first significant number of digits in the first dividend and the second significant number of digits in the first divisor; determining the number of shifts based on the first significant number of digits and the second significant number of digits; and shifting the numerical bits of the first divisor to the left by the number of shifts so that the position of the leading 1 in the first divisor is aligned with the position of the leading 1 in the first dividend.

[0010] In one possible implementation, determining the shift number based on the first significant number of digits and the second significant number of digits includes: determining the difference between the first significant number of digits and the second significant number of digits to obtain a first difference; adding 1 to the first difference to obtain an estimated significant number of digits; determining the default significant number of digits of the quotient; and determining the shift number based on the smaller value between the default significant number of digits and the estimated significant number of digits.

[0011] The number of loops in the data processing method of this application embodiment is generally less than the default number of significant digits of the quotient. In the prior art, the default number of significant digits of the quotient is used as the number of loops in the division operation. Therefore, the data processing method provided by this application embodiment can effectively reduce the number of loops in the division operation, that is, reduce the subtraction, shift and comparison operations in the loop process.

[0012] In one possible implementation, the shift bits are used as the total number of loops for the division operation of the first dividend and the first divisor.

[0013] The total number of loops in the data processing method of this application embodiment is generally less than the default number of significant digits in the quotient. Therefore, the data processing method provided by this application embodiment can effectively reduce the number of loops in the division operation process.

[0014] In one possible implementation, a subtraction operation, a comparison operation between the difference and zero, and a shift operation are performed sequentially on the first dividend and the first divisor to obtain the operation result, including: calculating the difference between the first dividend and the first divisor to obtain a second difference, and using the second difference as the second dividend; assigning a value to the bit of the total loop count of the quotient based on the second dividend, and obtaining the third dividend; subtracting 1 from the total loop count to obtain the remaining loop count, and shifting the value bit of the first divisor one bit to the right to obtain the second divisor; if the remaining loop count is less than 0, using the second dividend as the remainder; and determining the value of the quotient based on the assignment of the bit of the total loop count of the quotient.

[0015] In one possible implementation, if the remaining number of iterations is greater than or equal to 0, the third dividend is used as the first dividend, and the second divisor is used as the first divisor; the difference between the first dividend and the first divisor is calculated to obtain the second difference, and the second difference is used as the second dividend.

[0016] In one possible implementation, the process of assigning a value to the quotient's total cycle count bit based on the second dividend and obtaining the third dividend includes: assigning a value of 1 to the quotient's total cycle count bit when the second dividend is greater than or equal to 0; using the second dividend as the third dividend; assigning a value of 0 to the quotient's total cycle count bit when the second dividend is less than 0; calculating the sum of the second dividend and the second divisor to obtain a second value; and using the second value as the third dividend.

[0017] It is understandable that when the second dividend is greater than or equal to 0, that is, the first dividend is enough to divide the first divisor, so no borrowing or shifting is needed, so the quotient q is assigned the value 1 for the total number of cycles.

[0018] It is understandable that when the second dividend is less than 0, that is, the first dividend is not enough to divide the first divisor, so a borrow or shift is required. Therefore, the total number of cycles of the quotient q is assigned the value 0. The second dividend is added to the second divisor in order to obtain the original dividend for the calculation of the next cycle.

[0019] Secondly, embodiments of this application provide a divider, characterized in that it includes a division control logic unit; the division control logic unit is used to obtain a first dividend and a first divisor to be divided; determine the position of the leading 1 of the first dividend, and set the position of the leading 1 of the first divisor to be aligned with the position of the leading 1 of the first dividend; and sequentially perform a subtraction operation, a difference-to-zero comparison operation, and a shift operation on the first dividend and the first divisor to obtain the calculation result.

[0020] In the embodiments of this application, the leading 1 refers to the position of the first "1" in the binary number.

[0021] For example, if the first dividend is 1010, then the leading 1 of the first dividend is in the first position; if the first divisor is 0011, then the leading 1 of the first divisor is in the third position.

[0022] In this embodiment of the application, by setting the position of the leading 1 of the first divisor to be aligned with the position of the leading 1 of the first dividend, the number of loops in the division operation can be effectively reduced while ensuring the correctness of the division operation. That is, the subtraction, shifting and comparison operations in the loop process are reduced, thereby improving the calculation efficiency.

[0023] In one possible implementation, it further includes a first dividend register, a first divisor register, an arithmetic logic unit, a remainder register, and a quotient register. The first dividend register is used to store the first dividend in the division operation; the first divisor register is used to store the first divisor in the division operation; the quotient register is used to store the quotient in the division operation; the remainder register is used to store the remainder in the division operation; the arithmetic logic unit is used to obtain the first dividend from the first dividend register; and to obtain the first divisor from the first divisor register; the division control logic unit is used to control the start and end of the division operation, as well as the initialization, shifting, and updating of the first divisor register, the first dividend register, the remainder register, and the quotient register.

[0024] Thirdly, embodiments of this application provide a readable medium storing instructions that, when executed on an electronic device, cause the electronic device to implement any of the data processing methods provided by the first aspect and various possible implementations of the first aspect.

[0025] Fourthly, embodiments of this application provide an electronic device, including: a memory for storing instructions executed by one or more processors of the electronic device, and a processor, which is one of the one or more processors of the electronic device, for implementing any of the data processing methods provided by the first aspect and various possible implementations of the first aspect.

[0026] Fifthly, embodiments of this application provide an electronic device for implementing any of the dividers provided by the second aspect and various possible implementations of the second aspect described above.

[0027] In a sixth aspect, embodiments of this application provide a computer program product, characterized in that it includes: execution instructions, the execution instructions being stored in a readable storage medium, at least one processor of an electronic device being able to read the execution instructions from the readable storage medium, and the at least one processor executing the execution instructions causing the electronic device to implement any of the data processing methods provided by the first aspect and various possible implementations of the first aspect. Attached Figure Description

[0028] Figure 1 According to an embodiment of this application, a flowchart of a data processing method is shown;

[0029] Figure 2 According to an embodiment of this application, a flowchart of a data processing method is shown;

[0030] Figure 3 According to an embodiment of this application, a structural block diagram of a divider is shown;

[0031] Figure 4According to an embodiment of this application, a flowchart of a data processing method is shown;

[0032] Figure 5 According to an embodiment of this application, a schematic diagram of the structure of an electronic device is shown. Detailed Implementation

[0033] The illustrative embodiments of this application include, but are not limited to, a data processing method, a medium, an electronic device, and a program product.

[0034] The technical terms related to this application will be introduced below.

[0035] (1) Bit length: In the field of computer technology, bit length is also called "word length", which refers to the number of bits of binary numbers that a processor can process in one operation. Binary numbers can be 8 bits, 16 bits, 32 bits, or 64 bits. Generally, 8 bits is called one byte, 16 bits is called one word, 32 bits is called one double word, and 64 bits is called two double words.

[0036] (2) Binary calculation: Inside the computer, all characters and instructions are represented by binary numbers, which have only two numbers, 0 and 1, and are counted according to the rule of "carrying over when reaching two".

[0037] (3) Significant number of bits: The significant number of bits of a binary number refers to the number of bits from the highest non-zero bit to the lowest bit. For example, the number of bits of the data 00011001 is the number of bits from the first "1" value from left to right to the rightmost bit, that is, the significant part is "11001", and the significant number of bits is 5.

[0038] Integer division requires the default number of significant digits in the quotient (also called the precision of the quotient) to be used as the number of loops for the operation between the dividend and the divisor. In each loop, at least one subtraction operation between the dividend and the divisor, a shift operation between the divisor and the quotient, and a comparison operation between the difference between the dividend and the divisor and zero are performed. This results in a large number of loops, a long operation cycle, and low computational efficiency.

[0039] like Figure 1 As shown, the following example illustrates the division process using the recovery remainder method in integer division, where the dividend m1 is divided by the divisor n1, and the quotient q has a default number of significant digits i1:

[0040] 101: Get the default number of significant digits i1 of the quotient, shift the divisor n1 to the left by the default number of significant digits i1 of the quotient q, and get the shifted divisor n1o.

[0041] For example, the dividend m1 is equal to the binary data 1010 (corresponding to the decimal data 10), the divisor n1 is equal to the binary data 0011 (corresponding to the decimal data 3), and i1 = 4. Shifting the divisor n1 to the left by i1 bits, that is, shifting 0011 to the left by 4 bits, results in 00110000.

[0042] 102: Shift the dividend m1 one bit to the left to get the shifted dividend m1o.

[0043] For example, shifting the dividend m1o = 1010 one bit to the left = 10100 = 00010100. At this time, m1o = 00010100 and n1 = 00110000; that is, the last bit of the divisor is aligned with the first non-zero bit of the dividend.

[0044] 103: Update the shifted dividend m1o to the difference m2 between the dividend m1o and the divisor n1o.

[0045] That is, m10 = m2 = m1o - n1o.

[0046] For example, m2 = m1o - n1o = 00010100 - 00110000 = 11100100; at this time, m2 is less than 0.

[0047] 104: Determine if the updated dividend m2 is greater than 0. If the result is yes, proceed to 105; if the result is no, proceed to 106.

[0048] 105: Assign the i1th bit of the quotient q to 1, and update the dividend m3 to assign the least bit of the dividend m2 to 1, that is, m3 = assign the least bit of m2 to 1.

[0049] It is understandable that when m2 is greater than 0, that is, the dividend is divisible, so no borrowing or shifting is needed, so the i1th bit of the quotient q is assigned the value 1.

[0050] For example, when m2 = 0010, and m2 is greater than 0, the fourth bit of the quotient q is assigned the value 1, and the least significant bit of m2 is assigned the value 1, that is, m3 = 0011.

[0051] 106: Assign 0 to the i1th bit of the quotient q, and update the dividend m3 to the sum of the dividend m2 and the divisor n1, i.e., m3 = m2 + n1.

[0052] It is understandable that when m2 is less than or equal to 0, that is, the dividend is not enough to divide the divisor, so a borrow or shift is required. Therefore, the i-th bit of the quotient q is assigned the value 0. The dividend m2 is added to the divisor n1 in order to obtain the original dividend for the calculation of the next cycle.

[0053] For example, m2 = 11100100; at this time m2 is less than 0, therefore, m3 = m2 + n1 = 11100100 + 00110000 = 00010100 = m1.

[0054] 107: Update the loop count i1 to i2, i.e., i2 = i1 - 1.

[0055] 108: Check if the loop count i2 is equal to 0. If the result is no, update m3 to m1 and i2 to i1, then execute 102. If the result is yes, then end.

[0056] This is understandable; the loop terminates when the number of iterations reaches zero.

[0057] For example, q4 = 0; q3 = 0; q2 = 1; q1 = 1, m = 00010011; then the final calculated quotient is 0011(3), and the remainder is 0001(1).

[0058] It's understandable that since the divisor n1 is left-shifted by the number of significant bits i1 in the quotient q, and the quotient is calculated by iteratively calculating each bit, the dividend m1 needs to be left-shifted one bit at a time during the operation until the number of iterations equals 0. Therefore, in the restoring remainder method, the number of iterations is equal to the number of significant bits i in the quotient q. For example, if the quotient has a bit width of 32 bits, then 32 iterations are required; and at least one subtraction, shift, and comparison operation is performed in each iteration.

[0059] The following example illustrates the problem using the following scenario: the dividend m1 is equal to the binary data 1010 (corresponding to the decimal data 10), which is 00001010; the divisor n1 is equal to the binary data 0011 (corresponding to the decimal data 3), which is 00000011; and the number of iterations i is 4.

[0060] First, shift the divisor 0011 left by 4 bits. Since the dividend m1 is equal to 00001010, in order to align the number of bits of the dividend m1 with the divisor n1, the electronic device first shifts the divisor n1 left by 4 bits, resulting in n1o = 00110000. The remainder r is assigned the value 0000, and the quotient q is assigned the value 0000.

[0061] The process of dividing the dividend m = 1010 (10) and the divisor n = 0011 (3) is shown in Table 1:

[0062] Table 1:

[0063]

[0064]

[0065] When the loop count i1 = 4, the dividend m1o = 1010 shifts left by one bit = 10100 = 00010100, at this time m1o = 00010100, n1o = 00110000; that is, the last bit of the divisor is aligned with the first non-zero bit of the dividend. Calculate m2, m2 = m1o - n1o = 00010100 - 00110000 = 11100100. Since m2 is less than 0, therefore, q[4] = 0, m3 = m2 + n1o = 11100100 + 00110000 = 00010100, and store m3. Update the loop count i1 to i2, i2 = 4 - 1 = 3; then update i2 to i1, and update m3 to m1.

[0066] Since i1 = 3, i1 is not 0, so shift m1 left by one bit = 00101000 = m1o. Calculate m2, m2 = m1o - n1o = 00101000 - 00110000 = 11111000. Since m2 is less than 0, q[3] = 0, m3 = m2 + n1o = 11111000 + 00110000 = 00101000, and store m3. Update the loop count i1 to i2, i2 = 3 - 1 = 2; then update i2 to i1, and update m3 to m1.

[0067] Since i1 = 2 and i1 is not 0, shift m1 left by one bit = 01010000 = m1o. Calculate m2, m2 = m1o - n1o = 01010000 - 00110000 = 00100000. Since m2 is greater than 0, q[2] = 1, assign 1 to the least significant bit of m2, i.e., m3 = 00100001, and store m3. Update the loop count i1 to i2, i2 = 2 - 1 = 1; then update i2 to i1, and update m3 to m1.

[0068] Since i1 = 1 and i1 is not 0, shift m1 left by one bit = 01000010 = m1o. Calculate m2, m2 = m1o - n1o = 01000010 - 00110000 = 00010010. Since m2 is greater than 0, q[1] = 1, assign 1 to the least significant bit of m2, i.e., m3 = 00010011, and store m3. Update the loop count i1 to i2, i2 = 1 - 1 = 0; then update i2 to i1, and update m3 to m1.

[0069] Since i1 = 0, i.e. i1 is 0, the loop terminates. From m3 = 00010011, we know that the quotient q = 0011 (3) and the remainder r = 0001 (1).

[0070] It is understood that in the embodiments of this application, q[1] = 1 means that the least significant bit of q is 1, q[2] = 1 means that the bit before the least significant bit of q is 1, and so on, which will not be repeated here.

[0071] As can be seen, integer division requires shifting the divisor to the left by the default number of significant digits of the quotient, so that the first non-zero digit of the dividend is aligned with the last digit of the divisor. However, as shown in Table 2, the division operation process has 4 iterations and at least one subtraction, shift, and comparison operation in each iteration, which makes the operation cycle long and significantly reduces the computational efficiency.

[0072] To address the technical problem in the background art, namely, to reduce the number of loops in the division operation, this application proposes a data processing method that can reduce the number of loops, applied to electronic devices. The method includes:

[0073] First, obtain the dividend and divisor, and determine the significant digits of the dividend and divisor. Second, determine the estimated significant digits of the quotient based on the significant digits of the dividend and divisor. Third, determine the number of iterations based on the smaller value between the estimated significant digits of the quotient and the default significant digits of the quotient, and shift the divisor to the left by the number of iterations. Finally, perform a division operation based on the dividend, the divisor shifted to the left by the number of iterations, and the number of iterations to obtain the division result, which includes the quotient and the remainder.

[0074] In some embodiments, the above method of determining the estimated number of significant digits of the quotient based on the significant digits of the dividend and the divisor can be: calculating the difference between the significant digits of the dividend and the divisor, and adding 1 to the difference to obtain the estimated number of significant digits of the quotient.

[0075] In some embodiments, the method for determining the number of iterations based on the smaller of the estimated number of significant digits of the quotient and the default number of significant digits of the quotient can be: subtracting 1 from the smaller of the estimated number of significant digits of the quotient and the default number of significant digits of the quotient to obtain the number of iterations.

[0076] It is understandable that in the division process, the quotient is calculated by iteratively calculating each digit. For example, the restoring remainder method in the prior art shifts the divisor left by the default number of significant digits of the quotient so that the last digit of the divisor aligns with the first non-zero digit of the dividend. Because the divisor is shifted left by the default number of significant digits of the quotient, the number of iterations is equal to the default number of significant digits of the quotient. However, in the division process, it can be found that because the last digit of the divisor is aligned with the first non-zero digit of the dividend, the divisor is shifted by an extra number of digits. This extra shift leads to unnecessary repeated iterations. Therefore, in this embodiment, the number of digits the divisor needs to be shifted (i.e., the number of iterations) is determined based on the number of significant digits of the dividend and the divisor, so that the first non-zero digit of the dividend is aligned with the first non-zero digit of the divisor, thereby reducing repeated iterations. Therefore, using the smaller of the estimated number of significant digits of the quotient and the default number of significant digits of the quotient minus 1 as the number of iterations can also obtain the correct division result.

[0077] It is understood that in the prior art, the default number of significant digits of the quotient is used as the number of loops in the division operation. However, in the embodiments of this application, the number of loops is determined by subtracting 1 from the smaller number of the estimated number of significant digits of the quotient and the default number of significant digits of the quotient. Therefore, the number of loops in the data processing method of this application is generally less than the default number of significant digits of the quotient. Thus, the data processing method provided by this application can effectively reduce the number of loops in the division operation while ensuring the correctness of the division operation, that is, reduce the subtraction, shifting and comparison operations in the loop process, and improve the calculation efficiency.

[0078] The default number of significant bits in the quotient depends on the registers of the electronic device. For example, if the machine word length of the register is 8 bits, then the default number of significant bits in the quotient is 8 bits.

[0079] The effective number of bits refers to the number of bits from the highest non-zero bit to the lowest bit of a binary number. For example, the effective number of bits for 00001100 is 4. In the embodiments of this application, the number of zeros between the highest sign bit and the first 1 can be calculated first using the CountLeadingZeros (CLZ) instruction; then, the number of bits calculated by CLZ is subtracted from the original bit width of the dividend or divisor to obtain the effective number of bits of the dividend or divisor.

[0080] The original bit width of the dividend or divisor is consistent with the machine word length of the register that processes the dividend or divisor. For example, for the dividend 00001100, the CLZ calculates 4 bits for 00001100, while the original bit width of 00001100 is 8. Therefore, the effective number of bits for 00001100 = 8 - 4 = 4.

[0081] It is understood that in division operations, the quotient is calculated by iteratively calculating each bit. The number of iterations depends on the machine word length of the electronic device's register, i.e., the default number of significant bits in the quotient q. The method provided in this application uses the minimum value q_width between the default number of significant bits in the quotient q and the estimated number of significant bits in the quotient q minus 1 as the number of iterations, i.e., (q_width-1) as the number of iterations, to reduce the number of iterations in the division operation and thus improve computational efficiency.

[0082] The following example illustrates the data processing method of this application, with the dividend m equal to binary data 1010 (corresponding to decimal data 10), the divisor n equal to binary data 0011 (corresponding to decimal data 3), and the quotient having a default number of 8 significant digits.

[0083] Since the dividend m = 1010, the number of significant digits of the dividend m is 4; since the divisor n = 0011, the number of significant digits of the divisor n is 2; therefore, the estimated number of significant digits of the quotient = 4 - 2 + 1 = 3.

[0084] Since the estimated number of significant digits in the quotient is 3, which is less than the default number of significant digits in the quotient is 8, the actual number of significant digits in the quotient, q_width, is 3. Shifting the divisor n0011 to the left by (q_width-1) = 3 - 1 = 2 bits yields the divisor n = 001100, and the loop count i = 2.

[0085] When i = 2, calculate the difference between (dividend m - divisor n), i.e., 1010 - 001100 = 00001010 - 00001100 = 11111110. Since 11111110 is less than 0, q[2] = 0. Update the dividend to the difference between (dividend m - divisor n) + divisor = 11111110 + 00001100 = 00001010; shift the divisor n one position to the right to get n = 00000110; decrement the loop count i by 1 to get 1.

[0086] It can be understood that when the difference between (dividend m and divisor n) is less than 0, it means that the dividend is not enough to divide the divisor. Therefore, a borrow or shift is required. So, the i-th bit of the quotient q is assigned the value 0. Adding the dividend to the divisor is to obtain the original dividend for the calculation in the next loop.

[0087] When i = 1, calculate the difference between (dividend m - divisor n), i.e., 00001010 - 00000110 = 00000100. Since 00000100 is greater than 0, q[1] = 1. Update the dividend to the difference between (dividend m - divisor n) = 00000100; shift the divisor n one position to the right to get n = 00000011; decrement the loop count i by 1 to get 0.

[0088] It is understandable that when the difference between (dividend m and divisor n) is greater than 0, that is, the dividend is divisible by the divisor, so no borrowing or shifting is needed, and the i-th bit of the quotient q is assigned the value 1.

[0089] When i = 0, calculate the difference between (dividend m - divisor n), i.e., 00000100 - 00000011 = 00000001. Since 00000001 is greater than 0, q[0] = 1. Update the dividend to the difference between (dividend m - divisor n) = 00000001; shift the divisor n one position to the right to get n = 00000001; decrement the loop count i by 1 to get -1.

[0090] It is understandable that when the difference between (dividend m and divisor n) is greater than 0, that is, the dividend is divisible by the divisor, so no borrowing or shifting is needed, and the i-th bit of the quotient q is assigned the value 1.

[0091] Since -1 is less than 0, the loop terminates. At this point, the dividend m = remainder r = 00000001, and the quotient = 011 = 00000011.

[0092] In this embodiment, the number of shifts in the divisor is used as the loop count. Specifically, the smaller value is selected from the default significant digits of the quotient and the estimated significant digits of the quotient, and then subtracted by 1 to determine the loop count. Since the estimated significant digits of the quotient are generally smaller than the default significant digits, this method, compared to using the default significant digits of the quotient as the loop count, reduces the number of loops in the division operation. This reduces the subtraction, shifting, and comparison operations during the loop, shortens the computation cycle, and improves computational efficiency.

[0093] In practical applications, assuming the quotient has a bit width of 32 bits and both the divisor and dividend are random numbers, conventional algorithms require 32 iterations. However, using the algorithm in this embodiment, the same result can be obtained in an average of about 7 iterations.

[0094] It is understood that electronic devices can be various devices that have the functionality to use the data processing method provided in this application, such as computers, tablets, mobile phones, and PCs. Electronic devices can also be various electronic structures that have the functionality to use the data processing method provided in this application, such as chips and dividers.

[0095] It is understood that the data processing method mentioned in this application can be used in scenarios where the CPU in various electronic devices performs division operations. The following description uses an arithmetic logic unit (ALU) deployed in an electronic device for division operations as an example to illustrate the data processing method mentioned in the embodiments of this application.

[0096] First, the CPU acquires the data to be processed, which includes the dividend and divisor. The arithmetic logic unit (ALU) determines the significant digits of the dividend and divisor. Second, based on the significant digits of the dividend and divisor, the estimated significant digits of the quotient are determined. Third, based on the smaller value between the estimated significant digits of the quotient and the default significant digits of the quotient, the number of iterations is determined, and the divisor is shifted left by the number of iterations. The default significant digits of the quotient depend on the machine word length of the register in the ALU. Finally, a division operation is performed based on the dividend, the divisor shifted left by the number of iterations, and the number of iterations to obtain the division result, which includes the quotient and the remainder. The result is then output.

[0097] Figure 2 According to some embodiments of this application, a schematic flowchart of a data processing method is shown. Figure 2 As shown, the method includes the following steps:

[0098] 201: Assign an initial value of divisor to the dividend m, an initial value of divisor to the divisor n, an initial value of 0 to the quotient q, and an initial value of 0 to the remainder r.

[0099] It can be understood that the dividend m and divisor n are binary data, and that the dividend m and divisor n are integer data, that is, data values ​​that do not include a decimal part. The dividend m and divisor n can be 8-bit binary integer data, 16-bit binary integer data, 32-bit binary integer data, or 64-bit binary integer data.

[0100] 202: Determine the effective number of digits m_width for the dividend m and the effective number of digits n_width for the divisor n.

[0101] As can be understood, the number of significant bits refers to the number of bits in binary data from the first non-zero data bit to the last data bit from left to right.

[0102] For example, if the dividend m is 0101 (corresponding to the decimal number 5), that is, the significant part is "101", then the significant number of digits m_width of 0101 is 3. If the dividend m is 0011 (corresponding to the decimal number 3), that is, the significant part is "11", then the significant number of digits m_width of 0011 is 2.

[0103] 203: Determine the difference d between the significant number of digits m_width of the dividend m and the significant number of digits n_width of the divisor n, and add 1 to the difference d to obtain the estimated significant number of digits of the quotient.

[0104] For example, if the dividend m is 0101 (corresponding to the decimal number 5), then the significant digits m_width of 0101 are 3. If the divisor m is 0011 (corresponding to the decimal number 3), then the significant digits m_width of 0011 are 2. The difference between the significant digits of the dividend 0101 and the significant digits of the divisor 0011 is 1. Adding 1 to the difference d gives the estimated significant digits of the quotient as 2.

[0105] 204: Determine the minimum value between the default number of significant digits of the quotient q and the estimated number of significant digits of the quotient, and use the minimum value as the actual number of significant digits of the quotient q_width.

[0106] It is understood that in division operations, the quotient is calculated by iteratively calculating each bit. The number of iterations depends on the machine word length of the electronic device's register, i.e., the default number of significant bits in the quotient q. The method provided in this application uses the minimum value q_width between the default number of significant bits in the quotient q and the estimated number of significant bits in the quotient q minus 1 as the number of iterations, i.e., (q_width-1) as the number of iterations, to reduce the number of iterations in the division operation and thus improve computational efficiency.

[0107] 205: Shift the divisor n to the left by -1 (q_width-1) bits of the actual effective number of quotients, and let the loop count i = (q_width-1).

[0108] It can be understood that shifting the divisor n to the left by -1 bit of the actual effective number of bits in the quotient is equivalent to multiplying the divisor n by a power of 2 (q_width-1). The purpose of this step is to align the first non-zero bit of the divisor with the first non-zero bit of the dividend, thereby reducing the number of iterations required.

[0109] It is understandable that in the division process, the quotient is calculated by iteratively calculating each digit. For example, the restoring remainder method in the prior art shifts the divisor left by the default number of significant digits of the quotient so that the last digit of the divisor aligns with the first non-zero digit of the dividend. Because the divisor is shifted left by the default number of significant digits of the quotient, the number of iterations is equal to the default number of significant digits of the quotient. However, in the division process, it can be found that because the last digit of the divisor is aligned with the first non-zero digit of the dividend, the divisor is shifted by an extra number of digits. This extra shift leads to unnecessary repeated iterations. Therefore, in this embodiment, the number of digits the divisor needs to be shifted (i.e., the number of iterations) is determined based on the number of significant digits of the dividend and the divisor, so that the first non-zero digit of the dividend is aligned with the first non-zero digit of the divisor, thereby reducing repeated iterations. Therefore, using the smaller of the estimated number of significant digits of the quotient and the default number of significant digits of the quotient minus 1 as the number of iterations can also obtain the correct division result.

[0110] 206: Update the dividend m to the difference between the dividend m and the divisor n, i.e., m = (mn).

[0111] It's understandable that when performing decimal division, the first step is to determine if the number is divisible. For example, when dividing a decimal number 3 by a decimal number 5, if the number is not divisible, the quotient is 0; if it is divisible, the quotient is 1. Similarly, when performing binary division on an electronic device, the device first needs to perform a subtraction operation on the dividend m and the divisor n. If the result is negative, the quotient is 0; if the result is positive, the quotient is 1.

[0112] 207: Determine if the dividend m is greater than or equal to 0. If yes, proceed to step 208; otherwise, proceed to step 209.

[0113] 208: Assign the value 1 to the i-th bit of the quotient q.

[0114] It is understandable that when m is greater than or equal to 0, that is, the dividend is divisible, so no borrowing or shifting is needed, so the i-th bit of the quotient q is assigned the value 1.

[0115] 209: Assign 0 to the i-th bit of the quotient q, and update the dividend m to the sum of the dividend m and the divisor n, i.e., m = (m + n).

[0116] It is understandable that when m is less than 0, the dividend is not enough to divide the divisor, so a borrow or shift is needed. Therefore, the i-th bit of the quotient q is assigned the value 0. The dividend m is added to the divisor n in order to obtain the original dividend for the calculation in the next loop.

[0117] 210: Subtract 1 from the loop count i and shift the divisor one position to the right.

[0118] 211: Determine if the loop count i is less than zero. If yes, end the loop; otherwise, proceed to step 206.

[0119] The following example illustrates the calculation process, with the dividend m equal to binary data 1010 (corresponding to decimal data 10), the divisor n equal to binary data 0011 (corresponding to decimal data 3), and the quotient having a default number of 8 significant digits. The calculation process is shown in Table 2.

[0120] Dividend m = 1010 (10); divisor n = 0011 (3). That is: m = 00001010, n = 00000011.

[0121] Since the dividend m = 1010, m_width = 4; since the divisor n = 0011, n_width = 2; therefore, the estimated number of significant digits of the quotient = 4 - 2 + 1 = 3.

[0122] Since the estimated number of significant digits in the quotient is 3, which is less than the default number of significant digits in the quotient is 8, i.e., q_width = min{q_width,d+1} = min{8,3} = 3, the actual number of significant digits in the quotient, q_width, is 3. Shifting the divisor n0011 to the left by (q_width-1) = 3 - 1 = 2 bits, we get the divisor n = 001100, and let the loop count i = 2.

[0123] When i = 2, calculate the difference between (dividend m - divisor n), i.e., 00001010 - 001100 = 00001010 - 00001100 = 11111110. Since 11111110 is less than 0, q[2] = 0. Update the dividend to the difference between (dividend m - divisor n) + divisor = 11111110 + 00001100 = 00001010; shift the divisor n one position to the right to get n = 00000110; decrement the loop count i by 1 to get i = 1.

[0124] It is understandable that when the difference between (dividend m and divisor n) is less than 0, that is, the dividend is not enough to divide the divisor, so borrowing or shifting is required. Therefore, the i-th bit of the quotient q is assigned the value 0. Adding the dividend m to the divisor n is to obtain the original dividend for the calculation in the next loop.

[0125] When i = 1, calculate the difference between (dividend m - divisor n), i.e., 00001010 - 00000110 = 00000100. Since 00000100 is greater than 0, q[1] = 1. Update the dividend to the difference between (dividend m - divisor n) = 00000100; shift the divisor n one position to the right to get n = 00000011; decrement the loop count i by 1 to get 0.

[0126] It is understandable that when the difference between (dividend m and divisor n) is greater than or equal to 0, that is, the dividend is divisible by the divisor, so no borrowing or shifting is needed, and the i-th bit of the quotient q is assigned the value 1.

[0127] When i = 0, calculate the difference between (dividend m - divisor n), i.e., 00000100 - 00000011 = 00000001. Since 00000001 is greater than 0, q[0] = 1. Update the dividend to the difference between (dividend m - divisor n) = 00000001; shift the divisor n one position to the right to get n = 00000001; decrement the loop count i by 1 to get i = -1.

[0128] It is understandable that when the difference between (dividend m and divisor n) is greater than or equal to 0, that is, the dividend is divisible by the divisor, so no borrowing or shifting is needed, and the i-th bit of the quotient q is assigned the value 1.

[0129] Since i = -1 is less than 0, the loop terminates. At this point, the remainder r = the dividend m = 00000001, and the quotient = 011 = 00000011.

[0130] It is understood that in the embodiments of this application, q[0] = 1 means that the least significant bit of q is 1, q[1] = 1 means that the bit before the least significant bit of q is 1, and so on, which will not be repeated here.

[0131] Table 2:

[0132]

[0133]

[0134] As can be seen from Tables 1 and 2 above, the method of this application embodiment can reduce the number of loops by one, that is, reduce one subtraction, shift and comparison operation, reduce the operation cycle and improve the computation efficiency.

[0135] The following uses an electronic device as an example to introduce a divider 100. A schematic diagram of the divider 100 is shown below. Figure 3 As shown, the divider 100 includes a divisor register 101, an arithmetic logic unit 102, a dividend register 103, a remainder register 104, a quotient register 105, and a division control logic unit 106.

[0136] The division register 101 stores the divisor during the division operation, and the dividend register 103 stores the dividend during the division operation. The arithmetic logic unit 102 retrieves the divisor from the divisor register 101 and the dividend from the dividend register 103. The remainder register 104 stores the remainder during the division operation. The division control logic unit 106 controls the start and end of the division operation, as well as the initialization, shifting, and updating of the divisor register 101, dividend register 103, remainder register 104, and quotient register 105. For example, the division control logic unit 106 assigns an initial value of `diviend` to the dividend `m`, an initial value of `divisor` to the divisor `n`, an initial value of 0 to the quotient `q`, and an initial value of 0 to the remainder `r`.

[0137] Arithmetic logic unit 102 is used to determine the number of significant digits m_width of the dividend m and the number of significant digits n_width of the divisor n; determine the difference d between the number of significant digits m_width of the dividend m and the number of significant digits n_width of the divisor n; then, add 1 to the difference d to obtain the estimated number of significant digits of the quotient q; determine the minimum value between the default number of significant digits of the quotient q and the estimated number of significant digits of the quotient; subtract 1 from the minimum value to obtain the actual number of significant digits q_width of the quotient; shift the divisor n to the left by the actual number of significant digits of the quotient by 1, that is, shift the divisor n to the left by (q_width-1) bits; and subtract 1 from the actual number of significant digits to obtain the loop count i, i.e., i = (q_width-1). Update the dividend m to the difference between the dividend m and the divisor n, i.e., m = (mn). Check if the dividend m is greater than or equal to zero. If the result is yes, set the (i-1)th bit of the quotient q to 1. If the result is no, set the (i-1)th bit of the quotient q to 0. Update the dividend m to the sum of the dividend m and the divisor n, i.e., m = (m+n). Subtract 1 from the loop count i. Check if the loop count i is less than zero. If the result is yes, end the loop. If the result is no, return: Update the dividend m to the difference between the dividend m and the divisor n.

[0138] This application also provides a data processing method. Specifically, Figure 4 The diagram illustrates a data processing method according to an embodiment of this application. The execution entity of this process is the processor of an electronic device, and the processor can run software to implement the above-mentioned data processing method.

[0139] 401: Get the first dividend and the first divisor of the division operation to be performed.

[0140] It is understood that in some embodiments, the user can input the first dividend and the first divisor into the electronic device, and then the division operation module of the electronic device can obtain the first dividend and the first divisor.

[0141] 402: Determine the position of the leading 1 in the first dividend, and set the position of the leading 1 of the first divisor to be aligned with the position of the leading 1 of the first dividend.

[0142] In the embodiments of this application, the leading 1 refers to the position of the first "1" in the binary number.

[0143] For example, if the first dividend is 1010, then the leading 1 of the first dividend is in the first position; if the first divisor is 0011, then the leading 1 of the first divisor is in the third position.

[0144] To align the leading 1 of the first divisor with the leading 1 of the first dividend, first determine the difference between the number of significant digits of the first dividend and the number of significant digits of the first divisor, add 1 to the difference to obtain the estimated number of significant digits of the quotient, then determine the total number of iterations based on the smaller of the estimated number of significant digits of the quotient and the default number of significant digits of the quotient, and shift the first divisor to the left by the total number of iterations.

[0145] For example, if the first dividend is 1010 (corresponding to the decimal number 10), then 1010 has 4 significant digits. If the first divisor is 0011 (corresponding to the decimal number 3), then 0011 has 2 significant digits. The difference between the significant digits of the first dividend 1010 and the significant digits of the divisor 0011 is 2. Adding 1 to this difference gives the estimated significant digits of the quotient as 3.

[0146] It is understood that in division operations, the quotient is calculated by iteratively calculating each bit. The number of iterations depends on the machine word length of the electronic device's register, i.e., the default number of significant bits in the quotient. The method provided in this application uses the minimum value between the default number of significant bits in the quotient and the estimated number of significant bits in the quotient minus 1 as the total number of iterations, thereby reducing the number of iterations in the division operation and improving computational efficiency.

[0147] It is understood that in this embodiment of the application, the default number of significant bits of the quotient is 8, and the estimated number of significant bits of the quotient is 3. Therefore, the total number of loops is 2. The first divisor 0011 is shifted left by 2 bits, that is, 001100, and the first dividend is 1010. At this time, the position of the leading 1 of the first divisor is aligned with the position of the leading 1 of the first dividend.

[0148] 403: Perform subtraction, comparison of difference with zero, and shift operations sequentially on the first dividend and the first divisor to obtain the division result of the first dividend and the first divisor.

[0149] In this embodiment, the difference between the first dividend and the first divisor is calculated. This difference is compared with 0. If the difference is greater than or equal to 0, the total loop count bit of the quotient is assigned a value of 1, and the first dividend is updated to the difference. If the difference is less than 0, the total loop count bit of the quotient is assigned a value of 0, and the first dividend is updated to the difference plus the first divisor. Then, the total loop count is subtracted by 1, and the first divisor is shifted one position to the right. The process returns to calculating the difference between the first dividend and the first divisor until the total loop count is less than 0, at which point the loop terminates.

[0150] For example, let the total number of loops i = 2, calculate the difference between (first dividend - first divisor), i.e., 1010 - 001100 = 00001010 - 00001100 = 11111110. Since 11111110 is less than 0, q[2] = 0. Update the first dividend to the difference between (first dividend - first divisor) + first divisor = 11111110 + 00001100 = 00001010; shift the first divisor one position to the right to get 00000110; subtract 1 from the total number of loops i to get 1.

[0151] It is understandable that when the difference between (first dividend and first divisor) is less than 0, it means that the first dividend is not enough to divide the first divisor. Therefore, a borrow or shift is required. So, the i-th bit of the quotient is assigned the value 0. Adding the first dividend to the first divisor is to obtain the original dividend for the calculation in the next loop.

[0152] When i = 1, calculate the difference between (first dividend - first divisor), i.e., 00001010 - 00000110 = 00000100. Since 00000100 is greater than 0, q[1] = 1. Update the first dividend to the difference between (first dividend - first divisor) = 00000100; shift the first divisor n one position to the right to get 00000011; decrement the total number of iterations i by 1 to get 0.

[0153] It is understandable that when the difference between (first dividend and first divisor) is greater than 0, that is, the first dividend is enough to divide the first divisor, so no borrowing or shifting is needed, so the i-th bit of the quotient q is assigned the value 1.

[0154] When i = 0, calculate the difference between (first dividend - first divisor), i.e., 00000100 - 00000011 = 00000001. Since 00000001 is greater than 0, q[0] = 1. Update the first dividend to the difference between (first dividend - first divisor) = 00000001; shift the first divisor one position to the right to get 00000001; decrement the loop count i by 1 to get -1.

[0155] It is understandable that when the difference between (first dividend and first divisor) is greater than 0, that is, the first dividend is enough to divide the first divisor, so no borrowing or shifting is needed, so the i-th bit of the quotient is assigned the value 1.

[0156] Since -1 is less than 0, the loop terminates. At this point, the first dividend = remainder = 00000001, and the quotient = 011 = 00000011.

[0157] In this embodiment, the number of shifts in the first divisor is used as the loop count. Specifically, the smaller value is selected from the default significant digits of the quotient and the estimated significant digits of the quotient, and then subtracted by 1 to obtain the total loop count. Since the estimated significant digits of the quotient are generally smaller than the default significant digits, this method, to a certain extent, reduces the number of division loops compared to using the default significant digits of the quotient as the total loop count. This reduces the number of subtraction, shifting, and comparison operations during the loop process, shortens the computation cycle, and improves computational efficiency.

[0158] further, Figure 5 According to some embodiments of this application, a schematic diagram of the structure of an electronic device 100 is shown. For example... Figure 5 As shown, the electronic device 100 includes one or more processors 101A, system memory 102, non-volatile memory (NVM) 103, communication interface 104, input / output (I / O) devices 105, and system control logic 106 for coupling the processors 101A, system memory 102, NVM 103, communication interface 104, and input / output (I / O) devices 105. Wherein:

[0159] Processor 101A can be used to control an electronic device to execute the data processing method of this application. Processor 101A may include one or more processing units, such as a central processing unit (CPU), a graphics processing unit (GPU), a digital signal processor (DSP), a micro-programmed control unit (MCU), an AI (Artificial Intelligence) processor, or a field-programmable gate array (FPGA) processing module or processing circuit, which may include one or more single-core or multi-core processors. System memory 102 is volatile memory, such as random-access memory (RAM), double data rate synchronous dynamic random-access memory (DDR SDRAM), etc. System memory is used for temporary storage of data and / or instructions. For example, in some embodiments, system memory 102 may be used to store the aforementioned divisor register, arithmetic logic unit, dividend register, remainder register, quotient register, and division control logic unit.

[0160] The non-volatile memory 103 may include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, the non-volatile memory 103 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as a hard disk drive (HDD), a compact disc (CD), a digital versatile disc (DVD), a solid-state drive (SSD), etc. In some embodiments, the non-volatile memory 103 may also be a removable storage medium, such as a secure digital (SD) memory card, etc. In other embodiments, the non-volatile memory 103 may be used to store the aforementioned divisor register, arithmetic logic unit, dividend register, remainder register, quotient register, and division control logic unit, etc.

[0161] Specifically, system memory 102 and non-volatile memory 103 may each include a temporary copy and a permanent copy of instruction 107. Instruction 107 may include, when executed by processor 101A, causing electronic device 100 to implement the data processing methods provided in the embodiments of this application.

[0162] The communication interface 104 may include a transceiver for providing a wired or wireless communication interface for the electronic device 100, thereby enabling communication with any other suitable device via one or more networks. In some embodiments, the communication interface 104 may be integrated into other components of the electronic device 100, for example, the communication interface 104 may be integrated into the processor 101A. In some embodiments, the electronic device 100 may communicate with other devices through the communication interface 104; for example, the electronic device 100 may obtain a data processing method to be executed from other electronic devices through the communication interface 104.

[0163] Input / output (I / O) device 105 may include input devices such as keyboard, mouse, etc., and output devices such as monitor, etc. Users can interact with electronic device 100 through input / output (I / O) device 105.

[0164] System control logic 106 may include any suitable interface controller to provide any suitable interface to other modules of electronic device 100. For example, in some embodiments, system control logic 106 may include one or more memory controllers to provide an interface to system memory 102 and non-volatile memory 103.

[0165] In some embodiments, at least one of the processors 101A may be packaged together with the logic of one or more controllers for system control logic 106 to form a system in package (SiP). In other embodiments, at least one of the processors 101A may also be integrated on the same chip with the logic of one or more controllers for system control logic 106 to form a SoC.

[0166] It is understood that electronic device 100 can be any electronic device capable of running DCLS, including but not limited to mobile phones, wearable devices (such as smartwatches), tablets, desktops, laptops, handheld computers, notebook computers, ultra-mobile personal computers (UMPCs), netbooks, as well as cellular phones, personal digital assistants (PDAs), augmented reality (AR) / virtual reality (VR) devices, etc., which are not limited in the embodiments of this application.

[0167] Understandable. Figure 5 The structure of the electronic device 100 shown is merely an example. In other embodiments, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0168] The various embodiments of the mechanisms disclosed in this application can be implemented in hardware, software, firmware, or a combination of these implementation methods. Embodiments of this application can be implemented as computer programs or program code executable on a programmable system, the programmable system including at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.

[0169] Program code can be applied to input instructions to execute the functions described in this application and generate output information. The output information can be applied to one or more output devices in a known manner. For the purposes of this application, the processing system includes any system having a processor such as, for example, a Digital Signal Processor (DSP), a microcontroller, an Application Specific Integrated Circuit (ASIC), or a microprocessor.

[0170] The program code can be implemented using a high-level procedural language or an object-oriented programming language to communicate with the processing system. Assembly language or machine language can also be used when needed. In fact, the mechanisms described in this application are not limited to any particular programming language. In either case, the language can be a compiled language or an interpreted language.

[0171] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored thereon on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, the instructions may be distributed via a network or through other computer-readable media. Therefore, machine-readable media may include any mechanism for storing or transmitting information in a machine-readable (e.g., computer-readable) form, including but not limited to floppy disks, optical disks, CD-ROMs, magneto-optical disks, read-only memory (ROM), random access memory (RAM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), magnetic cards or optical cards, flash memory, or tangible machine-readable storage for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in the form of electrical, optical, acoustic, or other forms of propagated signals. Therefore, machine-readable media include any type of machine-readable medium suitable for storing or transmitting electronic instructions or information in a machine-readable (e.g., computer-readable) form.

[0172] In the accompanying drawings, some structural or methodological features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order may not be necessary. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the illustrative drawings. Furthermore, the inclusion of structural or methodological features in a particular figure does not imply that such features are required in all embodiments, and in some embodiments, these features may be omitted or may be combined with other features.

[0173] It should be noted that all units / modules mentioned in the device embodiments of this application are logical units / modules. Physically, a logical unit / module can be a physical unit / module, a part of a physical unit / module, or a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important factor; the combination of functions implemented by these logical units / modules is the key to solving the technical problems proposed in this application. Furthermore, to highlight the innovative aspects of this application, the above-described device embodiments of this application have not introduced units / modules that are not closely related to solving the technical problems proposed in this application. This does not mean that the above-described device embodiments do not contain other units / modules.

[0174] It should be noted that, in the examples and description of this patent, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one" does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0175] Although this application has been illustrated and described with reference to certain preferred embodiments thereof, those skilled in the art should understand that various changes in form and detail may be made thereto without departing from the spirit and scope of this application.

Claims

1. A data processing method applied to electronic devices, characterized in that, include: Get the first dividend and the first divisor of the division operation to be performed; Calculate the first significant digits of the first dividend and the second significant digits of the first divisor; The number of bits to move is determined based on the first significant number of bits and the second significant number of bits. Shift the numerical value of the first divisor to the left by the shifted number of bits, so that the position of the leading 1 of the first divisor is aligned with the position of the leading 1 of the first dividend; Subtraction, comparison of the difference with zero, and shift operations are performed sequentially on the first dividend and the first divisor to obtain the division result of the first dividend and the first divisor.

2. The data processing method according to claim 1, characterized in that, Determining the shift number based on the first significant number of bits and the second significant number of bits includes: The difference between the first significant number of digits and the second significant number of digits is determined to obtain the first difference; Add 1 to the first difference to obtain the estimated number of significant digits; Determine the default number of significant digits in the quotient; The number of bits to move is determined based on the minimum value between the default number of significant bits and the estimated number of significant bits.

3. The data processing method according to claim 1, characterized in that, The shifted number is used as the total number of loops for the division operation between the first dividend and the first divisor.

4. The data processing method according to claim 3, characterized in that, The step of sequentially performing subtraction, comparison of the difference with zero, and shift operation on the first dividend and the first divisor to obtain the calculation result includes: Calculate the difference between the first dividend and the first divisor to obtain a second difference, and use the second difference as the second dividend; The third dividend is obtained by assigning a value to the total number of cycles based on the second dividend as the quotient; Subtract 1 from the total number of loops to obtain the remaining number of loops, and shift the value of the first divisor one bit to the right to obtain the second divisor; If the remaining number of cycles is less than 0, the second dividend is taken as the remainder; The value of the quotient is determined based on the assignment of the bit of the total number of cycles in the quotient.

5. The data processing method according to claim 4, characterized in that, If the remaining number of cycles is greater than or equal to 0, the third dividend is used as the first dividend, and the second divisor is used as the first divisor; Calculate the difference between the first dividend and the first divisor to obtain a second difference, and use the second difference as the second dividend.

6. The data processing method according to claim 4, characterized in that, The step of assigning a value to the total number of cycles based on the second dividend as the quotient, and obtaining the third dividend, includes: For the case where the second dividend is greater than or equal to 0, the total number of cycles in the quotient is assigned a value of 1; the second dividend is used as the third dividend; When the second dividend is less than 0, the total number of cycles in the quotient is set to 0. The sum of the second dividend and the second divisor is calculated to obtain a second value, which is then used as the third dividend.

7. A divider, characterized in that, Including the division control logic unit; The division control logic unit is used to obtain the first dividend and the first divisor to be divided. Calculate the first significant digits of the first dividend and the second significant digits of the first divisor; The number of bits to move is determined based on the first significant number of bits and the second significant number of bits. Shift the numerical value of the first divisor to the left by the shifted number of bits, so that the position of the leading 1 of the first divisor is aligned with the position of the leading 1 of the first dividend; The first dividend and the first divisor are sequentially subjected to subtraction, comparison of the difference with zero, and shifting operations to obtain the result.

8. The divider according to claim 7, characterized in that, It also includes a first dividend register, a first divisor register, an arithmetic logic unit, a remainder register, and a quotient register. The first dividend register is used to store the first dividend during the division operation; The first divisor register is used to store the first divisor during the division operation; The quotient register is used to store the quotient during the division operation; The remainder register is used to store the remainder during the division operation; The arithmetic logic unit is used to obtain a first dividend from the first dividend register and to obtain a first divisor from the first divisor register; The division control logic is used to control the start and end of the division operation, as well as the initialization, shifting and updating of the first divisor register, the first dividend register, the remainder register and the quotient register.

9. A readable medium, characterized in that, The readable medium stores instructions that, when executed on an electronic device, cause the electronic device to perform the data processing method according to any one of claims 1 to 6.

10. An electronic device, characterized in that, It includes: a memory for storing instructions executed by one or more processors of the electronic device, and the processor being one of the one or more processors of the electronic device for performing the data processing method according to any one of claims 1 to 6.

11. An electronic device, characterized in that, The divider included in any one of claims 7 to 8.

12. A computer program product, characterized in that, include: An execution instruction is stored in a readable storage medium, and at least one processor of the electronic device reads the execution instruction from the readable storage medium, and the at least one processor executes the execution instruction to cause the electronic device to implement the data processing method of any one of claims 1 to 6.

Citation Information

Patent Citations

  • Fixed-point divider and operation processing method thereof

    CN101692201A

  • Method and apparatus for integer division

    CN1117763A