Multi-input comparison method, device, circuit and processor

By generating the initial mask and vertical code, efficient comparison of multiple numbers is achieved, and the problem of inefficient in the prior art is solved, and it is suitable for multi-input digital integrated circuits.

CN119093936APending Publication Date: 2024-12-06NANJING ILUVATAR COREX TECH CO LTD (DBA ILUVATAR COREX INC NANJING)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411006066.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-25
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The prior art is inefficient when comparing multiple numbers, especially when the number of data in the input digital integrated circuit is large, multiple comparisons are required, resulting in delay and efficiency impacts.

Method used

By using the multi-input comparison method, the initial mask with the same bit width as the number of comparison numbers, the vertical code and logical operations are used to compare multiple numbers at the same time, and the comparison is eliminated from high to low, and the comparison is improved. efficiency.

Benefits of technology

When ensuring correctness, the comparison efficiency between multiple comparison numbers is significantly improved, the comparison times are reduced, and the delay is reduced, and it is suitable for data of different types and bit widths.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119093936A_ABST
    Figure CN119093936A_ABST
Patent Text Reader

Abstract

The invention provides a multi-input comparison method, a multi-input comparison device, a multi-input comparison circuit and a processor. The multi-input comparison method comprises the following steps: acquiring a plurality of comparators for comparison; generating an initial mask of which the bit width is consistent with the number of the comparators; each bit of the initial mask corresponds to a comparative number, each bit of the initial mask is a preset first value, and the first value represents that the comparative number corresponding to the bit participates in comparison; forming a vertical code corresponding to the ith bit according to the value of the ith bit of each comparative number; i is selected from m to 0 in sequence, and m is the highest bit number of the comparative number; updating the mask of the ith bit according to the vertical code corresponding to the ith bit to obtain a mask of an (i-1) th bit; and repeating the comparison process until the comparison of the output mask is completed. Through the method, simultaneous comparison of a plurality of comparators can be realized, and the comparison efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of integrated circuits, and in particular, to a multi-input comparison method, device, circuit and processor. Background Art

[0002] In digital integrated circuits, multiple numbers are compared to determine the maximum or minimum value among them.

[0003] At present, to determine the maximum or minimum value from multiple numbers, usually subtract each two numbers, and determine the larger or smaller value based on the subtraction result, and then continue to compare them step by step until the final maximum or minimum value is obtained. This two-by-two comparison method is inefficient. When the number of data input to the digital integrated circuit for comparison is large, more comparisons need to be performed, resulting in a large delay, affecting work efficiency. Summary of the invention

[0004] In view of this, the present application aims to provide a multi-input comparison method, device, circuit and processor to improve the comparison efficiency between multiple input comparison numbers.

[0005] In a first aspect, an embodiment of the present application provides a multi-input comparison method, including: obtaining multiple comparison numbers for comparison; generating an initial mask whose bit width is consistent with the number of comparison numbers; each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value represents that the comparison number corresponding to the bit participates in the comparison; according to the value of the i-th bit of each comparison number, a vertical code corresponding to the i-th bit is formed; i takes m to 0 in sequence, and m is the highest bit number of the comparison number; according to the vertical code corresponding to the i-th bit, the i-th bit is updated in the mask New, obtain the mask of the i-1th bit; wherein the initial mask is the mask corresponding to the mth bit; wherein the value of the target bit in the mask of the i-1th bit is the second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison; repeat the above comparison process until all bits are compared, and output the mask of the -1th bit; or, repeat the above comparison process until only one bit in the mask of the i-1th bit is the first value, and output the mask of the i-1th bit.

[0006] In the embodiment of the present application, the vertical code is data composed of the values ​​on the i-th bit of all comparison numbers, then in the vertical code, the value size of each comparison number on the i-th bit can be determined, so as to realize the simultaneous comparison of multiple comparison numbers on the same bit. Since i takes m to 0 in turn, that is, the vertical code starts to take values ​​from the highest bit, the vertical code from the high bit to the low bit can compare the high bit to the low bit of the comparison number in turn, and use the mask to record the comparison result to determine whether it needs to participate in the subsequent comparison, thus, through the comparison from the high bit to the low bit, until all bits are compared, the mask of the -1th bit is output or only one comparison number is not eliminated, so as to realize the comparison of all comparison numbers. Compared with the method of comparing two by two, the method provided by the present application can compare multiple comparison numbers at the same time while ensuring the correct comparison, thereby improving the efficiency when comparing multiple comparison numbers. In addition, only one bit in the mask is the first value, indicating that only one comparison number can participate in the next round of comparison, that is, no other comparison number is compared with the comparison number. At this time, the mask is directly output, and there is no need to compare subsequent bits, thereby improving comparison efficiency.

[0007] In one embodiment, the obtaining of multiple comparison numbers for comparison includes: receiving multiple comparison numbers; if any different comparison numbers among the received multiple comparison numbers have different bit widths, expanding the bit width of the comparison number with the smaller bit width to be consistent with the bit width of the comparison number with the largest bit width.

[0008] In the embodiment of the present application, by expanding the comparison numbers with inconsistent bit widths to be consistent with the bit width of the comparison number with the largest bit width, comparison numbers with inconsistent bit widths can also be compared, thereby expanding the comparable range.

[0009] In one embodiment, before forming the vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number, the method also includes: obtaining the data type of the received comparison number; based on a first conversion relationship between a preset data type and a data format, converting all comparison numbers to a data format that matches the data type; forming the vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number includes: forming the vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number whose data format matches the data type.

[0010] In an embodiment of the present application, different types of data are converted into a data format that can be compared using the multi-input comparison method provided in the present application through a first conversion relationship. As a result, comparison of comparison numbers of different data types can be performed, effectively expanding the scope of application of the multi-input comparison method, thereby improving the efficiency of comparing comparison numbers of different types.

[0011] In one embodiment, the data type includes a signed number, and the first conversion relationship between the preset data type and the data format is used to convert all comparison numbers into a data format that matches the data type, including: if each comparison number is a signed number, an extension bit is configured on the highest bit of each comparison number, and a numerical value representing the sign of each comparison number is supplemented on the extension bit of each comparison number; on the extension bit, 1 represents a positive number and 0 represents a negative number.

[0012] In an embodiment of the present application, for signed numbers, bits can be expanded on the original comparison number, and the numerical value representing the sign can be supplemented in the extended bit, such as 0 for negative numbers and 1 for positive numbers. In this way, signed numbers can also be compared using the multi-input comparison method provided by the present application, thereby expanding the scope of application of the present application and improving the efficiency of comparing signed numbers.

[0013] In one embodiment, the data type includes floating-point numbers, and based on a first conversion relationship between a preset data type and a data format, all comparison numbers are converted into a data format that matches the data type, including: if each comparison number is a floating-point number and the data format is not binary, each comparison number is converted into a binary floating-point number.

[0014] A floating point number is composed of a sign, an exponent, and a mantissa. The sign of a positive floating point number is 0, and the sign of a negative floating point number is 1. However, the meaning represented by the binary value of a floating point number is similar to that of an unsigned number, and the weight of the data represented in sequence from high bit to low bit is reduced. Therefore, in an embodiment of the present application, a floating point number can be directly converted into binary data, so that the floating point number performs a comparison process similar to that of an unsigned number. While enabling comparison of multiple floating point numbers, the complexity of comparison is reduced. In this way, the comparison efficiency of floating point numbers can be effectively improved.

[0015] In one embodiment, the mask of the i-th bit is updated according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit, including: performing a logical operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result; if the logical operation result of the i-th bit indicates that the values ​​of the i-th bits of all comparison numbers are the same, then the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result of the i-th bit indicates that there is an elimination of comparison numbers in this round of comparison, then the logical operation result of the i-th bit is updated to the mask of the i-1-th bit.

[0016] In this embodiment, by performing a logical operation on the vertical code and the mask, it can be determined whether each comparison number participating in this round of comparison wins or is eliminated in this round of comparison. For different logical operation results, such as the case where the logical operation result is all 0 or all 1, at this time, the values ​​of different comparison numbers on the bit position are the same, then all comparison numbers participating in this round of comparison should continue to be compared. Therefore, the mask of the i-th bit position is updated to the mask of the i-1-th bit position so that the comparison number can continue to participate in subsequent comparisons. On the contrary, if the logical operation result is not 0 or 1, there is a comparison number that is eliminated. At this time, the logical operation result can represent the eliminated bit position, and the logical operation result is updated to the mask of the next bit position. By updating the mask, the subsequent comparison is performed correctly, thereby enabling multiple comparison numbers to be accurately compared.

[0017] In one embodiment, the logical operation is an AND operation, the first value is 1, and the second value is 0.

[0018] In the embodiment of the present application, the comparison result of the AND operation can be used to represent the winner and the elimination, and realize the required function of the aforementioned logic operation. Compared with the combinational logic, the AND operation is relatively simple and can improve the efficiency of multi-input comparison.

[0019] In one embodiment, before obtaining multiple comparison numbers for comparison, the method also includes: obtaining a comparison type; wherein the comparison type includes a maximum value comparison and a minimum value comparison; according to a second conversion relationship between a preset comparison type and a data format, converting each of the comparison numbers and into a data format corresponding to the comparison type; wherein the second conversion relationship includes: if the comparison type is a maximum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a minimum value comparison, inverting the value of each bit of the comparison number.

[0020] When performing an AND operation, the result is 1 when all the numbers involved in the operation are 1, and 0 when there is 0. It can be considered that the number with a value of 1 wins, and the number with a value of 0 will be eliminated. Therefore, in the embodiment of the present application, when performing a maximum value comparison, using an AND operation can have a higher comparison efficiency. In the case where the AND operation is not adjusted, the maximum value comparison can be performed, but it cannot be directly used for the minimum value comparison. Therefore, all comparison numbers can be negated to achieve a minimum value comparison. Therefore, whether it is for the maximum value or the minimum value, comparison can be achieved to meet the needs of different comparisons.

[0021] In one embodiment, the logical operation of the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit includes: performing an AND operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result corresponding to the i-th bit; wherein, if the values ​​corresponding to all bits in the logical operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result corresponding to the i-th bit is non-0 or non-1, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit; the logical operation result of the AND operation being non-0 and non-1 indicates that there is a comparison number elimination.

[0022] In the embodiment of the present application, if there is 0 in the principle of AND operation, the result is 0, and 0 is the smallest number. Therefore, when performing the maximum value comparison, it can be determined that the comparison number corresponding to 0 is eliminated. If the logical operation result is all 0, it means that the values ​​of all comparison numbers on the bit position are 0 at this time, and all comparison numbers involved in the comparison should not be eliminated, but should be regarded as the same and retained. Therefore, when the logical operation result is 0, it should be regarded as the same value on all comparison positions, and the mask used by the current bit position should continue to be used. When the logical operation result is non-0 or non-1, the logical operation result includes the comparison number eliminated by the previous bit position and the data eliminated by the current bit position. Therefore, the logical operation result can be used as the mask of the next bit position. In this way, when using the AND operation for comparison, the comparison result can be accurately determined, and the situation of comparison errors can be effectively reduced.

[0023] In one embodiment, the logical operation is an OR operation, the first value is 0, and the second value is 1.

[0024] In the embodiment of the present application, the comparison result of the OR operation can be used to represent the winning and the elimination, and realize the required function of the aforementioned logic operation. Compared with the combinational logic, the OR operation is relatively simple and can improve the efficiency of multi-input comparison.

[0025] In one embodiment, before obtaining multiple comparison numbers for comparison, the method also includes: obtaining a comparison type; wherein the comparison type includes a maximum value comparison and a minimum value comparison; according to a third conversion relationship between a preset comparison type and a data format, converting each of the comparison numbers and into a data format corresponding to the comparison type; wherein the third conversion relationship includes: if the comparison type is a minimum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a maximum value comparison, inverting the value of each bit of the comparison number.

[0026] When performing an OR operation, the result is 0 when all the numbers involved in the operation are 0, and 1 when there is 1. Therefore, it can be considered that the number with a value of 0 wins, and the number with a value of 1 will be eliminated. In the embodiment of the present application, when performing a minimum value comparison, using an OR operation can have a higher comparison efficiency, and there is no need to negate the comparison number. In the case where the AND operation is not adjusted, the minimum value comparison can be performed, but it cannot be directly used for the maximum value comparison. Therefore, all comparison numbers can be negated to achieve the maximum value comparison. Therefore, whether for the maximum value or the minimum value, the OR operation can achieve comparison, meeting the needs of different comparisons.

[0027] In one embodiment, the logical operation of the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit includes: performing an OR operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result corresponding to the i-th bit; wherein, if the values ​​corresponding to all bits in the logical operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result corresponding to the i-th bit is non-0 or non-1, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit; the logical operation result of the OR operation is non-0 and non-1, indicating that there is a comparison number elimination.

[0028] In the embodiment of the present application, if there is 1 in the principle of OR operation, the result is 1, and 1 is the largest number. Therefore, when performing minimum value comparison, it can be determined that the comparison number corresponding to 1 is eliminated. If the logical operation results are all 1, it means that the values ​​of all comparison numbers on this bit are 1 at this time, and all comparison numbers involved in the comparison should not be eliminated, but should be regarded as the same and retained. Therefore, when the logical operation result is 1, it should be regarded as the same value on all comparison bits, and the mask used by the current bit continues to be used. When the logical operation result is non-0 or non-1, the logical operation result includes the comparison number eliminated by the previous bit and the data eliminated by the current bit. Therefore, the logical operation result can be used as the mask of the next bit. In this way, when using OR operation for comparison, the comparison result can be accurately determined, and the situation of comparison errors can be effectively reduced.

[0029] In a second aspect, an embodiment of the present application provides a multi-input comparison device, including: an acquisition module for acquiring multiple comparison numbers for comparison; a data generation module for generating an initial mask with a bit width consistent with the number of comparison numbers; each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value indicates that the comparison number corresponding to the bit participates in the comparison; the data generation module is also used to form a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number; i takes m to 0 in sequence, and m is the highest bit number of the comparison number; the comparison module is used to convert the vertical code corresponding to the i-th bit into a vertical code corresponding to the i-th bit. The mask of the i-th bit is updated to obtain the mask of the i-1th bit; wherein the initial mask is the mask corresponding to the m-th bit; wherein the value of the target bit in the mask of the i-1th bit is the second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison; the output module is also used to repeat the above comparison process until all bits are compared, and output the mask of the -1th bit; or, repeat the above comparison process until only one bit in the mask of the i-1th bit is the first value, and output the mask of the i-1th bit.

[0030] In a third aspect, an embodiment of the present application provides a processor, comprising: a processing unit and a storage unit, wherein the storage unit stores a program, and the processing unit is used to execute the program to perform the multi-input comparison method as described in any one of the first aspects.

[0031] In a fourth aspect, an embodiment of the present application provides a multi-input comparison circuit, including: a register unit, used to receive and store multiple comparison numbers for comparison; a value-taking circuit, connected to the register unit, and used to form a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number; the i is m to 0 in sequence, and m is the number of the highest bit of the comparison number; a mask generation circuit, connected to the register unit, and generates an initial mask with a bit width consistent with the number of comparison numbers; each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value indicates that the comparison number corresponding to the bit participates in the comparison; the comparison unit, respectively connected to the value-taking circuit and the mask generation circuit unit connection; the comparing unit is used to update the mask of the i-th bit according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit; wherein the initial mask is the mask corresponding to the m-th bit; wherein the value of the target bit in the mask of the i-1-th bit is the second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison; repeat the above comparison process until all bits are compared, and output the mask of the -1-th bit; or, repeat the above comparison process until only one bit in the mask of the i-1-th bit is the first value, and output the mask of the i-1-th bit. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0033] Figure 1 A flowchart of a multi-input comparison method provided in one embodiment of the present application;

[0034] Figure 2 A schematic diagram of vertical numerical value selection provided in an embodiment of the present application;

[0035] Figure 3 A schematic diagram of a signed number provided in an embodiment of the present application;

[0036] Figure 4 A first comparative schematic diagram provided for an embodiment of the present application;

[0037] Figure 5 A second comparative schematic diagram provided for an embodiment of the present application;

[0038] Figure 6 A schematic diagram of performing minimum value comparison with operation provided in an embodiment of the present application;

[0039] Figure 7 A schematic diagram of performing minimum value comparison using an OR operation provided in an embodiment of the present application;

[0040] Figure 8 A schematic diagram of a multi-input comparison device provided in an embodiment of the present application;

[0041] Fig. 9 A structural block diagram of a multi-input comparison circuit provided in one embodiment of the present application.

[0042] Icon: multi-input comparison device 200; acquisition module 210; data generation module 220; comparison module 230; output module 240; multi-input comparison circuit 400; storage unit 410; value circuit 420; mask generation circuit 430; comparison unit 440; pre-processing unit 450. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0044] First, the present application provides a multi-input comparison method. The multi-input comparison method provided in the present application can be applied to a processing unit or other units that perform data comparison, and the processing unit can be a central processing unit, a graphics processing unit, etc., which is not limited here.

[0045] In the embodiment of the present application, the multi-input comparison method can be implemented as a software program and run in the processing unit, see Figure 1 , Figure 1 A flowchart of a multi-input comparison method provided in one embodiment of the present application. The multi-input comparison method includes:

[0046] S110, obtaining a plurality of comparison numbers for comparison.

[0047] In this embodiment, the comparison number is the data to be compared, and the comparison number can be a binary number, a decimal number, a hexadecimal number, etc., and the type of the comparison number can be an unsigned number, a signed number, and a floating point number, which is not limited here.

[0048] In this embodiment, the comparison type performed may be maximum value comparison or minimum value comparison.

[0049] Typically, the bit widths of the comparison numbers are consistent. However, in some scenarios, comparison numbers with inconsistent bit widths need to be compared. In an embodiment of the present application, when the comparison numbers with inconsistent bit widths are compared, the comparison numbers can be aligned. S110 may include: receiving multiple comparison numbers; if any different comparison numbers among the received multiple comparison numbers have different bit widths, expanding the bit width of the comparison number with a smaller bit width to be consistent with the bit width of the comparison number with the largest bit width.

[0050] In this embodiment, the comparison number with a smaller bit width is expanded by shifting the comparison number to the right and adding 0 to the high bit. For example, a comparison number is 1110, and its bit width is 4 bits, while the comparison number with the maximum bit width is 8 bits, then the comparison number can be expanded, and the comparison number after expansion is 00001110. By expanding the comparison number with a smaller bit width, each comparison number is made consistent, so that the multi-input comparison method provided by the present application can be performed correctly.

[0051] S120, generating an initial mask whose bit width is consistent with the number of comparison numbers.

[0052] In this embodiment, each bit of the initial mask corresponds to a comparison number. For example, if there are 8 comparison numbers to be compared, the initial mask is a number with 8 bits.

[0053] By making each comparison number correspond to a bit of the mask, the mask can be used to record whether each comparison number participates in the comparison. For example, the mask has a first value and a second value, the first value indicates that the comparison number corresponding to the bit participates in the comparison, and the second value indicates that the comparison number corresponding to the bit does not participate in the comparison. Before the comparison starts, the initial mask can be used to represent the comparison number participating in the comparison. At this time, each bit of the initial mask is a preset first value. In the subsequent comparison process, if there is a comparison number that is eliminated, the value of the mask bit corresponding to the comparison number is modified to the second value, so as to achieve the recording in the comparison process. Exemplarily, the initial mask can be 11111111. In a round of comparison, when the factor values ​​of the first comparison number and the second comparison number are larger than other comparison numbers and are retained, the corresponding mask can be 11000000.

[0054] In the embodiment of the present application, since the mask only needs to record whether the comparison number is eliminated, the bit only needs two states, namely the first value and the second value. Therefore, in the embodiment of the present application, the mask can be a binary value, for example, the first value can be 0 or 1, and the space occupied by the mask and the power consumption of mask-related calculations are reduced by using binary values. In other embodiments, the mask can also be a number in a different base, such as binary, decimal, hexadecimal, etc.

[0055] S130, constructing a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number.

[0056] As mentioned above, the bit widths of all comparison numbers are consistent or padded to be consistent, so the number of bits of each comparison number is the same. In an embodiment of the present application, m can be used to represent the number of bits of the comparison number, the mth bit represents the highest bit, and the 0th bit represents the lowest bit. And, i is any integer between 0 and m, used to characterize the selected bit.

[0057] In the embodiment of the present application, the comparison of each comparison number is to compare the values ​​of each comparison number at the same bit position. Taking a decimal number as an example, the comparison numbers are: 3000, 2000, 1500, respectively. At this time, the first comparison is the number on the thousands place, that is, 3, 2 and 1. Similarly, taking a binary number as an example, the comparison numbers are 1111, 0101, 1010, respectively. At this time, the values ​​on the highest bit position are compared first, that is, 1, 0 and 1, and then the values ​​of the second highest bit position are compared, that is, 1, 1 and 0. Therefore, in the embodiment of the present application, the value of the same bit position of each comparison number can be taken to form a corresponding vertical code, so as to characterize the value size of each comparison number at the bit position through the vertical code.

[0058] See also Figure 2 , Figure 2 A schematic diagram of vertical numerical value selection provided in an embodiment of the present application. Figure 2 For example, there are four comparison numbers, which are numbered from 1 to 4. For the four comparison numbers, the values ​​at the highest bit are 1, 1, 0 and 1 respectively, and the vertical code 1101 can be formed. Similarly, the vertical code corresponding to the second highest bit is 1110, the vertical code of the first bit is 1011, and the vertical code of the lowest bit (the 0th bit) is 1110. The above are only examples. In actual comparison, there may be more or fewer comparison numbers, and the bit width of each comparison number may be larger or smaller. The above are only examples and should not be a limitation to the present application.

[0059] As mentioned above, the data type of comparison number is not limited to signed number, unsigned number and floating point number. Different from unsigned number, signed number and floating point number have signs. When comparing, the sign will affect the comparison result.

[0060] Therefore, in an embodiment of the present application, before determining the vertical code, the data type of the received comparison number can also be obtained; based on a first conversion relationship between a preset data type and a data format, all comparison numbers are converted to a data format that matches the data type.

[0061] Each comparison number is converted through the first conversion relationship, so that each comparison number can be converted into a data format matching the data type so as to participate in the comparison.

[0062] Correspondingly, the vertical code corresponding to the i-th bit is formed according to the value of the i-th bit of each comparison number, or the vertical code corresponding to the i-th bit is formed according to the value of the i-th bit of each comparison number matching the data format and data type.

[0063] In the process of data processing, the data type of each comparison number is known. Therefore, after obtaining the comparison number, the data type of each comparison number can be obtained, which will not be expanded here.

[0064] In this embodiment, the first conversion relationship includes at least one of a conversion relationship between data formats of unsigned numbers, a conversion relationship between data formats of signed numbers, and a conversion relationship between data formats of floating-point numbers.

[0065] For unsigned numbers, due to the influence of the unsigned number, each comparison number can retain the original data form, that is, unchanged. For example, if the original comparison number is 1111, the conversion does not adjust it (or does not convert it), and the comparison number is still 1111.

[0066] If each comparison number is a signed number, the first bit of the signed number represents the sign. In binary signed numbers, the sign bit is also represented by 0 and 1, 1 represents a negative number, and 0 represents a positive number. When using the above method for comparison, since 0 is less than 1, the negative number will be smaller than the positive number, which is not in line with reality. Therefore, when using the above method for comparison, an extension bit can be added, and 1 is used in the extension bit to represent a positive number and 0 to represent a negative number, so that the comparison can be in line with reality.

[0067] The highest bit of the comparison number is also the sign bit. In an optional implementation, the sign bit can be directly replaced by the extended bit, that is, 1 is used to represent a positive number and 0 is used to represent a negative number on the original sign bit. Figure 2 For example, the original serial numbers 1-4 are 1111, 1101, 0111 and 1010 respectively. The first bit of the first, second and fourth numbers is 1, that is, the sign bit is 1, which indicates that the first, second and fourth numbers are negative numbers. Therefore, the sign bit can be replaced. After replacement, the first number is 0111, the second number is 0 101, and the fourth number is 0 010. On the contrary, the third number is a positive number. Therefore, the third number can be replaced to 1 111. In addition, the replacement operation can also be implemented using the negation operation.

[0068] In some other embodiments, an extension bit may be added before the sign bit, and in the extension bit, 1 represents a positive number and 0 represents a negative number. Figure 3 For example, Figure 3In the example, the comparison numbers of sequence numbers 1 to 4 are 1 111, 1 101, 0 111 and 1010 respectively. The first bit of each number is the sign bit. 1 on the sign bit indicates a negative number, and 0 indicates a positive number. The first bit of the numbers 1, 2 and 4 is 1, indicating that the three numbers are negative numbers. On the contrary, the first bit of the number 3 is 0, so the number 3 is a positive number. After adding extension bits to each comparison number, the comparison number of sequence number 1 is converted to 0 1111. Similarly, the comparison number of sequence number 2 is converted to 0 1101. The comparison number of sequence number 3 is a positive number, and a negative number can be converted to 1 0111. The comparison number of sequence number 4 is converted to 0 1010, where the first bit indicates the sign bit.

[0069] In the above manner, when comparing the vertical codes, the positive value 1 on the extended bit is always greater than the negative value 0, which is in line with reality.

[0070] As for floating-point numbers, floating-point numbers include a sign, an exponent and a mantissa. In a binary floating-point number, the sign is 0 for a positive number and 1 for a negative number. The exponent is on the left side of the mantissa, so the weight of the exponent is naturally greater than the weight of the mantissa. If the comparison order is from left to right, it is consistent with the order of the positive number comparison from high to low. Therefore, in an embodiment of the present application, if each comparison number is a floating-point number and the data format is not binary, each comparison number is converted to a binary floating-point number, and then the comparison of the present application is performed with a binary floating-point number. Similarly, since a floating-point number uses 0 to represent a positive number and 1 to represent a negative number, when a floating-point number is compared, the sign bit of the floating-point number can be replaced or an extension bit can be added, and 1 can be used to represent a positive number and 0 can be used to represent a negative number. At the same time, for a negative floating-point number, its exponent and mantissa also need to be negated; the positive floating-point number exponent and mantissa remain unchanged.

[0071] The data types of the comparison numbers for comparison are usually consistent, but in some scenarios, different types of data need to be compared. Therefore, in the embodiments of the present application, if the comparison numbers include numbers of different data types, each comparison number can be converted to a number of the same data type after obtaining the comparison number and then compared. For example, if there are both signed numbers and unsigned numbers, all comparison numbers can be converted to the data form corresponding to the unsigned number. Similarly, if there are signed numbers, unsigned numbers, and floating-point numbers, all comparison numbers can be converted to the data form corresponding to the floating-point number.

[0072] S140, updating the mask of the i-th bit according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit.

[0073] S150, repeat the above comparison process until all bits are compared, and output the mask of the -1th bit.

[0074] Or, S160, repeat the above comparison process until only one bit in the mask of the i-1th bit is the first value, and output the mask of the i-1th bit.

[0075] The comparison process refers to S140. In this embodiment, i takes m to 0 in sequence, that is, the high bit is taken first, and then the low bit is taken, and the vertical code is used to compare from the high bit, and then the second high bit to the lowest bit is compared in sequence. For S150, in this embodiment, the completion of the comparison of the last bit represents the completion of the comparison of all comparison numbers. At this time, if only one bit is the first value, the comparison number corresponding to the bit wins. If there are still multiple bits that are the first value in the comparison until the last bit, the comparison numbers of all bits that are the first value are the same, and they are all winners. For S160, if the winner can be determined in the middle comparison process, the comparison can be ended and the subsequent comparison process can be omitted.

[0076] In this embodiment, each bit of the mask is used to record whether each comparison number participates in the comparison corresponding to the current bit. Therefore, after the comparison of each bit is completed, the mask should be updated to obtain the mask of the next bit. That is, after the comparison of the i-th bit is completed, the mask of the i-th bit is updated according to the vertical code of the i-th bit representing the comparison result of the i-th bit to obtain the mask of the i-1-th bit.

[0077] Among them, in the embodiment of the present application, the mask of the mth bit (i.e., the highest bit) is the initial mask. At this time, all comparison numbers are compared for the first round, and all comparison numbers should participate in the comparison. Therefore, the values ​​corresponding to all comparison numbers in the mask should be the first value.

[0078] In this embodiment, in the i-th round of comparison, if there is a comparison number that is eliminated, the value corresponding to the comparison number in the mask is modified to the second value. If the comparison number wins, there is no need to modify the value corresponding to the comparison number in the mask, thereby obtaining the mask of the i-1th bit. Accordingly, the value of the target bit in the mask of the i-1th bit is the second value, and the target bit is the bit of the comparison number that needs to be eliminated determined according to the vertical code corresponding to the i-th bit.

[0079] In one embodiment of the present application, S140 may include: performing a logical operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result; if the logical operation result of the i-th bit indicates that the values ​​of the i-th bits of all comparison numbers are the same, then updating the mask of the i-th bit to the mask of the i-1-th bit; if the logical operation result of the i-th bit indicates that there is an elimination of comparison numbers in this round of comparison, then updating the logical operation result of the i-th bit to the mask of the i-1-th bit.

[0080] In this embodiment, the mask and the vertical code can be subjected to a logical operation method to obtain a logical operation result, so as to update the mask according to the logical operation result. For example, in some embodiments of the present application, the logical operation can be an AND operation, the first value is 1, and the second value is 0. For the AND operation, the principle of the AND operation is: if the two numbers involved in the operation are 1, the result is 1, and if the two numbers involved in the operation have 0, the output result is 0. Exemplarily, if the highest bits of the first comparison number and the second comparison number are 1 and 0 respectively, the corresponding vertical value is 10. At this time, it can be known that the first comparison number is larger, and the vertical value of the highest bit of the two is 10. If the initial mask is 11, 10 and 11 are subjected to an AND operation to obtain a logical operation result of 10. At this time, in the maximum value comparison, the value corresponding to the second number in the logical operation result is 0, indicating that the second number is eliminated. It can be seen that in the embodiment of the present application, a logical operation can be used to update the mask to record whether there is a comparison number that is eliminated.

[0081] In an embodiment of the AND operation of the present application, S140 may include: performing an AND operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result corresponding to the i-th bit; wherein, if the values ​​corresponding to all bits in the logical operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result corresponding to the i-th bit is non-0 or non-1, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit; the logical operation result of the AND operation is non-0 or non-1, indicating that there is a comparison number elimination.

[0082] Figure 4 A first comparative schematic diagram is provided for an embodiment of the present application. Figure 4For example, the AND operation uses 1 as the first value, indicating that it participates in the comparison; 0 is the second value, indicating that it does not participate in the comparison; the initial mask is 1111, and all comparison numbers participate in the comparison. The four comparison numbers are 1111, 1101, 0111, and 1010. First, for the vertical code of the highest bit is 1101, the vertical code of the highest bit is ANDed with the initial mask 1111, and the logical operation result corresponding to the highest bit is 1101. At this time, in the maximum value comparison, the value corresponding to the third number in the mask is 0, indicating that the third comparison number is eliminated, and the remaining numbers continue to participate in the comparison. Therefore, the logical operation result can be directly used as the mask of the second highest bit. When comparing the second highest bit, the vertical code is 1110, the mask is 1101, and the AND operation result is 1100, then the fourth number is also eliminated, and the mask of the second lowest bit is the logical operation result of the second highest bit 1100. The vertical code of the lowest bit is 1011, and the mask is 1100. The logical operation result of the two is 1000. 1000 is used as the mask of the lowest bit, and is ANDed with the mask of the lowest bit 1110, and the logical operation result 1000 is output. The logical operation result 1000 can indicate that the maximum comparison number is the comparison number with sequence number 1.

[0083] See also Figure 5 , Figure 5 A first comparative schematic diagram is provided for an embodiment of the present application. Figure 5 For example, the four comparison numbers are 1011, 1001, 1010 and 1010 respectively. It can be seen that the highest bits of the four comparison numbers are all 1, and the second highest bits are all 0, that is, the values ​​of all comparison numbers at the highest and second highest bits are the same. At this time, the logical operation result of the highest bit is 1111, and the logical operation result of the second highest bit is 0000. In this case, the second highest bit uses the initial mask 1111 of the highest bit, and the second lowest bit uses the mask of the second highest bit, that is, the mask of the second lowest bit is 1111, and subsequent comparisons are performed until the final logical operation result of 1000 is determined, indicating that the number with sequence number 1 is the largest.

[0084] In the embodiments of the present application, the comparison types may include maximum value comparison and minimum value comparison. The maximum value comparison is to determine the maximum value from a plurality of comparison numbers, and the minimum value comparison is to determine the minimum value from a plurality of comparison numbers. The above-mentioned AND operation method is suitable for maximum value comparison. When a minimum value comparison is required, the comparison number needs to be adjusted.

[0085] Therefore, in one embodiment of the present application, before obtaining multiple comparison numbers for comparison, it can also include: obtaining a comparison type; converting the sum of each comparison number into a data form corresponding to the comparison type according to a second conversion relationship between a preset comparison type and a data form; wherein the second conversion relationship includes: if the comparison type is a maximum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a minimum value comparison, inverting the value of each bit of the comparison number.

[0086] The comparison type is maximum value comparison or minimum value comparison, which can be directly determined before the comparison and will not be expanded here. After the comparison type is determined, the comparison number can be directly converted into a form that can be correctly calculated by the AND operation according to the preset second conversion relationship.

[0087] As mentioned above, if the comparison number is not adjusted, the AND operation can be directly used for maximum value comparison, while for minimum value comparison, it is a completely opposite process to the maximum value comparison. Therefore, in the embodiments of the present application, if the AND operation is used for minimum value comparison, each comparison number must also be inverted.

[0088] See also Figure 6 , Figure 6 Schematic diagram of the minimum value comparison provided by the embodiment of the present application. The input numbers are 1011, 1001, 1010 and 1110, and after inversion they are 0100, 0110, 0101 and 0001 respectively. Executing the same process as above may include: first, performing an AND operation on the highest vertical code and mask to obtain a result of 0000; if all are 0, the mask 1111 of the bit is used as the mask of the next bit, then the mask of the second highest bit is 1111, and an AND operation is performed with the second highest vertical code 1110 to obtain 1110; using 1110 as the mask of the second lowest bit, and performing an AND operation with the second lowest vertical code 0100 to obtain a result of 0100; using 0100 as the mask of the lowest bit, and performing an AND operation with the lowest vertical code 0011 to obtain a result of 0000; if all are 0, the mask 0100 of the current bit is used and output, and the comparison number corresponding to the second lowest bit is the minimum value.

[0089] For floating-point numbers, the comparison method is the same as that for unsigned numbers and will not be explained here.

[0090] For signed numbers, when using AND operations to find the maximum value, if there is a positive number among the comparison numbers, the comparison can be performed in the above manner. However, when all comparison numbers are negative, if the original binary code is used for comparison, comparison errors may occur. For example, for negative comparison numbers -15, -13, -7, and -10, the original binary codes are 01111, 0 1101, 0 0111, and 0 1010, respectively. Among them, if compared in the above manner, 0 1111 corresponding to -15 is the largest, and 0 0111 corresponding to -7 is the smallest. In fact, the values ​​of -15 and -7 are the smallest, so the comparison result is different from the actual value.

[0091] Therefore, in the embodiment of the present application, when all comparison numbers are negative numbers, all comparison numbers can be converted into their corresponding complements to be compared by complements. For example, for negative comparison numbers -15, -13, -7 and -10, the conversion into binary complements is 1 0001, 1 0011, 1 1001 and 1 0110 respectively. By comparing the complements in the above manner, it can be obtained that 1 0001 corresponding to -15 is the smallest and 1 1001 corresponding to -7 is the largest, which is consistent with the actual situation.

[0092] In addition, since signed negative numbers are stored in computers in the form of two's complement codes, using two's complement codes to compare negative numbers can also reduce unnecessary conversion processes and improve comparison efficiency.

[0093] If the signed comparison number includes both positive and negative numbers, the original code of the positive number and the complement code of the negative number can be compared, wherein the sign bit of the complement code of the negative number needs to be inverted. For example, taking +15, -15, -7 and +7 as examples, the original code of +15 is 01111, and the original code of +7 is 0 0111. When compared with a negative number, the sign bit becomes 1, then +15 corresponds to 1 1111, and +7 corresponds to 10111. The complement of -15 is 1 0001. It can be seen that the sign bit of a negative number in the complement code is 1, so the sign bit needs to be inverted. After the sign bit of -15 is inverted, it is 0 0001. The complement of -7 is 1 1001. After the sign bit is inverted, it is 0 1001. After comparison, the +15 corresponding to 1 1111 is the largest, followed by +7 corresponding to 1 0111 and -7 corresponding to 0 1001. The -15 corresponding to 00001 is the smallest.

[0094] In another embodiment, if the signed comparison number includes both positive and negative numbers, when comparing the original code of the positive number and the complement of the negative number, it is also possible to extend one bit on the left side based on the original code of the positive number and the complement of the negative number, and at this bit, the positive number is 1 and the negative number is 0. For example, taking +15, -15, -7 and +7 as examples, the original code of +15 is 0 1111, the original code of +7 is 0 0111, the complement of -15 is 1 0001, and the complement of -7 is 1 1001. After expansion, +15 is 10 1111, +7 is 100111, -15 is 01 0001, and -7 is 01 1001. The expanded comparison numbers are compared in the above method, and the comparison results are the same as the actual ones, that is, +15 corresponding to 10 1111 is the largest, followed by 10 0111 of +7 and 01 1001 corresponding to -7, and -15 corresponding to 010001 is the smallest.

[0095] Correspondingly, the OR operation and the AND operation are mutually opposite operations. In the embodiment of the present application, the logical operation used may also be an OR operation. In the case of the OR operation, the first value, the second value and the initial mask need to be negated, that is, if the first value of the AND operation is 1, then the first value of the OR operation is 0, and if the second value of the AND operation is 0, then the second value of the OR operation is 1, and if the initial mask of the AND operation is all 1, then the initial mask of the OR operation is all 0.

[0096] Similarly, after obtaining multiple comparison numbers for comparison, the method also includes: obtaining a comparison type; converting the sum of each comparison number into a data form corresponding to the comparison type according to a third conversion relationship between a preset comparison type and a data form; wherein the third conversion relationship includes: if the comparison type is a minimum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a maximum value comparison, inverting the value of each bit of the comparison number.

[0097] And, performing a logical operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit may include: performing an OR operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result corresponding to the i-th bit; wherein, if the values ​​corresponding to all bits in the logical operation result are 0 or 1, then the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result corresponding to the i-th bit is non-0 or non-1, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit; the logical operation result of the OR operation is non-0 or non-1, indicating that there is a comparison number elimination.

[0098] The comparison of maximum and minimum values ​​is also opposite, that is, when performing an OR operation, if the comparison number is not negated, a minimum value comparison is performed, and if the comparison number is negated, a maximum value comparison is performed.

[0099] See also Figure 7 , Figure 7 A schematic diagram of the minimum value comparison of the OR operation provided in the embodiment of the present application. In this example, the four comparison numbers are 1111, 1101, 0111 and 1010, respectively. The vertical code 1101 of the highest bit and the mask 0000 are ORed to obtain the result 1101, and 1101 is used as the mask of the next bit. Therefore, the vertical code 1110 of the second highest bit and the mask 1101 are ORed to obtain 1111. If all are 1, the mask 1101 of the current bit is used, and the OR operation results of the subsequent two bits are both 1111. Therefore, the output mask is 1101, that is, the comparison number of the second lowest bit is the smallest.

[0100] It can be understood that the OR operation and the AND operation are opposite operations to each other, and the comparison principles are similar. For details, please refer to the aforementioned AND operation part, which will not be elaborated here.

[0101] Furthermore, in some embodiments of the present application, in addition to inverting the comparison number, the vertical code may also be inverted, and the effects achieved by the two are the same.

[0102] In this embodiment, there are two ways to determine the completion. One is that after all bits are compared, the comparison result can be output normally, that is, S150.

[0103] Another case may be that the comparison result has been determined by the bits before the lowest bit, for example, Figure 4 For example, in the third round of comparison of the second lowest bit, only the highest bit corresponding to the value in the mask is 1, and there is no need to compare the lowest bit, and the comparison result 1000 can be directly output. Therefore, in the embodiment of the present application, the output method can also be to execute S160.

[0104] Based on the same inventive concept, the present application also provides a multi-input comparison device. Figure 8 , Figure 8 A schematic diagram of a multi-input comparison device provided in one embodiment of the present application. In the embodiment of the present application, the multi-input comparison device is a software program. The multi-input comparison device 200 includes: an acquisition module 210, a data generation module 220, a comparison module 230 and an output module 240, wherein each module is a software program module.

[0105] The acquisition module 210 is used to acquire a plurality of comparison numbers for comparison.

[0106] The data generation module 220 is used to generate an initial mask whose bit width is consistent with the number of comparison numbers; each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value indicates that the comparison number corresponding to the bit participates in the comparison.

[0107] The data generation module 220 is further used to construct a vertical code corresponding to the ith bit according to the value of the ith bit of each comparison number; i ranges from m to 0 in sequence, and m is the highest bit number of the comparison number.

[0108] The comparison module 230 is used to update the mask of the i-th bit according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit; wherein the initial mask is the mask corresponding to the m-th bit; wherein the value of the target bit in the mask of the i-1-th bit is the second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison.

[0109] The comparison module 230 is also used to repeat the above comparison process until all bits are compared, and the output module 240 outputs the mask of the -1th bit; or, the comparison module 230 repeats the above comparison process until only one bit in the mask of the i-1th bit is the first value, and the output module 240 outputs the mask of the i-1th bit.

[0110] The acquisition module 210 is specifically used to: receive a plurality of the comparison numbers; if any of the received plurality of comparison numbers have different bit widths, expand the bit width of the comparison number with the smaller bit width to be consistent with the bit width of the comparison number with the largest bit width.

[0111] The acquisition module 210 is further used to acquire the data type of the received comparison number; based on a first conversion relationship between a preset data type and a data format, all comparison numbers are converted into a data format that matches the data type. The data generation module is specifically used to form a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number that matches the data format and the data type.

[0112] The acquisition module 210 is specifically configured to, if each of the comparison numbers is a signed number, extend the sign bit before the highest bit of each of the comparison numbers, and supplement the sign bit of each of the comparison numbers with a value representing the sign of each of the comparison numbers.

[0113] The acquisition module 210 is specifically configured to convert each of the comparison numbers into a binary floating point number if each of the comparison numbers is a floating point number and the data format is not binary.

[0114] The comparison module 230 is also used to perform a logical operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result; if the logical operation result of the i-th bit indicates that the values ​​of the i-th bits of all comparison numbers are the same, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result of the i-th bit indicates that there is an elimination of comparison numbers in this round of comparison, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit.

[0115] In the logic operation and operation configured in the comparison module 230, the first value is 1 and the second value is 0.

[0116] The acquisition module 210 is also used to obtain a comparison type; wherein the comparison type includes a maximum value comparison and a minimum value comparison; according to a second conversion relationship between a preset comparison type and a data format, each of the comparison numbers and is converted into a data format corresponding to the comparison type; wherein the second conversion relationship includes: if the comparison type is a maximum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a minimum value comparison, inverting the value of each bit of the comparison number.

[0117] The comparison module 230 is specifically used to perform an AND operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result corresponding to the i-th bit; wherein, if the values ​​corresponding to all bits in the logical operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result corresponding to the i-th bit is non-0 or non-1, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit; the logical operation result of the OR operation is non-0 and non-1, indicating that there is a comparison number elimination.

[0118] The logic operation configured in the comparison module 230 may also be an OR operation, where the first value is 0 and the second value is 1.

[0119] Based on the same inventive concept, the embodiment of the present application further provides a processor, which includes: a processing unit and a storage unit, wherein the processing unit is connected to the storage unit; the storage unit stores a program, and when the program runs on the processing unit, the multi-input comparison method provided in any of the above embodiments is executed.

[0120] In the embodiments of the present application, the processor may be a GPU (Graphics Processing Unit), a CPU (Central Processing Unit), a data processing core of AI (Artificial Intelligence), etc., or a processor chip applied to some large-scale data computing scenarios. The above is only an example and should not be a limitation to the present application.

[0121] Based on the same inventive concept, an embodiment of the present application further provides an electronic device, which may include the processor provided by the aforementioned embodiment.

[0122] Based on the same inventive concept, an embodiment of the present application further provides a readable storage medium on which a program is stored. When the program runs on a processing unit, the processing unit executes the multi-input comparison method provided in the above embodiment.

[0123] The readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more available media. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a tape), an optical medium (such as a DVD), or a semiconductor medium (such as an SSD (Solid State Disk)).

[0124] In the embodiments of the present application, the multi-input comparison method can be implemented as a software program in a processing unit, or can be implemented using a hardware circuit. Therefore, based on the same inventive concept, the embodiments of the present application also provide a multi-input comparison circuit to implement the functions of the multi-input comparison method.

[0125] See also Fig. 9 , Fig. 9 This is a structural block diagram of a multi-input comparison circuit provided in an embodiment of the present application. The multi-input comparison circuit 400 includes: a register unit 410, a value circuit 420, a mask generation circuit 430 and a comparison unit 440.

[0126] The register unit 410 includes at least one register, and an input end of the register unit is used to receive and store a plurality of comparison numbers to be compared.

[0127] The value circuit 420 is connected to the register unit. It is used to form a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number. i is m to 0 in sequence, and m is the highest bit of the comparison number;

[0128] The mask generation circuit 430 is connected to the register unit to generate an initial mask whose bit width is consistent with the number of comparison numbers; each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value indicates that the comparison number corresponding to the bit participates in the comparison.

[0129] The comparison unit 440 is connected to the value obtaining circuit and the mask generating circuit unit respectively.

[0130] In this embodiment, the comparison unit is composed of one or more logic gates, and the logic calculation unit can be a combination of logic gates for AND operation, OR operation or other similar functions. If it is a single-function logic gate, the number of logic gates is at least equal to the bit width of the comparison number.

[0131] A comparison unit 440 is used to update the mask of the i-th bit according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit; wherein the initial mask is the mask corresponding to the m-th bit; wherein the value of the target bit in the mask of the i-1-th bit is a second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison; the above comparison process is repeated until all bits are compared, and the mask of the -1-th bit is output; or, the above comparison process is repeated until only one bit in the mask of the i-1-th bit is the first value, and the mask of the i-1-th bit is output.

[0132] The multi-input comparison circuit 400 may further include a preprocessing unit 450, which may be used to: if any of the received multiple comparison numbers have different bit widths, expand the bit width of the comparison number with the smaller bit width to be consistent with the bit width of the comparison number with the largest bit width.

[0133] The preprocessing unit 450 can also be used to: obtain the data type of the received comparison number; based on the first conversion relationship between the preset data type and the data format, convert all comparison numbers to a data format that matches the data type. The value circuit 420 can specifically form a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number that matches the data format and the data type.

[0134] The data type includes a signed number, and the preprocessing unit 450 can also be used to: if each of the comparison numbers is a signed number, extend the sign bit before the highest bit of each of the comparison numbers, and supplement the sign bit of each comparison number with a value representing the sign of each comparison number.

[0135] The data type includes a floating point number, and the preprocessing unit 450 is specifically configured to convert each comparison number into a binary floating point number if each comparison number is a floating point number and the data format is not binary.

[0136] Among them, the comparison unit 440 can be specifically used to perform a logical operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result; if the logical operation result of the i-th bit indicates that the values ​​of the i-th bit of all comparison numbers are the same, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result of the i-th bit indicates that there is an elimination of the comparison number in this round of comparison, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit.

[0137] If the logic operation is an AND operation, the first value is 1 and the second value is 0.

[0138] In one embodiment, the preprocessing unit 450 can also be used to obtain a comparison type; wherein the comparison type includes a maximum value comparison and a minimum value comparison; according to a second conversion relationship between a preset comparison type and a data format, each comparison number is converted into a data format corresponding to the comparison type; wherein the second conversion relationship includes: if the comparison type is a maximum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a minimum value comparison, inverting the value of each bit of the comparison number.

[0139] In one embodiment, the comparison unit 440 can be specifically used to perform an AND operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result corresponding to the i-th bit; wherein, if the values ​​corresponding to all bits in the logical operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result corresponding to the i-th bit is non-0 or non-1, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit; the logical operation result of the AND operation is non-0 and non-1, indicating that there is a comparison number elimination.

[0140] In another embodiment, the logical operation is an OR operation, the first value is 0, and the second value is 1.

[0141] The preprocessing unit 450 can be specifically used to obtain a comparison type; wherein the comparison type includes a maximum value comparison and a minimum value comparison; according to a third conversion relationship between a preset comparison type and a data format, each comparison number and is converted into a data format corresponding to the comparison type; wherein the third conversion relationship includes: if the comparison type is a minimum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a maximum value comparison, inverting the value of each bit of the comparison number.

[0142] The comparison unit 440 can be specifically used to perform an OR operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logical operation result corresponding to the i-th bit; wherein, if the values ​​corresponding to all bits in the logical operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; if the logical operation result corresponding to the i-th bit is non-0 and non-1, the logical operation result of the i-th bit is updated to the mask of the i-1-th bit; the logical operation result of the OR operation is non-0 and non-1, indicating that there is a comparison number elimination.

[0143] The above-mentioned multi-input comparison circuit can be obtained by connecting existing devices and circuits, which will not be elaborated here.

[0144] The technical features of the above embodiments can be freely combined without conflict, and the embodiments obtained by the combination are included in the protection scope of this application.

[0145] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0146] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

Claims

1. A multi-input comparison method, characterized in that: include: Get the number of comparisons for multiple comparisons; Generate an initial mask with a bit width consistent with the number of comparison numbers; Each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value indicates that the comparison number corresponding to the bit participates in the comparison; The vertical code corresponding to the i-th bit is formed according to the value of the i-th bit of each comparison number; i is m to 0 in sequence, and m is the highest bit number of the comparison number; The mask of the i-th bit is updated according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit; wherein the initial mask is the mask corresponding to the m-th bit; wherein the value of the target bit in the mask of the i-1-th bit is a second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison; Repeat the above comparison process until all bits are compared and output the mask of the -1th bit; or repeat the above comparison process until only one bit in the mask of the i-1th bit is the first value and output the mask of the i-1th bit.

2. The method according to claim 1, characterized in that The obtaining of a plurality of comparison numbers for comparison comprises: receiving a plurality of said comparison numbers; If any comparison numbers among the received multiple comparison numbers have different bit widths, the bit width of the comparison number with the smaller bit width is expanded to be consistent with the bit width of the comparison number with the largest bit width.

3. The method according to claim 1, characterized in that Before forming the vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number, the method further includes: Get the data type of the received comparison number; Based on a first conversion relationship between a preset data type and a data format, convert all comparison numbers into a data format matching the data type; The forming the vertical code corresponding to the ith bit according to the value of the ith bit of each comparison number includes: forming the vertical code corresponding to the ith bit according to the value of the ith bit of each comparison number that matches the data format and the data type.

4. The method according to claim 3, characterized in that The data type includes a signed number, and the first conversion relationship between the preset data type and the data format is used to convert all comparison numbers into a data format matching the data type, including: If each of the comparison numbers is a signed number, an extension bit is configured on the highest bit of each of the comparison numbers, and a numerical value representing the sign of each comparison number is supplemented on the extension bit of each comparison number. In the extension bit, 1 represents a positive number and 0 represents a negative number.

5. The method according to claim 3, characterized in that: The data type includes a floating point number, and the converting of all comparison numbers into a data format matching the data type based on a first conversion relationship between a preset data type and a data format includes: If each of the comparison numbers is a floating point number and the data format is not binary, each of the comparison numbers is converted into a binary floating point number.

6. The method according to any one of claims 1 to 5, characterized in that: The step of updating the mask of the i-th bit according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit includes: Performing a logic operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logic operation result; If the result of the logic operation of the i-th bit indicates that the values ​​of the i-th bits of all comparison numbers are the same, then the mask of the i-th bit is updated to the mask of the i-1-th bit; If the logic operation result of the i-th bit indicates that the comparison number is eliminated in this round of comparison, the logic operation result of the i-th bit is updated to the mask of the i-1-th bit.

7. The method according to claim 6, characterized in that The logical operation is an AND operation, the first value is 1, and the second value is 0.

8. The multi-input comparison method according to claim 7, characterized in that: After obtaining a plurality of comparison numbers for comparison, the method further includes: Obtaining a comparison type; wherein the comparison type includes a maximum value comparison and a minimum value comparison; According to a second conversion relationship between a preset comparison type and a data format, each of the comparison numbers and is converted into a data format corresponding to the comparison type; wherein the second conversion relationship includes: if the comparison type is a maximum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a minimum value comparison, inverting the value of each bit of the comparison number.

9. The multi-input comparison method according to claim 7, characterized in that: The performing a logical operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit includes: Perform an AND operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logic operation result corresponding to the i-th bit; If the values ​​corresponding to all bits in the logic operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; If the logic operation result corresponding to the i-th bit is non-0 or non-1, the logic operation result of the i-th bit is updated to the mask of the i-1-th bit; the logic operation result of the AND operation is non-0 and non-1, indicating that there is a comparison number elimination.

10. The method according to claim 6, characterized in that The logical operation is an OR operation, the first value is 0, and the second value is 1.

11. The multi-input comparison method according to claim 10, characterized in that: After obtaining a plurality of comparison numbers for comparison, the method further includes: Obtaining a comparison type; wherein the comparison type includes a maximum value comparison and a minimum value comparison; According to a third conversion relationship between a preset comparison type and a data format, each of the comparison numbers and is converted into a data format corresponding to the comparison type; wherein the third conversion relationship includes: if the comparison type is a minimum value comparison, retaining the values ​​of all current bits of all comparison numbers; if the comparison type is a maximum value comparison, inverting the value of each bit of the comparison number.

12. The multi-input comparison method according to claim 7, characterized in that: The performing a logical operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit includes: Perform an OR operation on the vertical code corresponding to the i-th bit and the mask corresponding to the i-th bit to obtain a logic operation result corresponding to the i-th bit; If the values ​​corresponding to all bits in the logic operation result are 0 or 1, the mask of the i-th bit is updated to the mask of the i-1-th bit; If the logic operation result corresponding to the i-th bit is non-0 and non-1, the logic operation result of the i-th bit is updated to the mask of the i-1-th bit; the logic operation result of the OR operation is non-0 and non-1, indicating that there is a comparison number elimination.

13. A multi-input comparison device, characterized in that: include: An acquisition module, used for acquiring a plurality of comparison numbers for comparison; A data generation module, used for generating an initial mask with a bit width consistent with the number of comparison numbers; Each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value indicates that the comparison number corresponding to the bit participates in the comparison; The data generation module is further used to form a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number; i is m to 0 in sequence, and m is the highest bit number of the comparison number; A comparison module, used for updating the mask of the i-th bit according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit; wherein the initial mask is the mask corresponding to the m-th bit; wherein the value of the target bit in the mask of the i-1-th bit is a second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison; The comparison module is also used to repeat the above comparison process until all bits are compared, and the output module outputs the mask of the -1th bit; or, the comparison module repeats the above comparison process until only one bit in the mask of the i-1th bit is the first value, and the output module outputs the mask of the i-1th bit.

14. A processor, characterized in that: include: A processing unit and a storage unit, wherein the storage unit stores a program, and the processing unit is used to execute the program to execute the multi-input comparison method according to any one of claims 1 to 12.

15. A multi-input comparison circuit, characterized in that: include: A register unit, used for receiving and storing a plurality of comparison numbers for comparison; A value-taking circuit connected to the register unit, used for forming a vertical code corresponding to the i-th bit according to the value of the i-th bit of each comparison number; i is m to 0 in sequence, and m is the highest bit number of the comparison number; A mask generation circuit is connected to the register unit to generate an initial mask whose bit width is consistent with the number of comparison numbers; each bit of the initial mask corresponds to a comparison number, and each bit of the initial mask is a preset first value, and the first value indicates that the comparison number corresponding to the bit participates in the comparison; A comparison unit, connected to the value taking circuit and the mask generating circuit unit respectively; The comparison unit is used to update the mask of the i-th bit according to the vertical code corresponding to the i-th bit to obtain the mask of the i-1-th bit; wherein the initial mask is the mask corresponding to the m-th bit; wherein the value of the target bit in the mask of the i-1-th bit is the second value, and the target bit is the bit of the comparison number to be eliminated determined according to the vertical code corresponding to the i-th bit; the second value indicates that the comparison number corresponding to the bit does not participate in the comparison; repeat the above comparison process until all bits are compared, and output the mask of the -1-th bit; or, repeat the above comparison process until only one bit in the mask of the i-1-th bit is the first value, and output the mask of the i-1-th bit.