Microprocessors Piplining Slides
Microprocessors Piplining Slides
Instruction
Clock number
Number
1 2 3 4 5 6 7 8 9 10 11 12
ME
load IF ID EX WB
M
Instruction ME
IF ID EX WB
i+1 M
Instruction ME
IF ID EX WB
i+2 M
Instruction ME
i+3
stall stall stall IF ID EX
M
WB
Instruction ME
IF ID EX WB
i+4 M
Instruction ME
IF ID EX
i+5 M
• Another way to represent the stall – no instruction is
initiated in clock cycle 4,5 and 6
Structural Hazards (5)
• Both IF and MEM use cache
– Sol:- Use separate cache for data and code each
• ID and WB use Register port.
– Sol:- in ist half of clock cycle use Register for ID
(Reading from the register) and in second half of cycle
use it for WB(Writing into the register)
Structural Hazards (4)
Instruction
Clock number
Number
1 2 3 4 5 6 7 8 9 10
ME
load IF ID EX WB
M
Instruction ME
IF ID EX WB
i+1 M
Instruction ME
IF ID EX WB
i+2 M
Instruction ME
IF ID EX WB
i+3 M
Instruction ME
IF ID EX WB
i+4 M
Instruction ME
IF ID EX WB
i+5 M
• After resolving the issue
Data Hazards (1)
• Data hazards occur when the pipeline changes the
order of read/write accesses to operands so that the
order differs from the order seen by sequentially
executing instructions on an un-pipelined machine
• Consider the execution of following instructions, on
our pipelined example processor:
– ADD R1, R2, R3
– SUB R4, R1, R5
– AND R6, R1, R7
– OR R8, R1, R9
– XOR R10, R1, R11
Data Hazards (2)
• The use of results from ADD instruction causes hazard since the
register is not written until after those instructions read it.
Software Solution
• Compiler may insert NOP in between the dependent
instructions
– In the previous example CC3, CC4 and CC5 must be
NOP , so that at the end of CC5 result will be available in
R1 which can be used later.
• Software Optimization
– Compiler may rearrange the independent instructions in
order to reduce NOP
Forwarding
• It’s a Hardware Solution
• Forwarding works as follow:
1.The ALU result from EX/MEM register is always
fed back to the ALU input latches
2.If the forwarding hardware detects that the previous
ALU operation has written the register corresponding
to a source for the current ALU operation, control
logic selects the forwarded result as the ALU input,
rather than the value read from the register file.
Data Hazards (3)
• Eliminate the stalls for the hazard involving SUB and AND
instructions using a technique called forwarding
Data Hazards (4)
ME
LW R1, B IF ID EX WB
M
ME
LW R2, C IF ID EX WB
M
ADD R3, R1, ME
R2 IF ID stall EX WB
M
ME
SW A, R3 IF ID EX WB
M
•It uses a separate adder to compute the branch target address during
ID. Because the branch target addition happens during ID, it will
happen for all instructions.