Lecture-16 CH-04 4
Lecture-16 CH-04 4
Edition
The Hardware/Software Interface
Chapter 4
The Processor
§4.8 Data Hazards: Forwarding vs. Stalling
Data Hazards in ALU Instructions
◼ Consider this sequence:
sub $2, $1,$3
and $12,$2,$5
or $13,$6,$2
add $14,$2,$2
sw $15,100($2)
◼ We can resolve hazards with forwarding
◼ How do we detect when to forward?
ForwardB = 00 ID/EX The second ALU operand comes from the register
file.
ForwardB = 10 EX/MEM The second ALU operand is forwarded from the prior
ALU result.
ForwardB = 01 MEM/WB The second ALU operand is forwarded from data
memory or an earlier ALU result.
Need to stall
for one cycle
Stall inserted
here
Flush these
instructions
(Set control
values to 0)
PC
… IF ID EX MEM WB
beq stalled IF ID
beq stalled IF ID
beq stalled ID