WO2017009596A1 - Comparison of wide data types - Google Patents
Comparison of wide data types Download PDFInfo
- Publication number
- WO2017009596A1 WO2017009596A1 PCT/GB2016/051506 GB2016051506W WO2017009596A1 WO 2017009596 A1 WO2017009596 A1 WO 2017009596A1 GB 2016051506 W GB2016051506 W GB 2016051506W WO 2017009596 A1 WO2017009596 A1 WO 2017009596A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- comparison
- value
- comparison operation
- sequence
- bits
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Ceased
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F7/00—Methods or arrangements for processing data by operating upon the order or content of the data handled
- G06F7/02—Comparing digital values
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30003—Arrangements for executing specific machine instructions
- G06F9/30007—Arrangements for executing specific machine instructions to perform operations on data operands
- G06F9/30018—Bit or string instructions
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30003—Arrangements for executing specific machine instructions
- G06F9/30007—Arrangements for executing specific machine instructions to perform operations on data operands
- G06F9/30021—Compare instructions, e.g. Greater-Than, Equal-To, MINMAX
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/30—Arrangements for executing machine instructions, e.g. instruction decode
- G06F9/30145—Instruction analysis, e.g. decoding, instruction word fields
- G06F9/30149—Instruction analysis, e.g. decoding, instruction word fields of variable length instructions
Definitions
- the present technique relates to the field of data processing.
- the present technique relates to the field of comparing wide data types.
- an instruction may be issued to perform a comparison between two data values.
- the instruction may indicate two locations of the values to be performed.
- the data processing apparatus may be limited in terms of the size of data values that it can store. For example, each register, which may be used to store a single value, may only be capable of storing a single 32-bit value. Accordingly, such a comparison instruction may normally only be capable of comparing two 32-bit values. If it is desired to perform a comparison on much wider numbers, i.e. numbers that require more than 32 bits to be represented, then this can be achieved by splitting each number up into multiple chunks and then performing a comparison on each chunk.
- each comparison can then be analysed in order to produce an end result.
- this process requires storage in order to store the individual results.
- the need for storage can be avoided by arranging each individual comparison in a branching structure. However, this can result in a much larger code sequence and due to branch prediction causing mispredictions, can result in code that takes longer to execute than if storage were used to store the individual results.
- processing circuitry to perform a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
- a method comprising the steps: performing a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
- an apparatus comprising: processing means for performing a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
- Figure 1 shows, schematically, the operation of the present technique in accordance with one embodiment
- Figure 2 shows how a number of comparison operations are chained together in order to provide the comparison of a wide data value in accordance with one embodiment
- Figure 3 is a table illustrating example values of a comparison function in accordance with one embodiment
- Figure 4 shows an example cumulative result in accordance with one embodiment
- Figure 5 illustrates an example descriptor in accordance with one embodiment
- Figure 6 gives an example of three different instructions being used in combination to perform a comparison of a wide data type
- Figure 7 illustrates a flow chart of a method for using the instructions illustrated in Figure 6 for performing a comparison of a wide data type
- Figure 8 is a diagram illustrating an example of early branching in accordance with one embodiment.
- Figure 9 illustrates a flow chart for performing a comparison of two wide floating point numbers.
- processing circuitry to perform a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
- a comparison of the first value and the second value is performed by performing a plurality of comparison operations, each of which operates on N bits of the first value and the corresponding N bits of the second value.
- Each of the comparison operations considers a different set of N bits.
- the comparison operations are chained. In other words, with the exception of the last comparison operation, each comparison operation provides an Accumulated Comparison Result (ACR), which is used by the next comparison operation in the sequence. The ACR thereby considers the result of the comparison up until the most recently executed comparison operation.
- ACR Accumulated Comparison Result
- the ACR of the comparison operation X represents the result of comparing the first XN bits of the first value and the first XN bits of the second value.
- the last comparison operation has no successor and so does not output an ACR. Instead, the final comparison operation provides a comparison result, which represents the result of comparing the first value and the second value.
- the processing circuitry is arranged, for at least each comparison operation after a first comparison operation in the sequence, to receive a descriptor for use as an input for that comparison operation; and the descriptor comprises the accumulated comparison result from a previous comparison operation in the sequence.
- the descriptor is used to pass intermediate data between successive comparison operations and thereby avoid the need to store large amounts of intermediate data for each of the comparison operations.
- the processing circuitry is responsive to a plurality of comparison instructions to perform the plurality of comparison operations, at least each comparison instruction other than a first comparison instruction identifying the descriptor in an input parameter.
- the instructions themselves may either contain the descriptor as a parameter or may contain a parameter that contains a reference to where the descriptor is located (in, for example, storage circuitry such as a register).
- the descriptor may be explicitly provided.
- the processing circuitry is responsive to a plurality of comparison instructions to perform the plurality of comparison operations, each of the plurality of comparison operations other than the final comparison operation providing the accumulated comparison result for use as the input by the next comparison operation in the sequence by updating the descriptor stored in the storage circuitry.
- the descriptor is implicitly provided, and the processing circuitry is able to locate the descriptor without being told explicitly where to find it.
- a special dedicated storage structure may be provided in which to store the descriptor.
- the plurality of comparison instructions includes a chained compare instruction; and the processing circuitry is responsive to the chained compare instruction to perform an associated comparison operation in the sequence, the associated comparison operation using as inputs the N bits of the first and second values to be operated on, and an input descriptor, and the processing circuitry is arranged to output, as a result of the associated comparison operation, the descriptor to be used as an input for a subsequent comparison operation.
- the chained compare instruction itself may be optional in certain circumstances.
- first value and the second value each comprise 2N bits, and each comparison operation operates on N bits
- first chained compare instruction specifies all the inputs of the associated comparison operation as input operands.
- the plurality of comparison instructions includes a final chained compare instruction; and the processing circuitry is responsive to the final chained compare instruction to perform the final comparison operation in the sequence, the final comparison operation using as inputs the N bits of the first and second values to be operated on, and an input descriptor, and the processing circuitry is arranged to output, as a result of the final comparison operation, a comparison result for a comparison of the first and second values.
- the final chained compare instruction is the final compare instruction in the sequence and produces the overall result of comparing the first value and the second value.
- the final chained compare instruction specifies all the inputs of the final comparison operation as input operands.
- the plurality of comparison instructions includes a first chained compare instruction; and the processing circuitry is responsive to the first chained compare instruction to perform the first comparison operation, the first comparison operation using as inputs the N bits of the first and second values to be operated on, and the processing circuitry is arranged to output, as a result of the first comparison operation, the descriptor to be used as an input for a subsequent comparison operation.
- a first chained compare instruction is optional and may instead be replaced by the chained compare instruction in which the descriptor that is provided has an ACR indicating that the comparison of the bits so far has been equal.
- the first chained compare instruction specifies all the inputs of the first comparison operation as input operands.
- a comparison function is provided as an input to the plurality of comparison operations, wherein the comparison function defines a type of comparison to be performed between the first value and the second value. The type of comparison may, for example, indicate that the comparison is to consider the first value and the second value as signed or unsigned numbers.
- the type of the comparison may indicate that the comparison is to determine whether the first value is greater than the second value, greater than or equal to the second value, equal to the second value, or not equal to the second value.
- the type of the comparison may also indicate that the comparison is to consider whether the first value is less than the second value or whether it is less than or equal to the second value.
- the comparison function may be provided to the plurality of comparison operations.
- the comparison function is provided as an input to the first comparison operation; and the descriptor provided for use as an input by each comparison operation other than the first comparison operation identifies the comparison function provided for use as an input to the first comparison operation.
- the comparison function is provided for use as an input by the final comparison operation in the sequence.
- the ACR may be determined by each comparison operation without knowledge of how the first value and the second value are to be compared to each other, which is defined by the comparison function.
- the ACR may therefore provide an indication of how the first value and the second value differ from each other and only when the final comparison operation is performed is the comparison function used to determine whether the difference between the first value and the second value falls within the scope of what is being asked by the comparison function itself.
- This process may be advantageous in that it can be used to reduce the size of the descriptor, since the comparison function need not be provided until the final comparison operation is to be performed. This may therefore reduce the storage requirements for storing the descriptor whilst other comparison instructions are executed.
- the first value and the second value are both integers.
- the first value and the second value are both floating point numbers. It may also be possible to compare other types and compare different types (e.g. an integer with a floating point number).
- the first value and the second value may have a size that is any number of bits
- the first value and the second value each have a length that is a multiple of N bits.
- the bits of the first value and the second value may thereby be exactly divided between the multiple comparison operations.
- one of the comparison operations (typically the first or last operation) may be extended in order to make up the shortfall in the number of bits. For example, if N is 32, then a 38-bit number may require two comparison operations. One of the operations could operate on 32 bits and the other operation could operate on the remaining 6 bits, extended to 32 bits.
- each comparison operation other than a first comparison operation in the sequence operates on more significant bits of the first and second values than the previous comparison operation.
- the comparison operations may therefore operate from the least significant bits to the most significant bits across successive comparison operations. Performing the comparison from the least significant bits to the most significant bits may be useful in the case where one of the comparison inputs is a multi-width addition result produced by a chain of add-with- carry instructions. In such a case, it is possible to feed the result of the addition into the comparison one step at a time, without storing the result anywhere.
- each comparison operation other than a first comparison operation in the sequence operates on less significant bits of the first and second values than the previous comparison operation.
- the comparison operations may therefore operate from the most significant bits to the least significant bits.
- the processing circuitry is responsive to the accumulated comparison result indicating a predetermined condition to perform an early branch operation that causes subsequent comparison operations in the sequence to be bypassed.
- the processing circuitry is responsive to the accumulated comparison result indicating a predetermined condition to perform an early branch operation that causes subsequent comparison operations in the sequence to be bypassed.
- the previously mentioned predetermined condition may be based on whether the accumulated comparison result indicates equality of bits compared by previous comparison operations. For example, whether or not the bits of the first value and the second value that have been compared so far are equal will determine whether or not the result of the comparison is known early and therefore whether or not subsequent comparison operations can be bypassed.
- Figure 1 illustrates an apparatus 100 for performing a comparison between two wide data types 105, 110.
- Each of these data types is 128 bits in length.
- the processing circuitry 115 is only capable of operating on 32-bit values. Consequently, in order to compare two 128-bit values, the apparatus 100 performs a sequence of comparison instructions, each of which causes an associated comparison operation to be performed by processing circuitry 115.
- Each instruction in the sequence of instructions 115 considers a different 32 bits of the 128-bit values.
- Figure 1 shows how each of the 128-bit values 105, 110 can be separated into four 32-bit values (1A, IB, 1C, ID) and (2A, 2B, 2C, 2D).
- Each of the comparison instructions then compares an associated pair of 32-bit values (1A with 2A, IB with 2B, 1C with 2C and ID with 2D).
- the processing circuitry 115 therefore takes two operands as inputs together with an optional Accumulated Comparison Result (ACR).
- ACR forms part of a descriptor which is output by a previous comparison operation.
- the format of the descriptor will be discussed later with reference to Figure 5.
- the descriptor is provided as part of the comparison instruction. This may either involve the descriptor being passed in as a parameter of the instruction, or may instead be achieved by providing a reference to a storage location in which the descriptor is stored. However, in other embodiments, control storage 120 may be provided. In these other embodiments, the descriptor is not passed in as part of the comparison instruction but is instead accessed from a known location (the control storage 120) by the processing circuitry 115 during the comparison operation.
- the embodiment shown in Figure 1 comprises four comparison instructions. These start with an Initial Comparison Instruction (ICMP32I), followed by two chained comparison instructions (ICMP32M), followed by a final comparison instruction (ICMP32F).
- the first comparison instruction receives a comparison function (cmpf) as an input parameter. This indicates a comparison type to be performed. The comparison type indicates the type of comparison to be performed between the two 128-bit values. Examples of possible values for the comparison type will be discussed with reference to Figure 3.
- the first comparison instruction also receives an output modifier (Ml) as an input parameter. The output modifier is used to affect the final comparison result output at the end of the chain of comparison operations. In particular, it controls whether the result is an integer 1 or all l 's vector if the comparison result is true. If the result is false, the output is all 0's vector.
- Each of the comparison instructions except the first comparison instruction receives a descriptor as one of the input parameters. The format of the descriptor will be discussed with reference to Figure 5.
- the output from the final comparison instruction is the final comparison result of comparing the two 128-bit values 105, 110.
- This final comparison result indicates the result of the comparison.
- the output is an all 0's vector (if the result of the comparison is false) or either an all l's vector or the integer 1 (if the result of the comparison is true), dependent on the value of the output modifier (Ml).
- Figure 2 illustrates an example of chaining a plurality of comparison operations in order to achieve the comparison of a first value and a second value, whereby the first value and the second value are wide data types.
- the comparison of the first value and the second value may be carried out by using an initial comparison instruction (ICMP32I) which causes processing circuitry 115 to perform a first or initial comparison operation on the first 32 bits of the first and second values and a final comparison operation on the last 32 bits of the first and second values.
- ICMP32I initial comparison instruction
- the result of the first comparison is a descriptor that is provided as an input to the second comparison instruction (ICMP32F).
- the output of the final comparison operation is the result of the comparison of the first value and second value.
- the chain may involve the inclusion of a chained comparison instruction (ICMP32M), which causes further comparison operations to be performed by the processing circuitry 115.
- ICMP32M chained comparison instruction
- chained comparison operations are termed "chained" comparison operations.
- Each of the chained comparison operations takes a descriptor provided by the previous comparison operation as an input.
- the result of the comparison operation results in an ACR being output, which forms part of the descriptor that is input to a subsequent comparison operation.
- the first and second values have a bit length that is a multiple of the number of bits that the processing circuitry 115 is able to compare at once. For example, in this case, the processing circuitry 115 is able to compare two sets of 32 bits at once.
- first and second values have a bit length that is a multiple of 32 bits.
- comparisons of other numbers of bits will be possible too. This may be achieved by extending the numbers to be compared. For example, if the first and second values are 100-bit values, an additional 28 bits may be provided such that the value is actually treated as a 128-bit value. For example, for a 100-bit unsigned value, 28 zeros may be added to the top bits in order to produce a 128-bit value for comparison.
- Figure 3 shows a table illustrating an example of different values for the comparison function (cmpf) in accordance with one embodiment. As previously described, the comparison value indicates the type of comparison that is to be performed between the first value and the second value.
- the comparison will be a signed greater than function.
- the function will be a signed greater than or equal to function.
- the value is 2
- the function will be an unsigned greater than function.
- the value is 3
- the function will be an unsigned greater than or equal to function.
- the value is 4
- the function will be for equality.
- the value is 5
- the function will be for non-equality.
- the values 6 and 7 are reserved, for future use for example. As an example, if the first value being compared is 5 and the second value being compared is 12, then if the comparison function is 1, then the result will be 0 or false, because 5 is not greater than or equal to 12.
- Figure 4 shows a table comprising example values for the ACR.
- the ACR indicates the result of comparing a subset of the bits of the first value and the second value.
- the ACR comprises the result of having compared all of the bits encountered so far.
- each comparison operation takes 32 bits from the first value and compares those to 32 bits of the second value
- the ACR in a third comparison operation will be the result of comparing the first 96 bits of the first value and 96 bits of the second value. If the value of the ACR is 1, then this means that the comparison so far indicates that the first value is less than the second value. If the value is 2 then this means that the comparison so far indicates that the first value is greater than the second value. If the value is 3 then this indicates that the comparison so far indicates that the first value and the second value are equal.
- the value 0 is reserved, for future use for example.
- Figure 5 illustrates an example of the descriptor in accordance with one embodiment. The descriptor may be passed between comparison operations in order to chain the comparison operations together.
- the output of one comparison operation may be provided as a parameter to a subsequent comparison operation.
- the descriptor is made up of 32 bits.
- the first 3 bits (0-2) comprise the comparison function (cmpf) as previously described with reference to Figure 3.
- the following 2 bits (3-4) comprise the ACR, as previously described with reference to Figure 4.
- the following bit (5) is used to store the output modifier (Ml). This controls whether the result output at the end of the sequence of chained comparison operations is an integer 1 or all l's vector if the comparison result is true. If the result is false, the output is an all 0's vector.
- the remaining bits (6-31) are reserved, for future use for example.
- Figure 6 shows an example illustrating the use of three comparison instructions, causing a chain of three comparison operations to compare a first value and a second value, and thereby output a comparison result.
- the process starts with a first comparison instruction (ICMP32I) 205.
- ICMP32I a first comparison instruction
- This receives a pair of operands (operand 0 and operand 1), each of 32 bits. In practice, these may refer to two 32-bit registers, where the first 32 bits of the first value and the second value, respectively, are stored.
- the instruction also comprises the comparison function (cmpf). As previously discussed with reference to Figure 3, this dictates how the first value and the second value are to be compared.
- the instruction comprises the output modifier (Ml), which dictates how the output is to be formatted.
- the first comparison instruction 205 results in a comparison operation being performed between operand 0 and operand 1.
- the result is an ACR, which together with the output modifier (Ml) and the comparison function (cmpf), make up a descriptor that is provided to a second comparison instruction (ICMP32M) 210.
- This second comparison instruction also takes a pair of operands (operand 0 and operand 1). Although these operands are also 32 bits each, they will be a different pair of operands than the pair of operands operated on by the first comparison instruction 205. Accordingly, the second comparison instruction 210 operates on a different set of bits to those of the first comparison instruction.
- the second comparison instruction 210 causes a second comparison operation to take place.
- the second comparison operation takes the pair of operands provided by the second comparison instruction 210.
- the second comparison operation also takes the comparison function (cmpf) and the ACR from the descriptor provided by the previous comparison operation.
- the result of performing the second comparison operation is an ACR, which together with the comparison function (cmpf) and the output modifier (Ml) from the input descriptor, make up a new descriptor.
- This new descriptor is provided to a final comparison instruction (ICMP32F) 215.
- the final comparison instruction 215 causes a final comparison operation to be performed.
- the instruction comprises a pair of operands, which are again different to the pair of operands provided by the first comparison instruction 205 or the second comparison instruction 210.
- the third comparison instruction 215 also takes as an input the descriptor that is output as a result of performing the second comparison instruction 210, which includes the output modifier (Ml).
- Ml the output modifier
- a comparison operation is performed on the pair of provided operands. The result of this is a comparison result, which is the overall result of comparing the first value with the second value (each of which is 96 bits in length).
- the first comparison instruction may be of the form illustrated by the second comparison instruction (ICMP32M) 210.
- the descriptor provided to the first comparison instruction comprises an ACR that indicates that the bits compared so far are equal, which thereby has no effect on the first comparison operation.
- the behaviour of the comparison operation should be clear.
- the comparison operation will consider the ACR that is provided as part of the input descriptor, in addition to performing a comparison on a subset of the bits of the first and second value in order to output a new ACR as part of an output descriptor.
- the output ACR will be the same as the input ACR if the input operands are equal. If the input operands are unequal, then the output ACR is set to to the result of comparing the input operands.
- the behaviour of the final comparison instruction may be similar except that the ACR is not output. Instead, the ACR is used by the comparison function (cmpf) to determine whether or not the condition dictated by the comparison function is passed or not.
- the input ACR is provided as the output ACR if the input ACR indicates that the bits analysed so far are not equal. If the input ACR indicates that the bits analysed so far are equal, then the output ACR is set to to the result of comparing the input operands.
- Figure 7 illustrates a flowchart 300 indicating the general method for executing the comparison instructions.
- the next instruction is fetched.
- the first operand and the second operand are received.
- the operands may be provided directly or may be provided in storage locations (such as registers) that are referred to in one or more parameters of the instruction.
- the comparison operation is performed.
- step 360 it is determined whether or not the instruction is an ICMP32F instruction. In other words, it is determined whether or not the instruction is a final comparison instruction in the sequence. If not, then an output descriptor is formed comprising the ACR from the comparison operation performed in step 350. Flow then proceeds to step 310 where the next instruction is fetched as previously described. The sequence therefore iterates through all of the instructions until at step 360, the final comparison instruction is reached. At this point, flow proceeds to step 380, where a final comparison result is output. The final comparison is dependant on the comparison function (cmpf), the result of the final comparison operation, and the result of the input ACR. The final comparison result may also be modified by the output modifier (Ml).
- Figure 8 shows an example of an early branch operation in a stream/sequence of comparison instructions.
- a large number of comparison instructions operate on different bits of a wide data type.
- the sequence of operations compares bits from the most significant bit to the least significant bit. Accordingly, it may be possible to determine the result of the comparison operation early. For example, as soon as the bits start to differ, it will be known which of the two values is larger or smaller and will also be known that the two values are non-equal. Accordingly, a conditional branch instruction, may be used in order to enable early branching and thereby prevent further comparisons of bits.
- the instruction stream shown in Figure 8 therefore contains a conditional branch instruction part way through the stream in order to allow the later instructions to be bypassed if the comparison result is already known.
- condition on which the branch occurs may be predetermined.
- the branch instruction may cause a branch to occur in dependence on the equality (or lack thereof) of the bits examined so far. It will be appreciated, from the discussion of Figure 6, that such a condition may make it possible to determine whether further comparisons of bits are necessary.
- conditional branch instruction must be used with caution.
- branch prediction it is possible that the wrong instructions may be chained comparison instruction pre-fetched. Where this happens, it may take a large number of processing cycles in order to correct for instructions that were prefetched due to an incorrect prediction. This is undesirable, as it can slow down the rate of instruction execution.
- the early branch instructions are best placed when a large number of comparison instructions follow, i.e. where there is a significant gain to potentially be made, and where there is a good chance that the result is already known, i.e. where there is less chance of misprediction occurring.
- a comparison instruction itself may perform the early branch operation, if appropriate. For example, if the number of remaining comparisons is known to a chained comparison instruction (ICMP32M) and if it is already known what the result of the comparison will be by virtue of the bits compared so far, then the chained comparison operation may branch to the end of the chain, thereby bypassing later instructions.
- ICMP32M chained comparison instruction
- the present technique may be used in the comparison of two wide floating point numbers.
- the way in which this is achieved may depend on whether or not a TotalOrder comparison is to be performed or not.
- a TotalOrder comparison uses a defined total ordering for all floating point numbers. Ordinarily, values that are not-a- number (NaN) are treated as unordered and -0 and +0 are treated as being equal. However, a TotalOrder comparison will order these cases as well as handle other situations that may be particular to floating point number representations.
- Figure 9 illustrates a flow chart 400 for performing a chained compare on two floating point numbers using a TotalOrder comparison.
- step 410 it is determined whether or not both the values (the first value and the second value) are positive. If so, then at step 420, a chained compare operation is performed on the first value and the second value, excluding the sign bits, as already described. Otherwise, at step 430, it is determined whether or not both values are negative. If not, then at step 440, the result of the comparison is determined based on the sign bits alone. For example, based on the sign bits alone (which are different at this point), it can be determined that the values are unequal and therefore that one value (the positive value) is bigger than the other value (the negative value).
- Step 450 determines whether or not the comparison function (cmpf) involves the greater than or less than function (including the greater than or equal to function as well as the less than or equal to function). If so, then at step 470, the result is inverted and output. If not, then at step 480, the result is output directly.
- the comparison function cmpf
- the words “configured to" are used to mean that an element of an apparatus has a configuration able to carry out the defined operation.
- a “configuration” means an arrangement or manner of interconnection of hardware or software.
- the apparatus may have dedicated hardware which provides the defined operation, or a processor or other processing device may be programmed to perform the function.
- Configured to does not imply that the apparatus element needs to be changed in any way in order to provide the defined operation.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Computational Mathematics (AREA)
- Mathematical Analysis (AREA)
- Mathematical Optimization (AREA)
- Pure & Applied Mathematics (AREA)
- Executing Machine-Instructions (AREA)
Abstract
There is provided an apparatus and method for comparing wide data types. The apparatus comprises processing circuitry to perform a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values. The plurality of comparison operations are chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
Description
COMPARISON OF WIDE DATA TYPES
The present technique relates to the field of data processing. In particular, the present technique relates to the field of comparing wide data types.
It is often desirable to perform a comparison between two data values, such as integers. In a data processing apparatus, an instruction may be issued to perform a comparison between two data values. The instruction may indicate two locations of the values to be performed. However, the data processing apparatus may be limited in terms of the size of data values that it can store. For example, each register, which may be used to store a single value, may only be capable of storing a single 32-bit value. Accordingly, such a comparison instruction may normally only be capable of comparing two 32-bit values. If it is desired to perform a comparison on much wider numbers, i.e. numbers that require more than 32 bits to be represented, then this can be achieved by splitting each number up into multiple chunks and then performing a comparison on each chunk. The individual results of each comparison can then be analysed in order to produce an end result. However, this process requires storage in order to store the individual results. The need for storage can be avoided by arranging each individual comparison in a branching structure. However, this can result in a much larger code sequence and due to branch prediction causing mispredictions, can result in code that takes longer to execute than if storage were used to store the individual results. Viewed from a first example configuration, there is provided processing circuitry to perform a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison
operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence. Viewed from a second example configuration, there is provided a method comprising the steps: performing a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
Viewed from a third example configuration, there is provided an apparatus comprising: processing means for performing a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
The present technique will be described further, by way of example only, with reference to embodiments thereof as illustrated in the accompanying drawings, in which:
Figure 1 shows, schematically, the operation of the present technique in accordance with one embodiment;
Figure 2 shows how a number of comparison operations are chained together in order to provide the comparison of a wide data value in accordance with one embodiment;
Figure 3 is a table illustrating example values of a comparison function in accordance with one embodiment;
Figure 4 shows an example cumulative result in accordance with one embodiment;
Figure 5 illustrates an example descriptor in accordance with one embodiment;
Figure 6 gives an example of three different instructions being used in combination to perform a comparison of a wide data type;
Figure 7 illustrates a flow chart of a method for using the instructions illustrated in Figure 6 for performing a comparison of a wide data type;
Figure 8 is a diagram illustrating an example of early branching in accordance with one embodiment; and
Figure 9 illustrates a flow chart for performing a comparison of two wide floating point numbers. Before discussing the embodiments with reference to the accompanying
Figures, the following description of embodiments and associated advantages is provided.
In accordance with one example configuration there is provided processing circuitry to perform a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated
comparison result is provided for use as an input by a next comparison operation in the sequence.
In the above configuration, a comparison of the first value and the second value (each having more than N bits) is performed by performing a plurality of comparison operations, each of which operates on N bits of the first value and the corresponding N bits of the second value. Each of the comparison operations considers a different set of N bits. The comparison operations are chained. In other words, with the exception of the last comparison operation, each comparison operation provides an Accumulated Comparison Result (ACR), which is used by the next comparison operation in the sequence. The ACR thereby considers the result of the comparison up until the most recently executed comparison operation. For example, if X comparison operations have been performed, each comparing N bits of the first value and N bits of the second value, then the ACR of the comparison operation X represents the result of comparing the first XN bits of the first value and the first XN bits of the second value. The last comparison operation has no successor and so does not output an ACR. Instead, the final comparison operation provides a comparison result, which represents the result of comparing the first value and the second value. By chaining the comparison operations in this manner, the need for storage of intermediate results can be reduced and in some instances may be eliminated altogether. Furthermore, this chaining of the comparison operations does not necessitate branching or long complex code structures because an ACR is passed between the comparison operations. Accordingly, a comparison of two wide data types can be efficiently carried out, without requiring large amounts of storage and without increasing the size and complexity of the underlying code. This results in a better computer by performing comparisons of wide data types more efficiently.
In some embodiments, the processing circuitry is arranged, for at least each comparison operation after a first comparison operation in the sequence, to receive a descriptor for use as an input for that comparison operation; and the descriptor comprises the accumulated comparison result from a previous comparison operation in
the sequence. The descriptor is used to pass intermediate data between successive comparison operations and thereby avoid the need to store large amounts of intermediate data for each of the comparison operations. There are a number of ways in which the descriptor may be provided for each of the comparison operations. In some embodiments, the processing circuitry is responsive to a plurality of comparison instructions to perform the plurality of comparison operations, at least each comparison instruction other than a first comparison instruction identifying the descriptor in an input parameter. Accordingly, the instructions themselves may either contain the descriptor as a parameter or may contain a parameter that contains a reference to where the descriptor is located (in, for example, storage circuitry such as a register). In other words, the descriptor may be explicitly provided. In some other embodiments, the processing circuitry is responsive to a plurality of comparison instructions to perform the plurality of comparison operations, each of the plurality of comparison operations other than the final comparison operation providing the accumulated comparison result for use as the input by the next comparison operation in the sequence by updating the descriptor stored in the storage circuitry. In these embodiments, the descriptor is implicitly provided, and the processing circuitry is able to locate the descriptor without being told explicitly where to find it. For example, a special dedicated storage structure may be provided in which to store the descriptor.
In some embodiments, the plurality of comparison instructions includes a chained compare instruction; and the processing circuitry is responsive to the chained compare instruction to perform an associated comparison operation in the sequence, the associated comparison operation using as inputs the N bits of the first and second values to be operated on, and an input descriptor, and the processing circuitry is arranged to output, as a result of the associated comparison operation, the descriptor to be used as an input for a subsequent comparison operation. The chained compare instruction itself may be optional in certain circumstances. For example, if the first value and the second value each comprise 2N bits, and each comparison operation operates on N bits, then it may be possible to perform the comparison of the first value
and the second value by using only a first chained compare instruction and a final chained compare instruction (each described below). In one embodiment, the chained compare instruction specifies all the inputs of the associated comparison operation as input operands.
In some embodiments, the plurality of comparison instructions includes a final chained compare instruction; and the processing circuitry is responsive to the final chained compare instruction to perform the final comparison operation in the sequence, the final comparison operation using as inputs the N bits of the first and second values to be operated on, and an input descriptor, and the processing circuitry is arranged to output, as a result of the final comparison operation, a comparison result for a comparison of the first and second values. The final chained compare instruction is the final compare instruction in the sequence and produces the overall result of comparing the first value and the second value. In one embodiment, the final chained compare instruction specifies all the inputs of the final comparison operation as input operands.
In some embodiments, the plurality of comparison instructions includes a first chained compare instruction; and the processing circuitry is responsive to the first chained compare instruction to perform the first comparison operation, the first comparison operation using as inputs the N bits of the first and second values to be operated on, and the processing circuitry is arranged to output, as a result of the first comparison operation, the descriptor to be used as an input for a subsequent comparison operation. Such a first chained compare instruction is optional and may instead be replaced by the chained compare instruction in which the descriptor that is provided has an ACR indicating that the comparison of the bits so far has been equal. However, by using a first chained compare instruction rather than providing a chained compare instruction as the first instruction, it is possible to avoid providing an instruction embedded constant or spending an instruction to preload an initial ACR value into the chained compare instruction. In one embodiment, the first chained compare instruction specifies all the inputs of the first comparison operation as input operands.
In some embodiments, a comparison function is provided as an input to the plurality of comparison operations, wherein the comparison function defines a type of comparison to be performed between the first value and the second value. The type of comparison may, for example, indicate that the comparison is to consider the first value and the second value as signed or unsigned numbers. Separately, the type of the comparison may indicate that the comparison is to determine whether the first value is greater than the second value, greater than or equal to the second value, equal to the second value, or not equal to the second value. The type of the comparison may also indicate that the comparison is to consider whether the first value is less than the second value or whether it is less than or equal to the second value.
There are a number of ways in which the comparison function may be provided to the plurality of comparison operations. In some embodiments, the comparison function is provided as an input to the first comparison operation; and the descriptor provided for use as an input by each comparison operation other than the first comparison operation identifies the comparison function provided for use as an input to the first comparison operation. In some other embodiments, the comparison function is provided for use as an input by the final comparison operation in the sequence. The ACR may be determined by each comparison operation without knowledge of how the first value and the second value are to be compared to each other, which is defined by the comparison function. The ACR may therefore provide an indication of how the first value and the second value differ from each other and only when the final comparison operation is performed is the comparison function used to determine whether the difference between the first value and the second value falls within the scope of what is being asked by the comparison function itself. This process may be advantageous in that it can be used to reduce the size of the descriptor, since the comparison function need not be provided until the final comparison operation is to be performed. This may therefore reduce the storage requirements for storing the descriptor whilst other comparison instructions are executed.
In some embodiments, the first value and the second value are both integers. In other embodiments, the first value and the second value are both floating point numbers. It may also be possible to compare other types and compare different types (e.g. an integer with a floating point number).
Although the first value and the second value may have a size that is any number of bits, in some embodiments, the first value and the second value each have a length that is a multiple of N bits. The bits of the first value and the second value may thereby be exactly divided between the multiple comparison operations. In other embodiments, one of the comparison operations (typically the first or last operation) may be extended in order to make up the shortfall in the number of bits. For example, if N is 32, then a 38-bit number may require two comparison operations. One of the operations could operate on 32 bits and the other operation could operate on the remaining 6 bits, extended to 32 bits.
In some embodiments, each comparison operation other than a first comparison operation in the sequence operates on more significant bits of the first and second values than the previous comparison operation. The comparison operations may therefore operate from the least significant bits to the most significant bits across successive comparison operations. Performing the comparison from the least significant bits to the most significant bits may be useful in the case where one of the comparison inputs is a multi-width addition result produced by a chain of add-with- carry instructions. In such a case, it is possible to feed the result of the addition into the comparison one step at a time, without storing the result anywhere.
In other embodiments, each comparison operation other than a first comparison operation in the sequence operates on less significant bits of the first and second values than the previous comparison operation. The comparison operations may therefore operate from the most significant bits to the least significant bits.
In some of these embodiments, the processing circuitry is responsive to the accumulated comparison result indicating a predetermined condition to perform an
early branch operation that causes subsequent comparison operations in the sequence to be bypassed. When comparing bits from most significant to least significant, it may be possible to determine the result of the comparison after only comparing a small number of bits. For example, if the comparison is to determine which of two unsigned numbers is the biggest and the first value has a T for its most significant bit and the second value has a '0' for its most significant bit, then the result of the comparison is already known (the first value is bigger). Accordingly, it may be desirable to insert an early branch instruction within the set of comparison operations to see if the result is known early and to bypass the remaining comparison operations if necessary. This may, in some circumstances, prevent the execution of unnecessary instructions.
The previously mentioned predetermined condition may be based on whether the accumulated comparison result indicates equality of bits compared by previous comparison operations. For example, whether or not the bits of the first value and the second value that have been compared so far are equal will determine whether or not the result of the comparison is known early and therefore whether or not subsequent comparison operations can be bypassed.
Particular embodiments will now be described with reference to the Figures. Figure 1 illustrates an apparatus 100 for performing a comparison between two wide data types 105, 110. Each of these data types is 128 bits in length. The embodiment shown in Figure 1, the processing circuitry 115 is only capable of operating on 32-bit values. Consequently, in order to compare two 128-bit values, the apparatus 100 performs a sequence of comparison instructions, each of which causes an associated comparison operation to be performed by processing circuitry 115. Each instruction in the sequence of instructions 115 considers a different 32 bits of the 128-bit values. For example, Figure 1 shows how each of the 128-bit values 105, 110 can be separated into four 32-bit values (1A, IB, 1C, ID) and (2A, 2B, 2C, 2D). Each of the comparison instructions then compares an associated pair of 32-bit values (1A with 2A, IB with 2B, 1C with 2C and ID with 2D). The processing circuitry 115 therefore takes two operands as inputs together with an optional Accumulated Comparison Result (ACR). The ACR forms part of a descriptor which is output by a previous
comparison operation. The format of the descriptor will be discussed later with reference to Figure 5. In the embodiment shown in Figure 1, the descriptor is provided as part of the comparison instruction. This may either involve the descriptor being passed in as a parameter of the instruction, or may instead be achieved by providing a reference to a storage location in which the descriptor is stored. However, in other embodiments, control storage 120 may be provided. In these other embodiments, the descriptor is not passed in as part of the comparison instruction but is instead accessed from a known location (the control storage 120) by the processing circuitry 115 during the comparison operation.
The embodiment shown in Figure 1 comprises four comparison instructions. These start with an Initial Comparison Instruction (ICMP32I), followed by two chained comparison instructions (ICMP32M), followed by a final comparison instruction (ICMP32F). In the embodiment shown in Figure 1, the first comparison instruction receives a comparison function (cmpf) as an input parameter. This indicates a comparison type to be performed. The comparison type indicates the type of comparison to be performed between the two 128-bit values. Examples of possible values for the comparison type will be discussed with reference to Figure 3. The first comparison instruction also receives an output modifier (Ml) as an input parameter. The output modifier is used to affect the final comparison result output at the end of the chain of comparison operations. In particular, it controls whether the result is an integer 1 or all l 's vector if the comparison result is true. If the result is false, the output is all 0's vector. Each of the comparison instructions except the first comparison instruction receives a descriptor as one of the input parameters. The format of the descriptor will be discussed with reference to Figure 5.
Also as shown in the embodiment of Figure 1, the output from the final comparison instruction is the final comparison result of comparing the two 128-bit values 105, 110. This final comparison result indicates the result of the comparison. The output is an all 0's vector (if the result of the comparison is false) or either an all l's vector or the integer 1 (if the result of the comparison is true), dependent on the value of the output modifier (Ml).
Figure 2 illustrates an example of chaining a plurality of comparison operations in order to achieve the comparison of a first value and a second value, whereby the first value and the second value are wide data types. In particular, in a system in which the first value and second value are each 64 bits and in which the processing circuitry 115 can compare a maximum of 32 bits at once, the comparison of the first value and the second value may be carried out by using an initial comparison instruction (ICMP32I) which causes processing circuitry 115 to perform a first or initial comparison operation on the first 32 bits of the first and second values and a final comparison operation on the last 32 bits of the first and second values. The result of the first comparison is a descriptor that is provided as an input to the second comparison instruction (ICMP32F). The output of the final comparison operation is the result of the comparison of the first value and second value. If the first value and second value are wider than 64 bits, the chain may involve the inclusion of a chained comparison instruction (ICMP32M), which causes further comparison operations to be performed by the processing circuitry 115. These further comparison operations are termed "chained" comparison operations. Each of the chained comparison operations takes a descriptor provided by the previous comparison operation as an input. The result of the comparison operation results in an ACR being output, which forms part of the descriptor that is input to a subsequent comparison operation. In the embodiment shown in Figure 2, it is assumed that the first and second values have a bit length that is a multiple of the number of bits that the processing circuitry 115 is able to compare at once. For example, in this case, the processing circuitry 115 is able to compare two sets of 32 bits at once. It is therefore assumed that the first and second values have a bit length that is a multiple of 32 bits. However, it will be appreciated that comparisons of other numbers of bits will be possible too. This may be achieved by extending the numbers to be compared. For example, if the first and second values are 100-bit values, an additional 28 bits may be provided such that the value is actually treated as a 128-bit value. For example, for a 100-bit unsigned value, 28 zeros may be added to the top bits in order to produce a 128-bit value for comparison.
Figure 3 shows a table illustrating an example of different values for the comparison function (cmpf) in accordance with one embodiment. As previously described, the comparison value indicates the type of comparison that is to be performed between the first value and the second value. In the case of the embodiment shown in Figure 3, where the value of the comparison function is 0, the comparison will be a signed greater than function. Where the value is 1, the function will be a signed greater than or equal to function. Where the value is 2, the function will be an unsigned greater than function. Where the value is 3, the function will be an unsigned greater than or equal to function. Where the value is 4, the function will be for equality. Where the value is 5, the function will be for non-equality. The values 6 and 7 are reserved, for future use for example. As an example, if the first value being compared is 5 and the second value being compared is 12, then if the comparison function is 1, then the result will be 0 or false, because 5 is not greater than or equal to 12. Alternatively, if the value of the comparison function is 5, then the result will be 1 or true, because 5 is not equal to 12. Whether the function is a signed function or an unsigned function dictates whether or not the first value and the second value are to be treated as signed numbered or unsigned numbers. Figure 4 shows a table comprising example values for the ACR. As previously described, the ACR indicates the result of comparing a subset of the bits of the first value and the second value. In other words, the ACR comprises the result of having compared all of the bits encountered so far. For example, if each comparison operation takes 32 bits from the first value and compares those to 32 bits of the second value, then the ACR in a third comparison operation will be the result of comparing the first 96 bits of the first value and 96 bits of the second value. If the value of the ACR is 1, then this means that the comparison so far indicates that the first value is less than the second value. If the value is 2 then this means that the comparison so far indicates that the first value is greater than the second value. If the value is 3 then this indicates that the comparison so far indicates that the first value and the second value are equal. The value 0 is reserved, for future use for example.
Figure 5 illustrates an example of the descriptor in accordance with one embodiment. The descriptor may be passed between comparison operations in order to chain the comparison operations together. For example, the output of one comparison operation may be provided as a parameter to a subsequent comparison operation. In the embodiment shown in Figure 5, the descriptor is made up of 32 bits. The first 3 bits (0-2) comprise the comparison function (cmpf) as previously described with reference to Figure 3. The following 2 bits (3-4) comprise the ACR, as previously described with reference to Figure 4. The following bit (5) is used to store the output modifier (Ml). This controls whether the result output at the end of the sequence of chained comparison operations is an integer 1 or all l's vector if the comparison result is true. If the result is false, the output is an all 0's vector. The remaining bits (6-31) are reserved, for future use for example.
Figure 6 shows an example illustrating the use of three comparison instructions, causing a chain of three comparison operations to compare a first value and a second value, and thereby output a comparison result. The process starts with a first comparison instruction (ICMP32I) 205. This receives a pair of operands (operand 0 and operand 1), each of 32 bits. In practice, these may refer to two 32-bit registers, where the first 32 bits of the first value and the second value, respectively, are stored. The instruction also comprises the comparison function (cmpf). As previously discussed with reference to Figure 3, this dictates how the first value and the second value are to be compared. Finally, the instruction comprises the output modifier (Ml), which dictates how the output is to be formatted. The first comparison instruction 205 results in a comparison operation being performed between operand 0 and operand 1. The result is an ACR, which together with the output modifier (Ml) and the comparison function (cmpf), make up a descriptor that is provided to a second comparison instruction (ICMP32M) 210. This second comparison instruction also takes a pair of operands (operand 0 and operand 1). Although these operands are also 32 bits each, they will be a different pair of operands than the pair of operands operated on by the first comparison instruction 205. Accordingly, the second comparison instruction 210 operates on a different set of bits to those of the first comparison instruction. The second comparison instruction 210 causes a second
comparison operation to take place. The second comparison operation takes the pair of operands provided by the second comparison instruction 210. The second comparison operation also takes the comparison function (cmpf) and the ACR from the descriptor provided by the previous comparison operation. The result of performing the second comparison operation is an ACR, which together with the comparison function (cmpf) and the output modifier (Ml) from the input descriptor, make up a new descriptor. This new descriptor is provided to a final comparison instruction (ICMP32F) 215. The final comparison instruction 215 causes a final comparison operation to be performed. The instruction comprises a pair of operands, which are again different to the pair of operands provided by the first comparison instruction 205 or the second comparison instruction 210. The third comparison instruction 215 also takes as an input the descriptor that is output as a result of performing the second comparison instruction 210, which includes the output modifier (Ml). Once again, as a consequence of the comparison instruction 215, a comparison operation is performed on the pair of provided operands. The result of this is a comparison result, which is the overall result of comparing the first value with the second value (each of which is 96 bits in length).
Note that this embodiment makes use of an initial comparison instruction (ICMP32I) 205. However, in other embodiments, the first comparison instruction may be of the form illustrated by the second comparison instruction (ICMP32M) 210. In such embodiments, the descriptor provided to the first comparison instruction comprises an ACR that indicates that the bits compared so far are equal, which thereby has no effect on the first comparison operation.
In each case, the behaviour of the comparison operation should be clear. In each case, the comparison operation will consider the ACR that is provided as part of the input descriptor, in addition to performing a comparison on a subset of the bits of the first and second value in order to output a new ACR as part of an output descriptor.
If the comparison operations operate from least significant bit to most significant bit, then the output ACR will be the same as the input ACR if the input
operands are equal. If the input operands are unequal, then the output ACR is set to to the result of comparing the input operands. The behaviour of the final comparison instruction may be similar except that the ACR is not output. Instead, the ACR is used by the comparison function (cmpf) to determine whether or not the condition dictated by the comparison function is passed or not.
If the comparison operations operate from most significant bit to least significant bit, then the input ACR is provided as the output ACR if the input ACR indicates that the bits analysed so far are not equal. If the input ACR indicates that the bits analysed so far are equal, then the output ACR is set to to the result of comparing the input operands.
Figure 7 illustrates a flowchart 300 indicating the general method for executing the comparison instructions. At step 310, the next instruction is fetched. At step 230, the first operand and the second operand are received. The operands may be provided directly or may be provided in storage locations (such as registers) that are referred to in one or more parameters of the instruction. In any event, at step 330, it is determined whether or not the instruction is an ICMP32I instruction. If not, then at step 340, the descriptor containing the ACR is obtained and flow continues to step 350. If at step 330, the instruction is an ICMP32I instruction, then flow proceeds directly to step 350. At step 350, the comparison operation is performed. At step 360, it is determined whether or not the instruction is an ICMP32F instruction. In other words, it is determined whether or not the instruction is a final comparison instruction in the sequence. If not, then an output descriptor is formed comprising the ACR from the comparison operation performed in step 350. Flow then proceeds to step 310 where the next instruction is fetched as previously described. The sequence therefore iterates through all of the instructions until at step 360, the final comparison instruction is reached. At this point, flow proceeds to step 380, where a final comparison result is output. The final comparison is dependant on the comparison function (cmpf), the result of the final comparison operation, and the result of the input ACR. The final comparison result may also be modified by the output modifier (Ml).
Figure 8 shows an example of an early branch operation in a stream/sequence of comparison instructions. In Figure 8, a large number of comparison instructions operate on different bits of a wide data type. The sequence of operations compares bits from the most significant bit to the least significant bit. Accordingly, it may be possible to determine the result of the comparison operation early. For example, as soon as the bits start to differ, it will be known which of the two values is larger or smaller and will also be known that the two values are non-equal. Accordingly, a conditional branch instruction, may be used in order to enable early branching and thereby prevent further comparisons of bits. The instruction stream shown in Figure 8 therefore contains a conditional branch instruction part way through the stream in order to allow the later instructions to be bypassed if the comparison result is already known. The condition on which the branch occurs may be predetermined. For example, the branch instruction may cause a branch to occur in dependence on the equality (or lack thereof) of the bits examined so far. It will be appreciated, from the discussion of Figure 6, that such a condition may make it possible to determine whether further comparisons of bits are necessary.
It must be noted that such a conditional branch instruction must be used with caution. In particular, as a consequence of branch prediction, it is possible that the wrong instructions may be chained comparison instruction pre-fetched. Where this happens, it may take a large number of processing cycles in order to correct for instructions that were prefetched due to an incorrect prediction. This is undesirable, as it can slow down the rate of instruction execution. Accordingly, the early branch instructions are best placed when a large number of comparison instructions follow, i.e. where there is a significant gain to potentially be made, and where there is a good chance that the result is already known, i.e. where there is less chance of misprediction occurring.
In some embodiments, a comparison instruction itself may perform the early branch operation, if appropriate. For example, if the number of remaining comparisons is known to a chained comparison instruction (ICMP32M) and if it is already known what the result of the comparison will be by virtue of the bits compared
so far, then the chained comparison operation may branch to the end of the chain, thereby bypassing later instructions.
The present technique may be used in the comparison of two wide floating point numbers. The way in which this is achieved may depend on whether or not a TotalOrder comparison is to be performed or not. A TotalOrder comparison uses a defined total ordering for all floating point numbers. Ordinarily, values that are not-a- number (NaN) are treated as unordered and -0 and +0 are treated as being equal. However, a TotalOrder comparison will order these cases as well as handle other situations that may be particular to floating point number representations.
Figure 9 illustrates a flow chart 400 for performing a chained compare on two floating point numbers using a TotalOrder comparison. At step 410, it is determined whether or not both the values (the first value and the second value) are positive. If so, then at step 420, a chained compare operation is performed on the first value and the second value, excluding the sign bits, as already described. Otherwise, at step 430, it is determined whether or not both values are negative. If not, then at step 440, the result of the comparison is determined based on the sign bits alone. For example, based on the sign bits alone (which are different at this point), it can be determined that the values are unequal and therefore that one value (the positive value) is bigger than the other value (the negative value). Alternatively, if both values are negative at step 430, then at step 450 a chained comparison operation is performed on the non-sign bits, as previously described. Step 460 determines whether or not the comparison function (cmpf) involves the greater than or less than function (including the greater than or equal to function as well as the less than or equal to function). If so, then at step 470, the result is inverted and output. If not, then at step 480, the result is output directly.
For other types of comparison (i.e. not TotalOrder), it is necessary to keep track of whether the significand is zero or non-zero and whether the exponent is all zeros, all ones, or something else. In order to achieve this, it is therefore necessary to know where the boundaries between the sign, exponent, and significand are in the
representation of the floating point number. By keeping track of this information, it is possible to determine whether a given value is zero (if both the exponent and significand are zero), infinity (if the exponent is all ones and the mantissa is zero), NaN (if the exponent is all ones and the mantissa is non-zero), or a normal number (otherwise). If both values are normal, or if one value is normal and the other is zero, or if one value is infinity and the other number is either normal or zero, then it is possible to perform a comparison as the same way illustrated in the flow chart of Figure 9. Otherwise, two zeros are considered to be identical (in other words, negative zero and positive zero are considered to be the same), two infinities with the same sign are identical, two infinities with different signs are compared according to their signs (negative infinity is smaller than positive infinity), and any comparison involving a NaN fails.
If the comparison is performed from most significant bit to least significant bit then at the point where you cross from the exponent into the significand you have sufficient information to classify each number as normal, infinity, NaN, or potentially zero. All three bits can be tracked for each operand (significand zero/non-zero, exponent all zeros/all ones/other). However, it is sufficient to track two bits for each of the operands. When comparing exponents, track whether the exponent is all zeros, all ones, or other. When switching to comparing the significand, track whether the overall value is zero/infinity /NaN/normal.
If the comparison is performed from least significant bit to most significant bit, it is possible to do similar tracking, but determine the "significand zero/non-zero" bit first, then consider the exponent value in order to determine whether or not the floating point number is zero/infinity /NaN/normal.
In the present application, the words "configured to..." are used to mean that an element of an apparatus has a configuration able to carry out the defined operation. In this context, a "configuration" means an arrangement or manner of interconnection of hardware or software. For example, the apparatus may have dedicated hardware which provides the defined operation, or a processor or other processing device may be programmed to perform the function. "Configured to" does not imply that the
apparatus element needs to be changed in any way in order to provide the defined operation.
Although illustrative embodiments of the invention have been described in detail herein with reference to the accompanying drawings, it is to be understood that the invention is not limited to those precise embodiments, and that various changes, additions and modifications can be effected therein by one skilled in the art without departing from the scope and spirit of the invention as defined by the appended claims. For example, various combinations of the features of the dependent claims could be made with the features of the independent claims without departing from the scope of the present invention.
Claims
An apparatus comprising:
processing circuitry to perform a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
An apparatus according to claim 1, wherein
the processing circuitry is arranged, for at least each comparison operation after a first comparison operation in the sequence, to receive a descriptor for use as an input for that comparison operation; and
the descriptor comprises the accumulated comparison result from a previous comparison operation in the sequence.
An apparatus according to claim 2, wherein
the processing circuitry is responsive to a plurality of comparison instructions to perform the plurality of comparison operations, at least each comparison instruction other than a first comparison instruction identifying the descriptor in an input parameter.
An apparatus according to claim 2, wherein
the processing circuitry is responsive to a plurality of comparison instructions to perform the plurality of comparison operations, each of the plurality of comparison operations other than the final comparison operation
providing the accumulated comparison result for use as the input by the next comparison operation in the sequence by updating the descriptor stored in storage circuitry.
An apparatus according to any one of claims 2-4, wherein
the plurality of comparison instructions includes a chained compare instruction; and
the processing circuitry is responsive to the chained compare instruction to perform an associated comparison operation in the sequence, the associated comparison operation using as inputs the N bits of the first and second values to be operated on, and an input descriptor, and the processing circuitry is arranged to output, as a result of the associated comparison operation, the descriptor to be used as an input for a subsequent comparison operation.
An apparatus according to any one of claims 2-5, wherein
the plurality of comparison instructions includes a final chained compare instruction; and
the processing circuitry is responsive to the final chained compare instruction to perform the final comparison operation in the sequence, the final comparison operation using as inputs the N bits of the first and second values to be operated on, and an input descriptor, and the processing circuitry is arranged to output, as a result of the final comparison operation, a comparison result for a comparison of the first and second values.
An apparatus according to any one of claims 2-6, wherein
the plurality of comparison instructions includes a first chained compare instruction; and
the processing circuitry is responsive to the first chained compare instruction to perform the first comparison operation, the first comparison operation using as inputs the N bits of the first and second values to be operated on, and the processing circuitry is arranged to output, as a result of the
first comparison operation, the descriptor to be used as an input for a subsequent comparison operation.
An apparatus according to any one of claims 2-7, wherein
a comparison function is provided as an input to the plurality of comparison operations, wherein the comparison function defines a type of comparison to be performed between the first value and the second value.
An apparatus according to claim 8, wherein
the comparison function is provided as an input to the first comparison operation; and
the descriptor provided for use as an input by each comparison operation other than the first comparison operation identifies the comparison function provided for use as an input to the first comparison operation.
10. An apparatus according to claim 8, wherein
the comparison function is provided for use as an input by the final comparison operation in the sequence.
An apparatus according to any preceding claim, wherein
the first value and the second value are both integers.
An apparatus according to any preceding claim, wherein
the first value and the second value are both floating point numbers.
An apparatus according to any preceding claim, wherein
the first value and the second value each have a length that is a multiple of N bits.
An apparatus according to any one of claims 1-13, wherein
each comparison operation other than a first comparison operation in the sequence operates on more significant bits of the first and second values than the previous comparison operation.
An apparatus according to any one of claims 1-13, wherein
each comparison operation other than a first comparison operation in the sequence operates on less significant bits of the first and second values than the previous comparison operation.
An apparatus according to claim 15, wherein
the processing circuitry is responsive to the accumulated comparison result indicating a predetermined condition to perform an early branch operation that causes subsequent comparison operations in the sequence to be bypassed.
An apparatus according to claim 16, wherein
the predetermined condition is based on whether the accumulated comparison result indicates equality of bits compared by previous comparison operations.
A method comprising the steps:
performing a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values;
the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
An apparatus comprising:
processing means for performing a plurality of comparison operations in order to compare a first value and a second value, each of the first value and the second value having a length greater than N bits, and each comparison operation operating on a corresponding N bits of the first and second values; the plurality of comparison operations being chained to form a sequence such that each comparison operation is arranged to output an accumulated comparison result incorporating the comparison results of any previous comparison operations in the sequence, and such that for each comparison operation other than a final comparison operation in the sequence the accumulated comparison result is provided for use as an input by a next comparison operation in the sequence.
Priority Applications (3)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| KR1020187003192A KR102560424B1 (en) | 2015-07-10 | 2016-05-25 | Comparison of wide data types |
| CN201680039390.0A CN107851007B (en) | 2015-07-10 | 2016-05-25 | Method and apparatus for comparison of wide data types |
| US15/743,008 US10474427B2 (en) | 2015-07-10 | 2016-05-25 | Comparison of wide data types |
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| GB201512140A GB2540216B (en) | 2015-07-10 | 2015-07-10 | Comparison of wide data types |
| GB1512140.3 | 2015-07-10 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2017009596A1 true WO2017009596A1 (en) | 2017-01-19 |
Family
ID=54013803
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/GB2016/051506 Ceased WO2017009596A1 (en) | 2015-07-10 | 2016-05-25 | Comparison of wide data types |
Country Status (5)
| Country | Link |
|---|---|
| US (1) | US10474427B2 (en) |
| KR (1) | KR102560424B1 (en) |
| CN (1) | CN107851007B (en) |
| GB (1) | GB2540216B (en) |
| WO (1) | WO2017009596A1 (en) |
Families Citing this family (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111381803A (en) * | 2018-12-28 | 2020-07-07 | 上海寒武纪信息科技有限公司 | Data comparator, data processing method, chip and electronic equipment |
| CN111381805A (en) * | 2018-12-28 | 2020-07-07 | 上海寒武纪信息科技有限公司 | Data comparator, data processing method, chip and electronic device |
| CN111381875B (en) * | 2018-12-28 | 2022-12-09 | 上海寒武纪信息科技有限公司 | Data comparator, data processing method, chip and electronic device |
| CN111381806A (en) * | 2018-12-28 | 2020-07-07 | 上海寒武纪信息科技有限公司 | Data comparator, data processing method, chip and electronic equipment |
| CN111381804A (en) * | 2018-12-28 | 2020-07-07 | 上海寒武纪信息科技有限公司 | Data comparator, data processing method, chip and electronic equipment |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6384627B1 (en) * | 2001-02-16 | 2002-05-07 | Xilinx, Inc. | Logic block used as dynamically configurable logic function |
| US7453286B1 (en) * | 2007-04-19 | 2008-11-18 | Xilinx, Inc. | Comparator and method of implementing a comparator in a device having programmable logic |
| US20130097408A1 (en) * | 2010-05-11 | 2013-04-18 | Arm Limited | Conditional compare instruction |
Family Cites Families (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US5226082A (en) * | 1992-07-02 | 1993-07-06 | At&T Bell Laboratories | Variable length decoder |
| US6384713B1 (en) * | 2000-04-21 | 2002-05-07 | Marvell International, Ltd. | Serial comparator |
| US7281006B2 (en) * | 2003-10-23 | 2007-10-09 | International Business Machines Corporation | System and method for dividing data into predominantly fixed-sized chunks so that duplicate data chunks may be identified |
| US8453043B2 (en) * | 2010-09-13 | 2013-05-28 | Taiwan Semiconductor Manufacturing Company, Ltd. | Built-in bit error rate test circuit |
| US8407245B2 (en) * | 2010-11-24 | 2013-03-26 | Microsoft Corporation | Efficient string pattern matching for large pattern sets |
| US9176733B2 (en) * | 2011-04-07 | 2015-11-03 | Via Technologies, Inc. | Load multiple and store multiple instructions in a microprocessor that emulates banked registers |
| US8581624B2 (en) * | 2012-03-29 | 2013-11-12 | Altera Corporation | Integrated circuits with multi-stage logic regions |
| CN103605485B (en) * | 2013-11-29 | 2017-01-18 | 深圳市道通科技股份有限公司 | Variable-length data storing method and device |
-
2015
- 2015-07-10 GB GB201512140A patent/GB2540216B/en active Active
-
2016
- 2016-05-25 WO PCT/GB2016/051506 patent/WO2017009596A1/en not_active Ceased
- 2016-05-25 CN CN201680039390.0A patent/CN107851007B/en active Active
- 2016-05-25 US US15/743,008 patent/US10474427B2/en active Active
- 2016-05-25 KR KR1020187003192A patent/KR102560424B1/en active Active
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US6384627B1 (en) * | 2001-02-16 | 2002-05-07 | Xilinx, Inc. | Logic block used as dynamically configurable logic function |
| US7453286B1 (en) * | 2007-04-19 | 2008-11-18 | Xilinx, Inc. | Comparator and method of implementing a comparator in a device having programmable logic |
| US20130097408A1 (en) * | 2010-05-11 | 2013-04-18 | Arm Limited | Conditional compare instruction |
Also Published As
| Publication number | Publication date |
|---|---|
| US20190087155A1 (en) | 2019-03-21 |
| US10474427B2 (en) | 2019-11-12 |
| CN107851007A (en) | 2018-03-27 |
| GB2540216B (en) | 2020-01-01 |
| KR102560424B1 (en) | 2023-07-27 |
| CN107851007B (en) | 2022-05-06 |
| KR20180027537A (en) | 2018-03-14 |
| GB201512140D0 (en) | 2015-08-19 |
| GB2540216A (en) | 2017-01-11 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| EP3719639B1 (en) | Systems and methods to perform floating-point addition with selected rounding | |
| KR102447636B1 (en) | Apparatus and method for performing arithmetic operations for accumulating floating point numbers | |
| US9146901B2 (en) | Vector floating point argument reduction | |
| US10474427B2 (en) | Comparison of wide data types | |
| US20150199173A1 (en) | Multiply adder | |
| WO2008036944A1 (en) | Performing rounding operations responsive to an instruction | |
| JP6738579B2 (en) | Apparatus and method for performing checks that optimize instruction flow | |
| TW202223633A (en) | Apparatuses, methods, and systems for instructions for 16-bit floating-point matrix dot product instructions | |
| EP2243074B1 (en) | Processor and method of determining a normalization count | |
| JP7461953B2 (en) | Mixed-precision processing unit | |
| KR100911786B1 (en) | Multipurpose multiply-add functional unit | |
| US11016731B2 (en) | Using Fuzzy-Jbit location of floating-point multiply-accumulate results | |
| US8055883B2 (en) | Pipe scheduling for pipelines based on destination register number | |
| EP4478176B1 (en) | Extended floating-point range processors, methods, systems, and instructions | |
| US20240329991A1 (en) | Instructions for floating point multiplication and addition and conversion employing variable precision | |
| US20250004768A1 (en) | Vector packed matrix multiplication and accumulation processors, methods, systems, and instructions | |
| TWI624802B (en) | Methods and apparatuses for calculating fp (full precision) and pp (partial precision) values | |
| US11720328B2 (en) | Processing unit with small footprint arithmetic logic unit | |
| US20180004485A1 (en) | Architecture and instruction set to support interruptible floating point division | |
| US11080054B2 (en) | Data processing apparatus and method for generating a status flag using predicate indicators | |
| US20110231635A1 (en) | Register, Processor, and Method of Controlling a Processor | |
| US20050210093A1 (en) | Data processing apparatus and method for comparing floating point operands | |
| US9361267B2 (en) | Splitable and scalable normalizer for vector data | |
| US11704092B2 (en) | High-precision anchored-implicit processing | |
| JPH1185469A (en) | Parallel processing unit |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| 121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 16744827 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| ENP | Entry into the national phase |
Ref document number: 20187003192 Country of ref document: KR Kind code of ref document: A |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 16744827 Country of ref document: EP Kind code of ref document: A1 |