计算机组成原理 第一章 作业

记录计算机组成原理的课后作业

教材为《计算机组成与设计:硬件、软件接口(第4版)》

Exercise 1.3

  • 1.3.1

    由CPU Time定义可得,
    $$
    CPU~Time = (Instruction~Count) \times (CPI) / (Clock~Rate)
    $$
    对于P1,$CPU~Time_{p1} = (1 \times 1.5) / (3 \times 10^9) = 0.5 \times 10^{-9}$

    对于P2,$CPU~Time_{P2} = (1 \times 1.0) / (2.5 \times 10^9) = 0.4 \times 10^{-9}$

    对于P3,$CPU~Time_{p3} = (1 \times 2.2) / (4 \times 10^9) = 0.55 \times 10^{-9}$

    因为P2的CPU Time最小,所以P2的性能最好

  • 1.3.2

    $$
    cycles = time \times Clock~Rate
    $$

    $$
    instructions = cycles / CPI
    $$

    由上式可得,对于a:

    ​ $cycles(P1) = 10 \times 3 \times 10^9 = 3 \times 10^{10} s$

    ​ $cycles(P2) = 10 \times 2.5 \times 10^9 = 2.5 \times 10^{10} s$

    ​ $cycles(P3) = 10 \times 4 \times 10^9 = 4 \times 10^{10} s$

    ​ $instructions(P1) = 3 \times 10^{10} / 1.5 = 2 \times 10^{10} $

    ​ $instructions(P2) = 2.5 \times 10^{10} / 1.0 = 2.5 \times 10^{10}$

    ​ $instructions(P3) = 4 \times 10^{10} / 2.2 = 1.82 \times 10^{10}$

    对于b:

    ​ $cycles(P1) = 10 \times 2 \times 10^9 = 2 \times 10^{10} s$

    ​ $cycles(P2) = 10 \times 3 \times 10^9 = 3 \times 10^{10} s$

    ​ $cycles(P3) = 10 \times 4 \times 10^9 = 4 \times 10^{10} s$

    ​ $instructions(P1) = 3 \times 10^{10} / 1.2 = 1.67 \times 10^{10} $

    ​ $instructions(P2) = 2.5 \times 10^{10} / 0.8 = 3.75 \times 10^{10}$

    ​ $instructions(P3) = 4 \times 10^{10} / 2.0 = 2 \times 10^{10}$

  • 1.3.3

    因为时间减少30%,所以$time_{new} = time_{old} \times 0.7 = 7s$

    因为CPI增加20%,所以$CPI_{new} = CPI_{old} \times 1.2$

    又$Clock~Rate = Instructions \times CPI / time$ ,由此可得,

    对于指令a:

    ​ $CPI(P1) = 1.5 \times 1.2 = 1.8$

    ​ $CPI(P2) = 1.0 \times 1.2 = 1.2$

    ​ $CPI(P3) = 2.2 \times 1.2 = 2.6$

    ​ $Clock~Rate(P1) = 20 \times 10^9 \times 1.8 / 7 = 5.14~\text{GHz}$
    ​ $Clock~Rate(P2) = 25 \times 10^9 \times 1.2 / 7 = 4.28~\text{GHz}$
    ​ $Clock~Rate(P1) = 18.18 \times 10^9 \times 2.6 / 7 = 6.75~\text{GHz}$

    对于指令b:

    ​ $CPI(P1) = 1.2 \times 1.2 = 1.44$
    ​ $CPI(P2) = 0.8 \times 1.2 = 0.96$
    ​ $CPI(P3) = 2.0 \times 1.2 = 2.4$

    ​ $Clock~Rate(P1) = 16.66 \times 10^9 \times 1.44 / 7 = 3.42~\text{GHz}$
    ​ $Clock~Rate(P2) = 37.75 \times 10^9 \times 0.96 / 7 = 5.14~\text{GHz}$
    ​ $Clock~Rate(P1) = 20 \times 10^9 \times 2.4 / 7 = 6.85~\text{GHz}$

  • 1.3.4

    $$
    IPC = 1 / CPI = instructions / (time \times clock~rate)
    $$

    由上式可得,对于a:

    ​ $IPC(P1) = 20 / (7 \times 3) = 0.95$
    ​ $IPC(P2) = 30 / (10 \times 2.5) = 1.2$
    ​ $IPC(P3) = 90 / (9 \times 4) = 2.5$

    对于b:

    ​ $IPC(P1) = 20 / (5 \times 2) = 2$
    ​ $IPC(P2) = 30 / (8 \times 3) = 1.25$
    ​ $IPC(P3) = 25 / (7 \times 4) = 0.89$

  • 1.3.5

    对于a:$\frac{Time_{new}}{ Time_{old}} = \frac{Clock~Rate_{old}}{Clock~Rate_{new}} \Rightarrow Clock~Rate_{new} = 2.5 / 0.7 = 3.57 ~ \text{GHz}$

    对于b:$\frac{Time_{new}}{ Time_{old}} = \frac{Clock~Rate_{old}}{Clock~Rate_{new}} \Rightarrow Clock~Rate_{new} = 3 / 0.625 = 4.8 ~ \text{GHz}$

  • 1.3.6

    因为$\frac{Time_{new}}{Time_{old}} = \frac{instructions_{new}}{instructions_{old}}$ ,则

    对于a: $instructions_{new} = 30 \times 10^9 \times 0.9 = 27 \times 10^9$

    对于b: $instructions_{new} = 30 \times 10^9 \times 0.875 = 26.25 \times 10^9$

Exercise 1.4

  • 1.4.1

    Class A: $10^6 \times 0.1 = 10^5$

    Class B: $10^6 \times 0.2 = 2\times 10^5$

    Class C: $10^6 \times 0.5 = 5 \times 10^5$

    Class D: $2 \times 10^5$

    $\because ~ time = No. instructions \times CPI / Clock~Rate$

    $\therefore ~ $对于a:

    ​ $time_{P1} = \frac{(10^5 + 2 \times 10^5 \times 2 + 5 \times 10^5 \times 3 + 2 \times 10^5 \times 3)}{2.5 \times 10^9} = 10.4 \times 10^{-4} s$

    ​ $time_{P2} = \frac{(10^5 \times 2 + 2 \times 10^5 \times 2 + 5 \times 10^5 \times 2 + 2 \times 10^5 \times 2)}{3 \times 10^9} = 6.66 \times 10^{-4} s$

    $\therefore~$ 对于b:

    ​ $time_{P1} = \frac{(10^5 \times 2 + 2 \times 10^5 \times 1.5 + 5 \times 10^5 \times 2 + 2 \times 10^5)}{2.5 \times 10^9} = 6.8 \times 10^{-4} s$

    ​ $time_{P2} = \frac{(10^5 + 2 \times 10^5 \times 2 + 5 \times 10^5 + 2 \times 10^5)}{3 \times 10^9} = 4 \times 10^{-4} s$

  • 1.4.2

    $$
    CPI = time \times Clock~Rate / No. Instructions
    $$

    由上式可得,对于a:

    ​ $CPI(P1) = 10.4 \times 10^{-4} \times 2.5 \times 10^9 / 10^6 = 2.6$

    ​ $CPI(P2) = 6.66 \times 10^{-4} \times 3 \times 10^9 / 10^6 = 2.0$

    对于b:

    ​ $CPI(P1) = 6.8 \times 10^{-4} \times 2.5 \times 10^9 / 10^6 = 1.7$

    ​ $CPI(P2) = 4 \times 10^{-4} \times 3 \times 10^9 / 10^6 = 1.2$

  • 1.4.3

    对于a:

    ​ $clock~cycles(P1) = 10^5 + 2 \times 10^5 \times 2 + 5 \times 10^5 \times 3 + 2 \times 10^5 \times 3= 26 \times 10^5$

    ​ $clock~cycles(P2) =10^5 \times 2 + 2 \times 10^5 \times 2 + 5 \times 10^5 \times 2 + 2 \times 10^5 \times 2 = 20 \times 10^5$

    对于b:

    ​ $clock~cycles(P1) = 10^5 \times 2 + 2 \times 10^5 \times 1.5 + 5 \times 10^5 \times 2 + 2 \times 10^5 = 17 \times 10^5$

    ​ $clock~cycles(P2) = 10^5 + 2 \times 10^5 \times 2 + 5 \times 10^5 + 2 \times 10^5 = 12 \times 10^5$

  • 1.4.4

    $time_a = \frac{(650 \times 1 + 100 \times 5 + 600 \times 2 + 50 \times 2) }{2 \times 10^9} = 2125~ns$

    $time_b = \frac{(750 \times 1 + 250 \times 5 + 500 \times 2 + 500 \times 2) }{2 \times 10^9} = 2750~ns$

  • 1.4.5

    $$
    CPI = time \times Clock~Rate / No. instructions
    $$

    由上式可得,

    $CPI(a) = 2125 \times 2 / 1400 = 3.03$

    $CPI(b) = 2750 \times 2 / 2000 = 2.75$

  • 1.4.6

    对于a:

    ​ $time_{new} = \frac{(650 \times 1 + 100 \times 5 + 300 \times 2 + 50 \times 2) }{2 \times 10^9} = 1375~ns$

    $\Rightarrow speedup_a = 2125 / 1375 = 1.54$

    $\Rightarrow CPI = 1375 \times 2 / (1400-300) = 2.5$

    对于b:

    ​ $time_{new} = \frac{(750 \times 1 + 250 \times 5 + 250 \times 2 + 500 \times 2) }{2 \times 10^9} = 2125~ns$

    $\Rightarrow speedup_b = 2750 / 2125 = 1.29$

    $\Rightarrow CPI = 2125 \times 2 / (2000 - 250) = 2.43$

Exercise 1.5

  • 1.5.1

    对于a:

    ​ $peek~performance(P1) = 2\times 10^9~instr/sec$

    ​ $peek~performance(P2) = 2 \times 10^9~instr/sec$

    对于b:

    ​ $peek~performance(P1) = 2 \times 10^9$

    ​ $peek~performance(P2) = 3 \times 10^9$

  • 1.5.2

    $$
    time = No. instructions \times CPI / Clock~Rate
    $$

    由上式和题意可得,

    对于a:

    ​ $time(P1) / time(P2) = \frac{(1 \times 2 + 2 + 3 + 4 + 3) / 2}{(2 \times 2 + 2 + 2 + 4 + 4) / 4} = \frac{4}{7}$ 所以P2更快,是P1的1.75倍

    对于b:

    ​ $time(P1)/time(P2) = \frac{(1 \times 2 + 1 + 2 + 3 + 2) / 2}{(1 \times 2 + 2 + 3 + 4 + 3)/3} = \frac{5}{4.66}$ 所以P2更快,是P1的1.07倍

  • 1.5.3

    1.5.2可得,

    对于a:$time(P1) / time(P2) = 8 / 4.5$ 所以P2更快,是P1的1.77倍

    对于b:$time(P1)/time(P2) = 5.5/5.33$ 所以P2更快,是P1的1.03倍

  • 1.5.4

    $time_a = \frac{600 + (600 + 200) \times 10 + 50 \times 3}{3} = 2916.67~ns$

    $time_b = \frac{900 + (500+100) \times 10 + 200 \times 3}{3} = 2500~ns$

  • 1.5.5

    $time_a = \frac{600 + (600 + 200) \times 2 + 50 \times 3}{3} = 783.33~ns$

    $time_b = \frac{900 + (500 + 100) \times 2 + 200 \times 3}{3} = 900~ns$

  • 1.5.6

    对于a:$time_{new} = \frac{300 + (600 + 200) \times 2 + 50 \times 3}{3} = 683.33~ns \Rightarrow 783.33/683.33 = 1.14倍$

    对于b:$time_{new} = \frac{450 + (500 + 100) \times 2 + 200 \times 3}{3} = 750~ns \Rightarrow 900 / 750=1.2倍$

Exercise 1.12

  • 1.12.1

    由CPI定义可知:
    $$
    CPI = Clock~Rate \times CPU~time / instruction~count
    $$
    又$Clock~Rate = 1/cycle~time = 3~\text{GHz}$,则

    $CPI(bzip2) = 3 \times 750 / 2389 = 0.94 $

    $CPI(go) = 3 \times 700 / 1658 = 1.26$

  • 1.12.2

    由SPEC定义可知
    $$
    SPECratio = ref~time / exec~time
    $$
    $\Rightarrow SPECratio(bzip2) = 9650 / 750 = 12.86$

    $~SPECratio(go) = 10490 / 200 = 14.98$

  • 1.12.3

    几何平均值为:

    ​ $\sqrt{12.86 \times 14.98} = 13.88$

  • 1.12.4

    $$
    CPU~time = instruction~count \times CPI / Clock~Rate
    $$

    由上式可知,若指令数增加10%,CPI不变,则CPU time也增加10%

  • 1.12.5

    1.12.4 的公式可知,若指令书增加10%,CPI增加5%,则

    ​ $CPU~time_{new} / CPU~time_{old} = 1.1 \times 1.05 = 1.155$

    所以,CPU time增加了(1.155 - 1) = 15.5%

  • 1.12.6

    1.12.5可得,

    ​ $SPECratio_{new} / SPECratio_{old} = CPU~time_{old} / CPU~time_{new} = 1 / 1.155 = 0.86$