Professional Documents
Culture Documents
CS 6461: Computer Architecture Instruction Level Parallelism
CS 6461: Computer Architecture Instruction Level Parallelism
January 2013
January 2013
January 2013
January 2013
Processor features
Pipeline stages and their functions
Interrelationships
How do program properties limit performance? Under what
circumstances?
January 2013
January 2013
January 2013
January 2013
10
Reduces
Branch prediction
Control stalls
Ideal CPI
Hardware Speculation
Loop unrolling
January 2013
11
January 2013
12
January 2013
13
Pipeline Hazards
Hazards make it necessary to stall the pipeline.
Some instructions in the pipeline are allowed to proceed while
others are delayed
For this example pipeline approach, when an instruction is
stalled, all instructions further back in the pipeline are also
stalled
No new instructions are fetched during the stall
Instructions issued earlier in the pipeline must continue
January 2013
14
January 2013
15
Data Dependences
Code Example
LOOP:
L.D
F0,0(R1)
;F0=array element
ADD.D
F4,F0,F2
;add scalar in F2
S.D
F4,0(R1)
;store result
DADDUI R1,R1,#-8
BNE
;decrement pointer 8
R1,R2,LOOP;
The above dependencies are in floating point data for the first two
arrows, and integer data in the last two instructions
January 2013
16
January 2013
17
January 2013
18
;decrement pointer 8
BNE
R1,R2,LOOP
January 2013
19
IF.Flush
Hazard
detection
unit
ID/EX
0
M
u
x
1
WB
Control
WB
EX
IF/ID
WB
Control
0
Branch
ALUSrc
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
Write
data
Zero
ALU ALU
result
0
M
u
x
1
MemtoReg
Shift
left 2
MemWrite
Read
register 1
Address
Data
memory
Read
data
Write
data
Instruction 16
[15 0]
Instruction
[20 16]
Instruction
[15 11]
WB
EX
MEM/WB
WB
Sign
extend
32
ALU
control
0
M
u
x
1
1
M
u
x
0
PC
Shift
left 2
Registers
Instruction
memory
MemRead
ALUOp
M
u
x
ALU
Data
memory
M
u
x
M
u
x
Sign
extend
M
u
x
Forwarding
unit
RegDst
January 2013
EX/MEM
Add
Add result
RegWrite
Instruction
Instruction
memory
M
u
x
IF/ID
Address
WB
MEM/WB
Add
PC
ID/EX
M
u
x
EX/MEM
20
January 2013
21
Overcoming Dependences
Two Ways
1. Maintain dependence but avoid the hazard
January 2013
22
January 2013
23
January 2013
24
DADD R1,R2.#-8
DADD R2,R5,0
2. An output dependence
i
j
January 2013
DADD R1,R2.#-8
DADD R1,R4,#10
25
Name Dependences
Not true data dependencies, and therefore we could execute
them simultaneously or reorder them if the name (register or
memory location) used in the instructions is changed so that
the instructions do not conflict
Register renaming is easier
i
j
DADD R1,R2,#-8
DADD R2,R4,#10
i
j
DADD R1,R2,#-8
DADD R5,R4,#10
January 2013
26
Data Hazards
A hazard is created whenever there is a dependence between
instructions, and they are close enough that the overlap caused
by pipelining or other reordering of instructions would change
the order of access to the operand involved in the dependence.
We must preserve program order; the order the instructions
would execute if executed in a non-pipelined system
However, program order only need be maintained where it
affects the outcome of the program
January 2013
27
January 2013
28
January 2013
29
January 2013
30
Control Dependencies
Determines ordering of instruction, i with respect to a branch
instruction so that the instruction i is executed in the correct
program order and only when it should be.
Example
if p1 {
S1;
};
if p2 {
S2;
}
January 2013
31
Control Dependencies
Example
if p1 {
S1;
};
if p2 {
S2;
}
January 2013
32
Control Dependencies
Two constraints imposed
An instruction that is control dependent on a branch cannot be moved
before the branch so that its execution is no longer controlled by the
branch. For example we cannot take a statement from the then portion of
an if statement and move it before the if statement.
An instruction that is not control dependent on a branch cannot be moved
after the branch so that the execution is controlled by the branch. For
example, we cannot take a statement before the if and move it into the
then portion
if p1 {
S1;
};
if p2 {
S2;
}
January 2013
33
Control Dependencies
Two properties of our simple pipeline preserve control
dependencies
Instructions execute in program order
Detection of control or branch hazards ensures that an instruction
that is control dependent on a branch is not executed until the
branch direction is known
January 2013
34
January 2013
35
L1:
DADDU R2,R3,R4
BEQZ
R2, L1
LW
R1,0(R2) ;Could cause illegal mem acc
January 2013
36
January 2013
37
January 2013
38
OR
R7,R1,R8 ; depends on branch taken
Cannot move DSUBU above branch
January 2013
39
R1,R2,R3
R1,skip
R4,R5,R6
R5,R4,R9
R7,R1,R8 ; suppose R4 not used after here
If R4 unused after this point, changing the value of R4 just before the
branch would not affect data flow
If R4 were dead and DSUBU could not generate an exception* we could
move the DSUBU instruction before the branch
This is called speculation since compiler is betting on branch outcome
January 2013
40
January 2013
41