Académique Documents
Professionnel Documents
Culture Documents
Course Leader:
PRAKASH P
prakashp.cs.et@msruas.ac.in
1
M. S. Ramaiah University of Applied Sciences
Objectives
At the end of these lectures, students will be
able to
Differentiate the hazards that a pipeline is
susceptible to
Explain implementations of the techniques that
are used to overcome these hazards
Analyze the effect that these hazards and their
resolution, have on the performance of the
pipeline
2
M. S. Ramaiah University of Applied Sciences
Pipelining Hazards
Structural
Resource conflicts when the hardware cant support all
combinations of overlapped stages
e.g. Might use ALU to add 4 to PC and execute op
Data
An instruction depends on the results of some previous
instruction that is still being processed in the pipeline
e.g. R1 = R2 + R3; R4 = R1 + R6; problem here?
Control
Branches and other instructions that change the PC
If we branch, we may have the wrong instructions in the
pipeline
3
M. S. Ramaiah University of Applied Sciences
Structural Hazard
Overlapped execution may require duplicate
resources
Clock 4:
Memory access for i may conflict with IF for i+4
May solve via separate cache/buffer for instructions,
data
4
M. S. Ramaiah University of Applied Sciences
5
M. S. Ramaiah University of Applied Sciences
6
M. S. Ramaiah University of Applied Sciences
7
M. S. Ramaiah University of Applied Sciences
8
M. S. Ramaiah University of Applied Sciences
9
M. S. Ramaiah University of Applied Sciences
10
M. S. Ramaiah University of Applied Sciences
Instruction Throughput
Pipelining increases processor performance
by increasing the instruction throughput
If several instructions overlapped in the
pipeline cycle time can be reduced,
increasing the rate at which instructions
execute
11
M. S. Ramaiah University of Applied Sciences
Limiting Factors
Number of factors limit a pipeline's ability to
execute instructions at its peak rate
Dependencies between instructions operands
(called data dependency hazards)
Branches (called program flow control hazards),
and the time required to access memory
12
M. S. Ramaiah University of Applied Sciences
RAR
RAW
WAR
WAW
13
M. S. Ramaiah University of Applied Sciences
Stall
The instruction at the later stage waits for
the front one to complete and thus clock
cycle(s) is not utilized during that period
Stall a bubble in the pipeline
14
M. S. Ramaiah University of Applied Sciences
15
M. S. Ramaiah University of Applied Sciences
Read-After-Read
Occurs when two instructions both read
from the same register
Don't cause a problem for the processor
because reading a register doesn't change
the registers value
16
M. S. Ramaiah University of Applied Sciences
Detection Condition
In an n-th instruction at an advanced
stage of processing
In+1 an n+1 th instruction at previous
stage of processing
In and In+1 contain at least one common
operand
Input operands be same in In+1 as in In
17
RAR Example
Instructions
ADD r1, r2, r3
SUB r4, r5, r3
18
M. S. Ramaiah University of Applied Sciences
RAW Example
Instructions
ADD r1, r2, r3
SUB r4, r5, r1
of the addition,
20
M. S. Ramaiah University of Applied Sciences
Clock Cycles
21
M. S. Ramaiah University of Applied Sciences
22
M. S. Ramaiah University of Applied Sciences
23
M. S. Ramaiah University of Applied Sciences
Pipeline Stall
24
M. S. Ramaiah University of Applied Sciences
Inserting NoPs
In cycle 5, the subtract would normally
enter the execute stage, but it is prevented
from doing so because it was not able to
read r1 on cycle 4
Instead, the hardware inserts a special nooperation(NOP) instruction, known as a
bubble, into the execute stage of the
pipeline, and the subtract tries to read its
input registers again on cycle 5
25
M. S. Ramaiah University of Applied Sciences
26
M. S. Ramaiah University of Applied Sciences
27
M. S. Ramaiah University of Applied Sciences
28
M. S. Ramaiah University of Applied Sciences
29
M. S. Ramaiah University of Applied Sciences
WAR Detection
The detection condition of WAR hazards is
that
In and On+1 contain at least one common
operand
30
M. S. Ramaiah University of Applied Sciences
WAR Example
ADD r1, r2, r3
SUB r2, r5, r6
Subtract writes r2, which is read by the
addition, creating a WAR hazard
31
M. S. Ramaiah University of Applied Sciences
WAW Detection
The detection condition for WAW hazards is
that On and On+1 contain at least one
common operand
32
M. S. Ramaiah University of Applied Sciences
WAW Example
ADD r1, r2, r3
SUB r1, r5, r6
Subtract writes the same register as the
addition, creating a WAW hazard
33
M. S. Ramaiah University of Applied Sciences
In-Order Execution
If a processor executes instructions in the
order that they appear in the program and
uses the same pipeline for all instructions,
WAR and WAW hazards do not cause the
delays because of the way instructions
through the pipeline
34
M. S. Ramaiah University of Applied Sciences
WAW
The output register of an instruction written
in the write back stage of the pipeline
Instructions with WAW hazards will enter
the write back stage in the order in which
they appear in the program
Write their results into the register in the
right order
35
M. S. Ramaiah University of Applied Sciences
WAR
Even less of a problem, because the register read
stage of the pipeline occurs before the write back
stage
By the time an instruction enters the write back
stage of the pipeline, all previous instructions in
the program have already passed through the
register read stage and read their input values
Writing instruction can go ahead and write its
destination register without causing any problems
36
M. S. Ramaiah University of Applied Sciences
Different Latencies
WAW and WAR hazards can cause problems,
because it is possible for a low-latency
instruction to complete before a longerlatency instruction that appeared earlier in
the program
These processors must keep track of name
dependencies between instructions and
stall the pipeline as necessary to resolve
these hazards
37
M. S. Ramaiah University of Applied Sciences
38
M. S. Ramaiah University of Applied Sciences
Summary
Data Dependent Hazards
RAR
RAW causes bubble
WAR and WAW results in name dependencies
WAR and WAW create the issue in out-of order
executing processor pipeline
39
M. S. Ramaiah University of Applied Sciences