Optimization of initialization of parallel compare predicates in a computer system
Granted 7 Jan 2003 · 1 office action
Assignee: Intel Corporation
Law firm: Law firm · Log in to unlock
Attorney: Attorney · Log in to unlock
Inventors: William Y. Chen, Dong-Yuan Chen · Examiner: Gregory Morse · AU 2122 · TC 2100
Life of the application
7 dated eventsAbstract
An optimization process is disclosed. The process first finds a parallel compare sequence in a program flow, for example using a flow graph. The guarding predicate (gp) is obtained for the compares. If a new dominating predicate (dp) can be found, the process proceeds to determining if compares for the dp generate the correct or needed initial value for the gp. If there are free result slots available, the proper compares are generated and folded into the initialization. If no free slots are available, it is determined if there is a use of a gp between the dp and gp. If not, the dp is renamed to gp, and the proper compares are generated and folded into the initialization. If there is such a use, the guarding predicate of the compares is found and the process reiterates until it ends with the failure to find a new dominating predicate dp.
Description
5 parts›TECHNICAL FIELD OF THE INVENTION
The present invention pertains generally to computers, and more particularly to processing of computer instructions in a computer system.
›BACKGROUND OF THE INVENTION
Many microprocessors use instruction pipelining as one way to increase instruction throughput, sometimes using very deep instruction pipelines including many pipeline stages and substages. Another approach to improving instruction execution speed is called “out-of-order” execution. In a microprocessor providing for out-of-order execution, instructions may be executed out of program order to take advantage of instruction parallelism. Instruction pipelining and out-of-order execution techniques may be used separately or together in the same microprocessor.
In a microprocessor having a pipelined architecture, instruction throughput is most efficient when the pipeline or pipelines are kept “fall.” In other words, it is most advantageous to have instructions being processed at every pipeline stage in each processor clock cycle. To keep an instruction pipeline full, instructions must generally be fetched continuously. Often an instruction pipeline is many pipeline stages deep such that instructions are fetched several clock cycles before they are executed. This can be an issue where the instruction fetched is a program flow control instruction such as a conditional branch instruction.
Conditional branch instructions often rely on data from other instructions for resolution of the condition specified within the instruction. If an instruction effecting the resolution of the condition has not been executed at the time the conditional branch instruction is fetched, the processor does not have the information necessary to resolve the branch instruction. If the branch instruction cannot be resolved because the necessary data is not available, the processor does not know how to direct the program flow and therefore, which instructions are the correct instructions to fetch next.
If the branch instruction is resolved to be taken, the target instruction and instructions sequentially following the target instruction, referred to herein as the target instruction stream, must be fetched. If the branch instruction is resolved to be not taken, instructions sequentially following the branch instruction must be fetched. Thus, the program flow depends on resolution of the branch instruction. Where the branch instruction cannot be resolved at the time it is fetched because the required data is not available, there can be an issue.
Some processors address this issue by using some form of branch prediction logic. Although the use of branch prediction logic can help to improve microprocessor performance, it is virtually impossible to accurately predict the resolution of a branch instruction every time regardless of the branch prediction scheme used. Mispredictions by the branch prediction logic can have a significant impact on microprocessor performance. The microprocessor relies on the branch prediction logic to determine whether to fetch instructions from the sequential instruction stream following the conditional branch instruction or the target instruction stream. A misprediction means that the wrong instructions are being processed in the microprocessor pipeline.
When a misprediction is identified, the processor instruction pipeline is usually “flushed”. Thus, instructions in the microprocessor at various phases of execution are cleared from the pipeline and instructions from the correct instruction stream, and thus the correct program flow, must be fetched. Instructions flushed from the pipeline create “bubbles” in the pipeline such that several clock cycles may be required before the next instruction completes execution. Thus, instruction throughput and overall microprocessor performance is compromised.
One approach addresses the misprediction penalty using a method called predication, also referred to as guarding. Predication is actually used in lieu of branch instructions in this approach. Predicate registers are defined by special instructions and these “predicate” registers are associated with subsequent instructions and may be used to guard them. The predicate specifies a condition that determines whether or not the instruction will be executed. Once the condition is resolved, the predicated instructions are executed and the architectural state of the processor is updated appropriately.
Predication can be used to perform parallel compares, which are used to collapse the height of two or more conditional compares for execution in parallel within the same cycle despite output dependency. Parallel ‘and’ is used for Booleanand conditions and parallel ‘or’ is used for Boolean-or conditions. Parallel compares that execute simultaneously and write the same target register must write the same value. Parallel-and compares can only write a value of zero, thus the target register must be initialized to a one. Parallel-or compares can only write a value of one, thus the target register must be initialized to a zero.
One drawback of using parallel compares is the initialization of predicate registers. An initialization instruction is an additional instruction at the head of a dependence chain of instructions. For parallel-and compares, the predicate register initialization placement is important because the initial value is true (one). If there is an execution path on which the predicate register is undefined, the initial value should be false (zero) for the path. This situation restricts the initialization of the parallel-and result register to be directly before the parallel compares. Since there is a dependency between the initialization and the parallel compare instruction group, this adds to the overall critical path length. In general, materialization of initialization instructions that are restricted in code motion is not desirable because of the increase in resource usage and addition to the critical path length. Thus, it is desirable to optimize these predicate initialization instructions away.
›SUMMARY OF THE INVENTION
According to one embodiment of the invention, there is provided a method and apparatus for finding a parallel compare sequence in a computer program using predication wherein the sequence requires an initialization, and using a predicate defined in the program in advance of the parallel compare sequence to initialize the parallel compares.
›BRIEF DESCRIPTION OF THE DRAWINGS
FIGS. 1-5 illustrate one example illustration of an example embodiment of the invention.
FIGS. 6-9 illustrate another example illustration of an example embodiment of the invention.
FIG. 10 illustrates a flow chart of an example embodiment of the process of the invention.
FIGS. 11 and 12 illustrate alternate embodiments of the invention.
›DETAILED DESCRIPTION OF THE INVENTION
In the following detailed description of the preferred embodiments, reference is made to the accompanying drawings which form a part hereof, and in which is shown by way of illustration specific preferred embodiments in which the invention may be practiced. These embodiments are described in sufficient detail to enable those skilled in the art to practice the invention, and it is to be understood that other embodiments may be utilized and that changes may be made without departing from the spirit and scope of the present invention. The following detailed description is, therefore, not to be taken in a limiting sense, and the scope of the present invention is defined only be the appended claims.
As described in more detail below, the present invention uses the property of the flow graph to recognize opportunities to use previously defined predicates to initialize the parallel compares, thus eliminating the need for additional initialization instructions and reducing the number of cycles required to process a stream of instructions. According to one embodiment of the invention, for a parallel-and compare, a flow graph analysis is used to recognize a dominating predicate register whose value is a one on the path to a group of instructions using a parallel-and compare. For a parallel-or compare, a flow graph analysis recognizes a dominating predicate register whose value is a zero on the path to a group of instructions using a parallel-or. If free compare result slots in the instruction stream are available, the compare instructions in this stream are modified to fold in the predicate initialization. If necessary, the compare opcode is modified to generate the correct predicate values. If free slots are not available, it is detennined if there are no other uses of the dominating predicate register, and if so, renaming is used to fold in the predicate initialization.
The following is a simple example of when initialization of a predicate compare can be optimized away, according to one embodiment of the invention. FIG. 1 illustrates the original source code 10 corresponding to the flow graph 12 of FIG. 2 . FIG. 3 illustrates a code sequence 14 for the source code 10 using sequential compare operations. In this example, the code takes 6 instructions in 6 cycles. FIG. 4 shows the equivalent parallel compare code sequence 16 using traditional initialization technique. Here the sequence takes 8 instructions in 5 cycles. Also, initialization for p3 has no dependence and is assumed to be free, or in other words does not require an additional cycle and is hence represented as cycle 0 . This code sequence is an increase of two instructions over sequence 14 due to predicate initialization with a reduction of one cycle. It is noted that the initialization of p5 to a value of ‘1’ cannot be speculated upward due to the uncovered path from p2 to the end block (p6). On that path, p5 should be ‘0’, and an initialization at the entry dominating block produces incorrect code. This initialization thus causes serialization thus producing a sub-optimal code sequence.
FIG. 5 illustrates an example of an optimized code sequence 18 . This optimization recognizes that the combined node of p1 and p2 produces a predicate that dominates the parallel-and code sequence, which presents an opportunity to create the initialization of p5. As there is a free predicate definition slot for both of the compares, the initialization can be merged together. The resulting code sequence 18 is 7 instructions and takes 4 cycles.
A more complex example of the application of an embodiment of the invention is shown respect to the source code 20 illustrated in FIG. 6, which corresponds to the flow graph 22 shown in FIG. 7 . The parallel compare code sequence 24 with a traditional initialization technique is shown in FIG. 8 . FIG. 9 illustrates a code sequence 26 which is optimized. Since there is no free predicate result slot available, p3 and p6 are renamed since there is no use of these predicates. It is noted that without renaming, the initialization could not be optimized away. The optimized code sequence 26 saves two initialization instructions and reduces the critical path by one cycle.
Referring now to FIG. 10, there is illustrated a flow chart of an overview of the optimization process 30 according to one example embodiment of the invention. The process first finds a parallel compare sequence 32 in a program flow, for example using a flow graph. The guarding predicate (gp) is obtained for the compares 34 . If a new dominating predicate (dp) 36 can be found, the process proceeds to determining 38 if compares for the dp generate the correct or needed initial value for the destination predicate register of the parallel compares in 32 . If there are free result slots available 40 , the proper compares are generated and folded into the initialization 42 . If no free slots are available, it is determined if there is a use of a gp between the dp and gp 44 . If not, the dp is renamed 46 to gp, and the proper compares are generated and folded into the initialization 42 . If there is such a use, the guarding predicate of the compares is found and the process re-iterates until it ends with the failure to find a new dominating predicate dp.
Referring now to FIG. 11, there is illustrated another example embodiment of the invention wherein a compiler 50 receives a source code sequence 52 , applies the process of the invention, and outputs an optimized code sequence 54 . Another example embodiment of the invention is illustrated in FIG. 12, in which a processor system 60 includes stored therein, in temporary or permanent memory, an optimized code sequence 62 , which is in turn executed by the processor system 60 . System 60 may, in one embodiment, comprise a microprocessor, or, in another embodiment, comprise a computer system including peripheral devices including mass storage, a display device, input devices, and interconnections to a network.
Thus, there has been described above various embodiments of system, method and apparatus for optimizing parallel compares using predication. These optimizations can reduce the total number of instructions required to execute groups of instructions with parallel compares and/or reduce the number of cycles required to execute such sequences.
Claims as granted
19 claimsLog in to read the claims of this application.
Log in to unlockClassifications
4 codes- G06F9/45
- G06F9/38
Claim changes
SoonSee which claims were amended, added or cancelled during examination, with every added and removed word marked.
The published claims of this application are not paired with the granted ones in what we hold.
File wrapper
See the full prosecution history — every USPTO and applicant action on this file, in order.
Log in to unlockDocuments
Log in to open the documents of this file: the application as filed, every office action and response, the notice of allowance.
Log in to unlockChain of title
See the full assignment history — every owner this patent has passed through, with recordation dates and reel/frame numbers.
Log in to unlock