Lectures 3 and 4 - Pipelining Flashcards
Hazard Classes
Structural Hazards - arise from resource conflicts
Data Hazards - Arise from inter-instruction dependencies
Control Hazards - Cause by instructions that change the program counter
Pipeline hazards
Situations that arise that force the pipeline to stall.
Data dependencies
Real - If j uses the result of i then it is data dependent on i. They are also dependent if there is a chain of dependencies.
Name - simply a result of register reuse with no data actually communicated.
Data Hazard
Created whenever the parallel execution of instructions makes it possible for a dependency to be violated.
Methods for Avoiding Data Hazards
Add hardware to avoid hazard such as data forwarding or bypass paths
Transform or schedule the code in order to prevent a data dependence becoming a data hazard, this could be done by inserting independent instructions to separate dependent instructions that would cause a stall. It can be performed by the compiler or by hardware.
Hazards arising from name dependencies can be avoided by renaming either in compiler or hardware.
Load-use Data Hazard
ALU operation must wait for result from load, it cannot execute in same lock cycle even with forwarding.
Cukd insert independent instructions or do nothing instructions in load-delay slot.
Alternatively hardware could detect hazard and stall pipeline
Control Hazards
Branch instructions may or may not change the value of the PC so how do we know what to do after we fetch a branch. Simplest approach is to just stall until outcome of branch is known.
Precise Exceptions
A processor is said to support precise exceptions if it can guarantee all instructions prior to the faulting instruction have executed and all those prior to it have not begun to execute.
Method of handling exceptions
Tag instruction if it causes an exception.
Deal with exception when instruction reaches the write back stage.
Faulting instructions are prevented from updating state. They’re handled at WB stage to ensure they’re handle in order. We save the program counter of the faulting instruction and use it to restart the program after the exception handler had completed.
Flush remaining instructions from pipeline.
Alternative approaches to exception handling
Settle for imprecise exceptions.
Use special hardware for handling exceptions which doesn’t require flushing but just stalling while dedicated hardware deals with exception.
Limits of pipelining
Difficult to achieve linear performance gains with deeper pipelines because:
- pipelining registers introduce overheads and it is difficult to provide low-skew global clock within a reasonable power budget
- adding stages may increase complexity
- must balance logic in each stage
- number of stalls due to pipeline hazards grow
Optimal Pipeline Depth
Throughout = 1/(1+(s-1)b) x 1/(t/s+c)
Then can differentiate to get ideal pipeline length ends up being approximately 23 stages.
Condition codes or flags
Branches test special flags set by ALU operations. These usually include zero, carry, negative and overflow.
CCs may constrain instruction ordering.
Condition Registers
Perform comparison and place condition codes in general purpose registers. This permits a simple implementation but costs the use of a register.
Compare and branch
Performs compare and branch in single instruction. This however potentially complicates pipelining.