108 年 國立臺灣聯合大學系統(清華、政治、陽明交通、中央四校聯招)研究所電機類《計算機系統(計算機組織)》
第 一 題15 分
Below is one implementation of the datapath of the simple MIPS processor. Suppose that all instructions have the same instruction fetch and decode steps. The critical paths for the different instruction types that need to be considered are: R-format, Load-word, and Store-word.
🖼️【此處有附圖,請對照原卷】
The operation times for the major functional components for this machine are listed as follows:
| Component | Latency (ns) |
|---|---|
| ALU | 10 |
| Adder | 8 |
| ALU Control Unit | 2 |
| Shifter | 3 |
| Control Unit/ROM | 4 |
| Sign / zero extender | 3 |
| 2:1 MUX | 2 |
| Memory (read/write) (instruction or data) | 15 |
| PC Register (read action) | 1 |
| PC Register (write action) | 1 |
| Register file (read action) | 7 |
| Register file (write action) | 5 |
| Logic (1 or more levels of gates) | 1 |
(a) Please indicate the components that determine the path delay for each type of R-format, Load-word, and Store-word instructions, respectively, in the order that the critical path occurs.
(b) For this MIPS processor, what will the resultant clock cycle time be? And what frequency will the machine run?
登入後即可作答並保存紀錄。
核心觀念
本題考查單周期 MIPS 處理器的:
- 關鍵路徑(critical path)
- 各硬體元件的延遲時間
- 同一條指令中,資料必須依序通過的元件延遲總和
- 時脈週期由所有指令類型中最長的路徑決定
計算公式為:
題目附件目前顯示的是工程數學考卷,未包含本題所需的 MIPS datapath 圖。以下依照標準單周期 MIPS datapath,假設資料路徑包含:
- PC 暫存器
- Instruction Memory
- Register File
- ALUSrc 2:1 MUX
- ALU
- Data Memory
- MemtoReg 2:1 MUX
- Register File 寫入
解題方法
所有指令都必須先經過:
之後依照指令類型分流。
控制訊號由 Control Unit 與 ALU Control Unit 平行產生;若其延遲沒有比資料本身抵達更晚,就不列入主要資料關鍵路徑。
(a) 各類指令的關鍵路徑
1. R-format
R-format 使用兩個暫存器運算,ALU 的結果再寫回 Register File。
關鍵路徑為:
延遲為:
其中第一個 MUX 是 ALUSrc MUX,第二個 MUX 是 MemtoReg MUX。
2. Load-word
Load-word 先利用 ALU 計算記憶體位址,再從 Data Memory 讀取資料,最後寫回暫存器。
關鍵路徑為:
延遲為:
3. Store-word
Store-word 使用 ALU 計算記憶體位址,並將 Register File 讀出的資料寫入 Data Memory。
關鍵路徑為:
第 二 題10 分
The following table shows the number of instructions for a typical program:
| Instruction Type | Number of Instructions |
|---|---|
| Arithmetic | 500 |
| Store | 50 |
| Load | 100 |
| Branch | 50 |
| Total | 700 |
(a) Assuming that Load instruction takes 5 cycles, Arithmetic and Store 4 cycles and Branch 3 cycles, what is the execution time of the program running in 2 GHz processor? Find the CPI for the program?
(b) If the number of load instructions can be reduced by one-half, what is the speed-up and CPI.
登入後即可作答並保存紀錄。
核心觀念
本題考查計算機系統結構中「CPU 效能方程式(CPU Performance Equation)」與「加權平均每指令週期數(Cycles Per Instruction, CPI)」的核心計算。
關鍵公式如下:
- CPU 執行時間(CPU Execution Time):
- 加權平均 CPI:
- 加速比(Speedup):
解題方法
(a) 原始程式之執行時間與 CPI 計算
-
步驟一:計算原始總時脈週期數(Total Clock Cycles)
根據題目表格與各指令的 CPI 權重:- Arithmetic:
- Store:
- Load:
- Branch:
-
步驟二:計算平均 CPI
原始總指令數 :
-
步驟三:計算 CPU 執行時間
處理器時脈頻率 :
(b) Load 指令減半後之加速比與 CPI 計算
第 三 題10 分
(a) Given by a floating-point number 24A60004(hex) that is represented by IEEE 754 standard. What decimal number is it?
(b) Write down the binary representation of the decimal number -1609.5, assuming the IEEE 754 double precision format.
登入後即可作答並保存紀錄。
(a) 24A60004₁₆ → 十進位
IEEE‑754 單精度 (32 bit) 之欄位:
- 符號位 (正)
- 指數位 0x49 =
實際指數 - 尾數位 0x00260004
- 正規化尾數
【答案】(約值)
(b) 的 IEEE‑754 雙精度 (64 bit) 二進位表示
第 四 題15 分
For a direct-mapped cache design with 32-bit address [31-0], the following bits of the address are used to access the cache:
| Case | Tag field | Index field | Offset field |
|---|---|---|---|
| Case I | [31-10] | [9-4] | [3-0] |
| Case II | [31-12] | [11-5] | [4-0] |
Starting from power on, the following byte-addressed cache references are recorded:
address 0, 4, 16, 132, 232, 160, 1024, 30, 140, 3100, 180, 2180
(a) What is the block size (in words) of each case?
(b) For each case, what is the ratio between total bits required for such a cache implementation over the data storage bits?
(c) For each case, how many blocks are replaced?
(d) For each case, what is the hit ratio?
登入後即可作答並保存紀錄。
(a) Block size (words)
- Case I:位元組位元 → B words
- Case II:位元組位元 → B words
(b) 總位元/資料位元比例
| Index bits | 行數 | 區塊大小 (bit) | 資料位元 | 標籤位元/行 | 標籤總位元 | 有效位元總數 | 總位元 | 比例 | |
|---|---|---|---|---|---|---|---|---|---|
| Case I |
第 五 題17 分
Some recursive procedures can be implemented iteratively without using the recursion. Given the following C program segment, the converted MIPS assembly codes are shown as below. Assume that arguments n and acc locate in $a0 and $a1.
int prod(int n, int acc) {
if (n > 0)
return prod(n-2,n*acc);
else
return acc;
}
(a) [7%] Please fill in the blanks (I) to (VII) to complete this assembly codes.
Prod: slti $t0, $a0, ___(I)___
bne $t0, $zero, Exit
mult ___(II)___, $a0, ___(III)___
addi ___(IV)___, $a0, -2
j Prod
Exit: add ___(V)___, ___(VI)___, $zero
jr ___(VII)___
The corresponding machine language instructions (addresses in decimal):
| Address | op | rs | rt | rd | sht | funct |
|---|---|---|---|---|---|---|
| 48000 | ||||||
| 48004 | 5 | 8 | 0 | (VIII) | ||
| 48008 | ||||||
| 48012 | 8 | 4 | (IX) | |||
| 48016 | 2 | (X) | ||||
| 48020 | ||||||
| 48024 |
(b) [6%] Parts of the corresponding machine language instructions are also given. Please fill the blanks (VIII), (IX), and (X) in decimal.
(c) [4%] Let the initial values of $a0 and $a1 are 8(hex) and 7(hex), respectively. How many times is the instruction "j Prod" executed before the completion of the program? What is the value of $v0 when the last instruction is executed? Please express in decimal.
登入後即可作答並保存紀錄。
核心觀念
這題考兩件事:把尾端遞迴改寫成迴圈,以及依 MIPS 指令格式填入暫存器、分支位移與跳躍目標。
函式呼叫 prod(n-2, n*acc) 是尾端呼叫:每次呼叫的結果直接作為目前函式的結果,不需要保留返回後要做的運算。因此,可直接在暫存器中更新參數並跳回 Prod。
解題方法
條件 n > 0 成立時,依序更新:
- 累積值:
acc = n * acc n:n = n - 2- 回到
Prod繼續判斷
slti $t0, $a0, 1 在 $a0 < 1 時令 $t0=1;此時 n 不大於 0,分支至 Exit。所以分支條件與原程式的 if (n > 0) 相符。
依題目提供的三運算元乘法格式,完整程式為:
Prod: slti $t0, $a0, 1
bne $t0, $zero, Exit
mult $a1, $a0, $a1
addi $a0, $a0, -2
j Prod
Exit: add $v0, $a1, $zero
jr $ra
其中 mult 的目的暫存器是 $a1,來源是 $a0 與 $a1,因此乘積更新累積值。
(a)填空答案
| 空格 | 答案 |
|---|---|
| (I) | 1 |
| (II) | $a1 |
| (III) | $a1 |
| (IV) | $a0 |
| (V) | $v0 |
| (VI) | $a1 |
| (VII) | $ra |
機器碼欄位計算
(VIII):分支位移
bne 位於位址 48004,Exit 位於 48020。分支位移以 PC+4 為基準,並以指令字為單位:
所以 (VIII) = 3。
(IX):addi 的立即數
第 六 題25 分
Assume that an engineer is asked to design a new pipeline processor, which is based on the MIPS ISA, to accelerate neural network computations. Thus, he plans to add a new instruction "macc", which combines multiplication and addition in a single instruction. Its operation example is given as follows.
macc $s0,$s1,$s2 = mult $t0,$s1,$s2
add $s0,$s0,$t0
Assume that in a conventional 5-stage pipelined MIPS ISA design, the individual pipeline stages are named as IF, ID, EX, MEM, and WB. The latencies of five stages are given as 120ps, 100ps, 170ps, 200ps, 120ps. In the new processor, due to the revision of ID and EX to support the new instruction, the latencies of ID and EX stages become 120ps and 240ps. Now, let's examine the effect of his design by the following C codes and assembly codes given that variable NodeOut and LENG are in register s4. The bases of arrays Weight and InMap are in s1.
for (i = 0; i <LENG; i += 1)
NodeOut=NodeOut+Weight[i]*InMap[i];
| Line | Label | Instruction | Operands |
|---|---|---|---|
| 1 | add | zero, $zero | |
| 2 | LOOP: | sll | t1, 2 |
| 3 | add | s0, $t2 | |
| 4 | add | s1, $t2 | |
| 5 | lw | t3) | |
| 6 | lw | t2) | |
| 7 | mult | t4, $t5 | |
| 8 | add | t5, $s3 | |
| 9 | addi | t1, 1 | |
| 10 | slt | t1, $s4 | |
| 11 | beq | zero, EXIT | |
| 12 | j | LOOP | |
| 13 | EXIT: |
(a) [6%] Consider only the effect inside the loop. If there is no forwarding or hazard detection, please insert nops and rewrite the assembly to ensure correct execution for the assembly codes from line 2 and line 8 given the conventional MIPS ISA.
(b) [4%] From (a), what is the processing time for completing these 7 instructions given the maximum operating frequency?
(c) [6%] Let the new instruction "macc" replace line 7 and line 8 of the above assembly codes. If there is no forwarding or hazard detection, please insert nops and rewrite the assembly to ensure correct execution for the assembly codes on the new pipeline processor.
(d) [4%] From (c), what is the processing time for completing these 6 instructions given the maximum operating frequency?
(e) [5%] Please comment according to (b) and (d). (You will get points only when answers in (b) and (d) are correct.)
登入後即可作答並保存紀錄。
核心觀念
本題考查五級管線中的資料危障、插入 nop 的方法,以及管線執行時間。
指令依序經過 IF、ID、EX、MEM、WB 五個階段。沒有資料轉送時,消費者必須等到生產者將結果寫回暫存器後,才能在 ID 階段讀取該值。本題採用標準 MIPS 暫存器檔假設:同一個時脈週期內,WB 先寫入、ID 後讀取,因此消費者可在生產者 WB 的同一週期讀取結果。
若生產者與消費者相鄰,兩者之間要插入兩個 nop,讓消費者的 ID 階段延後至生產者的 WB 週期。更一般地,若兩指令之間原有 條指令,至少需要:
個 nop。
管線時脈週期由最慢的階段決定:
一段指令序列有 條指令(包含插入的 nop),在五級管線中完成並排空管線需要 個週期。
(a) 傳統管線:插入 nop
只考慮迴圈內第 2 至第 8 行。主要相依關係如下:
sll產生$t2,第 3 行的add使用它:兩指令相鄰,插入兩個nop。- 第 3 行的
add產生$t3,第 5 行的lw使用它;中間已有一條第 4 行指令,因此再插入一個nop。 - 第 6 行的
lw產生$t5,第 7 行的mult使用$t5,插入兩個nop。 - 第 7 行的
mult產生$t5,第 8 行的add使用它,插入兩個nop。
改寫如下:
LOOP:
sll $t2, $t1, 2
nop
nop
add $t3, $s0, $t2
add $t2, $s1, $t2
nop
lw $t4, 0($t3)
lw $t5, 0($t2)
nop
nop
mult $t5, $t4, $t5
nop
nop
add $s3, $t5, $s3
原本 7 條指令共插入 7 個 nop,因此序列總長度為 14 條指令。
(b) 傳統管線:完成時間
傳統管線的時脈週期為:
時脈頻率為:
14 條指令完成並排空五級管線,需要 $14+4=18
第 七 題8 分
(a) If we want to use multi-processors to speedup the computation of an inner product of two vectors of size 100×1. Let the execution time of a single processor for this inner-product operation of two vectors of size 100×1 is t. Assume that 90% instructions associated with arithmetic operations can be processed in parallel, what is the execution time and speed-up with 10 processors?
(b) From (a), given that the vector size become 400×1 and the processing time of a single processor for this inner-product operation is 3.8t, if we want to achieve more than 8 × speed-up, at least how many processors should we use? What is the execution time?
登入後即可作答並保存紀錄。
核心觀念
本題旨在考驗計算機系統結構中多處理器系統效能優化與**阿姆達爾定律(Amdahl's Law)**的應用。
-
阿姆達爾定律(Amdahl's Law):
用於計算系統某一部份經平行化或優化後,整體系統所能獲得的加速比(Speedup)與優化後執行時間(Execution Time)。公式定義如下:
其中:- :單一處理器(Single Processor)執行時間。
- :使用 個處理器時的平行執行時間。
- :程式中可被平行處理(Parallelizable)部分的比例。
- :必須串行執行(Sequential)無法平行化部分的比例。
- :採用的處理器數量。
-
理論加速極限(Speedup Bound):
當處理器數量增加至無限多個()時,最大平行加速比受限於串行執行的比例:
解題方法
(a) 子題 (a) 求解推導
-
給定條件:
- 向量尺寸:。
- 單處理器執行時間 。
- 可平行化算術指令比例 ,串行比例 。
- 處理器數量 。
-
計算 10 個處理器之執行時間 :
-
計算加速比 :
(b) 子題 (b) 求解推導
-
給定條件:
- 向量尺寸擴展至 。
- 單處理器執行時間 。
- 延續 (a) 之系統特性,平行化比例 ,串行比例 。
- 目標加速比:。
-
求解最少處理器數量 :
根據阿姆達爾定律加速比公式設定不等式:
求解此不等式: