免費詳解 / 中山 / 硬體 / 102

102 中山資工所考古題解答|硬體逐題詳解

102 中山資工所硬體考古題的逐題詳解,共 8 題,免費公開。

逐題詳解

118%

You are the lead designer of a new processor. The processor design and compiler are complete, and now you must decide whether to produce the current design as it stands or spend additional time to improve it.

1.1 [10%] (a) Leave the design as it stands. Call this base machine Mbase. It has a clock rate of 500 MHz. (b) Optimize the hardware: clock rate of 600 MHz. Call this machine Mopt.

Instruction classFrequencyCPI
MbaseMopt
A40%22
B25%32
C25%33
D10%54

What are the CPI and MIPS rate for Mbase and Mopt? (Table 1-1)

1.2 [8%] The compiler team proposes to improve the compiler (Mcomp = improved compiler + base machine). Percentage of instructions executed vs. base machine: A 90%, B 90%, C 85%, D 95%. What is the CPI for Mcomp? How much faster is Mcomp than Mbase? (Table 1-2)

1.1 \(\text{CPI}=\sum f_i\,\text{CPI}_i\),\(\text{MIPS}=\dfrac{\text{clock (MHz)}}{\text{CPI}}\)

Mbase:\(0.4\cdot2+0.25\cdot3+0.25\cdot3+0.1\cdot5=0.8+0.75+0.75+0.5=2.8\)

Mopt:\(0.4\cdot2+0.25\cdot2+0.25\cdot3+0.1\cdot4=0.8+0.5+0.75+0.4=2.45\)

MachineCPIMIPS rate
Mbase2.8\(500/2.8\approx178.6\)
Mopt2.45\(600/2.45\approx244.9\)

1.2 設 Mbase 執行 1 條指令為基準,Mcomp 各類指令數:A 0.36、B 0.225、C 0.2125、D 0.095

指令數 \(0.36+0.225+0.2125+0.095=0.8925\)

cycles \(0.36\cdot2+0.225\cdot3+0.2125\cdot3+0.095\cdot5=0.72+0.675+0.6375+0.475=2.5075\)

\(\text{CPI}=2.5075/0.8925\approx2.81\)

時脈相同(500 MHz),時間比 = cycles 比:\(2.8/2.5075\approx1.12\)

MachineCPITime(Mbase) / Time(Mcomp)
Mcomp2.811.12

Mcomp 的 CPI 比 Mbase 大(2.81 \(\gt\) 2.8),但指令數少 10.75%,總時間仍較短;CPI 不能單獨比效能。

210%

Here is a loop in C:

Loop:  g = g + A[i];
       i = i + j;
       if (i != h) goto Loop;

A is an array of 100 elements; g, h, i, j are in $s1, $s2, $s3, $s4; the base of A is in $s5. Other registers that can be used are $t0 and $t1. A possible MIPS assembly code:

Loop:  add  $t1, $s3, OPA
       add  $t1, $t1, $t1
       add  $t1, $t1, OPB
       lw   $t0, 0(OPC)
       add  OPD, $s1, $t0
       add  $s3, $s3, $s4
       bne  $s3, OPE, Loop

Determine proper values for the operands (OPA, OPB, OPC, OPD, OPE). (Table 2)

第 1 行 \(\$t1=\$s3+\text{OPA}\),第 2 行再自加一次 → 要得到 \(4i\),所以第 1 行是 \(2i\):OPA \(=\$s3\)

第 3 行 \(\$t1=4i+\text{OPB}\),要成為 \(A[i]\) 位址 → OPB \(=\$s5\)

lw 取 \(A[i]\),位址在 \(\$t1\) → OPC \(=\$t1\)

\(g=g+A[i]\),結果寫回 \(g\) → OPD \(=\$s1\)

\(i\ne h\) 才繼續 → OPE \(=\$s2\)

OperandOPAOPBOPCOPDOPE
Value$s3$s5$t1$s1$s2
310%

Figure 1 shows a 16-bit adder consisting of four 4-bit ALUs using carry lookahead. Assume \(g_i=a_i\cdot b_i\) (generate) and \(p_i=a_i+b_i\) (propagate). Determine the value of P0, P1, P2, P3, G0, G1, G2, G3, and C4 (CarryOut) when adding two 16-bit numbers 0001101000110011 and 1110010111101011 with Carry_In bit equal to 0. (Table 3)

ALU3a15..a12 ALU2a11..a8 ALU1a7..a4 ALU0a3..a0 Carry-lookahead unit (P0–P3, G0–G3 → C1–C4) P3 G3P2 G2P1 G1P0 G0 C4 ← 出口(CarryOut)Cin=0

每個 4-bit 區塊:\(P=p_3p_2p_1p_0\),\(G=g_3+p_3g_2+p_3p_2g_1+p_3p_2p_1g_0\)

A = 0001 1010 0011 0011,B = 1110 0101 1110 1011

區塊ab\(p_3p_2p_1p_0\)\(g_3g_2g_1g_0\)PG
ALU0(bit 3–0)001110111011001100
ALU1(bit 7–4)001111101111001011
ALU2(bit 11–8)101001011111000010
ALU3(bit 15–12)000111101111000010

\(C_1=G_0+P_0C_0=0\)

\(C_2=G_1+P_1C_1=1+0=1\)

\(C_3=G_2+P_2C_2=0+1\cdot1=1\)

\(C_4=G_3+P_3C_3=0+1\cdot1=1\)

SignalP0P1P2P3G0G1G2G3C4
Value011101001

直接相加:\(6707+58859=65566=65536+30\),bit 16 確實為 1。

415%

Compare the single-cycle implementation, in which all instructions take 1 clock cycle, with the five-stage (IF, ID, EX, MEM, WB) pipelined implementation using the following eight instructions: lw, sw, sub, and, or, slt and beq. The operation times: 2 ns for memory access, 2 ns for ALU operation, and 1 ns for register file read or write.

4.1 [5%] Complete Table 4-1: the time of each component and the total time of each instruction in the single-cycle implementation (multiplexors, control unit, PC accesses, sign extension have no delay).

4.2 [5%] What is the clock cycle time for the single-cycle and the pipelined implementation? (Table 4-2)

4.3 [5%] A program has 100 lw instructions, each dependent upon the instruction before it. What would the actual CPI be on the single-cycle implementation and the pipelined implementation with a forwarding unit and a hazard detection unit?

4.1 各指令走過的元件:lw 五項全走,sw 不寫 register,R-format 不碰 data memory,beq 只比較

Instruction classInstr. fetchRegister readALU op.Data accessRegister writeTotal
lw212218 ns
sw2122—7 ns
R-format212—16 ns
beq212——5 ns

4.2 single-cycle:取最慢的 lw,clock \(=8\) ns

pipeline:取最慢的 stage,IF/EX/MEM 都是 2 ns(ID、WB 為 1 ns),clock \(=2\) ns

4.3 single-cycle:每條指令 1 個 cycle,CPI \(=1\)

pipeline:lw 之後立刻要用 lw 的結果(load-use),forwarding 也要 stall 1 拍,100 條有 99 個相依

cycles \(=(5-1)+100+99=203\),CPI \(=203/100=2.03\)

DesignClock cycle timeActual CPI
Single-cycle8 ns1
Pipelined2 ns2.03

執行時間:pipeline \(203\times2=406\) ns,single-cycle \(100\times8=800\) ns。

512%

Increasing associativity requires more comparators, as well as more tag bits per cache block. Assuming a cache of 4K blocks, a four-word block size, and a 32-bit address, find the total number of sets and the total number of tag bits for caches that are direct mapped, two-way and four-way set associative, and fully associative. (Table 5)

block = 4 words = 16 bytes → offset 4 bits

sets \(=4096/\text{ways}\),tag \(=32-\text{index}-4\),總 tag bits \(=\text{tag}\times4096\)

Cachesetsindextag / blocktotal tag bits
Direct mapped4K1216\(16\times4K=64\)K bits
Two-way2K1117\(17\times4K=68\)K bits
Four-way1K1018\(18\times4K=72\)K bits
Fully associative1028\(28\times4K=112\)K bits

way 數加倍,index 少 1 bit、tag 多 1 bit,總 tag 多 4K bits。

615%

Here is a series of address references given as word addresses: 1, 4, 8, 5, 20, 17, 19, 56, 9, 11, 4, 43, 5, 6, 9, 17. Assuming a direct-mapped cache with four-word blocks and a total size of 16 words that is initially empty, label each reference in the list as a hit or a miss and show the final contents of the cache. (Table 6-1, 6-2)

16 words ÷ 4 words = 4 個 block;block address \(=\lfloor\text{addr}/4\rfloor\),index \(=\) block address mod 4

Reference14852017195691144356917
block addr012154414221101124
index0121100222121120
Hit or missMMMHMMHMMHMMHHMH

index 1 有 block 1(word 4~7)與 block 5(word 20)互相替換;index 2 有 block 2(word 8~11)、14(word 56)、10(word 43)互相替換

最後 index 0 為 block 4、index 1 為 block 1、index 2 為 block 2、index 3 從頭到尾沒用到

Block #0123
Starting address1648—(空)

hit 共 6 次(5、19、11、5、6、17),miss 10 次。

715%

Suppose we have a processor with a base CPI of 1.0, assuming all references hit in the primary cache, and a clock rate of 1 GHz. Assume a main memory access time of 100 ns, including all the miss handling.

7.1 [7%] Suppose the miss rate per instruction at the primary cache is 5%. What is the effective CPI for the machine with one level of caching?

7.2 [8%] If we add a secondary cache that has a 10-ns access time for either a hit or a miss and is large enough to reduce the miss rate to main memory to 2%. What is the effective CPI for the machine with the two-level cache?

1 GHz → 1 cycle = 1 ns;主記憶體 100 cycles,L2 10 cycles

7.1 \(\text{CPI}=1.0+0.05\times100\)

6.0

7.2 L1 miss(5%)都要付 L2 的 10 cycles,其中 2% 還要走主記憶體

\(\text{CPI}=1.0+0.05\times10+0.02\times100=1+0.5+2\)

3.5

加 L2 後快 \(6.0/3.5\approx1.71\) 倍。

85%

Suppose you want to achieve a speedup of 50 with 100 processors. What fraction of the original computation can be sequential?

設 sequential 比例為 \(s\),Amdahl:\(\dfrac{1}{s+\frac{1-s}{100}}=50\)

\(s+\dfrac{1-s}{100}=0.02\) → \(100s+1-s=2\) → \(99s=1\)

\(s=\dfrac{1}{99}\approx1.01\%\)

超過約 1% 的部分無法平行,100 個處理器就達不到 50 倍。

109–115 的詳解也是這樣寫的。

國立中山大學 109–115 的詳解收錄在付費版;106–115 全年度完整詳解共 236 頁,逐題推導。

購買 · NT$ 850 看中山其他免費詳解

其他年度與考科

同一年的其他科

同一科的其他年度

聯絡我們

題目有錯、詳解看不懂,都歡迎來信

想許願補哪一份、對購買有疑問也可以,收到後會盡快回覆。

william.chou.123123@gmail.com