CS3410 Spring 2016
Design Preliminary Documentation Due: 11:59pm, Tuesday, March 8th, 2016
Project Due: 11:59pm, Tuesday, March 15th, 2016
1a. EX/MEM.RegisterRd == ID/EX.RegisterRs 1b. EX/MEM.RegisterRD == ID/EX.RegisterRt 2a. MEM/WB.RegisterRd == ID/EX.RegisterRs 2b. MEM/WB.RegisterRd == ID/EX.RegisterRtTo resolve the first two data hazards, we can forward value from the EX/MEM pipeline registers. To resolve the latter two hazards, we can forward value from the MEM/WB pipeline registers. In order to figure out the correct forwarding control logic, we note that forward will happen:
1. only if the forwarding instruction will write to a register EX/MEM.Regwrite, MEM/WB.Regwrite 2. AND only if Rd for that instruction is not $zero EX/MEM.RegisterRd != 0, MEM/WB.RegisterRd != 0 3. AND only if forwarding instruction is not a load in MEM stage EX/MEM.MemRead == 0From the above, we can derive the following forwarding conditions:
if (EX/MEM.RegWrite and (EX/MEM.RegisterRd != 0) and (EX/MEM.RegisterRd == ID/EX.RegisterRs)) ForwardA = 10 if (EX/MEM.RegWrite and (EX/MEM.RegisterRd != 0) and (EX/MEM.RegisterRd == ID/EX.RegisterRt)) ForwardB = 10MEM Hazard
if (MEM/WB.RegWrite and (MEM/WB.RegisterRd != 0) and (MEM/WB.RegisterRd == ID/EX.RegisterRs)) ForwardA = 01 if (MEM/WB.RegWrite and (MEM/WB.RegisterRd != 0) and (MEM/WB.RegisterRd == ID/EX.RegisterRt)) ForwardB = 01However, if we have a sequence of code that causes both data hazards to happen:
add $1, $1, $2 sub $1, $1, $3 or $1, $1, $4then we want to use the most recent result--the result from the sub instruction.
if (MEM/WB.RegWrite and (MEM/WB.RegisterRd != 0)
and not (EX/MEM.RegWrite and (EX/MEM.RegisterRd != 0)
and (EX/MEM.RegisterRd == ID/EX.RegisterRs))
and (MEM/WB.RegisterRd == ID/EX.RegisterRs))
ForwardA = 01
if (MEM/WB.RegWrite and (MEM/WB.RegisterRd != 0)
and not (EX/MEM.RegWrite and (EX/MEM.RegisterRd != 0)
and (EX/MEM.RegisterRd == ID/EX.RegisterRt))
and (MEM/WB.RegisterRd == ID/EX.RegisterRt))
ForwardB = 01
Note that the forward condition for MEM hazard on page 369 in the revised 4th edition textbook (and earlier versions) is WRONG! Starting in the 5th edition (page 311), it is correct.