












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













1)Fetch instruction from instruction register(IR)
2)Determine what action to take 3)Execute the instruction
4)Access cache if needed
5)Write result in register
Example: MOV Reg1, Mem 1)fetch instruction(MOV Reg1, Mem1) 2)decided it is a move instruction from memory to register 3)fetch address of memory to be move 4)fetch data from memory 5)write data to Reg
FI - fetch instruction DI - decode instruction EX - execute instruction MEM – data cache access WB - write back
Instruction (^1 2 3 4 5 6 7 8 )
1 FI DI EX MEM WB
2 FI DI EX MEM WB
3 FI DI EX MEM WB
4 FI DI EX MEM WB
5 FI DI EX MEM WB
MOV Reg1,Mem
MOV Reg2,(Reg1)
MOV Reg1,Mem
MOV Reg2,(Reg1)
Write data from Mem1 into Reg
Must wait for data to be loaded into Reg
Stall(bubble)
move data from Mem1 to Reg
move data from Reg1 to Reg
(b)Data dependency delay
MOV Reg1,Mem
NOP
MOV Reg2,(Reg1)
move data from Mem1 to Reg
no operation perform
move data from Reg1 to Reg
Add a NOP(no operation perform) to fill the gap
101 ADD Reg3, Reg2, Reg
102 NOP
103 BEQ Reg3 ,Reg4, 106
104 MOV Mem1, Reg
105 ADD Reg4, Reg1, Reg
106 MOV Mem1, Reg
Reg3 = Reg4, jump to 106, no time wasted
At this point Reg3 equal Reg2 + Reg1, and line 103 can compare Reg3 to Reg4 and decide jumping to 106 or not
101 add Reg2 to Reg1 and put in Reg
102 no operation perform
103 if Reg3 = Reg4, jump to 106 else 104
104 move Reg3 to Mem
105 add Reg2 to Reg1 and put in Reg
106 move Reg4 to Mem
Data dependency delay
Guess branch will happen
101 ADD Reg3, Reg2, Reg
102 NOP
103 BEQ Reg3 ,Reg4, 106
104 MOV Mem1, Reg
105 ADD Reg4, Reg1, Reg
106 MOV Mem1, Reg
107 MOV Reg2, Mem
Reg3 not= Reg4, clear and fetch 104 next
At this point Reg3 equal Reg2 + Reg1, and line 103 can compare Reg3 to Reg4 and decide jumping to 106 or not
Data dependency delay
Guess wrong can lead to wasted time
Instruction (^1 2 3 4 5 6 )
1 F E W
2 F E
3 F E
4 F
5 F E W
100 move Mem1 to Reg
101 add 1 to Reg
102 Jump to 105
103 add Reg1 to Reg
105 move Reg1 to Mem
100 MOVE Reg1, Mem
101 ADD 1, Reg
102 JUMP 105
103 ADD Reg1, Reg
105 MOVE Mem2, Reg
a) Traditional pipeline
Jump execute and 103 is cleared from the pipeline, 105 is fetch
F – fetch E – execute W – write back
Instruction (^1 2 3 4 5 6 )
1 F E W
2 F E
3 F E
4 F E W
100 move Mem1 to Reg
101 Jump to 105
102 add Reg1 to Reg
105 move Reg1 to Mem
100 MOVE Reg1, Mem
101 JUMP 105
102 ADD 1, Reg
105 MOVE Mem2, Reg
a) Reversed instructions
Delayed branch When a branch occur, delay the execution and fetch the next instruction first. ex) fetch 102 before executing JUMP to 105, this way 102 can execute at the same time 105 is fetch
F – fetch E – execute W – write back
In theory, more and shorter stages could allow more instructions to be process at the same time. But a branch could lead to wasted cycles.
Branch executed and pipeline is clear
RISC Pipelining
Fetch Instruction(2 stages)
Decode(5 stages)
Execute, Memory, Writeback(6 stages)
Dynamic Branch Prediction 95% accuracy
Fetch
Decode
Execute
Memory, Writeback