Week 11
Week 11
EE-371/CS-330
Spring 2019
Hasan Baig
[email protected]
Habib University
The contents in these lecture slides are prepared with a help of the official lecture slides of the book “Computer Organization and Design –
RISC V edition” by Patterson and Hennessy .
2
Recap
3
Performance Issues
Take/Give Order 1
Token counter 1
5
Pipelining Laundry Analogy
An implementation technique in which multiple instructions are
overlapped in execution
Four loads:
Speedup
= 8/3.5 = 2.3
Non-stop:
Speedup
= 2n/(0.5n + 1.5) ≈ 4
= number of stages
6
Pipelining
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
7
Pipelining Example
T = 2400
T = 1400
12
Pipelining Speedup
Instructions = 1,000,000
Pipelined Non-Pipelined
Each instruction will add 200 ps Each instruction will add 800 ps
Total time = 1,000,000 x 200 = 200000000 + 1400 Total time = 1,000,000 x 800 = 800000000 + 2400
= 200001400 = 800002400
13
Latency Exercise
14
Latency Solultion
Data hazards occur when the pipeline must be stalled because one
step must wait for another to complete.
add x19, x0, x1
sub x2, x19, x3
23
Pipelining Data Hazards
Forwarding - Also called bypassing. A method of resolving a data hazard by retrieving the
missing data element from internal buffers rather than waiting for it to arrive from
programmer- visible registers or memory.
25
Pipelining Data Hazards
• In RISC-V pipeline
– Need to compare registers and compute target
early in the pipeline
– Add hardware to do it in ID stage
29
Pipelining Control Hazards
Stall on branch
• Wait until branch outcome determined before
fetching next instruction
30
Pipelining Control Hazards
Branch Predictions
• Longer pipelines can’t readily determine
branch outcome early
– Stall penalty becomes unacceptable
• Predict outcome of branch
– Only stall if prediction is wrong
• In RISC-V pipeline
– Can predict branches not taken
– Fetch instruction after branch, with no delay
31
Pipelining Control Hazards
Branch Predictions
32
Pipelining Control Hazards
For each code sequence below, state whether it must stall, can avoid stalls using
only forwarding, or can execute without stalling or forwarding.