Lecture-5-09 01 2025
Lecture-5-09 01 2025
Course Website
https://iit-plt.github.io/cs528/
Practice Problem - 1
◦Consider a pipeline having 5 phases with duration 30, 40,
60, 70 and 50 ns. Given latch delay is 10 ns. Calculate-
◦ Pipeline cycle time
◦ Non-pipeline execution time
◦ Speed up ratio
◦ Pipeline time for 100 tasks
◦ Sequential time for 100 tasks
Solution
◦ Given:
◦ Delay of stages = 30, 40, 60, 70, and 50 ns
◦ Latch Delay = 10 ns
◦ Pipeline Cycle Time = Max (Delay of stages) + Latch Delay
= (70 + 10) ns = 80 ns
◦ Non-pipeline execution time for one instruction
◦ = 30 ns + 40 ns + 60 ns + 70 + 50 ns = 250 ns
◦ Speedup ratio = Non-pipeline / Pipeline = 250/80 = 3.125
◦ Pipeline time for 100 tasks = Time taken for 1st task + Time taken for remaining 999
tasks
= 1 x 5 clock cycles + 99 x 1 clock cycle = 5 x 80 ns + 99 x 80 ns = 8320 ns
◦ Sequential Time For 100 Tasks = 100 x Time taken for one task = 100 x 250 ns
= 25000 ns
Practice Problem - 2
◦ A four stage pipeline has the stage delays as 50, 60, 80 and 70 ns respectively.
Registers are used between the stages and have a delay of 5 ns each. Assuming
constant clocking rate, the total time taken to process 10000 data items on the
pipeline will be-
◦ Pipeline cycle time = Max (Delay due to any stages) + 5 = 85 ns
◦ Pipeline to process 10000 = Time taken for 1st data item + Time taken for
remaining 9999 data items
= 1 x 4 clock cycles + 9999 x 1 clock cycle = (4 * 85) + (9999 * 85)
= 850255 ns
Pipelining Hazards
◦ Hazards: situations that prevent the next instruction from
executing in the designated clock 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
• Program Counter (PC) changes (e.g., branches)
Structural Hazards
◦Example
ideal CPI is 1;
40% data references;
structural hazard with 1.05 times higher clock rate than ideal;
Question:
is pipeline w/wo hazard faster?
by how much?
Structural Hazard
Stall for
one clock cycle
◦ Answer
avg instr time without hazard
=CPI x clock cycle timeideal
=1 x clock cycle timeideal
IF IF IF IF ID EX MEM
Data forwarding (bypasses)
NPC
MUX
A
ALU
RF D$
MUX
B
MUX
IMM
Data forwarding (bypasses)
NPC
MUX
A
ALU
RF D$
MUX
B
MUX
IMM
preliminary:
moved this
mux to prior
stage
Data forwarding (bypasses)
bypass 3
bypass 2
bypass 1
MUX
NPC
MUX
A
ALU
RF D$
MUX
B
MUX
MUX
IMM
Data forwarding (cont.)
IF IF ID EX MEM
WAR and WAW Hazards
◦ WAR hazard
◦ A: ADD R1, R2, R3
◦ B: ADD R2, R4, R5
◦ Problem if B writes R2 before A reads R2
◦ A will get the wrong value of R2 (that of B)
◦ Doesn’t happen in most in-order pipelines (like ours)
◦ Happens in out-of-order pipelines
◦ A may be stalled and B may be ready to execute out-of-order and write R2
◦ WAW hazard
◦ A: ADD R1, R2, R3
◦ B: ADD R1, R4, R5
◦ Problem if B writes R1 before A writes R1
◦ Later instructions will get the wrong value of R1 (that of A)
◦ Doesn’t happen in most in-order pipelines (like ours)
◦ Happens in out-of-order pipelines
◦ A may be stalled and B may be ready to execute out-of-order and write R1 first
WAR and WAW Hazards (cont.)
◦Options for handling WAR and WAW hazards
◦ Stall the later instruction to defer its register write, OR
◦ Register renaming (see next major topic: ILP)