### Hardware  ### Forwarding Unit #### The condition of Data Hazard 1. 前面指令有寫入 register 2. 前面指令的 `rd` 不得為 `$0` 3. 前面指令的 `rd` 和後面指令的 `rs` 或 `rt` 相同 #### Contorl Signals | MUXControl | Source | | ---------- | ------ | | ForwardA = 00 | ID/EX | | ForwardA = 01 | EX/MEM | | ForwardA = 10 | MEM/WB | | ForwardB = 00 | ID/EX | | ForwardB = 01 | EX/MEM | | ForwardB = 10 | MEM/WB | #### Behavior Code - EX Hazard ```python if(EX/MEM.RegWrite and (EX/MEM.RegRd != 0) and (EX/MEM.RegRd == ID/EX.RegRs)) ForwardA = 01 if(EX/MEM.RegWrite and (EX/MEM.RegRd != 0) and (EX/MEM.RegRd == ID/EX.RegRt)) ForwardB = 01 ``` - MEM Hazard 要注意不可同時有 EX Hazard ```python if(MEM/WB.RegWrite and (MEM/WB.RegRd != 0) and not(EX/MEM.RegWrite and (EX/MEM.RegRd != 0) and (EX/MEM.RegRd == ID/EX.RegRs)) and (MEM/WB.RegRd == ID/EX.RegRs)) ForwardA = 10 if(MEM/WB.RegWrite and (MEM/WB.RegRd != 0) and not(EX/MEM.RegWrite and (EX/MEM.RegRd != 0) and (EX/MEM.RegRd == ID/EX.RegRt)) and (MEM/WB.RegRd == ID/EX.RegRt)) ForwardB = 10 ``` ### Hazard Dection Unit #### Goal 1. 偵測 `load use` 並且 `stall` pipeline 2. Branch Taken 時負責殺指令 #### Behavior Code ```python if(ID/EX.MemRead and ((ID/EX.RegRt == IF/ID.RegRs) or(ID/EX.RegRt == IF/ID.RegRt))) stall the pipeline (1 cycle) ``` #### Stall pipeline - 同時暫停 `IF` 及 `ID` 指令 -> `PCWrite = 0` and `IF/IDWrite = 0` - 但 ID 至另會複製一份過去,所以要把他此份 flush 掉,作法是將 Ex stage 的九根控制信號線都設成 0 -> `ID.Flush = 1` #### Branch Not Taken 假設 branch 每次不會跳,又 branch decision 是在 `MEM stage`,所以只要 branch 有跳就要把 IF, ID, EX 的指令給 flush 掉 -> `IF.Flush = 1`, `ID.Flush = 1`, `EX.Flush = 1`
×
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