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解决
#------未完待续------#