# Patent

## Title
Promoting and appending traces in an instruction processing circuit based upon a bias value

## Abstract

A method, system and computer program product for promoting a trace in an instruction processing circuit is disclosed. They comprise determining if a current trace is promotable and determining if a next trace is appendable to the current trace. They include promoting the current trace and the next trace if the current trace is promotable and the next trace is appendable.

## Background
CROSS REFERENCE TO RELATED APPLICATIONS
This application claims the benefit of priority document U.S. Provisional Application No. 60/721,385, filed on Sep. 28, 2005, entitled “Efficient Trace Cache Management During Self-Modifying Code Processing,” by Leonard Shar et al., and further claims the benefit of priority document U.S. Provisional Application No. 60/730,550, filed on Oct. 26, 2005, entitled “Checkpointing Status Flags for Atomic Traces,” by John Gregory Favor et al., and further claims the benefit of priority document U.S. Provisional Application No. 60/730,810, filed on Oct. 27, 2005, entitled “Allocation and Deallocation of Shadow Registers used by Atomic Traces,” by John Gregory Favor et al., and further claims the benefit of priority document U.S. Provisional Application No. 60/731,962, filed on Oct. 31, 2005, entitled “Determining the Highest Priority Abort Trigger in an Atomic Trace,” by John Gregory Favor et al., and further claims the benefit of priority document U.S. Provisional Application No. 60/731,785, filed on Oct. 31, 2005, entitled “Maintaining Memory Coherency within a Trace Cache,” by Richard W. Thaik, and further claims the benefit of priority document U.S. Provisional Application No. 60/732,438, filed Nov. 1, 2005, entitled “Zero-Cycle Execution of Clear Operation and Automatic Register Free,” by John Gregory Favor et al., and further claims the benefit of priority document U.S. Provisional Application No. 60/832,848, filed on Jul. 23, 2006, entitled “Microprocessor with Caches for Instructions, Basic Blocks, and Traces,” by Don Alpert et al., and further claims the benefit of priority document U.S. Provisional Application No. 60/832,822, filed on Jul. 23, 2006, entitled “Microprocessor with Coherent Caches for Basic Blocks and Traces,” by Don Alpert et al., and further claims the benefit of priority document U.S. Provisional Application No. 60/862,609, filed Oct. 24, 2006, entitled “Exception Handling for Atomic Traces,” by Christopher P. Nelson, and further claims the benefit of priority document U.S. Provisional Application No. 60/866,205, filed Nov. 16, 2006, entitled “Processor with Optimized Operation Sequences for Basic Block and Multi-Block Trace Caches,” by John Gregory Favor, and further claims the benefit of priority document U.S. Provisional Application No. 60/866,203, filed Nov. 16, 2006, entitled “Processor with Basic Block and Multi-Block Trace Caches,” by Matt Ashcraft et al. John Gregory Favor is also known as John Favor or as Greg Favor. Each of the above named priority documents is hereby incorporated by reference.
This application is a continuation-in-part of U.S. patent application Ser. No. 11/535,971, filed Sep. 27, 2006, entitled “Efficient Trace Cache Management During Self-Modifying Code Processing,” by Leonard Eric Shar et al., and is a continuation-in-part of U.S. patent application Ser. No. 11/535,972, filed Sep. 27, 2006, entitled “Selective Trace Cache Invalidation for Self-Modifying Code Via Memory Aging,” by Leonard Eric Shar et al., is a continuation-in-part of U.S. patent application Ser. No. 11/535,977, filed Sep. 27, 2006, entitled “Trace Cache for Efficient Self-Modifying Code Processing,” by Leonard Eric Shar, is a continuation-in-part of U.S. patent application Ser. No. 11/553,453, filed Oct. 26, 2006, entitled “Checkpointing Status Flags for Atomic Traces,” by Greg Favor et al., and is a continuation-in-part of U.S. patent application Ser. No. 11/553,455, filed Oct. 26, 2006, entitled “Checkpointing Flags On-Demand for Atomic Traces,” by John Gregory et al., and is a continuation-in-part of U.S. patent application Ser. No. 11/553,458, filed Oct. 26, 2006, entitled “Flag Restoration from Checkpoints for Aborts of Atomic Traces,” by John Gregory Favor et al., and is a continuation-in-part of U.S. patent application Ser. No. 11/591,024, filed Oct. 31, 2006, entitled “Maintaining Memory Coherency within a Trace Cache,” by John Gregory Favor. John Gregory Favor is also known as John Favor an Greg Favor. Each of the above named applications for which this application is a continuation in part is hereby incorporated by reference.
This application is related to U.S. patent application Ser. No. 11/941,900, filed on Nov. 16, 2007, and entitled “FLAG OPTIMIZATION OF A TRACE”, the disclosure of which is herein incorporated by reference as though set forth in full.


BACKGROUND OF THE INVENTION
Processors have evolved throughout recent decades by becoming smaller in size, more sophisticated in design and exhibiting faster performance. Such an evolution has resulted for various reasons, one of which is portability of systems incorporating processors. Portability introduces demands on processors such as smaller size, reduced power and efficient performance.
While processors have experienced tremendous advancements, the code or software program used to program them essentially uses the same code as that of its origin. The original PC-based code is referred to as the “x86” instruction code. Thus, the x 86 instruction codes remains the code largely used for programming even in the most advanced processors.
Applications of processors are, for example, in personal computers (PCs), workstations, networking equipment and portable devices. Examples of portable devices include laptops, which are portable PCs, and hand-held devices.
More advanced processors use a sequencer to sequence operations, which are translated from sequences of x86 instructions, to improve throughput and increase performance. However, current sequencing techniques leave room for improvement, as the performance improvement realized thereby does not meet the demands imposed on future processors.
Moreover, power consumption is of vital importance to systems using processors, particularly to portable systems, such as laptops or hand-held electronic devices. While power consumption has been reduced in recent processor designs, nevertheless, a need for further reduction in power consumption remains.
Due to the wide use of code based on the x86 instruction set, particularly by software programmers who have become well accustomed to this code and are not likely to readily adapt to another code, backward compatibility of code is key in the architecture of a new processor. That is, the user of a newly-designed processor must enjoy the ability to use the same code utilized in a previous processor design without experiencing any problems.
In light of the foregoing, there is a need for a processor having a trace unit (or front end) for efficiently and in an improved manner sequencing traces, to be executed by an execution unit (or back end), while improving power consumption and maintaining code backward compatibility.
SUMMARY OF THE INVENTION
To overcome the limitations in the prior art described above, and to overcome other limitations that will become apparent upon reading and understanding the present specification, the present invention discloses a method and corresponding structures for an improved trace unit.
A method, system and computer program product for promoting a trace in an instruction processing circuit is disclosed. The method, system and computer program product comprise determining if a current trace is promotable and determining if a next trace is appendable to the current trace. The method, system and computer program product include promoting the current trace and the next trace if the current trace is promotable and the next trace is appendable.
These and other objects and advantages of the present invention will no doubt become apparent to those skilled in the art after having read the following detailed description of the preferred embodiments illustrated in the several figures of the drawing.



BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1 shows a trace unit including basic block sequences of instructions, a decoder circuit, decoder sequences of operations, a basic block builder circuit, and basic block sequences of operations, in accordance with an embodiment of the present invention.
FIG. 2 shows a trace unit to include a trace cache circuit and a multi-block builder circuit, in accordance with an embodiment of the present invention.
FIG. 3 shows a processor core including a trace unit coupled to an execution unit and to a table walker (TW), in accordance with an embodiment of the present invention.
FIG. 3(a) shows an example of a basic block trace ‘ABC’, where ABC represents operations, in the basic block trace circuit.
FIG. 4 shows the overall flow of the four types of traces to the execution unit, in accordance with an embodiment of the present invention.
FIG. 5 illustrates an example format of a promotion field for a Basic Block Cache (basic block trace) entry or Multi-Block Cache (multi-block trace) entry, in accordance with the invention.
FIG. 6 illustrates another example format of a promotion field for a Basic Block Cache (basic block trace) entry or Multi-Block Cache (multi-block trace) entry, in accordance with the invention, where the 5-bit promotion value is identified as a “bias” value.
FIG. 7(a) shows, in flow chart form, the steps performed, by the sequencer circuit, when sequencing operations for a current trace.
FIG. 7(b) shows a flow chart of the steps performed by the sequencer circuit in promoting traces.
FIGS. 7(c) and (d) show examples of building multi-block trace.
FIG. 7(e) shows a flow chart of the steps performed by the sequencer circuit and the operation fetcher circuit for adding or entering a trace to the sequence buffer and fetching operations to be sent to the execution unit.



DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT
In the following description of the embodiments, reference is made to the accompanying drawings that form a part hereof, and in which is shown by way of illustration of the specific embodiments in which the invention may be practiced. It is to be understood that other embodiments may be utilized because structural changes may be made without departing from the scope of the present invention.
Referring now to FIG. 1, a trace unit is shown to include basic block sequences of instructions 1, a decoder circuit 5, decoder sequences of operations 6, a basic block builder circuit 7 and basic block sequences of operations 8, in accordance with an embodiment of the present invention. A “trace unit”, as used herein, is synonymously referred to as an “instruction processing circuit” or a “front end”. A “sequence of operations”, as used herein, is synonymously referred to as a “trace”.
The basic block sequences of instructions 1 is shown to include ‘N’ number of basic block sequence of instructions 2-4, with ‘N’ being an integer value. Each of the basic block sequence of instructions, of the basic block sequences of instructions 1, ends with, at most, one control transfer. In fact, detection of a control transfer ends a sequence of instructions or a portion thereof. A sequence of operation that is based on a sequence of instruction having at most a control transfer is a basic block. A basic block sequence of instructions alternatively ends due to capacity constraints, as discussed in further detail below.
The decoder circuit 5 receives the sequence of instructions 2-4 of the basic block sequences of instructions 1. Upon receiving the sequence of instructions 2, the decoder circuit 5 decodes the received sequence of instructions into a decoder sequence of operations (or decoder trace), which includes a sequencing action. The decoder trace is either provided to an execution unit (not shown in FIG. 1) or provided to the basic block builder 7 or both. If the decoder trace is provided to the execution unit, other than the decoding operation performed by the decoder circuit 5, no further optimization of the operations is performed. If the decoder trace is provided to the basic block builder circuit 7, further optimization of the operations, which are now included, at least in part, in a sequence of operations (or decoder trace), is performed.
The basic block builder circuit 7 builds a basic block trace (or basic block sequence of operations), which is one of the basic block traces of the M number of basic block traces 8, based on the decoder trace received from the decoder circuit 5. M is an integer value that may be the same as the value N, in which case the number of basic block sequence of instructions is the same as the number of basic block sequence of operations. Alternatively, M and N are different in value where the number of basic block sequence of instructions is different than the number of basic block sequence of operations.
While the built basic block trace includes operations from the decoder trace, various other information is included in the basic block trace, which is advantageously used to effectuate faster sequencing of operations resulting in higher trace unit performance. Furthermore, operations within a basic block trace are advantageously grouped to further increase performance.
In some cases, a basic block trace, such as one of the basic block sequence of operations 8 only include operations of one instruction, in which case the trace is referred to as a single-instruction trace.
FIG. 2 shows a trace unit 21 to include a trace cache circuit 11 and a multi-block builder circuit 19, in accordance with an embodiment of the present invention. The trace cache circuit 11 is shown to cache ‘N’ number of basic block traces 13 and ‘M’ number of multi-block traces 15, where ‘N’ and ‘M’ are each integer values. In one embodiment of the present invention, the basic block traces 13 are the basic block traces 8 of FIG. 1. However, there is no correlation between the N and M used in FIG. 1 and the N and M used in FIG. 2. That is, while the same notation is used, they may or may not be the same value and are accordingly independent of each other.
At least two traces 17 that are any combination of the basic block traces 13 and/or the multi-block traces 15 are used to build a multi-block trace by the multi-block builder circuit 19. The built multi-block trace is cached in the trace cache circuit 11. In one embodiment, the multi-block builder 19 allows for incremental builds utilizing one or more multi-block traces.
While the built multi-block trace includes operations from one or more basic block traces and/or one or more multi-block traces or a combination thereof, various other information is included in the multi-block trace, which is advantageously used to effectuate faster sequencing of operations and therefore achieve higher trace unit performance. Furthermore, operations within a multi-block trace are advantageously grouped to further increase performance.
Referring now to FIG. 3, a processor core 10 is shown to include a trace unit 12 coupled to an execution unit 14 and to a table walker (TW) 95, in accordance with an embodiment of the present invention. “Processor” as used herein is synonymous referred to as “microprocessor”. “Execution unit”, as used herein is synonymously referred to as “back end”.
The execution unit 14 generally executes a sequence of operations (also known as “sequence of code”) provided thereto, by the trace unit 12. The trace unit 12 generally builds sequences of operations for use by the execution unit. In so doing, the trace unit 12 operates to reduce the workload of the execution unit 14 by optimizing the sequence of operations in a basic block and/or multi-block trace. The trace unit 12 also attempts to sequence traces ahead of the execution unit 14 so that the execution unit 14 does not need to wait for operations to execute thereby increasing instruction execution throughput.
In accordance with an embodiment of the present invention, the trace unit 12 is shown to include an instruction cache circuit 16, a decoder circuit 18, a basic block builder circuit 20, a basic block cache circuit 22, a microcode cache circuit 24, a multi-block cache circuit 26, an operations fetcher circuit 28, a sequencer circuit 29, a branch predictor circuit 30, a sequence buffer circuit 32, a multi-block builder circuit 34, a page translation buffer (PTB) (also known as “page translation cache (PTC)”) 91 and an instruction translation look-aside buffer (ITLB) 93. The ITLB 93 of the trace unit 12 is shown coupled to the table walker 95.
In an alternative embodiment, the basic block cache circuit 22 and the multi-block cache circuit 26 collectively comprise the trace cache circuit 11 of FIG. 2.
The basic block builder circuit 20 and the multi-block builder circuit 34 are collectively referred to as a trace builder circuit 36. While the trace builder circuit 36 is a single circuit in one embodiment of the present invention, in an alternative embodiment, the trace builder circuit 36 is physically more than one circuit. For example, the basic block builder circuit 20 of the trace builder circuit 36 is a physically-separate circuit than the multi-block builder circuit 34 of the trace builder circuit 36.
While in the embodiment of FIG. 3, the basic block cache circuit and multi-block cache circuits 22 and 26 are shown to be physically separate circuits, alternatively, they may physically be the same circuit, as shown in FIG. 2.
In FIG. 3, the instruction cache circuit 16 is shown coupled to the decoder circuit 18 and, through the decoder circuit 18, receives requests from the sequencer circuit 29. The decoder circuit 18 is shown coupled to the basic block builder circuit 20 and to the operations fetcher circuit 28. The basic block builder 20 is shown coupled to the basic block trace circuit 22, the operations fetcher circuit 28 and to the sequencer circuit 29. The PTB 91 is shown coupled to the sequencer circuit 29 and is further shown to provide information to the basic block cache circuit 22 and the multi-block cache circuit 26. The PTB 91 is further shown coupled to the ITLB 93, which is shown coupled to the table walker 95 and the decoder circuit 18.
The multi-block builder circuit 34 is shown coupled to the operations fetcher circuit 28 for receiving traces used to build a multi-block trace. Optionally, the multi-block builder circuit 34 is coupled to the basic block cache circuit 22 and the multi-block cache circuit 26 for receiving traces used to build a multi-block trace.
The operations fetcher circuit 28 is shown coupled to the microcode cache circuit 24, the basic block cache circuit 22, the multi-block cache circuit 26, the sequence buffer circuit 32 and the decoder circuit 18. The sequencer circuit 29 is shown coupled to the branch predictor circuit 30, the multi-block trace circuit 26, the microcode cache circuit 24 and the basic block cache circuit 22. The operations fetcher circuit 28 is shown coupled to the execution unit 14.
The instruction cache circuit 16 is a cache, which is a known form of memory, and is generally used to store instructions for optimization by the trace unit 12 before execution thereof by the execution unit 14. The instruction cache circuit 16 provides the stored sequence of instructions to the decoder circuit 18. Instructions, as are referred to herein, are any Reduced Instruction Set Computer (RISC)- or Complex Instruction Set Computer (CISC)-based instruction code, such as but not limited to the x86 instruction code.
The decoder circuit 18 receives the sequence of instructions from the instruction cache circuit 16 and decodes the received sequence of instructions into a sequence of operations.
In one embodiment of the present invention, the decoder circuit 18 is operable to detect a decode time instruction mode that is one of a plurality of instruction modes, and based, in part, on the decode time instruction mode, the decoder circuit 18 decodes the sequence of instructions into a decoder trace.
A decoder trace is based on the sequence of instructions from the instruction cache circuit 16. During decoding, the instruction mode is detected and embedded into the decoder trace. An instruction mode includes information such as the number of parallel bits used in the architecture of the processor core, such as 16 parallel bits vs. 32 parallel data bits vs. 64 parallel bits, which are referred to as 16-bit mode, 32-bit mode, or 64-bit mode, respectively. Alternatively, any other parallel number of bits may be used by the processor core.
Information, in an instruction mode, other than the number of parallel bits used by a processor core, include default data size, default stack size, relative addressing modes, whether a data segment is good or bad and whether or not data is used and any other information relevant to the decoding of instructions.
Optimization generally causes operations within the sequence of operations to be re-ordered and serves to reduce the workload of the execution unit 14. Basic block traces, which are at least, in part, based on the sequence of instructions generated by the instruction cache circuit 16, are further optimized. Multi-block traces, which are based on basic block traces or multi-block traces or any combination thereof are still further optimized. One reason for further optimization of a multi-block trace relative to a basic block trace is its size. Multi-block traces are typically longer sequences of operations than basic block traces and in this respect, there are more ways of re-arranging operations to cause further optimization thereof.
Optimization of basic block and multi-block traces is similar. An alternative embodiment may use dissimilar optimization, such as complementary optimization.
Exemplary optimization techniques used by the embodiment of FIG. 3 include elimination or removal of certain operations, which essentially serves to reduce the execution unit 14's workload, removal of dependencies between operations, which also essentially serves to reduce the execution unit 14's workload; and more efficient grouping or packing of operations, which essentially benefits the efficiency of the trace unit 12, by causing more compact or denser traces to be built.
An example of elimination of certain operations includes removing dead code or code that does not offer any value if executed. In one embodiment of the present invention, grouping of operations is done by the use of operation “triplet”, as will be discussed with reference to subsequent figures.
In an exemplary embodiment, all traces are executed atomically, i.e. completely executed or completely aborted. When a trace is aborted, none of the operations within the trace have any effect on the architectural state. In other words, trace execution is atomic in that the trace's effects are either committed in their entirety to the architectural state, or prevented in their entirety from having any impact on the architectural state.
If a trace is aborted, the architectural state of the various components of the trace unit 12 and the execution unit 14 are returned to their states as they were prior to the start of the trace. Architectural state is commonly understood as the part of the processor core which holds the state of a process, such as the state of control registers or general purpose registers.
The multi-block builder circuit 34 receives basic block and multi-block traces for building a multi-block trace. In one embodiment of the present invention, the multi-block builder circuit 34 is coupled to the operations fetcher circuit 28 for receiving the basic block and multi-block traces. Alternatively, the multi-block builder circuit 26 receives basic block and multi-block traces from the basic block cache circuit 22 and the multi-block cache circuit 26, respectively.
In one embodiment of the present invention, the sequencer circuit 29 operates to select a next sequence of operations from among the decoder sequence of operations (or traces), the basic block sequence of operations (or traces), and the multi-block sequence of operations (or traces). In an alternative embodiment of the present invention, the sequencer circuit 29 sequences the next microcode trace, to be executed by the execution unit 14, by addressing the next microcode trace in the microcode cache 24. Upon identifying the next microcode trace, the microcode cache circuit 24 provides the next microcode trace to be executed to the execution unit 14 for execution thereof.
In operation, the sequencer circuit 29 determines the order in which traces are sent to the execution unit 14 and which traces to promote, which traces to combine ops fetcher circuit 28, and fetches operations from any of the sources: the decoder circuit 18, the basic block cache circuit 22, the multi-block cache circuit 26; or the microcode cache circuit 33, to send to the execution unit 14. At the same time the ops fetcher circuit 28 is sending the fetched operations to the execution unit 14, it also sends the fetched operations to the one or both of the builder circuits 20 and 34.
A microcode trace is used when, for example, a sequence of instructions is either complex or rare. The execution of rare instructions need not be efficient. Certain complex instructions, such as “string manipulation” need to be optimized, and are done so manually into microcode traces. During manual optimization, the objective is to try to make the operations compact or create traces that include the least number of operations possible.
An example of a microcode trace is based on segmentation changing code known to be used by x86 code programmers. In the case of segmentation changing code, microcode traces, rather than decoder, basic block or multi-block traces are used and no additional optimization thereof is performed.
A microcode trace is generally not desirable from a performance standpoint because a single instruction can correspond to multiple traces, which degrades performance efficiency. Accordingly, microcode traces are advantageously optimized to execute as fast as possible so as to mitigate performance hits associated therewith.
A microcode trace is represented by a sequencing action. That is, the decoder circuit 18 determines that a sequencing action is microcode and terminates a current basic block trace. Upon termination of the current basic block trace, by the decoder circuit 18, a sequencing action results in a ‘call’ to a microcode trace identified at a particular address in the microcode cache circuit 24. The microcode trace is retrieved, from the microcode cache circuit 24, by the operations fetcher circuit 28 and is provided, by the operations fetcher circuit 28, to the execution unit 14 for execution thereof.
Thereafter, either the sequencer circuit 29 sequences the next basic block trace, another trace, or additional microcode traces are sequenced and executed.
The sequencer circuit 29 performs various critical functions. Among which, identifying the next trace to be executed by the execution unit 14, and in doing so the trace unit 12 decouples the sequencing time from the execution time. The sequencing rate refers to the number of clock cycles used for sequencing a next trace. A typical sequencing rate is once every four clock cycles although in other embodiments other sequencing times are employed. A “cycle”, as used herein, refers to a clock cycle.
In one method and embodiment of the present invention, the sequencer circuit 29 sequences ahead of the execution unit 14 and instructs the branch predictor circuit 30 to predict all predictions associated with a sequencing action. The next address resulting from a sequencing action is predicted by the branch predictor circuit 30. A predicted result is also known as a “projected result”.
FIG. 3(a) shows an example of a basic block trace ‘ABC’, where ABC represents operations, in the basic block cache circuit 22. The trace ABC includes a TA that points to trace ‘DEF’ and a sequential address (SA) that points to trace ‘GH’. Trace ABC is stored in the basic block cache circuit 22 from which multiple multi-block traces ‘ABCDEF’ and ‘ABCGH’ are built and stored in the multi-block cache circuit 26.
The built multi-block trace ABCDEF represents a sequence of operations that represents a sequence of instructions. The sequence of operations, represented by the trace ABCDEF, is independent of the operations ABC and DEF, it is rather, based on the sequence of instructions from which ABC and DEF are built. This similarly applied to multi-block trace ABCGH. That is, the sequence of operations, represented by the trace ABCDGH, is independent of the operations ABC and GH, it is rather, based on the sequence of instructions from which ABC and GH are built.
Each of the traces ABCDEF and ABCGH is referred to as an ‘alternate’ trace and obviously includes a different predicted address. Additional multi-block traces may be built if there are further branches that can be taken after each set of operations ‘DEF’ or GH. The multi-block traces ABCDEF and ABCGH are both associated with a single basic block trace, i.e. trace ABC. The built and unused traces are invalidated, or not, depending on the design choices employed, such as the rules for invalidation of traces. The foregoing example of more than one trace with a predicted result obviously requires a higher capacity cache circuit, as all built traces or at least a subset thereof, are stored in a cache circuit.
Referring back to FIG. 3, the sequencer circuit 29 also decides whether or not to promote a trace, to validate a trace, and whether or not a trace is obsolete. Validation of a trace includes ensuring proper instruction mode of the trace. That is, during decoding of instructions by the decoder circuit 18, the instruction mode that is used to decode the instructions is noted and embedded in the trace being built. In one embodiment of the present invention, the instruction mode used to decode the instructions of a trace is in the trace verification information part of the trace. During trace validation, the current instruction mode of the processor core is verified against the actual instruction mode that was used during building of the trace being verified. If this verification proves to be unsuccessful, i.e. the current instruction mode of the processor core is not found to match the actual instruction mode that was used during building of the trace, the trace is invalidated. If not, the trace is identified as a valid trace, at least as to its instruction mode. There are other reasons for invalidation a trace; one such reason is if one or more instructions, which form the basis of a trace, are modified. Other reasons will be noted herein in the context in which they arise.
Verification of a trace refers to a trace being validated or trace validation.
Invalidation of a trace results in preventing (also known as “blocking”) the trace from being executed by the execution unit 14.
Alternatively, the instruction mode is reflected by a flag that is part of the trace and stored in a cache circuit.
The sequencer circuit 29 also activates the decoder circuit 18 and possibly the basic block builder circuit 20, to build a basic block trace in the event a trace is determined to not exist in the basic block trace circuit nor in the multi-block trace circuit, and is further discussed relative to subsequent figures. In the event a trace is determined to not exist, bypass mode is recognized in one embodiment of the present invention. The sequencer circuit 29 also serves to update information in the branch prediction circuit 30, which, at times, requires cleanup when the branch prediction circuit 30 has inaccurately predicted.
Due to the inclusion of a variety of information within a trace, the sequencer circuit 29 can advantageously afford to operate at a slower rate, which promotes power savings. Additionally, the branch predictor circuit 30 is advantageously afforded more sophistication thereby improving branch prediction accuracy and sequencing. Moreover, use of multi-block traces as often as is typically done lowers the demands on the sequencer circuit 29. It has been shown that during operation of the processor core 10, approximately 85% of instructions are from traces in the multi-block trace circuit 26.
The goal of the trace unit 12 is generally to keep the execution unit 14 busy to the extent where the latter is used substantially optimally. One of many of the ways in which this is accomplished is by providing decoder traces to the execution unit 14 when the operations fetcher circuit 30 is not providing traces to the execution unit 14. More specifically, a decoder trace is “bypassed” to the operations fetcher circuit 28 if the latter has no other traces to send to the execution unit 14 and the next trace should be from the decoder circuit 18.
In operation, the sequencer circuit 29, using the branch predictor circuit 30, is configured to generate a prediction for the result of a particular control transfer instruction, and to select, based on the predicted result, a next sequence of the operations to be provided to the execution unit 14. The sequencer circuit 29, then, operates to provide an indication of the next sequence of operations to the instruction cache circuit 16, the basic block cache circuit 22, and the multi-block cache circuit 26.
The instruction cache 16, the decoder circuit 18, and the basic block cache circuit 22 are also configurable such that the instruction cache 16 provides zero or more program instructions to the decoder circuit 18. An example of zero program instructions is the case of error handling, in which case no program instructions are provided to the decoder circuit 18.
The sequencer circuit 29 determines the next sequence of operations to be executed by first checking for the latter in the basic block cache circuit and multi-block cache circuits 22 and 26. If the next trace is not found in either of the basic block cache circuit and multi-block cache circuits 22 and 26, the sequencer circuit 29 resorts to the instruction cache 16 for instructions, which are decoded by the decoder circuit 18, i.e. as a decoder trace, as the next trace to be executed.
In an alternative embodiment of the present invention, the basic block cache circuit 22, the multi-block cache circuit 26 and the instruction cache circuit 16 are accessed substantially simultaneously. In this embodiment, while performance improves, power consumption is increases.
When a trace in a cache circuit is found, this is referred to herein as a ‘hit’ and when a trace is not found in a cache circuit, this is referred to as a ‘miss’.
As previously noted, there are generally four types of traces (or sequences of operations) that are generated by the trace unit 12. One such type is a decoder trace (or decoder sequence of operations), generated by the decoder circuit 18. Another such type is a basic block trace (or a basic block sequence of operations) generated by the basic block builder circuit 20. A third type of trace is a multi-block trace (or multi-block sequence of operations) generated by the multi-block builder circuit 34. Yet a fourth and optional type of trace is a microcode trace (or microcode sequence of operations).
A memory controller, located externally to the processor core 10, receives instructions stored in its memory and provides information, such as microcode instructions. Alternatively, the memory controller and its memory may be included in the same semiconductor device that houses the trace unit 12.
In one embodiment of the present invention, basic block, multi-block, and microcode traces are cached. In an alternative embodiment thereof, in addition to basic block, multi-block and microcode traces being cached, decoder traces are also cached. An average multi-block trace includes four and a half basic block traces and a typical basic block trace includes five x86 instructions, in the case where x86 instructions are used. It is understood that the foregoing are merely exemplary trace sizes and other sizes thereof are contemplated.
The basic block builder circuit 20 is operable to receive at least a portion of the decoder trace that is generated by the decoder circuit 18, and to generate, based thereon, a basic block trace, and to provide the built basic block trace to the basic block cache circuit 22. At least a portion of the decoder trace represents a portion of the sequence of instructions received by the decoder circuit 18, where the received portion of the sequence of instructions includes, at most, one control transfer instruction that, when present, ends the portion of the sequence of instructions. A control transfer instruction is an instruction that directs the flow of instructions in a sequential or non-sequential order.
Examples of control transfer instructions include, but are not limited to, a ‘JUMP’ instruction, or a ‘BRANCH’ instruction. In this manner, the first encountered control transfer, in the received portion of sequence of instructions, is used to denote the end of the basic block unless capacity constraints are used to do so. Upon detection of the end of a basic block, the decoder circuit 18 provides the basic block to the basic block builder 20 for building a basic block trace.
In one embodiment of the present invention, the basic block builder circuit 20 builds a basic block trace through one or more unconditional control transfer instructions. Examples of such unconditional control transfer instructions include unconditional jumps or unconditional subroutine calls. Examples of conditional control transfer instructions include indirect branches, conditional branches and conditional subroutine calls. In so doing however, it is preferable to apply certain restrictions to the basic block trace, such as restricting the resultant trace to have a sequential next trace address that is effectively managed by the trace unit 12 and to restrict the resultant trace to span a manageable number of PTB pointers, which are discussed in further detail below.
A basic block trace is at least a portion of the sequence of operations received from the decoder circuit 18, which is based on a basic block, which ends by the control transfer instruction. Alternatively, the basic block trace ends due to a capacity constraint.
After the building of a basic block trace, the basic block builder circuit 20 provides the built basic block trace to the basic block cache circuit 22 for caching thereof. The built trace is executed by the execution unit 14. In the embodiment where multiple multi-block traces are built, each based on a unique prediction, a number of alternate traces associated with the same sequence of instructions, may be maintained. To accomplish the foregoing, however, the multi-block cache circuit 26 is required to be large enough, in capacity, to accommodate additional traces.
One of the ways in which traces are optimized is by eliminating “NOP” or “no operation” operations, which are readily generated by the decoder circuit 18 when decoding instructions. The basic block builder circuit 20 and the multi-block builder circuit 34 automatically remove as many NOPs as possible. Removal of unnecessary NOPs results in efficient use of the basic block cache circuit 22 and the multi-block cache circuit 26.
Multi-block traces are invalidated for various reasons. One of which is when a multi-block trace includes one or more mis-predicted interior branches (or mis-prediction). An example of a mis-predicted branch is the result of a ‘jump’ or non-sequential instruction, such as conditional control transfer, where the result is a target address erroneously predicted to be the result of the control transfer. In such a case, the multi-block trace is invalidated.
The basic block builder circuit 20 is coupled to the basic block trace circuit 22 and provides basic block traces, after having built them, to the basic block trace circuit 22 for caching thereof. The basic block builder circuit 20 receives decoder traces and uses them to build a basic block.
Similarly, the multi-block builder circuit 34 is coupled to the multi-block trace circuit 26, and provides multi-block traces, after having built them, to the multi-block trace circuit 26 for caching thereof. The multi-block builder circuit 34 uses basic block traces from the basic block cache circuit 22, or multi-block traces from the multi-block cache circuit 26, or a combination thereof, to build a multi-block trace.
The hardware described above, including any logic or transistor circuit, may be generated automatically by computer based on a description of the hardware expressed in the syntax and the semantics of a hardware description language, as known by those skilled in the art. Applicable hardware description languages include those provided at the layout, circuit netlist, register transfer, and schematic capture levels. Examples of hardware description languages include GDS II and OASIS (layout level), various SPICE languages and IBIS (circuit netlist level), Verilog and VHDL (register transfer level) and Virtuoso custom design language and Design Architecture-IC custom design language (schematic capture level). The hardware description may also be used, for example, in various behavior, logic and circuit modeling and simulation purposes.
FIG. 4 shows the overall flow of the four types of traces to the execution unit 14, in accordance with an embodiment of the present invention. As shown in FIG. 4, the operations fetcher circuit 28 is operable to receive the four types of traces, i.e. decoder trace 103, basic block trace 31, multi-block trace 35 and microcode trace 33, from various sources. The microcode cache circuit 24 is shown to receive a microcode trace 47 from the externally-located memory controller. The microcode trace 47 is cached in the microcode cache circuit 24 and when it is accessed, it is provided as microcode trace 33. The decoder trace 29 is shown provided, by the decoder circuit 18, to the operations fetcher circuit 28. The basic block trace 31 is shown, provided by the basic block trace circuit 22, to the operations fetcher circuit 28. The multi-block trace 35 is shown provided, by the multi-block trace 26, to the operations fetcher circuit 28. The microcode trace is shown provided, by the microcode cache circuit 24, to the operations fetcher circuit 28. The operations fetcher circuit 28, as directed by the sequencer circuit 29, selects one of the four traces and provides the selected trace as the next trace to be executed by the execution unit 14.
A multi-block trace is a trace that is built from one or more basic block traces or one or more multi-block traces or a combination thereof. A basic block trace is promoted into a multi-block trace for various reasons, one of which is the number of times a basic block trace has been executed. A multi-block trace represents the first portion of the sequence of instructions, as does a basic block trace, however, a multi-block trace is further optimized and allowed to continue past a control transfer instruction. That is, a multi-block trace combines at least two traces by continuing past control transfer instructions. Thus, the trace unit 12 optimizes across a control transfer instruction whereas known prior art methods of optimization, such as software compilers, are generally incapable of optimizing across conditional control transfer instructions because they are ignorant as to which way the branch instruction will go.
During the building of a multi-block trace, the sequencer circuit 29 provides promotion information, or ‘bias’, to the multi-block builder 34. In an exemplary embodiment of the present invention, bias is represented in the form of a flag.
To build a multi-block trace from a basic block trace, the latter would have to be promoted. Promoting a basic block trace occurs when the number of times a branch instruction has been consistently noted to have branched to the same target address, as reflected by bias, is equal to or exceeds a promotion threshold (or predetermined value). Promotion occurs when it is more efficient for a trace to be combined with other traces for execution. A trace is promoted if its bias is the same or higher than the promotion threshold and if its final control transfer is predictable. The test for comparing a trace's bias to the promotion threshold may alternatively, result in promotion of the trace if the trace's bias is higher than the promotion threshold or the trace's bias is less than the promotion threshold or the trace's bias is less than or equal to the promotion threshold. Promotion threshold is a dynamically alterable value, yet, in an alternative embodiment, it may be fixed.
Promotion of a basic block trace and a multi-block trace are substantially the same. Multi-block trace optimization, however, tends to be more effective than basic block trace optimization because larger chunks of operations are combined in a multi-block trace, therefore, leaving more opportunity for optimization in the form of internal rearrangement of the operations. To describe the features of promotion refer now to the following description in conjunction with the accompanying Figures.
Promotion
FIG. 5 illustrates an example format of a promotion field for a basic block trace entry or multi-block trace entry, in accordance with the invention. When a basic block trace or multi-block trace entry is first allocated, the promotion direction is set to an initial value that, for example, can always be taken, always not taken, a statically predicted value, or a dynamically predicted value. The 5-bit promotion level is initialized to 0.
When a basic block trace is executed, execution unit reports the outcome of the terminating branch, if any, to trace unit. Similarly, when a multi-block trace is executed, execution unit reports the outcome of all interior and terminating branches to trace unit. When execution unit reports that the terminating branch of a basic block trace or all branches of a multi-block trace have been correctly predicted, trace unit increments the promotion level of the corresponding entry. If the promotion level has reached the maximum level, which in this case is 31, the basic block trace or multi-block trace is promoted, and the promotion level is reset to 0. Alternatively, when execution unit reports that the terminating branch of a basic block trace or multi-block trace has been incorrectly predicted, trace unit resets the promotion level of the corresponding entry to 0. If an interior branch of a multi-block trace has been incorrectly predicted, trace unit may invalidate the trace.
Certain aspects of program behavior are addressed by various alternate embodiments. For example, it is observed that performance can be improved by promoting a trace after fewer correct predictions when the trace is initially allocated than when the trace has previously been mispredicted. To this end, an alternate embodiment initially sets the promotion value to a number biased toward the maximum. For another example, performance can also be improved when multiple iterations of a loop are combined quickly to form a trace, a process known as “loop unrolling.”
FIG. 6 illustrates another example format of a promotion field for a basic block trace entry or multi-block trace entry, in accordance with the invention, where the 5-bit promotion value is identified as a “bias” value. When a basic block trace entry or multi-block trace entry is first allocated, the bias value is set to a special attribute value near the maximum, such as 30. If trace unit identifies that the entry has this special attribute value when execution unit reports the outcome for the terminating branch for a basic block trace or multi-block trace entry, then trace unit sets the promotion history field D-bit to indicate the direction of the branch and sets the bias value to a predetermined “Initial Bias Level,” such as 15. From this state, when execution unit reports that the terminating branch of a basic block trace or all branches of a multi-block trace have been correctly predicted, trace unit increments the promotion level of the corresponding entry. If the bias value has reached a predetermined “Promotion Bias Level,” such as 20, the basic block trace or multi-block trace is promoted. From this state, when execution unit reports that the terminating branch of a basic block trace or all branches of a multi-block trace have been correctly predicted, trace unit continues to increment the promotion level of the corresponding entry and to promote the basic block trace or multi-block trace until the bias level reaches a predetermined “Max Bias Level,” such as 25, at which point the bias level transitions to a predetermined “Reset Bias Level,” such as 5. Alternatively, when execution unit reports that the terminating branch of a basic block trace or any branch of a multi-block trace has been incorrectly predicted, trace unit resets the bias value of the corresponding entry to the Reset Bias Level. For this scheme, a loop that is consistently executed will be unrolled five times, after which further unrolling is inhibited.
With this alternate scheme, the bias value encodings that are greater than the Max Bias Level are reserved for Special Trace Attributes. One such special attribute is used for the first execution of a trace, as explained above. A second special attribute can be used to form traces with indirect branches. When a basic block trace that is terminated by an indirect branch is first executed, the promotion bias is initialized to this special attribute and a special operation, called newipassert, is appended to the basic block trace to specify the trace target address to be the next sequential address. When a newipassert operation is executed, execution unit checks whether the actual target address matches the basic block trace's target address, and reports the result to trace unit. If trace unit determines from the special attribute that this is the first execution of the indirect branch, trace unit sets the bias value to Initial Bias Level. In addition, if the indirect branch has been mispredicted, trace unit updates the target address of the block to the actual address reported by execution unit. In this manner, a basic block trace that is terminated by an indirect branch with a consistent target address can be promoted like a conditional branch.
It is possible to use different special attributes to indicate whether a block that is first being executed is terminated by a conditional or unconditional branch. Although an unconditional branch is known to be consistently taken, it may not be effective to from a trace from the block and its successor until the block is determined to be “hot”; that is, the basic block trace is known to be frequently executed. Therefore, after the first execution of a basic block trace terminated by an unconditional branch, the bias value may be set to a different, higher value than the Initial Bias Value used for conditional branches. Other special attributes can be used to indicate that a trace should not be promoted because it contains a non-cacheable reference or is already full.
One or more of the special attributes can be used to introduce hysteresis into the trace invalidation process so that two or more trace mispredictions must occur before the trace is invalidated. For example, when the bias level is in the range between Reset Bias Level and Max Bias Level and an interior branch of a trace has been incorrectly predicted, trace unit sets the bias value to a special attribute and keeps the trace valid. From this state, if execution unit reports that all interior branches of the trace have been correctly predicted, the bias value is set to Reset Bias Level or another predetermined value. Alternatively, if an interior branch is mispredicted, trace unit invalidates the trace.
Bias values between 0 and Reset Bias Level can also be used for special purposes. In one embodiment these values are used to indicate that a trace should be executed non-speculatively. For example, when an instruction performs a non-cacheable memory reference, the memory reference should not be performed out of order from other memory references. In addition, the instruction should not be executed speculatively; that is, the instruction should not be executed until any control dependencies and exceptions are resolved. When such a non-cacheable reference is detected, the single instruction that performs the reference can be placed in a basic block trace entry with a special bias level, such as 1. If the instruction of the basic block trace entry is later executed again, the memory reference may be cacheable, for example if the address differs from prior execution. In such a case, trace unit increments the bias level. If the instruction is then executed several consecutive times with a cacheable reference, the bias level may be incremented to reach the Reset Bias Level. Then if the instruction is again executed, trace unit recognizes the bias level is no longer a special value, and that the instruction can be combined with others to form a multi-instruction basic block trace entry. Similarly, such special bias values can be applied to instructions with microcoded sequences. For example, a special bias value for a basic block trace entry can indicate whether a speculative or non-speculative microcoded sequence should be executed.
In the embodiment described above, when a trace is formed and allocated to an multi-block trace entry, the promotion field bias value is set to a special value. In an alternate embodiment, the direction and bias value can be initialized to (or “inherited” from) that of the final basic block trace or multi-block trace entry used to form the trace. In this way, the history of the trace's terminating branch will be retained.
In another embodiment, trace unit can recognize high bias values, for example those between Initial and Max Bias Levels, to determine that the terminating branch of a basic block trace or multi-block trace entry is executed very consistently. In such a case, trace unit can use the bias level to predict the branch instead of using BRANCH PREDICTION. In this manner, aliasing with other branches in BRANCH PREDICTION can be reduced, and branch prediction accuracy can be increased.
The embodiments described above used fixed values for Reset, Initial, Promotion, and Max Bias Levels. In an alternate embodiment, one of more of those values can be programmable, for example to one or more values initialized at reset or by software control. In yet another embodiment, one or more of those values can be adaptable. For example, as the frequency of trace invalidations increases, the trace unit can raise the Promotion Bias Level. In this manner, the threshold for promoting traces will become higher, and traces that are promoted are then less likely to be invalidated. For another example, a short, backward branch often indicates a small loop that can be beneficially unrolled. When trace unit recognizes that a basic block trace entry is terminated by such a branch, trace unit can set the Initial Bias Level to a higher value than for other branch types. For a third example, trace unit can apply a higher Promotion Bias Level for traces with more internal conditional branches in order to maintain a high overall prediction accuracy for longer, more complex traces.
The promotion threshold is programmably alterable to adjust the sequencing of trace to the environment in which the processor core 10 is being used. For example, in the case where the environment is one where too many mis-predictions occur, the promotion threshold is increased to more selectively build traces. An example of a mis-prediction is when the interior control transfer indicates a branch that is erroneously taken. In the case where not enough traces are built, as reflected in the lack of efficient utilization of the cache circuits, promotion threshold is decreased allowing for more traces to be sequenced. This might occur after power-up of the processor core 10. A basic block trace is promoted to a multi-block trace when its bias meets or exceeds a threshold (or predetermined) value, as reflected by its bias. To illustrate the promotion of traces in a process flow refer now to the following.
FIG. 7(a) shows, in flow chart form, the steps 100 performed, by the sequencer circuit 29, when sequencing a current trace. A current trace is a trace that is being currently sequenced.
At step 105, the sequencing operation of the current trace starts. Next, at step 102, the operation, within the current trace, that represents the first instruction of the sequence of instructions corresponding to the current trace is used as the trace address to find a matching address in the basic block cache circuit or multi-block cache circuits 22 and 26. A trace address is the address of the first instruction appearing in the trace. This is done to essentially locate the current trace in either of the basic block or multi-block trace circuits.
At 104, a determination is made as to whether or not the current trace is found in either of the basic block cache circuit or multi-block cache circuits. If the current trace is determined to have been located in the multi-block cache circuit 26, the process continues to 108 where trace verification is performed and the found trace is verified, or not. If the trace is not successfully verified, the trace found in the multi-block cache circuit 26 is invalidated at step 114.
On the other hand, if the found trace is successfully verified, the process continues to step 130 where a flag is entered into the sequence buffer 32 indicating whether or not the current trace's final branch is predictable enough to promote the found trace into a new multi-block trace. Next, at step 132, the found multi-block trace is entered in the sequencing buffer 32. Next, step 122 is performed where a determination is made as to which trace is the next trace to be sequenced based on the sequencing information included within the current trace and the result(s) produced by the branch predictor circuit 30.
If at 104, the current trace is found in the basic block cache circuit 22 but not the multi-block cache circuit, the process continues to 110 where the found basic block trace is verified and if unsuccessfully verified, the process continues to the step 112 where the found basic block trace is invalidated in the basic block cache circuit 22. If the found basic block trace is successfully validated at step 110, the process continues to step 120.
At step 120, the sequencing buffer 32 is flagged with whether or not the final branch of the current trace, as evidenced by a representation of the final control transfer instruction, is predictable enough to promote the current trace. That is, a promotion flag indicative of the promotion status of the current trace is stored in the sequencing buffer 32. Next, at step 116, the basic block trace is entered into the sequencing buffer 32 and the process continues to and performs step 122.
After steps 114 and 112, the process returns to step 102 where the current trace is attempted to be found in the basic block cache circuit or multi-block cache circuits again.
In the event no hit is detected of the cache circuits 22 and 26, i.e. the current trace is not found in either of the cache circuits, the process continues to step 106 from 104 where a decoder trace is formed by activating the decoder circuit 18, which decodes instructions starting from the current trace's starting address until a capacity constraint or a representation of a control transfer instruction is detected, either of which denotes the end of the decoder trace. After the step 106, at 118, a determination is made as to whether or not the sequencing operation is far enough ahead of the execution unit 14 to keep the latter busy and if the determination proves to be false, step 128 is performed. If the determination at 118 proves to be true, step 124 is performed.
At step 128, the bypass mode (or path) is activated followed by performance of the step 122.
If at 118, it is determined that the sequencing operation is far enough ahead of the execution unit 14 to keep the latter busy, step 106 is performed followed by the step 124. At step 106, a decoder trace is formed by activating the decoder circuit 18, which decodes instructions starting from the current trace's starting address until a capacity constraint or a representation of a control transfer instruction is detected, either of which denotes the end of the decoder trace. After the step 106, at step 124, the sequencer circuit 29 instructs the basic block builder circuit 20 to build a new basic block trace. Next, at step 126, the newly-built basic block trace is entered into the sequencing buffer 32. Next, step 122 is performed.
After step 122, the sequencing of the current trace is complete and at step 134, the sequencer circuit 29 advances to sequencing of the next trace.
FIG. 7(b) shows a flow chart of the steps 140 performed by the sequencer circuit 29 in promoting traces.
In FIG. 7(b), at step 142, a determination is made as to whether or not the current trace is promotable based on its bias. That is, if the bias of the current trace is equal to or greater than a promotion threshold, the process continues to step 146 and if not, the process continues to step 144 where the current trace is added to the sequencing buffer 32 and the next trace is sequenced. Alternatively, the determination of the comparison of the bias to the promotion threshold may be made if the bias is less than the promotion threshold or less than or equal to the promotion threshold or greater than the promotion threshold.
If at 142, it is determined that the current trace is promotable, promotion of the current trace occurs as follows. First, at step 146, the current trace is added to the sequencing buffer 32 and marked as promoted and further marked as the first trace of a potential multi-block trace built therefrom and the next trace is sequenced.
Next, at step 148, a determination is made as to whether or not a newly-arrived trace, which is now the current trace is appendable and promotable. The trace is added or entered into the sequence buffer 32 and marked as promoted, at step 152 if the trace is determined to be appendable and promotable, and if not, it is determined if the current trace is appendable at step 154. If the current trace is appendable the trace is added to the sequence buffer 32, marked as promoted and the process sequences to the next trace at step 150. Thereafter the process returns to step 142. If the trace is not appendable then the trace is added to the sequence buffer 32 and the process sequences to the next trace at step 156. Thereafter the process returns to step 142.
It should be noted that while bias is one of the factors used to determine promotability, other factors may be employed, such as the trace being non-speculative, too many interior control transfer instructions and others.
FIGS. 7(c) and 7(d) show examples of building multi-block trace. In FIG. 7(c), the example 160 shows a trace A 162, a trace B 164 and a trace C 166 that are combined to build the multi-block trace. The trace 162 is shown to include operation sequence A 168, the trace 164 is shown to include operation sequence B 170 and the trace 166 is shown to include the operation sequence C 172.
The trace 162 is further shown to include a bias 174, the trace 164 is further shown to include a bias 176, and the trace 166 is further shown to include a bias 178. The bias of traces 162 and 164 are each the value 17 and the bias of trace 166 is the value 5. The promotion threshold value is set to 17, thus, as the traces 162 and 164 have biases with values equal to the promotion threshold, i.e. 17, these traces are promoted but the trace 166, having a bias with a value less than 17 is not promoted; yet the latter is included in the built multi-block trace because it is appendable to the end of trace 164. The traces 162, 164 and 166 are thus retrieved by the multi-block builder circuit 20 (or the multi-block builder circuit 34) from the output of the operations fetcher circuit 28 and the former builds the new multi-block trace 180. Any of the traces 162, 164 or 166 may be a basic block trace or a multi-block trace. The trace 180 is shown to include an operation sequence ABC 182 that represents the sequences A, B and C of traces 162, 164 and 166, respectively, and a bias 184 with a value of 5, which prevents it from being promoted yet.
While the multi-block trace 180 is shown to have a bias 184 in FIG. 7(c), in some cases an initial bias is assigned to the bias 184, which may be a fixed (or static value) or a configurable alterable value.
Dynamic analysis refers to analyzing promotability and updating bias accordingly. Static analysis refers to fixing bias.
Referring now to FIG. 7(d), another example 186 of building a multi-block trace 206 is presented. In the example 186, trace X 188, trace Y 190 and trace Z 192 are potential candidates for building the trace 206 and the promotion threshold is set to 17, as in the example of FIG. 7(c). The trace 188 is shown to have a bias 200, which is set to 17 and the trace 190 is shown to include a bias 202, which is shown set to 17.
But the bias 204, of the trace 192, is a “non-speculative” flag indicating that the trace 192 is not to be appended or promoted. The trace 188 is shown to include operation sequence X 194, the trace 190 is shown to include operation sequence Y 196, and the trace 192 is shown to include operation sequence Z 198.
The traces 188 and 190 are combined by the multi-block builder 34 to build the trace 206, which includes the operation sequence representing the sequences X and Y only, and not including the sequence Z of the trace 192 because the latter is not appendable and it has the certain condition referred to relative to the step 154 of FIG. 7(b). The bias 210 of the trace 206 is shown to be set to 17, nevertheless, it is not promoted and may or may not be promoted in the future, but it is stored in its corresponding cache circuit.
FIG. 7(e) shows a flow chart of the steps 220 performed by the sequencer circuit 29 and the operation fetcher circuit 28 for adding or entering a trace to the sequence buffer 32 and fetching operations to be sent to the execution unit 14.
In FIG. 7(e), the step 222 is performed, by the sequencer circuit 29, adding a trace to the sequence buffer 32. This step is the same as either of the steps 132 or 116 of FIG. 7(a). Next, the address of the added trace is held in the sequence buffer 32 until the execution unit 14 is ready for more operations. Next, the step 224 is performed by the operations fetcher circuit 28. Steps 224, 226, 228 and 230 are performed by the operations fetcher circuit 28. At step 224, the sequence buffer 32 is read for the address of the next trace to fetch. Next at 226, a determination is made as to whether or not the trace is marked as promoted and if so, the process continues to step 228 and if not, the process continues to step 230. At step 228, operations are fetched, by the operations fetcher circuit 28, and sent to the multi-block builder circuit 34 and to the execution unit 14 and the process then continues to the step 224.
If at 226, it is determined that the trace is not marked as being promoted, the process continues to step 230 where the operations fetcher circuit 28 fetches operations and sends the fetched operations to the execution unit 14 after which the process continues to step 224.
Bias, as previously discussed, is a count of the number of times a branch has been consistently taken the same way and is variably alterable. During initialization, an initial promotion threshold is set to a value that is generally higher than that which might be set later during normal operation. This is because the first time a trace is built and stored in the cache circuit, a higher promotion threshold results in sequencing more traces and later, as traces are sequenced, the promotion threshold is potentially lowered to reduce the number of mis-predictions. Bias is generally stored in the execution history information component of the cache circuit.
The basic block builder circuit 20 optionally initializes an execution history information component. For example, bias is set by the basic block builder circuit 20 during initialization.
Promotion threshold is set in accordance with the conditions of the environment in which the processor core 10 operates, as previously discussed. Under normal operations, based on currently-observed characteristics of the processor core 10, the promotion threshold is set. Another factor used to set bias is heuristics, such as rate of false predictions (or mis-predictions) of interior control transfers. Interior control transfers are essentially assertion upon which operations are built, or assertion operations. An assertion operation is used by the sequencer circuit 29 and the branch predictor circuit 30 to indicate the direction the prediction should have gone. The execution unit 14 verifies the accuracy of the prediction. More specifically, the branch predictor circuit 30 makes a prediction, the assertion operation indicates the direction of the prediction and the execution unit 14 checks the accuracy of the prediction to determine that the trace correctly committed, or not, and if not, the trace is invalidated.
Example Embodiments
In some embodiments, a promotion field contains direction and bias information to enable determining whether a trace is to be formed. A count held within the promotion field is initialized to zero, and incremented for a correct prediction. The count is reset to zero for a misprediction. If the count reaches a predetermined value, then promotion occurs. In some embodiments, the count is then saturated at the predetermined value, while in other embodiments the count is then reset to zero.
In some embodiments, the count is initialized to a value between zero and the predetermined value. In some embodiments, the promotion field holds one or more attributes. In some embodiments, the promotion field is used for non-speculative traces. In some embodiments, a non-cacheable access prevents promotion. In some embodiments, fullness of an entry prevents promotion.
In some embodiments, indirect branches are processed differently than other branches. In some embodiments, in response to high bias values, one or more branch predictors are overridden.
In some embodiments, an multi-block trace entry inherits a portion of information from a promotion field of the last trace of a multi-block build. In some embodiments, the portion includes a bias value.
According to various embodiments, the predetermined value, the initialization values, and threshold values are any combination of fixed, configurable, adaptable, and programmable.
In some embodiments, traces are processed according to a pre-optimizing phase, an optimizing phase, and a slot-and-pack phase. In some embodiments, a block length is estimated. In some embodiments, the estimation is conservative. In some embodiments, the estimation guarantees no overrun. In some embodiments, the estimation is aggressive. In some embodiments, the estimation conditionally results in overrun. In some embodiments, recovery from the overrun is recovered via a checkpoint.
In some embodiments, multi-block builder circuit is enabled to combine promoted blocks and/or traces to form an multi-block trace entry. In some embodiments, the multi-block builder circuit is further enabled to combine blocks and/or traces by modifying terminating branches. In some embodiments, the multi-block builder circuit is enabled to apply any combination of trace optimizations enabled by a basic block builder circuit.
In some embodiments, optimizations are selectively applied based on expected frequency of execution for a basic block trace and/or an multi-block trace entry. In some embodiments, information in a promotion field affects the selective application.
In some embodiments, multiple call and/or return operations are comprised in a trace, while limiting the trace to result in a net change of at most one push or one pop of a branch predictor call/return stack.
In some embodiments, the basic block trace entry is updated even when a multi-block trace is sequenced.
In some embodiments special encodings are provided which do not change once set by the trace unit. For example:
TU_BIAS_NO_PROMOTE If the trace unit can determine that the trace it is creating cannot be extended due to the trace already being at its maximum length the trace unit can mark the trace with this encoding. This trace will then not be considered as the starting trace for a new promotion.
TU_BIAS_CS_BAD_SEG If the code segment was bad when a trace was built, this attribute needs to remain with this trace until it is invalidated.
In some embodiments there are trace termination conditions. For example:
A trace can contain a maximum number of OpTs.
A trace can contain a maximum number of internal branches.
A trace is terminated by an encoded instruction.
A multi-block builder circuit is capable of converting a predetermined number of final new ip asserts into interior asserts.
A trace is to be protected by a maximum of a predetermined number of unique PTB pointers each of which represents a predetermined amount of memory.
A trace can modify the CRS (Call Return Stack) by pushing a new address, popping a return address, or doing nothing. This affects the order and number of internal Calls and Returns that can be embedded in a trace.
Loop unrolling can be inhibited under control of a register. A loop unrolling opportunity is defined as encountering a trace which is eligible for promotion whose initial relative instruction pointer matches the initial relative instruction pointer of the trace being built.
Although the present invention has been described in terms of specific embodiments, it is anticipated that alterations and modifications thereof will no doubt become apparent to those skilled in the art. It is therefore intended that the following claims be interpreted as covering all such alterations and modification as fall within the true spirit and scope of the invention.

## Claims

1. A method for promoting a trace in a microprocessor instruction processing circuit comprising:
a) determining if a current trace is promotable based upon a bias;
b) determining if a next trace is appendable to the current trace; and
c) promoting the current trace and the next trace if the current trace is promotable and the next trace is appendable,

wherein an initial bias is set based upon a set of conditions comprising:
sequencing type,
CS bad segment,
non-promotable, and
non-speculative.

2. The method of claim 1, wherein steps (a), (b) and (c) are repeated until either the current trace is not promotable or the next trace is not appendable.

3. The method of claim 1, wherein the promoting step (c) includes marking the current trace as promoted and the next trace as promoted if the current trace is promotable and the next trace is appendable.

4. The method of claim 1, wherein the current trace and the next trace are promoted together.

5. The method of claim 1, wherein the current trace and the next trace can be a basic block trace or a multi block trace.

6. The method of claim 1, wherein the current trace is determined to be promotable based upon a last branch direction.

7. The method of claim 1, wherein the next trace is determined to be appendable based upon a set of conditions that includes one or more of the following:
a) a maximum number of ops;
b) a maximum number of internal branches;
c) an encoded trace;
d) a maximum number of interior new ip asserts;
e) a maximum number of unique PTB pointers;
f) an allowed modification action to the call return stack (CRS);
g) a maximum offset for a return address to push onto the CRS; and
h) an unrolling of loops.

8. The method of claim 1, wherein based upon the bias comprises:
comparing the bias to a promotion threshold.

9. The method of claim 8, wherein the promotion threshold is dynamically adjustable.

10. The method of claim 1, wherein the bias comprises a number of times a branch has been consistently taken in the same direction.

11. The method of claim 1, wherein the bias represents one of a plurality of trace attributes, wherein each trace attribute indicates whether a current trace is not promotable or not appendable.

12. The method of claim 11, wherein the plurality of trace attributes include non-promotable, CS bad segment, CS bad segment non-speculative, and non-speculative.

13. The method of claim 11, wherein at least one of the trace attributes can be changeable.

14. The method of claim 11, wherein at least one of the trace attributes can be removed from the trace.

15. The method of claim 6, wherein the based upon a last branch direction comprises determining if the last branch direction is equal to the current branch prediction.