CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE...
Transcript of CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE...
![Page 1: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/1.jpg)
CSE 2021: Computer Organization
Lecture-10 CPU Design : Pipelining-1 Overview, Datapath and control
Shakil M. Khan
![Page 2: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/2.jpg)
Single Cycle (Review)
CSE-2021 July-12-2012 2
![Page 3: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/3.jpg)
Single Cycle with Jump
CSE-2021 July-12-2012 3
![Page 4: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/4.jpg)
Multi-Cycle Implementation
• Instruction:
– execution is broken into different steps
– each step requires 1 clock cycle
• Functional Unit:
– can be used more than once in an instruction (but still only once in a clock cycle)
• Advantages:
– functional units can be shared
• ALU and adder is combined
• single memory is used for instructions and data
– faster: each inst. is as long as it needs to be CSE-2021 July-12-2012 4
![Page 5: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/5.jpg)
Why Multi-Cycle?
CSE-2021 July-12-2012 5
• Given: – Memory unit ~ 2 ns, ALU ~ 2 ns, Register file ~ 1 ns
– lw: 24%, sw: 12%, ALU inst.: 44%, beq: 18%, j: 2%
• Average time per instruction: – single cycle= 8 ns
– multi-cycle = 0.24*8+0.12*7+0.44*6+0.18*5+0.02*2
= 6.34 ns
Instruction Functional units used (Steps involved)
ALU type Inst. fetch Registers ALU Registers 6ns
Load word Inst. fetch Registers ALU Data Memory Registers 8ns
Store word Inst. fetch Registers ALU Data Memory 7ns
Branch Inst. fetch Registers ALU 5ns
Jump Inst. fetch 2ns
![Page 6: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/6.jpg)
Pipelining Analogy
• Pipelined laundry: overlapping execution
– parallelism improves performance
Four loads:
Speedup = 8/3.5 = 2.3
Non-stop:
Speedup = 2n/0.5n + 1.5 ≈ 4 = number of stages
CSE-2021 July-12-2012 6
![Page 7: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/7.jpg)
MIPS Pipeline
• Five stages, one step per stage
1. IF: Instruction fetch from memory
2. ID: Instruction decode & register read
3. EX: Execute operation or calculate address
4. MEM: Access memory operand
5. WB: Write result back to register
CSE-2021 July-12-2012 7
![Page 8: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/8.jpg)
Pipeline Performance
• Assume time for stages is
– 100ps for register read or write
– 200ps for other stages
• Compare pipelined datapath with single-cycle datapath
Instr Instr fetch Register
read
ALU op Memory
access
Register
write
Total time
lw 200ps 100 ps 200ps 200ps 100 ps 800ps
sw 200ps 100 ps 200ps 200ps 700ps
R-format 200ps 100 ps 200ps 100 ps 600ps
beq 200ps 100 ps 200ps 500ps
CSE-2021 July-12-2012 8
![Page 9: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/9.jpg)
Pipeline Performance
Single-cycle (Tc= 800ps)
Pipelined (Tc= 200ps)
CSE-2021 July-12-2012 9
![Page 10: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/10.jpg)
Pipeline Speedup
• If all stages are balanced
– i.e., all take the same time
– Time between instructionspipelined =
Time between instructionsnonpipelined
Number of stages
• If not balanced, speedup is less
• Speedup due to increased throughput
– latency (time for each instruction) does not decrease
CSE-2021 July-12-2012 10
![Page 11: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/11.jpg)
Pipelining and ISA Design
• MIPS ISA designed for pipelining – all instructions are 32-bits
• easier to fetch and decode in one cycle
• c.f. x86: 1- to 17-byte instructions
– few and regular instruction formats • can decode and read registers in one step
– load/store addressing • can calculate address in 3rd stage, access memory in
4th stage
– alignment of memory operands • memory access takes only one cycle
CSE-2021 July-12-2012 11
![Page 12: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/12.jpg)
Hazards
• Situations that prevent starting the next instruction in the next cycle
• Structure hazards – a required resource is busy
• Data hazard – need to wait for previous instruction to
complete its data read/write
• Control hazard – deciding on control action depends on previous
instruction
CSE-2021 July-12-2012 12
![Page 13: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/13.jpg)
Structure Hazards
• Conflict for use of a resource
• In MIPS pipeline with a single memory
– load/store requires data access
– instruction fetch would have to stall for that cycle
• would cause a pipeline “bubble”
• Hence, pipelined datapaths require separate instruction/data memories
– or separate instruction/data caches
CSE-2021 July-12-2012 13
![Page 14: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/14.jpg)
Data Hazards
• An instruction depends on completion of data access by a previous instruction – add $s0, $t0, $t1 sub $t2, $s0, $t3
CSE-2021 July-12-2012 14
![Page 15: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/15.jpg)
Forwarding (AKA Bypassing)
• Use result when it is computed
– don’t wait for it to be stored in a register
– requires extra connections in the datapath
CSE-2021 July-12-2012 15
![Page 16: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/16.jpg)
Load-Use Data Hazard
• Can’t always avoid stalls by forwarding
– if value not computed when needed
– can’t forward backward in time!
CSE-2021 July-12-2012 16
![Page 17: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/17.jpg)
Code Scheduling to Avoid Stalls
• Reorder code to avoid use of load result in the next instruction
• C code for A = B + E; C = B + F;
lw $t1, 0($t0)
lw $t2, 4($t0)
add $t3, $t1, $t2
sw $t3, 12($t0)
lw $t4, 8($t0)
add $t5, $t1, $t4
sw $t5, 16($t0)
stall
stall
lw $t1, 0($t0)
lw $t2, 4($t0)
lw $t4, 8($t0)
add $t3, $t1, $t2
sw $t3, 12($t0)
add $t5, $t1, $t4
sw $t5, 16($t0)
11 cycles 13 cycles
CSE-2021 July-12-2012 17
![Page 18: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/18.jpg)
Control Hazards
• Branch determines flow of control – fetching next instruction depends on branch
outcome
– pipeline can’t always fetch correct instruction • still working on ID stage of branch
• In MIPS pipeline – need to compare registers and compute target
early in the pipeline
– add hardware to do it in ID stage
CSE-2021 July-12-2012 18
![Page 19: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/19.jpg)
Stall on Branch
• Wait until branch outcome determined before fetching next instruction
CSE-2021 July-12-2012 19
![Page 20: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/20.jpg)
Branch Prediction
• Longer pipelines can’t readily determine branch outcome early
– stall penalty becomes unacceptable
• Predict outcome of branch
– only stall if prediction is wrong
• In MIPS pipeline
– can predict branches not taken
– fetch instruction after branch, with no delay
CSE-2021 July-12-2012 20
![Page 21: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/21.jpg)
MIPS with Predict Not Taken
Prediction correct
Prediction incorrect
CSE-2021 July-12-2012 21
![Page 22: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/22.jpg)
More-Realistic Branch Prediction
• Static branch prediction – based on typical branch behavior
– example: loop and if-statement branches • predict backward branches taken
• predict forward branches not taken
• Dynamic branch prediction – hardware measures actual branch behavior
• e.g., record recent history of each branch
– assume future behavior will continue the trend • when wrong, stall while re-fetching, and update
history
CSE-2021 July-12-2012 22
![Page 23: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/23.jpg)
Pipeline Summary
• Pipelining improves performance by increasing instruction throughput
– executes multiple instructions in parallel
– each instruction has the same latency
• Subject to hazards
– structure, data, control
• Instruction set design affects complexity of pipeline implementation
The BIG
Picture
CSE-2021 July-12-2012 23
![Page 24: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/24.jpg)
MIPS Pipelined Datapath
WB
MEM
Right-to-left flow leads to hazards
CSE-2021 July-12-2012 24
![Page 25: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/25.jpg)
Pipeline registers
• Need registers between stages
– to hold information produced in previous cycle
CSE-2021 July-12-2012 25
![Page 26: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/26.jpg)
Pipeline Operation
• Cycle-by-cycle flow of instructions through the pipelined datapath
– “Single-clock-cycle” pipeline diagram
• shows pipeline usage in a single cycle
• highlight resources used
– c.f. “multi-clock-cycle” diagram
• Graph of operation over time
• We’ll look at “single-clock-cycle” diagrams for load & store
CSE-2021 July-12-2012 26
![Page 27: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/27.jpg)
IF for Load, Store, …
CSE-2021 July-12-2012 27
![Page 28: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/28.jpg)
ID for Load, Store, …
CSE-2021 July-12-2012 28
![Page 29: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/29.jpg)
EX for Load
CSE-2021 July-12-2012 29
![Page 30: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/30.jpg)
MEM for Load
CSE-2021 July-12-2012 30
![Page 31: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/31.jpg)
WB for Load
Wrong register number
CSE-2021 July-12-2012 31
![Page 32: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/32.jpg)
Corrected Datapath for Load
CSE-2021 July-12-2012 32
![Page 33: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/33.jpg)
EX for Store
CSE-2021 July-12-2012 33
![Page 34: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/34.jpg)
MEM for Store
CSE-2021 July-12-2012 34
![Page 35: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/35.jpg)
WB for Store
CSE-2021 July-12-2012 35
![Page 36: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/36.jpg)
Multi-Cycle Pipeline Diagram
• Form showing resource usage
CSE-2021 July-12-2012 36
![Page 37: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/37.jpg)
Multi-Cycle Pipeline Diagram
• Traditional form
CSE-2021 July-12-2012 37
![Page 38: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/38.jpg)
Single-Cycle Pipeline Diagram
• State of pipeline in a given cycle
CSE-2021 July-12-2012 38
![Page 39: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/39.jpg)
Pipelined Control (Simplified)
CSE-2021 July-12-2012 39
![Page 40: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/40.jpg)
Pipelined Control
• Control signals derived from instruction
– as in single-cycle implementation
CSE-2021 July-12-2012 40
![Page 41: CSE 2021: Computer Organizationskhan/course/2021S12/slides/Lec10-1up.pdf · 2012-07-11 · CSE 2021: Computer Organization Lecture-10 CPU Design : Pipelining-1 Overview, Datapath](https://reader034.fdocuments.us/reader034/viewer/2022042310/5ed83e310fa3e705ec0e1b1e/html5/thumbnails/41.jpg)
Pipelined Control
CSE-2021 July-12-2012 41