Escolar Documentos
Profissional Documentos
Cultura Documentos
6 PM 7 8 9 10 11 12 1 2 AM
Time
Task
order
1
Pipeline de instruções no MIPS
• Fetch da instrução
Exemplo
2
Tempo total para as oito instruções calculado a
partir do tempo de cada componente
Instruction Data
lw $2, 200($0) 8 ns Reg ALU Reg
fetch access
Instruction
lw $3, 300($0) 8 ns fetch
...
8 ns
Program
execution 2 4 6 8 10 12 14
Time
order
(in instructions)
Instruction Data
lw $1, 100($0) Reg ALU Reg
fetch access
Instruction Data
lw $2, 200($0) 2 ns Reg ALU Reg
fetch access
Instruction Data
lw $3, 300($0) 2 ns Reg ALU Reg
fetch access
2 ns 2 ns 2 ns 2 ns 2 ns
3
OBS.:
4
Projeto de um conjunto de instruções para pipeline
– Hazard
• Hazard Estrural
• Hazard de Controle
• Hazard de Dados
Pipeline Hazards
• Hazard Estrutural
5
Pipeline Hazards
• Hazard de Controle
Program
execution 2 4 6 8 10 12 14 16
order Time
(in instructions)
Instruction Data
add $4, $5, $6 Reg ALU Reg
fetch access
Instruction Data
beq $1, $2, 40 fetch
Reg ALU
access
Reg
2ns
Instruction Data
lw $3, 300($0) fetch
Reg ALU
access
Reg
4 ns
2ns
6
Branch prediction: Tentar “adivinhar” qual dos caminhos do branch
será tomado
Program
execution 2 4 6 8 10 12 14
order Time
(in instructions)
add $4, $5, $6
Instruction
Reg ALU
Data
Reg O branch não
fetch access
será tomado
Instruction Data
beq $1, $2, 40 Reg ALU Reg
2 ns fetch access
Instruction Data
lw $3, 300($0) Reg ALU Reg
2 ns fetch access
Program
execution 2 4 6 8 10 12 14
Time
order
(in instructions)
add $4, $5 ,$6 Instruction Data
Reg ALU Reg
fetch access
Instruction Data
or $7, $8, $9 Reg ALU Reg
4 ns fetch access
Program
execution 2 4 6 8 10 12 14
order Time
(in instructions)
beq $1, $2, 40 Instruction Data
Reg ALU Reg
fetch access
2 ns
7
Hazard de Dados
sub $t2,$s0,$t3
Soluções :
Compilador (programador) gera código livre de
data hazard (introduzindo, por ex., instruções nop
no código; alterando a ordem das instruções; ...)
Hazard de Dados
2 4 6 8 10
Time
Program
execution 2 4 6 8 10
order Time
(in instructions)
add $s0, $t0, $t1 IF ID EX MEM WB
8
Hazard de Dados
2 4 6 8 10 12 14
Program Time
execution
order
(in instructions) Stall
lw $s0, 20($t1) IF ID EX MEM WB
Exemplo
Solução:
# $t1 tem o end. de v[k]
lw $t0, 0($t1) # $t0 = v[k]
lw $t2,4($t1) # $t2 = v[k+1]
sw $t0, 4($t1) # v[k+1] = $t0
sw $t2, 0($t1) # v[k] = $t2
9
Pipeline: Idéia Básica
• 5 estágios: Fetch; Decodificação e leitura dos regs; execução ou cálculo
de end. ; acesso à memória; escrita no reg. destino
IF: Instruction fetch ID: Instruction decode/ EX: Execute/ MEM: Memory access WB: Write back
register file read address calculation
0
M
u
x
1
O que é necessário
Add
para tornar cada
Add
4
Shift
Add result
divisão em estágios?
left 2
Read
PC Address register 1 Read
Read data 1
register 2 Zero
Instruction Registers Read ALU ALU
Write data 2 0 result Address Read 1
Instruction register M data
u Data M
memory Write x u
memory x
data 1 0
Write
data
16 32
Sign
extend
10
Pipelined Datapath
0
M
u
x
1
Add
Add
4 Add result
Shift
left 2
Read
Instruction
PC Address register 1
Read
data 1
Read
register 2 Zero
Instruction Registers Read ALU ALU
memory Write data 2 0 Address Read 1
result data
register M
u M
Data u
Write x memory
data x
1
0
Write
data
16 32
Sign
extend
Pipelined Datapath
lw
Instruction fetch
0
M
u
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
11
Pipelined Datapath
lw
0
M Instruction decode
u
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
Pipelined Datapath
lw
0
M
u
Execution
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
12
Pipelined Datapath
lw
0
M
u
Memory
x
1
Add
Add
4 Add result
Shift
left 2
Read
Instruction
PC Address register 1
Read
Read data 1
register 2 Zero
Instruction
Registers Read ALU ALU
memory Write 0 Read
data 2 result Address 1
register M data
Data M
u
Write x memory u
data x
1
0
Write
data
16 32
Sign
extend
Pipelined Datapath
0
M
lw
u
x Write back
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
13
Pipelined Datapath
sw
0
M Execution
u
x
1
Add
Add
4 Add result
Shift
left 2
Read
Instruction
PC Address register 1
Read
Read data 1
register 2 Zero
Instruction
Registers Read ALU ALU
memory Write 0 Read
data 2 result Address 1
register M data
u Data M
Write x memory u
data x
1
0
Write
data
16 32
Sign
extend
Pipelined Datapath
sw
0
M
u
Memory
x
1
Add
Add
4 Add result
Shift
left 2
Read
Instruction
PC Address register 1
Read
Read data 1
register 2 Zero
Instruction
Registers Read ALU ALU
memory Write 0 Read
data 2 result Address 1
register M data
u M
Data u
Write x memory
data x
1
0
Write
data
16 32
Sign
extend
14
Pipelined Datapath
0
sw
M
u Write back
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
Datapath Correto
Add
4 Add Add
result
Shift
left 2
Read
Instruction
15
Datapath com os estágios usados para um instrução lw
0
M
u
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
T im e (in c lo c k c y cl e s )
P ro g ra m
CC 1 CC 2 CC 3 CC 4 CC 5 CC 6
e x e c u t io n
o rd e r
(in in s tr u c tio n s )
lw $ 1 0 , 2 0 ( $ 1 ) IM R eg ALU DM Reg
s ub $ 11 , $ 2 , $3 IM Reg ALU DM R eg
16
Representações Gráfica do Pipeline
lw $10, 20($1)
Instruction fetch
0
M
u
x
1
Add
4 Add
Add result
Shift
left 2
Read
Instruction
Clock 1
17
sub $11, $2, $3 lw $10, 20($1)
Instruction fetch Instruction decode
0
M
u
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
PC Address register 1
Read
data 1
Read
register 2 Zero
Instruction
Registers Read ALU ALU
memory Write 0 Read
data 2 result Address 1
register M data
u M
Data u
Write x memory
data x
1
0
Write
data
16 32
Sign
extend
Clock 2
Add
4 Add Add
result
Shift
left 2
Read
Instruction
Clock 3
18
sub $11, $2, $3 lw $10, 20($1)
0
M
u Execution Memory
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
Clock 4
0
sub $11, $2, $3 lw $10, 20($1)
M
u Memory Write back
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
Clock 5
19
0
sub $11, $2, $3
M
u Write back
x
1
Add
4 Add Add
result
Shift
left 2
Read
Instruction
Clock 6
Controle do Pipeline
PCSrc
0
M
u
x
1
Add
Add
4 Add
res ult
Branch
Shift
RegW rite left 2
R ead MemWrite
Instruction
RegDs t
20
Controle do Pipeline
Sinais de controle
21
Sinais de controle
Sinais de controle
Execution/Address Write-back
Calculation stage Memory access stage stage control
control lines control lines lines
22
WB
Instruction
Control M WB
EX M WB
ID/E X
0
M
u WB
x EX /ME M
1
C ontrol M WB
ME M/W B
EX M WB
IF/ID
Add
Add
4 A dd result
RegWrite
Branch
Shift
left 2
MemWrite
AL U Src
MemtoReg
R e ad
Instruction
PC Address register 1
R ea d
data 1
R e ad
register 2 Z ero
In struc tion
R egisters R ea d ALU ALU
mem ory W rite 0 Read
data 2 re sult A ddress 1
register M data
u D ata M
W rite x me mory u
data x
1
0
W rite
data
Instruction 16 32 6
[15– 0] Sign A LU M emR ead
extend control
Instruction
[20– 16]
0 ALU Op
M
Instruction u
[15– 11] x
1
RegD st
23
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 1o ciclo
or $13, $6, $7
add $14, $8, $9
IF: lw $10, 20($1) ID: before<1> EX: before<2> MEM: before<3> WB: before<4>
Add
Add
4 Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
Read
MemtoReg
Instruction
Instruction
[15– 0] Sign ALU MemRead
extend control
Instruction
[20– 16]
0 ALUOp
M
Instruction u
[15– 11] x
1
Clock 1 RegDst
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 2o ciclo
or $13, $6, $7
add $14, $8, $9
IF: sub $11, $2, $3 ID: lw $10, 20($1) EX: before<1> MEM: before<2> WB: before<3>
Add
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
1 Read
MemtoReg
Instruction
register 1
PC Address Read $1
X data 1
Read
register 2 Zero
Instruction
Registers Read $X ALU ALU
memory Write 0 Read
data 2 result Address 1
register M data
u Data M
Write x memory u
data x
1
0
Write
data
Instruction
20 [15– 0] Sign 20 ALU MemRead
extend control
Instruction
10 [20– 16] 10
0 ALUOp
M
Instruction u
X [15– 11] X x
1
Clock 2 RegDst
24
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 3o ciclo
or $13, $6, $7
add $14, $8, $9
IF: and $12, $4, $5 ID: sub $11, $2, $3 EX: lw $10, . . . MEM: before<1> WB: before<2>
Add
Add
4 Add result
MemWrite
ALUSrc
2 Read
MemtoReg
Instruction
Instruction
X [15– 0] Sign X 20 ALU MemRead
extend control
Instruction
X [20– 16] X 10
0 ALUOp
M
Instruction u
11 [15– 11] 11 x
1
Clock 3 RegDst
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 4o ciclo
or $13, $6, $7
add $14, $8, $9
IF: or $13, $6, $7 ID: and $12, $2, $3 EX: sub $11, . . . MEM: lw $10, . . . WB: before<1>
Add
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
4 Read
MemtoReg
Instruction
register 1
PC Address Read $4 $2
5 data 1
Read
register 2 Zero
Instruction
Registers Read $5 $3 ALU ALU
memory Write 0 Address Read
data 2 result 1
register M data
u Data M
Write x u
memory x
data 1
0
Write
data
Instruction
X [15– 0] Sign X ALU MemRead
extend control
Instruction
X [20– 16] X
0 ALUOp
M 10
Instruction u
12 [15– 11] 12 11 x
1
Clock 4 RegDst
25
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 5o ciclo
or $13, $6, $7
add $14, $8, $9
IF: add $14, $8, $9 ID: or $13, $6, $7 EX: and $12, . . . MEM: sub $11, . . . WB: lw $10, . . .
Add
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
6 Read
MemtoReg
Instruction
Instruction
X [15– 0] Sign X ALU MemRead
extend control
Instruction
X [20– 16] X
0 ALUOp
M 11 10
Instruction u
13 [15– 11] 13 12 x
Clock 5 1
RegDst
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 6o ciclo
or $13, $6, $7
add $14, $8, $9
IF: after<1> ID: add $14, $8, $9 EX: or $13, . . . MEM: and $12, . . . WB: sub $11, . . .
Add
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
8 Read
MemtoReg
Instruction
register 1
PC Address Read $8 $6
9 data 1
Read
register 2 Zero
Instruction
Registers Read $9 $7 ALU ALU
memory 11 Write 0 Read
data 2 result Address 1
register M data
u Data M
Write x memory u
data x
1
0
Write
data
Instruction
X [15– 0] Sign X ALU MemRead
extend control
Instruction
X [20– 16] X
0 ALUOp
M 12 11
Instruction u
14 [15– 11] 14 13 x
1
Clock 6 RegDst
26
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 7o ciclo
or $13, $6, $7
add $14, $8, $9
IF: after<2> ID: after<1> EX: add $14, . . . MEM: or $13, . . . WB: and $12, . . .
Add
Add
4 Add result
MemWrite
ALUSrc
Read
MemtoReg
Instruction
Instruction
[15– 0] Sign ALU MemRead
extend control
Instruction
[20– 16]
0 ALUOp
M 13 12
Instruction u
[15– 11] 14 x
1
Clock 7 RegDst
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 8o ciclo
or $13, $6, $7
add $14, $8, $9
IF: after<3> ID: after<2> EX: after<1> MEM: add $14, . . . WB: or $13, . . .
Add
4 Add
Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
Read
MemtoReg
Instruction
PC Address register 1
Read
data 1
Read
register 2 Zero
Instruction
Registers Read ALU ALU
memory 13 Write 0 Read
data 2 result Address 1
register M data
u Data M
Write x memory u
data x
1
0
Write
data
Instruction
[15– 0] Sign ALU MemRead
extend control
Instruction
[20– 16]
0 ALUOp
M 14 13
Instruction u
[15– 11] x
1
Clock 8 RegDst
27
lw $10, 20 ($1)
sub $11, $2, $3
and $12, $4, $5 9o ciclo
or $13, $6, $7
add $14, $8, $9
IF: after<4> ID: after<3> EX: after<2> MEM: after<1> WB: add $14, . . .
Add
Add
4 Add result
RegWrite
Shift Branch
left 2
MemWrite
ALUSrc
Read
MemtoReg
Instruction
Instruction
[15– 0] Sign ALU MemRead
extend control
Instruction
[20– 16]
0 ALUOp
M 14
Instruction u
[15– 11] x
1
Clock 9 RegDst
Dependências
28
Time (in clock cycles)
Value of CC 1 CC 2 CC 3 CC 4 CC 5 CC 6 CC 7 CC 8 CC 9
register $2: 10 10 10 10 10/– 20 – 20 – 20 – 20 – 20
Program
execution
order Se a escrita no banco
(in instructions)
Reg
de registradores é
sub $2, $1, $3 IM Reg DM
feita no 1o semi-ciclo
e a leitura no 2o, em
and $12, $2, $5 IM Reg DM Reg CC5 não há hazard.
Reg WR Reg RD
29
Solução por Hardware
Forwarding
Tim e (in clock cycles)
CC 1 CC 2 CC 3 CC 4 CC 5 CC 6 CC 7 CC 8 CC 9
Value of register $2 : 10 10 10 10 10/– 20 – 20 – 20 – 20 – 20
Value of EX/M EM : X X X – 20 X X X X X
Value of M EM /W B : X X X X – 20 X X X X
Program
execution order
(in instru ctions)
sub $2, $1, $ 3 IM Reg DM R eg
or $13, $6, $2 IM R eg DM R eg
sw $15, 100($2) IM R eg DM R eg
30
Condições que determinam Hazards de dados
• EX/MEM
– EX/MEM.RegisterRd = ID/EX.RegisterRs
– EX/MEM.RegisterRd = ID/EX.RegisterRt
• MEM/WB
– MEM/WB.RegisterRd = ID/EX.RegisterRs
– MEM/WB.RegisterRd = ID/EX.RegisterRt
• Exemplo:
sub $2, $1, $3 # reg $2 modificado
and $12, $2, $5 # valor de $2 depende do sub
or $13, $6, $2 # idem (2º operando)
add $14,$2, $2 # idem (1º e 2º operandos)
sw $15, 100($2) # idem (base do endereçamento)
31
Condições que determinam Hazard de dados
Registers ALU
Data
memory M
u
x
a. No forwarding
32
Datapath com Forwarding ( para add, sub, and e or )
M
u
x
Registers
ForwardA ALU
M Data
u memory
x M
u
x
Rs ForwardB
Rt
Rt M
u EX/MEM.RegisterRd
Rd
x
Forwarding MEM/WB.RegisterRd
unit
b. With forwarding
33
Detecção e Controle de hazard
34
Observações:
Observações:
35
Datapath modificado para fowarding
ID/EX
WB
EX/MEM
C ontrol M WB
MEM/WB
IF/ID EX M WB
M
Instruction
u
x
Registers
Instruction Data
PC ALU
mem ory memory M
u
M x
u
x
IF/ID.RegisterRs Rs
IF/ID.RegisterRt Rt
IF/ID.RegisterRt Rt
M EX/MEM.RegisterRd
IF/ID.RegisterRd Rd u
x
Forwarding MEM/WB.RegisterRd
unit
ID/EX
10 10
WB
EX/MEM
Control M WB
MEM/WB
IF/ID EX M WB
2 $2 $1
M
Instruction
5 u
x
Registers
Instruction Data
PC ALU
memory memory M
$5 $3
u
M x
u
x
2 1
5 3
M
4 2 u
x
Forwarding
unit
Clock 3
36
sub $2, $1, $3
Forwarding and $4, $2, $5
or $4, $4, $2
add $9, $4, $2
add $9, $4, $2 or $4, $4, $2 and $4, $2, $5 sub $2, . . . before<1>
ID/EX
10 10
WB
EX/MEM
10
Control M WB
MEM/WB
IF/ID EX M WB
4 $4 $2
M
Instruction
6 u
x
Registers
Instruction Data
PC ALU
memory memory M
$2 $5
u
M x
u
x
2 2
6 5
M 2
4 4 u
x
Forwarding
unit
Clock 4
ID/EX
10 10
WB
EX/MEM
10
Control M WB
MEM/WB
1
IF/ID EX M WB
4 $4 $4
M
Instruction
2 u
x
Registers
Instruction 2 Data
PC ALU
memory memory M
$2 $2
u
M x
u
x
4 4
2 2
M 4 2
9 4 u
x
Forwarding
unit
Clock 5
37
sub $2, $1, $3
Forwarding and $4, $2, $5
or $4, $4, $2
add $9, $4, $2
ID/EX
10
WB
EX/MEM
10
Control M WB
MEM/WB
1
IF/ID EX M WB
$4
M
Instruction
u
x
Registers
Instruction 4 Data
PC ALU
memory memory M
$2
u
M x
u
x
4
2
M 4 4
9 u
x
Forwarding
unit
Clock 6
M
u
x
Registers
ALUSrc
ALU
M M Data
u u memory
x x M
u
x
M
u
x
Forwarding
unit
38
Data Hazard e Stalls
Time (in clock cycles)
Program CC 1 CC 2 CC 3 CC 4 CC 5 CC 6 CC 7 CC 8 CC 9
execution
order
(in instructions)
lw $2, 20($1) IM Reg DM Reg
if (ID/EX.MemRead and
((ID/EX.RegisterRt = IF/ID.RegisterRs) or
( ID/EX.RegisterRt = IF/ID.RegisterRt)))
stall pipeline
Paulo C. Centoducatte 1998 Morgan Kaufmann Publishers
Ch6.a-78
39
Data Hazards e Stalls
bubble
• Como fazer?
Impedir a mudança no PC e no registrador IF/IF. A
instrução em IF continua sendo lida e em ID continuam
sendo lido os mesmos campos da instrução.
40
Datapath com forwarding e data hazard detection
Hazard ID/EX.MemRead
detection
unit ID/EX
WB
IF/IDWrite
EX/MEM
M
Control u M WB
x MEM/WB
0
IF/ID EX M WB
PCWrite
M
In struction
u
x
Registers
Instruction Data
PC ALU
mem ory memory M
u
M x
u
x
IF/ID.RegisterRs
IF/ID.RegisterRt
IF/ID.RegisterRt Rt M EX/MEM.RegisterRd
IF/ID.RegisterRd Rd u
x
ID/EX.RegisterRt Rs Forwarding MEM/WB.RegisterRd
Rt unit
EX/MEM
M
Control u M WB
x MEM/WB
0
IF/ID EX M WB
1 $1
PCWrite
M
Instruction
X u
x
Registers
Instruction Data
PC ALU
memory memory M
$X
u
M x
u
x
1
X
2
M
u
x
ID/EX.RegisterRt Forwarding
unit
Clock 2
41
Seqüência de execução do exemplo anterior
EX/MEM
M
Control u M WB
x MEM/WB
0
IF/ID EX M WB
2 $2 $1
PCWrite
M
Instruction
5 u
x
Registers
Instruction Data
PC ALU
memory memory M
$5 $X
u
M x
u
x
2 1
5 X
2 M
4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 3
EX/MEM
M 11
Control u M WB
x MEM/WB
0
IF/ID EX M WB
2 $2 $2
PCWrite
M
Instruction
5 u
x
Registers
Instruction Data
PC ALU
memory memory M
$5 $5
u
M x
u
x
2 2
5 5
M 2
4 4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 4
42
Seqüência de execução do exemplo anterior
add $9, $4, $2 or $4, $4, $2 and $4, $2, $5 bubble lw $2, . . .
Hazard
ID/EX.MemRead
detection
4 unit ID/EX
2
10 10
WB
IF/IDWrite
EX/MEM
M 0
Control u M WB
x MEM/WB
0
11
IF/ID EX M WB
4
PCWrite
$4 $2
M
Instruction
2 u
x
Registers
Instruction 2 Data
PC ALU
memory memory M
$2 $5
u
M x
u
x
4 2
2 5
M 2
4 4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 5
EX/MEM
M 10
Control u M WB
x MEM/WB
0
0
IF/ID EX M WB
4 $4
PCWrite
$4
M
Instruction
2 u
x
Registers
Instruction Data
PC ALU
memory memory M
$2 $2
u
M x
u
x
4 4
2 2
M 4
9 4 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 6
43
Seqüência de execução do exemplo anterior
after<2> after<1> add $9, $4, $2 or $4, . . . and $4, . . .
Hazard
detection ID/EX.MemRead
unit ID/EX
10 10
WB
IF/IDWrite
EX/MEM
M 10
Control u M WB
x MEM/WB
0
1
IF/ID EX M WB
$4
PCWrite
M
Instruction
u
x
Registers
Instruction 4 Data
PC ALU
memory memory M
$2
u
M x
u
x
4
2
M 4 4
9 u
x
ID/EX.RegisterRt Forwarding
unit
Clock 7
Branch Hazards
44
Branch Hazards
• Branch-delay Slots
Branch Hazards
• Redução do atraso de branches
45
Branch Hazards
IF.Flush
Hazard
detection
unit
M ID/EX
u
x
WB
EX/MEM
M
Control u M WB
x MEM/WB
0
IF/ID EX M WB
4 Shift
left 2
M
u
x
Registers =
Instruction Data
PC ALU
memory memory M
u
M x
u
x
Sign
extend
M
u
x
Forwarding
unit
46
Branch Hazards (exemplo)
and $12, $2, $5 beq $1, $3, 7 sub $10, $4, $8 before<1> before<2>
IF.Flush
Hazard
detection
unit
72 ID/EX
M
u
48 x WB
EX/MEM
M
Control u M WB
x MEM/WB
28
0
IF/ID EX M WB
48 44 72
4
$1
Shift M $4
left 2 u
x
=
Registers
Instruction Data
PC ALU
memory memory M
72 44 $3
u
M $8 x
7 u
x
Sign
extend
10
Forwarding
unit
Clock 3
IF.Flush
Hazard
detection
unit
ID/EX
M
u
76 x WB
EX/MEM
M
Control u M WB
x MEM/WB
0
IF/ID EX M WB
76 72
Shift M $1
left 2 u
x
Registers
=
Instruction Data
PC ALU
memory memory M
76 72
u
M $3 x
u
x
Sign
extend
10
Forwarding
unit
Clock 4
47
Dymanic Branch Prediction
• Implementação
• branch prediction buffer
• branch history table
48
Tratamento de Exceção
Hazard
detection
unit
M ID/EX
40000040 u M
x u
WB x
0 EX/MEM
M M
Control u M u WB
x x MEM/WB
0
0
EX Cause M WB
IF/ID
Except
PC
4 Shift
left 2
M
u
x
Registers = Data
Instruction ALU
PC memory
memory M
u
M x
u
x
Sign
extend
M
u
x
Forwarding
unit
Tratamento de Exceção
Exemplo:
Dado a seqüência abaixo:
40hex sub $11, $2, $4
44hex and $12, $2, $5
48hex or $13, $2, $6
4Chex add $1, $2, $1
50hex slt $15, $6, $7
54hex lw $16, 50($7)
Assumir que as instruções a serem chamadas em um tratamento de exceção
comecem com:
40000040hex sw $25, 1000($0)
40000044hex sw $26, 1004($0)
49
Tratamento de Exceção - A figura abaixo mostra o que acontece a
partir da instrução add em EX (clock 5)
lw $ 1 6 , 5 0 ( $ 7 ) s lt $ 1 5 , $ 6 , $ 7 add $1, $2, $1 or $13, . . . and $12, . . .
IF .F l u s h ID .F lu s h E X . F lu s h
H a za rd
d e te c ti o n
u nit
M ID / E X
u M 0
4 0 00 0 0 4 0
x 0 10 u
W B x
0 E X /M E M
M 0 01 0 M 0
C o n t ro l u M u W B
x x M E M /W B
0
0
0 C ause 1
IF / I D EX M W B
58 54 50 E xce pt
PC
4 S h i ft
le f t 2 $6
M $2
u
x
12 R e g is t e r s = D ata
In s t r u c tio n ALU
PC m em ory
m e m ory $7 M
40 0 0 0 0 4 0 u
M $1 x
54 u
x
S ig n
e x te n d
M 13 12
$1 u
15 x
F o r w a r d in g
u n it
C lo c k 5
sw $ 2 5 , 1 0 0 0 ($ 0 ) b u b b le (n o p ) b u b b le b u b b le or $13, . . .
IF .F l u s h I D . F lu s h E X . F lu s h
H a za rd
d e te c ti o n
u nit
M ID / E X
u M 00
4 0 00 0 0 4 0 u
x 0 00
W B x
0 E X /M E M
C o n tr o l M 0 000 M 00
u M u W B
x x M E M /W B
0
0
4 0 0 0 00 4 4 0 1
EX C ause M W B
IF / I D
E xce pt
PC
4 S h i ft
le ft 2
M
u
x
13 R e g is t e r s = D a ta
In s t r u c tio n ALU
PC m em o ry
m e m ory M
4 0 0 0 0 0 44 u
M x
40000040 u
x
S ig n
e x te n d
M 13
u
x
F o r w a r d in g
u n it
C lo c k 6
M
u
x
4
ALU
M
Registers u
Instruction x
PC
memory Write
data
Data
memory
M
u
x
50
Pipeline Super Escalar
Exemplo:
Solução:
A primeira com a terceira e as duas últimas instruções
tem dependência de dados.
51
Pipeline Super Escalar
Loop unrolling para pipelines escalares técnica para aumentar o
desempenho para loops que acessam arrays múltiplas cópias do corpo do
loop são feitas e instruções de diferentes iterações são escalonadas juntas
Datapath final
Branch
Hazard
detection
unit
M ID/EX
u M
40000040 u
x
WB x
0 EX/MEM
M M
Control u M u WB
x x MEM/WB
0
0
e EX Cause M WB
IF/ID t
ri
W e
g
e Except rit
W
R PC m
4 Shift ALUSrc e
M
left 2 Read
Read g
data 1 M e
register 1 R
u Data o
Instruction n Read x tm
o memory e
memory i
ctu
register 2 = M
Registers
r ALU Address
PC Address stn Write
I register Read Read
Read M
data Write data 2 M data u
M Write x
data u data
x u
x ALU
control
16 Sign 32 MemRead
extend ALUOp
RegDst
Instruction [25– 21]
Instruction [20– 16]
Instruction [20– 16] M
Instruction [15– 11] u
x
Forwarding
unit
52