Worked Examples All 11 examples from the slides, fully solved. Try each before revealing โ that's where the real learning happens.
Clock & Cycles WE-1 small Clock frequency = 200 MHz. Find the cycle time.
Show solution T = 1 F = 1 200 ร 10 6 = 5 ร 10 โ 9 โ s T = \frac{1}{F} = \frac{1}{200 \times 10^{6}} = 5 \times 10^{-9}\,\text{s} T = F 1 โ = 200 ร 1 0 6 1 โ = 5 ร 1 0 โ 9 s 5 nanoseconds .
WE-2 big A program runs in 10 s on computer A (4 GHz). Computer B should run it in 6 s, but needs 1.2ร as many clock cycles. What clock rate should B target?
Show solution Cycles A = 10 ร 4 ร 10 9 = 40 ร 10 9 Cycles B = 1.2 ร 40 ร 10 9 = 48 ร 10 9 Rate B = 48 ร 10 9 6 \begin{aligned} \text{Cycles}_A &= 10 \times 4 \times 10^{9} = 40 \times 10^{9} \\ \text{Cycles}_B &= 1.2 \times 40 \times 10^{9} = 48 \times 10^{9} \\ \text{Rate}_B &= \frac{48 \times 10^{9}}{6} \end{aligned} Cycles A โ Cycles B โ Rate B โ โ = 10 ร 4 ร 1 0 9 = 40 ร 1 0 9 = 1.2 ร 40 ร 1 0 9 = 48 ร 1 0 9 = 6 48 ร 1 0 9 โ โ 8 GHz .
CPI & Comparing Machines WE-3 big Same ISA. A: cycle 250 ps, CPI 2.0. B: cycle 500 ps, CPI 1.2. Which is faster, by how much?
Show solution Same ISA
โน \Longrightarrow โน same IC.
Time A = IC ร 2.0 ร 250 = 500 โ
ICย ps Time B = IC ร 1.2 ร 500 = 600 โ
ICย ps \begin{aligned} \text{Time}_A &= \text{IC} \times 2.0 \times 250 = 500 \cdot \text{IC}\ \text{ps} \\ \text{Time}_B &= \text{IC} \times 1.2 \times 500 = 600 \cdot \text{IC}\ \text{ps} \end{aligned} Time A โ Time B โ โ = IC ร 2.0 ร 250 = 500 โ
IC ย ps = IC ร 1.2 ร 500 = 600 โ
IC ย ps โ A is faster, by 600 / 500 = 1.2 ร 600/500 = 1.2\times 600/500 = 1.2 ร . WE-4 small 30 ADD (CPI 2) and 10 MUL (CPI 4). Find total cycles and average CPI.
Show solution Cycles = 30 ร 2 + 10 ร 4 = 100 IC = 40 \text{Cycles} = 30 \times 2 + 10 \times 4 = 100 \qquad \text{IC} = 40 Cycles = 30 ร 2 + 10 ร 4 = 100 IC = 40 Average CPI =
100 40 \frac{100}{40} 40 100 โ =
2.5 .
WE-5 big Classes A,B,C have CPI 1,2,3. Seq 1 = (A=2,B=1,C=2); Seq 2 = (A=4,B=1,C=1). Which is faster, by how much, and the CPI of each?
Show solution Seq IC Cycles CPI 1 5 2 โ
1 + 1 โ
2 + 2 โ
3 = 10 2 \cdot 1 + 1 \cdot 2 + 2 \cdot 3 = 10 2 โ
1 + 1 โ
2 + 2 โ
3 = 10 2.0 2 6 4 โ
1 + 1 โ
2 + 1 โ
3 = 9 4 \cdot 1 + 1 \cdot 2 + 1 \cdot 3 = 9 4 โ
1 + 1 โ
2 + 1 โ
3 = 9 1.5
Seq 2 is faster by 10 / 9 โ 1.11 ร 10/9 \approx 1.11\times 10/9 โ 1.11 ร . Note: Seq 2 has MORE instructions yet still wins.
WE-6 small A Java app runs 15 s. A new compiler needs 0.6ร as many instructions but raises CPI by 1.1ร. New run time?
Show solution Time scales with
IC ร CPI \text{IC} \times \text{CPI} IC ร CPI :
15 ร 0.6 ร 1.1 15 \times 0.6 \times 1.1 15 ร 0.6 ร 1.1 =
9.9 s .
The MIPS Pitfall WE-7 big 4 GHz. CPI A/B/C = 1/2/3. Compiler 1 โ (A=5,B=1,C=1) billions; Compiler 2 โ (A=10,B=1,C=1). Faster by MIPS? By execution time?
Show solution IC Cycles Time MIPS Comp 1 7 ร 10 9 7 \times 10^{9} 7 ร 1 0 9 10 ร 10 9 10 \times 10^{9} 10 ร 1 0 9 2.5 s 2800 Comp 2 12 ร 10 9 12 \times 10^{9} 12 ร 1 0 9 15 ร 10 9 15 \times 10^{9} 15 ร 1 0 9 3.75 s 3200
By MIPS: Comp 2 (3200) looks faster. By time: Comp 1 (2.5 s) is actually faster. The classic MIPS pitfall โ they disagree. Trust execution time.
Amdahl's Law WE-8 small Fraction f of time enhanced by factor r. Prove Speedup = 1/(1 โ f + f/r).
Show solution Old =
t t t . Affected =
f โ
t f \cdot t f โ
t , Unaffected =
( 1 โ f ) โ t (1 - f)\,t ( 1 โ f ) t .
New = ( 1 โ f ) โ t + f โ
t r Speedup = t New \text{New} = (1 - f)\,t + \frac{f \cdot t}{r} \qquad \text{Speedup} = \frac{t}{\text{New}} New = ( 1 โ f ) t + r f โ
t โ Speedup = New t โ Speedup = 1 1 โ f + f r \text{Speedup} = \frac{1}{1 - f + \frac{f}{r}} Speedup = 1 โ f + r f โ 1 โ โ
WE-9 big Program runs 100 s; multiply takes 80 s. How much must multiply speed up to make the program (a) 4ร faster, (b) 5ร faster?
Show solution Unaffected = 20 s.
Newย time = 20 + 80 x \text{New time} = 20 + \frac{80}{x} Newย time = 20 + x 80 โ (a) target = 25 s:
25 = 20 + 80 x 25 = 20 + \frac{80}{x} 25 = 20 + x 80 โ โน \Longrightarrow โน x = 16 .
(b) target = 20 s:
80 x = 0 \frac{80}{x} = 0 x 80 โ = 0 โน \Longrightarrow โน impossible (max speedup =
100 / 20 = 5 ร 100/20 = 5\times 100/20 = 5 ร , only at
x = โ x = \infty x = โ ).
WE-10 big All FP instructions made 5ร faster. Benchmark was 10 s, half spent on FP. Find the overall speedup.
Show solution FP =
5 โ s โ 1 โ s 5\,\text{s} \to 1\,\text{s} 5 s โ 1 s ; other = 5 s. New = 6 s. Speedup =
10 6 \frac{10}{6} 6 10 โ =
1.667 .
WE-11 big All FP instructions made 5ร faster. Program runs 100 s; new hardware gives overall speedup 3. How much of the original time was FP?
Show solution FP =
x x x .
New = 100 โ x + x 5 3 = 100 100 โ 0.8 x โ
โ โน โ
โ 100 โ 0.8 x = 33.33 \text{New} = 100 - x + \frac{x}{5} \qquad 3 = \frac{100}{100 - 0.8x} \;\Longrightarrow\; 100 - 0.8x = 33.33 New = 100 โ x + 5 x โ 3 = 100 โ 0.8 x 100 โ โน 100 โ 0.8 x = 33.33 x โ 83.33 โ s x \approx 83.33\,\text{s} x โ 83.33 s