Pipelining
Technique in which multiple instructions are overlapped in
execution
Pipeline Hazards
Situations in pipelining when the next instruction
cannot execute in the following clock cycle
Three types
i.
Structural hazard
Structural Hazards
A planned instruction cannot execute in the proper
clock cycle because the hardware cant support the
combination of instructions that are set to execute in
the given clock cycle
Data Hazards
A planned instruction cannot execute in the proper
clock cycle because data that is needed to execute
the instruction is not yet available
To solve this we use forwarding or bypassing
technique
Forwarding - Retrieving the missing data element from
internal buffers rather than waiting for it to arrive from
programmer-visible registers or memory
Data Hazards
Data Hazards
Load-use data hazard A data hazard in which the
data requested by a load instruction has not yet
become available when it is requested
We need a pipeline stall to resolve this
Pipeline stall (Bubble) - A stall initiated to resolve a
hazard
Data Hazards
Control Hazards
A planned instruction cannot execute in the proper
clock cycle because the instruction that was fetched is
not the one that is needed; i.e., the flow of instruction
addresses is not what the pipeline expected
Arises from the need to make a decision based on the
results of one instruction while others are executing
Control Hazards
When the branch is not taken
Control Hazards
When the branch is to be taken
Control Hazards
Branch prediction - A method of resolving a branch
hazard by assuming a given outcome for the branch
and proceeding from that assumption rather than
waiting to ascertain the actual outcome
Dynamic branch prediction works by keeping a history
for each branch as taken or untaken, and then using
the recent past behavior to predict the future
Control Hazards
Delayed branch is another solution
MIPS software will place an instruction immediately
after the delayed branch instruction that is not affected
by the branch
Pipelined datapath
Pipelined datapath
Stages of lw instruction
Stages of lw instruction
Stages of lw instruction
Stages of lw instruction
Stages of lw instruction
Stages of sw instruction
Stages of sw instruction
Stages of sw instruction
Stages of sw instruction
Stages of sw instruction
Pipelined Control
if (ID/EX.MemRead and
((ID/EX.RegisterRt = IF/ID.RegisterRs) or
(ID/EX.RegisterRt = IF/ID.RegisterRt)))
stall the pipeline
Branch hazards
Branch hazards
When a branch is taken we will discard or flush the
instruction in IF, ID & EX stages by setting the control
signals to 0
Calculate the branch target address and make the branch
decision at ID stage of the pipeline.
Dynamic branch prediction
Delayed branch
36 sub $10, $4, $8
40 beq $1, $3, 7 # PC-relative branch to 40 + 4 + 7 * 4 = 72
44 and $12, $2, $5
48 or $13, $2, $6
52 add $14, $4, $2
56 slt $15, $6, $7
...
72 lw $4, 50($7)
Exceptions