CAP EndSem Unit 5
CAP EndSem Unit 5
Pipeline Hazards
Earlier we had mentioned that the memory limits the speed of the CPU. Now there is
one more case. In a pipelined design few instructions are in some stage of execution.
There are possibilities for some kind of dependency amongst these set of instructions
and thereby limiting the speed of the Pipeline. The dependencies occur for a few
reasons which we will be discussing soon. The dependencies in the pipeline are called
Hazards as these cause hazard to the execution. We use the
word Dependencies and Hazard interchangeably as these are used so in Computer
Architecture. Essentially an occurrence of a hazard prevents an instruction in the pipe
from being executed in the designated clock cycle. We use the word clock cycle,
because each of these instructions may be in different machine cycle of theirs.
Structural Hazards
Data Hazards
Control Hazards
Structural Hazards
Structural hazards arise due to hardware resource conflict amongst the instructions in
the pipeline. A resource here could be the Memory, a Register in GPR or ALU. This
resource conflict is said to occur when more than one instruction in the pipe is requiring
access to the same resource in the same clock cycle. This is a situation that the hardware
cannot handle all possible combinations in an overlapped pipelined execution.
A better solution would be to increase the structural resources in the system using one
of the few choices below:
The pipeline may be increased to 5 or more stages and suitably redefine the
functionality of the stages and adjust the clock frequency. This eliminates the issue
of the hazard at every 4th instruction in the 4-stage pipeline
The memory may physically be separated as Instruction memory and Data
Memory. A Better choice would be to design as Cache memory in CPU, rather than
dealing with Main memory. IF uses Instruction memory and Result writing uses
Data Memory. These become two separate resources avoiding dependency.
It is possible to have Multiple levels of Cache in CPU too.
There is a possibility of ALU in resource dependency. ALU may be required in IE
machine cycle by an instruction while another instruction may require ALU in IF
stage to calculate Effective Address based on addressing mode. The solution would
be either stalling or have an exclusive ALU for address calculation.
Register files are used in place of GPRs. Register files have multiport access with
exclusive read and write ports. This enables simultaneous access on one write
register and read register.
The last two methods are implemented in modern CPUs. Beyond these, if dependency
arises, Stalling is the only option. Keep in mind that increasing resources involves
increased cost. So the trade-off is a designer’s choice.
Data Hazards
Data hazards occur when an instruction's execution depends on the results of some
previous instruction that is still being processed in the pipeline. Consider the example
below. Occur when given instruction depends on data from an instruction ahead of it in
pipeline.
Solution 1: Introduce three bubbles at SUB instruction IF stage. This will facilitate SUB –
ID to function at t6. Subsequently, all the following instructions are also delayed in the
pipe.
Solution 4: In the event, the above reordering is infeasible, the compiler may detect and
introduce NOP ( no operation) instruction(s). NOP is a dummy instruction equivalent
bubble, introduced by the software.
The compiler looks into data dependencies in code optimisation stage of the
compilation process.
This is a case where an instruction uses data produced by a previous one. Example
This is a case where the second instruction writes onto register before the first
instruction reads. This is rare in a simple pipeline structure. However, in some
machines with complex and special instructions case, WAR can happen.
WAW and WAR hazards can only occur when instructions are executed in parallel or out
of order. These occur because the same register numbers have been allotted by the
compiler although avoidable. This situation is fixed by renaming one of the registers by
the compiler or by delaying the updating of a register until the appropriate value has
been produced. Modern CPUs not only have incorporated Parallel execution with
multiple ALUs but also Out of order issue and execution of instructions along with many
stages of pipelines.
Control Hazards
Control hazards are called Branch hazards and caused by Branch Instructions. Branch
instructions control the flow of program/ instructions execution. Recall that we use
conditional statements in the higher-level language either for iterative loops or with
conditions checking (correlate with for, while, if, case statements). These are transformed
into one of the variants of BRANCH instructions. It is necessary to know the value of the
condition being checked to get the program flow. Life is complicating you! So it is for
the CPU!
Thus a Conditional hazard occurs when the decision to execute an instruction is based
on the result of another instruction like a conditional branch, which checks the
condition’s resultant value.
The branch and jump instructions decide the program flow by loading the appropriate
location in the Program Counter(PC). The PC has the value of the next instruction to be
fetched and executed by CPU. Consider the following sequence of instructions.
Figure 16.6
Branch Table Buffer
This method is successful to the extent of the temporal locality of reference in the
programs. When the prediction fails flushing needs to take place.
------------------------------------------------------------------------------------
Instruction Level Parallelism (ILP) is used to refer to the architecture in which multiple
operations can be performed parallelly in a particular process, with its own set of
resources – address space, registers, identifiers, state, program counters. It refers to
the compiler design techniques and processors designed to execute operations, like
memory load and store, integer addition, float multiplication, in parallel to improve
the performance of the processors. Examples of architectures that exploit ILP are
VLIWs, Superscalar Architecture.
ILP processors have the same execution hardware as RISC processors. The machines
without ILP have complex hardware which is hard to implement. A typical ILP allows
multiple-cycle operations to be pipelined
Architecture :
-----------------------------------------------------------------------------------------------------------------
What is Indirect instruction cycle? Explain data flow in it?
DATA Flow:-