計算機組織Ch4 === ###### tags: `計算機組織` Pipeline --- - ### 定義 : overlapping execution , 不同指令在不同元件中被執行 - ### all stages are balanced : - speed up due to increased throughput > 因為單位時間執行的指令變多 - Latency doesn't decrease > 一個指令執行的時間增加 - 總結 : pipeline只會提高單位時間執行的指令個數,不會減少每一個指令執行的時間 Hazard --- - ### 定義 : 無法在下個cycle執行下個指令 - ### Structure hazards : - 定義 : 資源上的不夠 - e.g : 暫存器可寫讀,如果共用情況下讀的時候就不可以寫,寫的時候就不可以讀 - ### Data hazards : - 定義 : 指令之間有相依性,前面指令還沒做完但後面的指令就要使用了 :::success e.g. add <font color=#FF0000>$s0</font> , $t0 , $t1 sub $s2 , <font color=#FF0000> $s0</font> , $t3  ::: - ### Control hazards : - 定義 : fetch next instruction depends on branch outcome > branch要執行完ID stage之後才知道IF stage要抓取的指令位置,如果猜錯就會flush掉 - static branch prediction : 經過統計後去判斷 - dynamic branch prediction : 相關行為紀錄下來 - ### Data hazard happen when : :::success - EX/MEME.RegisterRd = ID/EX.RegisterRs - EX/MEME.RegisterRd = ID/EX.RegisterRt > fwd from EX/MEME ::: :::success - MEME/WB.RegisterRd = ID/EX.RegisterRs - MEME/WB.RegisterRd = ID/EX.RegisterRt > fwd from MEM/WB ::: - ### Detecting the need to forward : - 前指令或前前指令必須是會更新暫存器的 - 前指令或前前指令寫入的暫存器必須是非$0 - ### Forwarding Condition : :::success 1. EX hazard - if (EX/MEM.RegWrite and (EX/MEM.RegisterRd != 0) and (EX/MEM.RegisterRd = ID/EXE.RegisterRs)) - if (EX/MEM.RegWrite and (EX/MEM.RegisterRd != 0) and (EX/MEM.RegisterRd = ID/EXE.RegisterRt)) 2. MEM hazard - if (MEM/WB.RegWrite and (MEM/WB.RegisterRd != 0) <font color=#808080>and not (EX/MEM.RegWrite and (EX/MEM.RegitserRd != 0) and (EX/MEM.RegisterRd = ID/EXE.RegisterRs)) </font> and (MEM/WB.RegisterRd = ID/EXE.RegisterRs)) - if (MEM/WB.RegWrite and (MEM/WB.RegisterRd != 0) <font color=#808080>and not (EX/MEM.RegWrite and (EX/MEM.RegitserRd != 0) and (EX/MEM.RegisterRd = ID/EXE.RegisterRt)) </font>and (MEM/WB.RegisterRd = ID/EXE.RegisterRt)) > <font color=#808080>前前指令要給資料時,必須是在前指令無法給資料的條件下</font> ::: - ### Load-Use hazard detection - Check when using instruction is decoded in ID stage - Load-use hazard when : > ID/EX.MemRead and ((ID/EX.RegisterRt = IF/ID.RegisterRs) or (ID/EXE.RegisterRt = IF/ID.RegisterRt)) > 即將進到ID階段的指令有無使用到即將進到EX階段要寫入的暫存器 - ### Data Hazard solution - Stall - Forwarding - Reordering - ### Branch hazard - branch outcome determined in MEM - 因為在EXE階段結束才能確定是否相等,因此taken或not taken要在MEM階段確定 - ### Reducing branch delay - move hardware to determine outcome to ID stage - target address adder - register comparator - ### Data hazard for branch   - ### Branch prediction buffer - 紀錄branch指令之前的執行紀錄 - 因為要計算taken產生的位置所以比較花時間  - ### Branch target buffer : - 記錄過去使用過的branch target位置 - 成本較貴 - ### Control hazard solution : - Stall - Predict - Delayed branch - ### The way to improve instruction-level parallelist : 1. deeper pipeline 2. superscalar 3. code scheduling - ### Out of order execution : 後面沒有相依性的指令可以先執行 - ### Precise exceptions : 前面指令所發生的exception先處理
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up