Buscar

Pipelining e Hazards de Dados

Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original

Aula 7: Pipelining (parte 4 – Hazards de dados e Forwarding)
Professor: Leandro Marzulo
Arquiteturas Avançadas de Computadores
Exemplo
IM
REG
ALU
DM
REG
sub $t2, $t1, $t3
and $t4, $t2, $t5
or $t7, $t6, $t2
CC 1
CC 2
CC 3
CC 4
CC 5
CC 6
CC 7
IM
REG
ALU
DM
REG
IM
REG
ALU
DM
REG
add $t8, $t2, $t2
IM
REG
ALU
DM
REG
CC 8
Tempo (ciclo)
sw $t9, 100($t2)
IM
REG
ALU
DM
REG
CC 9
Valor de $t2
10
10
10
10
10/-20
-20
-20
-20
-20
Exempo - Questões
Quando é produzido realmente o resultado da instrução sub?
R: No final do ciclo 3 (estágio EX)
Quando os dados são realmente necessários para instruções and e or?
R: No início do estágio EX das mesmas, ou seja, no ciclos 4 e 5
Existe algum problema para a instrução sw?
R: Não, pois a leitura do banco é feita no ciclo 6, depois do WB já ter sido feito pelo sub.
Solução em software (compilador)
sub $t2, $t1, $t3
and $t4, $t2, $t5
or $t7, $t6, $t2
add $t8, $t2, $t2
sw $t9, 100($t2)
lw $s0, 100($s1)
slt $s2, $s3, $s4
OU
sub $t2, $t1, $t3
and $t4, $t2, $t5
or $t7, $t6, $t2
add $t8, $t2, $t2
sw $t9, 100($t2)
nop
nop
MIPS: nop = “no operation” = 00…0 (32bits) = sll $0, $0, 0
Condições de Hazard
1a – EX/MEM.RegistradorRd = ID/EX.RegistradorRs
1b - EX/MEM.RegistradorRd = ID/EX.RegistradorRt
2a – MEM/WB.RegistradorRd = ID/EX.RegistradorRs
2b - MEM/WB.RegistradorRd = ID/EX.RegistradorRt
Classificando as dependências
sub $t2, $t1, $t3
and $t4, $t2, $t5
or $t7, $t6, $t2
add $t8, $t2, $t2
sw $t9, 100($t2)
2b
1a
As duas dependências não são hazards, pois a escrita por sub é feita no início do ciclo 5 e as leituras por add são feitas no final do ciclo 5
Não é hazard, pois a escrita por sub é feita no início do ciclo 5 e a leitura por sw é feita no feita no final do ciclo 6
Exemplo
IM
REG
ALU
DM
REG
sub $t2, $t1, $t3
and $t4, $t2, $t5
or $t7, $t6, $t2
CC 1
CC 2
CC 3
CC 4
CC 5
CC 6
CC 7
IM
REG
ALU
DM
REG
IM
REG
ALU
DM
REG
add $t8, $t2, $t2
IM
REG
ALU
DM
REG
CC 8
Tempo (ciclo)
sw $t9, 100($t2)
IM
REG
ALU
DM
REG
CC 9
Valor de $t2
10
10
10
10
10/-20
-20
-20
-20
-20
Caminho de dados sem forward (resumido)
M
u
x
A
L
U
I
D
/
E
X
M
E
M
/
W
B
D
a
t
a
m
e
m
o
r
y
E
X
/
M
E
M
R
e
g
i
s
t
e
r
s
Caminho de dados com forward (resumido) – Apenas para resolver hazard do tipo R
R
e
g
i
s
t
e
r
s
M
u
x
M
u
x
A
L
U
I
D
/
E
X
M
E
M
/
W
B
D
a
t
a
m
e
m
o
r
y
M
u
x
F
o
r
w
a
r
d
i
n
g
u
n
i
t
E
X
/
M
E
M
F
o
r
w
a
r
d
B
R
d
E
X
/
M
E
M
.
R
e
g
i
s
t
e
r
R
d
M
E
M
/
W
B
.
R
e
g
i
s
t
e
r
R
d
R
t
R
t
R
s
F
o
r
w
a
r
d
A
M
u
x
Controle dos multiplexadores de forwarding
Controle
Origem
Explicação
ForwardA= 00
ID/EX
O1ºoperandodaALUvemdobanco
ForwardA= 10
EX/MEM
O 1º operando da ALUé encaminhado do resultado anterior da ALU
ForwardA= 01
MEM/WB
O 1º operando da ALUé encaminhado da memória de dados ou de um resultado anterior da ALU *
ForwardB= 00
ID/EX
O2ºoperandodaALUvemdobanco
ForwardB= 10
EX/MEM
O 2º operando da ALUé encaminhado do resultado anterior da ALU
ForwardB= 01
MEM/WB
O 2º operando da ALUé encaminhado da memória de dados ou de um resultado anterior da ALU *
* Dependendo da seleção do multiplexador controlado por MemReg
Hazards de dados: Detecção e Forwarding
Forwarding unit determina o controle do multiplexador de acordo com as regras de forwarding:
EX hazard
if (EX/MEM.RegWrite		// se temos uma escrita…
 and ( EX/MEM.RegisterRd  0 )	// para um registrador  de $zero…
 and ( EX/MEM.RegisterRd = ID/EX.RegisterRs ) ) // que case com RS… ForwardA = 10
if (EX/MEM.RegWrite		// se temos uma escrita…
 and ( EX/MEM.RegisterRd  0 )	// para um registrador  de $zero…
 and ( EX/MEM.RegisterRd = ID/EX.RegisterRT ) ) // que case com RT… ForwardB = 10
Hazards de dados: Detecção e Forwarding
MEM hazard
if (MEM/WB.RegWrite		 // se temos uma escrita…
and ( MEM/WB.RegisterRd  0 ) 	// para um registrador  de $zero…
 and ( EX/MEM.RegisterRd  ID/EX.RegisterRs ) //e não tivemos um casamento com TS
 //em um estágio de pipe anterior
 and ( MEM/WB.RegisterRd = ID/EX.RegisterRs ) ) // mas temos um casamento com RS em MEM…
 ForwardA = 01
if (MEM/WB.RegWrite		 // se temos uma escrita…
and ( MEM/WB.RegisterRd  0 ) 	// para um registrador  de $zero…
 and ( EX/MEM.RegisterRd  ID/EX.RegisterRt ) //e não tivemos um casamento com RT
 //em um estágio de pipe anterior
 and ( MEM/WB.RegisterRd = ID/EX.RegisterRt ) ) // mas temos um casamento com RT em MEM…
 ForwardB = 01
Caminho de dados e controle – Apenas para resolver hazard do tipo R
sub $2, $1, $3
and $4, $2, $5
or $4, $4, $2
add $9, $4, $2
Exemplo:
		
Simulando
P
C
I
n
s
t
r
u
c
t
i
o
n
m
e
m
o
r
y
R
e
g
i
s
t
e
r
s
M
u
x
M
u
x
M
u
x
E
X
M
W
B
W
B
D
a
t
a
m
e
m
o
r
y
M
u
x
F
o
r
w
a
r
d
i
n
g
u
n
i
t
I
n
s
t
r
u
c
t
i
o
n
I
F
/
I
D
a
n
d
 
$
4
,
 
$
2
,
 
$
5
s
u
b
 
$
2
,
 
$
1
,
 
$
3
I
D
/
E
X
b
e
f
o
r
e
<
1
>
E
X
/
M
E
M
b
e
f
o
r
e
<
2
>
M
E
M
/
W
B
o
r
 
$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n
t
r
o
l
A
L
U
1
0
W
B
2
1
4
Simulando
if (EX/MEM.RegWrite and ( EX/MEM.RegisterRd  0 )
 and ( EX/MEM.RegisterRd = ID/EX.RegisterRs)) ForwardA = 10
if (MEM/WB.RegWrite and ( MEM/WB.RegisterRd  0 )
 and ( EX/MEM.RegisterRd  ID/EX.RegisterRt ) 
 and ( MEM/WB.RegisterRd = ID/EX.RegisterRt ) ) ForwardB = 01
P
C
I
n
s
t
r
u
c
t
i
o
n
m
e
m
o
r
y
M
u
x
M
u
x
M
u
x
E
X
M
W
B
M
W
B
D
a
t
a
m
e
m
o
r
y
M
u
x
F
o
r
w
a
r
d
i
n
g
u
n
i
t
a
f
t
e
r
<
1
>
a
f
t
e
r
<
2
>
a
d
d
 
$
9
,
 
$
4
,
 
$
2
o
r
 
$
4
,
 
.
 
.
 
.
E
X
/
M
E
M
a
n
d
 
$
4
,
 
.
 
.
 
.
M
E
M
/
W
B
C
l
o
c
k
 
6
1
0
$
4
$
2
2
4
9
A
L
U
1
0
4
W
B
4
1
R
e
g
i
s
t
e
r
s
I
n
s
t
r
u
c
t
i
o
n
I
F
/
I
D
I
D
/
E
X
4
C
o
n
t
r
o
l
Simulando
if (EX/MEM.RegWrite and ( EX/MEM.RegisterRd  0 )
 and ( EX/MEM.RegisterRd = ID/EX.RegisterRs)) ForwardA = 10
ForwardB = 00
Contatos
19
leandro@ime.uerj.br
lmarzulo@cos.ufrj.br
leandro.marzulo@gmail.com

Teste o Premium para desbloquear

Aproveite todos os benefícios por 3 dias sem pagar! 😉
Já tem cadastro?

Continue navegando