1. Technical Field
The present invention relates generally to processors and computing systems, and more particularly, to a processor having branch prediction mechanisms, in which the depth of instruction buffers for predicted and non-predicted branches are dynamically adjusted.
2. Description of the Related Art
Present-day high-performance microprocessors include an instruction fetch unit (IFU) that fetches, decodes and dispatches instructions for execution by other processor core functional units. Instruction streams are sequentially fetched until execution is re-directed. A common example of such re-direction is a branch instruction. The branch may be “taken”, which causes a non-sequential fetch, or “not taken”, in which instruction fetching continues past the branch instruction. In a branch-predicting processor, instruction streams are pre-fetched according to a prediction of whether a branch will be “taken” or “not taken”. Various mechanisms have been used to determine whether a branch will be taken to ensure that the correct path is fetched. When a branch instruction is predicted as “taken”, the current instruction fetch path is re-directed to a new target address, and the instruction fetching proceeds linearly from the new target address. When the branch instruction is predicted as “not taken”, the instruction fetching is not redirected.
As instructions are fetched, they are typically stored in an instruction buffer (IB). Instructions are then removed from the IB, decoded and then sent to an instruction dispatch unit (IDU), which dispatches the instructions for execution by various functional units within the processor. When a branch instruction is executed, a branch processing unit (BU) determines whether or not the branch path was predicted correctly, and if the prediction was correct, no interruption in instruction sequence occurs. However, if the branch was mis-predicted, the current fetch path must be abandoned and the sequence of execution re-directed to the non-predicted branch path. Several penalties are incurred, including the time required to redirect the instruction sequence, the time required to flush the mis-predicted entries, and the power and thread resources wasted on fetching and preparing to execute the instructions on the mis-predicted path.
The amount of resources and processing power wasted on mis-prediction can be reduced by disabling predictive execution and stalling the pipeline pending resolution of each branch instruction. However, such behavior negates the advantage provided by branch prediction, that of providing a full instruction pipeline for full processor performance, with the pipeline being correctly filled most of the time.
It is therefore desirable to provide a methodology and a microprocessor that reduce the amount of resources and energy wasted on branch mis-prediction, while keeping the instruction pipeline full for full processing performance.
The objective of providing a processor that reduces resources and energy wasted on branch mis-prediction, while retaining the advantages of branch-predicting instruction pre-fetch is provided in a processor and method of operation of the processor.
The processor includes a control unit that measures the quality of branch predictions for a given instruction thread, and dynamically adjusts the sizes of instruction buffer portions that store both the predicted branch and the non-predicted branch instruction streams. The buffer portion sizes are adjusted in conformity with a measured branch prediction confidence, so that when the branch prediction confidence for a given instruction thread is high, the buffer portion for the non-predicted instruction stream is lowered and can be set to zero under high confidence conditions. The relative sizes of the buffer portions can be dynamically varied for individual threads in a multi-threaded environment, so that for threads encountering low branch-prediction confidence intervals, more buffer space is allocated for non-predicted branch path.
The foregoing and other objectives, features, and advantages of the invention will be apparent from the following, more particular, description of the preferred embodiment of the invention, as illustrated in the accompanying drawings.
The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as a preferred mode of use, further objectives, and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein like reference numerals indicate like components, and:
The present invention concerns methodologies and processor circuits that provide buffering for both predicted and non-predicted instruction streams for branch instruction paths. In the present invention, the buffer size for the predicted and non-predicted instruction paths is dynamically varied in conformity with a measurement of the confidence in the branch predictions. The confidence measurement may be made in a number of ways, but generally provide a measurement of the correct predictions versus the incorrect predictions made by the branch prediction circuits.
With reference now to the figures, and in particular with reference to
Processor group 5 is connected to an L3 cache unit 6, system local memory 8 and various peripherals 4, as well as to a service processor 2. Service processor 2 can provide fault supervision, startup assistance and test capability to processor group 5 and may have a dedicated interconnect path to other processor groups as well as interconnecting to each of processors 10A-D. Processors 10A-D provide instruction execution and operation on data values for general-purpose processing functions. Bridge 7, as well as other bridges within the system provide communication over wide buses with other processor groups and bus 35 provides connection of processors 10A-D, bridge 7, peripherals 4, L3 cache 6 and system local memory 8. Other global system memory may be coupled external to bridge 7 for access by all processor groups.
Processors 10A-D are simultaneous multi-threaded (SMT) processors capable of concurrent and speculative execution of multiple threads. Each of processors 10A-D includes execution resources to support multiple streams of simultaneous execution, i.e. multiple instruction threads and further includes control circuitry (hardware) that determines the quality of branch prediction for each instruction thread, and alters the size of instruction buffers provided for non-predicted instruction streams upon determining that branch prediction for that instruction thread is not proceeding efficiently.
Referring now to
Fixed point unit 14 and floating point unit 15 are coupled to various resources such as general-purpose registers (GPR) 18A, floating point registers (FPR) 18B, condition registers (CR) 18C and rename buffers 18D. GPR 18A and FPR 18B provide data value storage for data values loaded and stored from L1 Dcache 22 by load store unit (LSU) 19. Rename buffers 18D (which may comprise several rename units associated with the various internal execution units) provides operand and result storage for the execution units. IFU 16 receives direction from a program control unit/thread table unit (TTBL/PCU) 24 that contains settings for managing thread execution, such as thread priority and per-thread control information so that IFU 16 can be directed to load an instruction sequence that represents the allocation of execution resources among the multiple instruction threads executing within processor 10. TTBL/PCU 24 is responsible for determining which instruction thread(s) receives the most processing cycles, instruction fetch cycles and/or execution time slices, depending on what particular method is used to sequence the instructions between threads.
The instruction execution pipelines of present-day super-scalar processors such as processor 10 are very deep (for example, 25 or more clock cycles may be required for an instruction to clear the pipeline), and for simplicity, resolution of branch conditions has generally been handled very late in the pipeline, when the condition register value upon which the branch instruction depends is assured to be in the resolved state. In addition, there is generally a finite and significant physical and electrical distance between the branch prediction unit and the unit resolving the branch condition. Therefore, even if the branch condition is actually known at the time a conditional branch is decoded, branch processing unit 26 generally still predicts the outcome of the branch using branch history table 25 and dispatches the instructions following the predicted path of the branch speculatively. If a branch prediction is incorrect, the pipeline resources allocated for the predicted instruction stream must be flushed, and all of the power and resources associated with the incorrectly predicted branch path that was loaded into the pipeline are wasted. In the present invention, the wasted resources and power are reduced for branches for which prediction has a low confidence, e.g., those branches for which the “branch taken” and “branch not-taken” probabilities both approach 50%. The reduction in power consumption and resource conservation occurs because the instructions fetched ahead of a predicted taken branch, which would ordinarily be flushed due to the predicted instruction fetch path redirection, are instead retained. The retained non-predicted instruction path prevents the instruction fetch mechanism from being held up when a mis-predict occurs for the predicted taken branch.
For the above purpose, IFU 16 receives input from control logic 29 within branch processing unit 26. A branch execution unit (BXU) 27 within branch processing unit 26 manages execution of instruction groups associated with branch instructions. A branch history table (BHT) 25 stores information about each branch instruction encountered (within a limit of storage of the table, which is content-addressed by a subset of bits from the branch address), and further stores information used by BXU 27 to decide which path is predicted as the likely path for a branch instruction. Each entry in BHT 25 includes bits that indicate for each branch, a relative confidence and direction of likely execution for each branch. BHT 25 is updated as to the direction and strength of actual taken branch paths at the time of execution of the branch instructions. The present invention uses BHT 25 information to inform control logic 29 to control the relative sizes of instruction buffer portions in IB 28 in conformity with the quality of branch prediction for that branch instruction and instruction thread.
Referring now to
In pipeline cycle cycle 0, the address from instruction fetch address register IFAR is used to access I-cache 34 and branch prediction structures such as branch history tables 36. The branch prediction information and instruction retrieved from I-cache is latched and used in the following pipeline cycle cycle 1. In pipeline cycle cycle 1, branch scan logic 39 determines whether the instruction is a branch, and if so, whether the branch is taken or not taken. In the next cycle cycle 2, instructions are stored in instruction buffer (IB) 38. If the branch prediction for a predicted taken branch has low confidence, the alternate path instructions are also stored in instruction buffer 38, since the alternate path instructions are the sequential instructions following the branch instruction. The alternate path address is calculated and sent to alternate fetch address register table 32. The alternate path address will either be the predicted taken address or the next sequential address, which are already stored and therefore only a selection between the two addresses is required. If the branch is a low confidence predicted not taken branch, then the branch destination address is loaded into alternate IFAR table 32, so that the alternate path can be fetched when idle cycles are available.
In subsequent cycles cycle 2+, the alternate (non-predicted) path is stored along with the main (predicted) branch path, until another branch instruction is detected, the portion of IB 38 allocated for the alternate path is full, or a limit on instruction look-ahead for alternate path fetching is met. At the end of an alternate path fetch group, the next address is written into the alternate IFAR table 32. Also, concurrently with subsequent instruction fetching, instructions are decoded and dispatched to the issue unit(s). Once a branch instruction is resolved, if the branch was not mis-predicted, the alternate path portion of instruction buffer 38 for the instruction thread is flushed. If the branch instruction was mis-predicted, then the portion of IB 38 that contains the main path instructions is flushed, and instructions are retrieved from the alternate path buffer until the buffer is empty. Concurrently, the alternate IFAR table 32 is used to fetch the alternate path instructions into the main portion of IB 38, which improves performance by greatly reducing the mis-predict penalty. Once the alternate path buffer is emptied, the instructions are retrieved from the main path portion of instruction buffer 38.
After each branch instruction is resolved by branch execution logic 37, the branch history and confidence values are updated and the buffer portion sizes are adjusted in conformity with the updated confidence values. The instruction buffer portion sizes can either be dynamically adjusted for each next branch instruction for an instruction thread in conformity with a branch prediction confidence for the particular branch instruction (fine granularity) or adjusted in conformity with an overall branch prediction confidence for the instruction thread. The invention, in particular, provides a large degree of improvement for predicted taken branches that are mis-predicted. For the predicted taken branch case, the non-predicted path sequentially follows the branch instruction and the alternate instruction fetch buffers can be filled while the IFAR is redirected to the new branch target address. By including an address table and previously fetched values for the not-taken branch path, pipeline stalls due to branch mis-predictions can be more easily avoided or greatly reduced. The amount of space allocated for the non-predicted path, relative to the predicted path buffer size, is generally set to a value between 0% and 50%, depending on the branch prediction confidence, since any value greater than 50% would limit the space allocated for the instructions more likely to be used. Additionally the technique can be disabled entirely for instruction threads in which the branch prediction confidence exceeds a predetermined threshold, e.g., 90%, where the resources used to fetch the non-predicted path instructions yield a negative result due to cached arbitration and other overhead, along with the additional power consumed in fetching the non-predicted branch path.
Referring now to
Referring now to
While the invention has been particularly shown and described with reference to the preferred embodiment thereof, it will be understood by those skilled in the art that the foregoing and other changes in form, and details may be made therein without departing from the spirit and scope of the invention.
Number | Name | Date | Kind |
---|---|---|---|
5870599 | Hinton et al. | Feb 1999 | A |
5881278 | Tran et al. | Mar 1999 | A |
5918046 | Hoyt et al. | Jun 1999 | A |
5935241 | Shiell et al. | Aug 1999 | A |
6766441 | Sinharoy | Jul 2004 | B2 |
7124287 | Prasky et al. | Oct 2006 | B2 |
20050216714 | Grochowski | Sep 2005 | A1 |
Number | Date | Country | |
---|---|---|---|
20090063819 A1 | Mar 2009 | US |