Documente Academic
Documente Profesional
Documente Cultură
Average CPI:4.1
Mux x
32
PC Mux M
1 32 32
0 32
Mux
Ideal Memory
WrAdr 32 Din Dout
Rt 0 Rd 1
Reg File B
32
0 1 2 3 32
1 Mux 0
Mux
32
32
<< 2
ALU Control
Imm 16
Extend
32
ALUOp ALUSelB
ExtOp
MemtoReg
The Big Picture: Where are We Now? The Five Classic Components of a Computer
Processor Input Control Memory Datapath
Output
Next Topics:
Pipelining by Analogy Pi li hazards Pipeline h d
Pipelining is Natural! Laundry Example Ann, Brian, Cathy, Dave each have one load of clothes to wash, dry, and fold Washer takes 30 minutes Dryer takes 40 minutes Folder takes 20 minutes Folder A B C D
Sequential Laundry 6 PM 7 8 9
Time
10
11
Midnight
30 40 20 30 40 20 30 40 20 30 40 20
T a s k O r d e r
A B C D Sequential laundry takes 6 hours for 4 loads pipelining, If they learned pipelining how long would laundry take?
10
11
Midnight
30 40
T a s k O r d e r
40
40
40 20
Pipelining Lessons 6 PM 7 8 9
Time
Pipelining doesnt help latency of single task, it helps throughput of entire workload kl d Pipeline rate limited by slowest pipeline stage Multiple tasks operating simultaneously using different resources Potential speedup = Number pipe stages Unbalanced lengths of pipe stages reduces speedup Time to fill pipeline and time to drain it reduces speedup Stall for Dependences
30 40
T a s k O r d e r
40
40
40 20
A B C D
Load Ifetch L d If t h
Reg/Dec R /D
Exec E
Mem M
Wr W
Reg/Dec: Register Fetch and Instruction Decode Exec: Calculate the memory address Mem: Read the data from the Data Memory Wr: Write the data back to the register file
0000
D Decode e
0001 R-type
ALUout <= A fun B
ORi
ALUout <= A op ZX
LW
ALUout <= A + SX
SW
ALUout <= A + SX
BEQ
If A = B then PC <= ALUout
0100
0110
1000
M <= MEM[ALUout]
1011
MEM[ALUout] <= B
0010
1001
R[rd] <= ALUout R[rt] <= ALUout R[rt] <= M
1100
0101
0111
1010
Basic Idea
IFetch Dcd
IFetch Dcd
IFetch Dcd
IFetch Dcd
Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6 Cycle 7 Cycle 8 Cycle 9 Cycle 10 Clk Multiple Cycle Implementation: Load Ifetch Reg g Exec Mem
Wr
Store Ifetch
Reg g
Exec
Mem
R-type Ifetch
Pipeline Implementation: Load Ifetch Reg Exec Reg Mem Exec Reg Wr Mem Exec Wr Mem Wr
Store Ifetch
R-type Ifetch
ALU
I n s t r. O r d e r
Im
Reg
Dm ALU
Reg
Im
Reg
Dm ALU
Reg
Im
Reg
Dm ALU
Reg
Im
Reg
Dm ALU A
Reg
Im
Reg
Dm
Reg
ALU
I n s t r. O r d e r
Mem
Reg
Mem ALU
Reg
Mem
Reg
Mem ALU A
Reg
Mem
Reg
Mem AL LU
Reg
Mem
Reg
Mem ALU U
Reg
Mem
Reg
Mem
Reg
Detection is easy in this case! (right half highlight means read, left half write)
Structural Hazards limit performance Example: if 1.3 memory accesses per instruction and only one memory access per cycle then
average CPI 1.3 otherwise resource is more than 100% utilized
Mem
Reg
Mem ALU U
Reg
Mem
Reg
Mem
Reg
ALU U
Lost potential
Mem
Reg
Mem
Reg
Stall: wait until decision is clear Impact: 2 lost cycles (i.e. 3 clock cycles per branch instruction) => slow i t ti ) l Move decision to end of decode
save 1 cyc e pe b a c sa e cycle per branch
Mem
Reg
Mem ALU
Reg
Mem
Reg
Mem
Reg
ALU
Mem
Reg
Mem
Reg
Predict: guess one direction then back up if wrong Impact: 0 lost cycles per branch instruction if right, 1 if wrong (right - 50% of time)
Need to Squash and restart following instruction if wrong Produce CPI on branch of (1 *.5 + 2 * .5) = 1.5 Total CPI might then be: 1.5 * .2 + 1 * .8 = 1.1 (20% branch)
Mem M
Reg R
Mem M ALU U
Reg R
Mem
Reg g
Mem ALU U
Reg
Mem
Reg Mem
Mem ALU
Reg
Delayed Branch: Redefine branch behavior (takes place after next instruction) Impact: 0 clock cycles per branch instruction if can find instruction to put in slot (- 50% of time) As launch more instruction per clock cycle less useful cycle,
Data Hazard on r1
I n s t r. O r d e r
E X
ME M Dm
ALU
W B Reg
Dm ALU Reg
Reg
Im
ALU
Reg
Dm ALU A
Reg
Im
Reg
Dm AL LU
Reg
xor r10,r1,r11
Im
Reg R
Dm
Reg
I n s t r. O r d e r
E X
ME M Dm
ALU
W B Reg
Dm ALU Reg
Reg
Im
ALU
Reg
Dm ALU A
Reg
Im
Reg
Dm AL LU
Reg
xor r10,r1,r11
Im
Reg R
Dm
Reg
Forwarding (or Bypassing): What about Loads? Dependencies backwards in time are hazards
Time (clock cycles) I F Im ID/R F Reg
Im
lw r1,0(r2) , ( )
E X
ME M Dm
ALU
W B Reg
Dm Reg
sub r4,r1,r3
Reg
ALU
Forwarding (or Bypassing): What about Loads Dependencies backwards in time are hazards
Time (clock cycles) I F Im ID/R F Reg E X ME M Dm
Reg
lw r1,0(r2) , ( )
W B Reg
ALU Dm Reg
ALU
sub r4,r1,r3
Stall
Im
Designing a Pipelined Processor Go back and examine your datapath and control diagram associated resources with states conflict ensure that flows do not conflict, or figure out how to resolve assert control in appropriate stage