Professional Documents
Culture Documents
BY
N R REJIN PAUL LECTURER,CSE DEPT
1/24/02
ALU
I n s t r.
O r d e r
ALU
Ifetch
Reg
DMem
Reg
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
1/24/02
Limits to pipelining
Hazards: circumstances that would cause incorrect execution if next instruction were launched
Structural hazards: Attempting to use the same hardware to do two different things at the same time Data hazards: Instruction depends on result of prior instruction still in the pipeline Control hazards: Caused by delay between the fetching of instructions and decisions about changes in control flow (branches and jumps).
1/24/02
ALU
ALU
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
Structural Hazard
1/24/02
ALU
ALU
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
Ifetch
Reg
DMem
Reg
Bubble
Bubble Bubble
Bubble
ALU
Bubble
Reg
Ifetch
Reg
DMem
Data Hazards
Time (clock cycles)
IF ID/RF EX MEM
DMem
WB
Reg
I n s t r. O r d e r
add r1,r2,r3
Ifetch
Reg
ALU
ALU
sub r4,r1,r3
and r6,r1,r7 or r8,r1,r9
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
xor r10,r1,r11
1/24/02
ALU
Ifetch
Reg
DMem
Reg
1/24/02
ALU
I n s t r.
O r d e r
ALU
Reg
DMem
Reg
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
xor r10,r1,r11
Ifetch
Reg
DMem
Reg
1/24/02
ALU
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
1/24/02
Ifetch
Reg
DMem
Reg
Ifetch
Reg
Bubble
ALU
DMem
Reg
ALU
Ifetch
Bubble
Reg
DMem
Reg
Ifetch
Reg
ALU
Bubble
DMem
1/24/02
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
ALU
Ifetch
Reg
DMem
Reg
1/24/02
Memory Access
Write Back
MUX
Adder
Adder
4
Address
1/24/02
Zero?
RS1
MEM/WB
Imm
Sign Extend
RD
RD
RD
WB Data
Memory
RS2
EX/MEM
Reg File
ID/EX
ALU
IF/ID
Data Memory
MUX
MUX
1/24/02
Cont
So some algorithm needs to be implemented in order to perform the operation Functional unit should be redesigned to perform all operations and this type of functional unit require longer pipeline cycle Latency in the functional unit : - Latency is defined as the number of intervening cycles between an instruction that produces a result and an instruction that uses the result. initiation interval : number of cycles that must elapse between issuing two operations of a given type
1/24/02 CS252/Culler Lec 2.20
Cont.
1/24/02
1/24/02
1/24/02
FP example
1/24/02
Cont.
1/24/02
Cont.
Assuming that the pipeline does all hazard detection in ID, there are three checks that must be performed before an instruction can issue: Check For Structural Hazards: Wait until the required functional unit is available Check for a RAW data hazard: Wait until the source registers are not listed as pending destinations in a pipeline register that will not be available Check for a WAW data hazard: Determine if any instruction in Al, . A4,D, Ml, . . . , M7 has the same register destination as this instruction.
1/24/02 CS252/Culler Lec 2.26
1/24/02
1/24/02
1/24/02
Is this loop parallel? If not how to make it parallel? Statement s1 uses the value assigned in the previous iteration by statement s2, so there is a loop-carried dependency between s1 and s2. Despite this dependency, this loop can be made parallel because the dependency is not circular: - neither statement depends on itself; - while s1 depends on s2, s2 does not depend on s1. CS252/Culler
Lec 2.30
Reduces Data hazard stalls Control stalls Ideal CPI Data and control stalls Data hazard stalls involving memory Control hazard stalls Data hazard stalls Ideal CPI and data hazard stalls Ideal CPI and data hazard stalls Ideal CPI, data and control stalls
CS252/Culler Lec 2.31
InstrJ is data dependent on InstrI InstrJ tries to read operand before InstrI writes it
1/24/02
Dependences are a property of programs Presence of dependence indicates potential for a hazard, but actual hazard and length of any stall is a property of the pipeline Importance of the data dependencies 1) indicates the possibility of a hazard 2) determines order in which results must be calculated Today looking at HW schemes to avoid hazard
1/24/02
Name dependence: when 2 instructions use same register or memory location, called a name, but no flow of data between the instructions associated with that name; 2 versions of name dependence InstrJ writes operand before InstrI reads it
Called an anti-dependence by compiler writers. This results from reuse of the name r1 If anti-dependence caused a hazard in the pipeline, called a Write After Read (WAR) hazard
1/24/02
1/24/02
Control Dependencies
Every instruction is control dependent on some set of branches, and, in general, these control dependencies must be preserved to preserve program order if p1 { S1; }; if p2 { S2; } S1 is control dependent on p1, and S2 is control dependent on p2 but not on p1.
36
1/24/02
Out-Of-Order Execution
DIVD F0,F2,F4 ADDD F10,F0,F8 SUBD F12,F8,F14 Enables out-of-order execution => out-of-order completion
1/24/02
THANK YOU
1/24/02