Gestione degli hazard etodologie di progettazione Hardware/Software- LS Ing. Informatica Limiti alla eseczione pipeline: i conflitti ( Hazard ) I conflitti (Hazard) impediscono che na istrzione venga esegita nel ciclo di clock atteso -Strctral hazards: Le risorse HW non spportano alcne combinazioni di istrzioni -Data hazards: Un istrzione dipende dal risltato di na istrzione che è ancora nella pipeline -Control hazards: Pipelining di branch e altre istrzioni che cambiano il PC La solzione più semplice è introdrre dei cicli di clck di stallo nella pipeline fino a qando l hazard non è risolto, inserendo na o più bolle nella pipeline. etodologie di progettazione Hardware/Software- LS Ing. Informatica
Strctral Hazard Esempio di strctral hazard qando è presente n nica memoria per le istrzioni e i dati Solzioni Introdrre na bolla, na nop (not operation): Viene bloccata l'istrzione nella fase IF impedendo l'aggiornamento del PC; Viene scritto sl registro IF/ID na NOP Dplicare le risorse hardware etodologie di progettazione Hardware/Software- LS Ing. Informatica 3 Data Hazard ( cycles Time (in clock Vale of register $: Program eection order ( instrctions (in sb $, $, $3 CC CC CC 3 CC CC CC 6 I CC 7 CC 8 CC 9 / D and $, $, $ I D or $3, $6, $ I D add $, $, $ I D ( ($ sw $, I D etodologie di progettazione Hardware/Software- LS Ing. Informatica
Data Hazard: introdzione degli stalli Una solzione ai data hazard è l'introdzione di cicli di clock di stallo. Poichè il data hazard viene scoperto nella fase ID, qando viene introdotto no stallo per i data hazard: Viene bloccata l'istrzione nella fase ID impedendo l'aggiornamento del registro IF/ID; Viene bloccata l'istrzione nella fase IF non aggiornando il PC Vengono scritti sl registro ID/ i segnali di controllo relativi a na nop I cicli di stallo vengono ripetti fino a qando non viene aggiornato il registro destinazione Il nmero di cicli di clock di stallo dipende dalla distanza tra le istrzioni etodologie di progettazione Hardware/Software- LS Ing. Informatica Data Hazard: introdzione degli stalli add r, r, r3 IF ID E sb r, r, r IF ID stall stall E add r, r, r3 IF ID E sbi r3, r, IF ID E addi r, r, IF ID stall E etodologie di progettazione Hardware/Software- LS Ing. Informatica 6 3
Data Forwarding ( cycles Time (in clock CC CC CC 3 CC CC CC 6 CC 7 CC 8 CC 9 Vale of register $ : / Vale of /E : X X X X X X X X Vale of E/ : X X X X X X X X Program eection order ( instrctions (in sb $, $, $3 I D and $, $, $ I D or $3, $6, $ I D add $, $, $ I D ( ($ sw $, I D etodologie di progettazione Hardware/Software- LS Ing. Informatica 7 Implementazione del forwarding ID / / E E / is t e rs F o r w a r d A D a ta m e m o ry R s F o rw a r d B R t R t R d / E. is te rr d F o rw a r d in g n it E /. is t e rr d b. W i th fo rw a rd in g etodologie di progettazione Hardware/Software- LS Ing. Informatica 8
Implementazione del forwarding ID/ C ontrol / E E/E.Write E / IF/ID em/.write PC Instrc tion m em ory I n s tr c tio n isters ALU Data m em ory IF /ID.R egis terr s R s IF /ID.R egis terrt R t IF /ID.R egis terrt R t / E.isterRd IF /ID.R egis terr d R d Forwarding nit E /.R egisterrd etodologie di progettazione Hardware/Software- LS Ing. Informatica 9 Control+Forwarding o r $, $, $ a n d $, $, $ s b $, $, $ 3 b e f o re < > b e fo re < > ID / / E C o n tro l E / IF / ID $ $ I n s t r c t io n In s t r c t io n is te r s $ $ 3 m e m o ry 3 F o r w a r d in g n it C lo c k 3 etodologie di progettazione Hardware/Software- LS Ing. Informatica
Control+Forwarding a d d $ 9, $, $ o r $, $, $ a n d $, $, $ s b $,... b e fo r e < > ID / / E C o n tro l E / IF /I D $ $ Instrc tion m e m o ry I n s t r c t io n 6 is te r s $ $ 6 F o r w a r d in g n it C lo c k etodologie di progettazione Hardware/Software- LS Ing. Informatica Control+Forwarding after< > a d d $ 9, $, $ o r $, $, $ a n d $,... s b $,... ID / / E C o n tro l E / I F /I D $ $ Instrc tion In s t r c t io n is t e r s $ $ 9 F o r w a r d in g n it C lo c k etodologie di progettazione Hardware/Software- LS Ing. Informatica 6
Control+Forwarding a f te r < > a f te r< > a d d $ 9, $, $ o r $,... a n d $,... ID / / E C o n tr o l E / IF / ID $ Instrctio n I n s t r c t io n is t e r s $ 9 F o rw a rd in g n it C lo c k 6 etodologie di progettazione Hardware/Software- LS Ing. Informatica 3 Forwarding per lw ( ycles T im e (in clock c P r o g ra m e e c tio n o rd e r ( s (in in s tr c tio n C C C C C C 3 C C C C C C 6 C C 7 C C 8 C C 9 ( ($ lw $, I D a n d $, $, $ I D o r $ 8, $, $ 6 I D a d d $ 9, $, $ I D s l t $, $ 6, $ 7 I D etodologie di progettazione Hardware/Software- LS Ing. Informatica 7
Introdzione di no stallo per lw P ro gr am e ec tion o rd e r ( instrctions (in ( cycles Tim e (in clock C C C C C C 3 C C C C C C 6 C C 7 C C 8 C C 9 C C lw $, ( ($ I D a n d $, $, $ I D o r $ 8, $, $ 6 I I D bbble a d d $ 9, $, $ I D R eg slt $, $ 6, $ 7 I R eg D etodologie di progettazione Hardware/Software- LS Ing. Informatica Hazard detection nit Ha zard detec tion nit ID /.e mr ead ID/ IF /ID W r ite C ontrol / E E / IF/ID W rite Instrction m em ory In s tr c tio n isters ALU D ata memory IF /ID.isterR s IF /ID.isterR t IF /ID.isterR t IF /ID.isterR d Rt R d / E.isterRd ID /.R egisterrt R s Rt Forw arding nit E /.isterrd etodologie di progettazione Hardware/Software- LS Ing. Informatica 6 8
Hazard detection nit and $, $, $ lw $, ($ ) befo re< > b efore<> be fore<3> H a z a rd d e te c t io n I D /. e m R e a d n it ID / X I F /I D W ri te C o n tro l / E E / IF /I D W r it e Instrc tio n m e m o ry In s t r c t io n X i ste r s $ $ X X I D /. is te rr t F o r w a r d in g n it C lo c k etodologie di progettazione Hardware/Software- LS Ing. Informatica 7 Hazard detection nit o r $, $, $ a n d $, $, $ lw $, ($ ) b e fo r e < > b e fo r e < > H a z a r d d e te c ti o n n it ID /. e m R e a d ID / IF / ID W r i te C o n tr o l / E E / IF /I D W r ite Instrc tio n In s t r c t io n i s te r s $ $ $ $ X X I D /. ist e rr t F o rw a r d in g n it C lo c k 3 etodologie di progettazione Hardware/Software- LS Ing. Informatica 8 9
Hazard detection nit o r $, $, $ a n d $, $, $ b b b le lw $,... b e fo re < > H a z a r d d e te c tio n n it ID /. e m R e a d ID / IF /ID W r it e C o n t r o l / E E / I F /ID W r it e Ins tr ction I n s tr c tio n is t e r s $ $ $ $ ID /. is te r R t F o r w a r d in g n it C lo c k etodologie di progettazione Hardware/Software- LS Ing. Informatica 9 Hazard detection nit a d d $ 9, $, $ o r $, $, $ a n d $, $, $ b b b l e lw $,... H a z a r d d e t e c tio n n it ID /. e m R e a d ID / IF / ID W r i te C o n t ro l / E E / I F /ID W r it e Ins tr ction In s tr c t io n is t e rs $ $ $ $ D a ta I D /. is t e r R t F o r w a rd in g n it C lo c k etodologie di progettazione Hardware/Software- LS Ing. Informatica
Hazard detection nit a f te r< > a d d $ 9, $, $ o r $, $, $ a n d $,... b b b l e H a z a r d d e te c tio n n it I D /. e m R e a d ID / IF /ID W r ite C o n tro l / E E / IF /I D W r it e Instrc tio n I n s t r c t io n i st e r s $ $ $ $ m e m o ry 9 I D /. is te r R t F o rw a r d in g n it C lo c k 6 etodologie di progettazione Hardware/Software- LS Ing. Informatica Hazard detection nit a f te r< > a ft e r< > a d d $ 9, $, $ o r $,... a n d $,... H a z a rd d e t e c t io n n it I D /. e m R e a d ID / IF / ID W r i te C o n tr o l / E E / IF / ID W r i te Instrctio n In s tr c t io n is te r s $ $ D a ta m e m o ry 9 I D /. i st e r R t F o r w a r d in g n it C lo c k 7 etodologie di progettazione Hardware/Software- LS Ing. Informatica
Branch Program eection order (in instrctions) Time (in clock cycles) CC CC CC 3 CC CC CC 6 CC 7 CC 8 CC 9 beq $, $3, 7 I D and $, $, $ I D 8 or $3, $6, $ I D add $, $, $ I D 7 lw $, ($7) I D etodologie di progettazione Hardware/Software- LS Ing. Informatica 3 Branch I control hazard pò essere gestiti mediante stalli impedendo il completamento della fase di fetch dell istrzione sccessiva fino a qando non si conosce l esito del branch Disabilitando l incremento del PC Scrivendo s registro IF/ID na NOP etodologie di progettazione Hardware/Software- LS Ing. Informatica
Branch IF.Flsh Hazard detection nit ID/ /E Control E/ IF/ID PC Instrction memory Shift left isters = ALU Data memory Sign etend Forwarding nit etodologie di progettazione Hardware/Software- LS Ing. Informatica Branch a n d $, $, $ b e q $, $ 3, 7 s b $, $, $ 8 b e f o r e < > b e f o r e < > IF.Flsh H a z a r d d e t e c ti o n n it 7 8 ID / / E C o n tr o l 8 E / I F / ID 8 7 $ S h if t l e f t = $ 7 In s tr c ti o n is t e r s $ 3 7 $ 8 S ig n e t e n d F o r w a rd in g n it C l o c k 3 etodologie di progettazione Hardware/Software- LS Ing. Informatica 6 3
Branch lw $, ( $ 7 ) b b b l e ( n o p ) b e q $, $ 3, 7 s b $,... b e f o r e < > IF.Flsh H a z a rd d e te c ti o n n it 7 6 ID / / E C o n tr o l E / IF / I D 7 6 7 S h if t l e f t $ = 7 6 7 In s tr c ti o n i s t e rs $ 3 S ig n e t e n d F o r w a r d in g n it C l o c k etodologie di progettazione Hardware/Software- LS Ing. Informatica 7