Pipeline_cpu pipeline hazard解決方案---stall+Foward技術
#-----個人粗淺理解,僅供參考---------#
一,先來看forwarding技術
如圖所示加入Forwarding unit在excution與memory/write back 的stage之間的bypath結構
工作原理:
- 比較excution的source register 和 memory/write back的dst register是否相同 ,若memory/write back的dst register相同則選擇memory的data進行bypath(mem stage的data是最新的)
- 若match則將memory/write back的dst register的data bypath給excution stage
- 通過MUX直接將data遞給ALU進行操作
有些指令執行場景只通過forwarding技術沒辦法解決,需要stall技術來協同解決
二,stall+forwarding技術
such as:1.lw $2 ..... 2.add $4,$2,$5(先執行lw後執行add)
這時如圖所示使用forwarding技術將會跨兩級組合邏輯,這是無法滿足timing要求的。
stall技術,需要在instruction decoding 和excution stage之間加入Hazard detection unit(如下圖)
Hazard detection unit工作原理:
- 確認到excution stage的指令是lw,且instruction decoding stage的指令的source register 與在excution stage的指令 dst register進行對比發現match
- stall住PC,instruction fetch,等控制信號產生一個bubble stage在lw與下一條指令之間
- 當lw指令進行到write back stage時再通過forwarding unit將hazard解決
#------未完待續------#