112 年 國立成功大學電機工程學系碩士班戊組《計算機組織》
第 1 題10 分
(10pts, no partial point, no penalty) Consider a pipelined RISC-V/MIPS processor. Which of the following statement is/are TRUE?
(a) If input of a subsequent instruction has some dependences on output of previous instruction, this is called structure hazard.
(b) ID stages is for registers fetch and instruction decode.
(c) IF stage use only instruction memory, no data memory access required.
(d) If we are designing a processor that can only execute R-type instruction, only 4 stages (IF, ID, EXE, MEM) are needed to be implemented.
登入後即可作答並保存紀錄。
參考書等級:教材《計算機組織與設計》(Computer Organization and Design)或《Computer Architecture: A Quantitative Approach》,均列於大學部與研究所必修範圍。
| 選項 | 正誤說明 |
|---|---|
| (a) 結構危險(structural hazard)指的是同一時間點硬體資源(例如 ALU、記憶體埠)不足,同時需要被多條指令使用,不是資料相依。故此敘述 錯誤。 |
第 2 題10 分
(10pts, no partial point, no penalty) Pipelining is an implementation technique in which multiple instructions are overlapped in execution. Which of the following statement about pipeline is/are TRUE?
(a) The clock rate of a pipelined hardware is determined by the fastest stage.
(b) The speedup of pipelining comes from shorter clock period, which results in smaller overall delay.
(c) Since the shortest delay determines clock period, we can split the acyclic combinational logic of critical path into two parts for faster clock period.
(d) In a 5-stage pipelined RISC-V/MIPS CPU, hardware resources can be shared across different stages.
登入後即可作答並保存紀錄。
核心觀念
本題考查計算機組織中**管線化技術(Pipelining)**的核心原理、時脈週期(Clock Period)與時脈頻率(Clock Rate)的決定機制、效能提升(Speedup)的本質來源,以及硬體資源爭用與結構冒險(Structural Hazards)的防範。
相關關鍵定義與公式如下:
-
時脈週期與關鍵路徑:
管線化硬體的時脈週期 取決於延遲最長的階段(最慢階段 / Critical Path Stage),加上管線暫存器(Pipeline Register)的開銷(如 Setup Time 與 Propagation Delay):
時脈頻率 因此受限於最慢的階段。 -
吞吐量與延遲(Throughput vs. Latency):
- 吞吐量(Throughput):單位時間內完成的指令數量。管線化的加速比(Speedup)完全來自於指令吞吐量的提升。
- 延遲(Latency / Overall Delay):單一指令從開始執行到完成所需的總時間。管線化不會縮短單一指令的執行延遲;相反地,因為加入了管線暫存器開銷與階段不平衡(Stage Imbalance),單一指令的 Latency 通常會持平或微幅增加。
-
結構冒險與硬體資源獨立性:
在管線化架構中,多個指令在同一時脈週期內處於不同階段重疊執行。若不同階段試圖存取同一個硬體資源,會產生結構冒險(Structural Hazard)。因此各階段所需的硬體資源必須獨立配置(如分離的指令快取與資料快取)。
解題方法
針對題目中關於管線化技術的四個敘述,以計算機組織理論與硬體架構規範逐一驗證:
- 時脈決定機制:檢驗時脈週期與頻率係由最快還是最慢階段決定。
- 效能提升來源:檢驗 Speedup 是來自於提升 Throughput 還是降低單一指令 Latency。
- 路徑分割原則:檢驗切分組合邏輯以降低時脈週期的前提與邏輯是否正確。
- 硬體資源共享:檢驗管線化 CPU 各階段能否在同一時脈週期內共用硬體資源。
選項分析
- (a) 錯誤
- 原敘述:The clock rate of a pipelined hardware is determined by the fastest stage.
- 分析:管線硬體的時脈週期(Clock Period, )受限於最慢的階段(slowest stage),即 critical path。若時脈頻率(Clock Rate, )依最快階段設定,最慢階段將無法在一個時脈週期內完成運算與資料傳遞,導致電路功能錯誤。
第 3 題10 分
(10pts, no partial point, no penalty) Parallelism is a technique to enhance performance. Which of the following statement about parallelism is/are TRUE?
(a) Since course-grained multithreading switches threads only on expensive stalls, it is limited in its ability to overcome throughput losses.
(b) Simultaneous multithreading (SMT) is a variation on hardware multithreading that uses the resources of multiple single-issue, dynamically scheduled pipelined processor.
(c) MIMD is more energy efficient than SIMD, since MIMD can process multiple instruction at same time.
(d) Instruction pipeline with Out-of-order execution or superscalar execution can be regarded as Instruction Level Parallelism (ILP)
登入後即可作答並保存紀錄。
核心觀念
本題考驗電腦架構中**平行處理技術(Parallelism)**的分類、硬體機制與效能權衡(Trade-offs),涵蓋以下四大核心領域:
-
硬體多執行緒(Hardware Multithreading):
- 粗粒度多執行緒(Coarse-grained Multithreading):僅在遇到高延遲停頓(Costly/Expensive Stalls,如 L2/L3 快取未命中)時才進行執行緒切換。切換時需清空或填補管線(Pipeline Flush/Fill),具備切換開銷(Switching Overhead)。
- 細粒度多執行緒(Fine-grained Multithreading):每個時脈週期輪流切換執行緒,可掩蓋長短停頓,但會拉長單一執行緒的執行時間。
- 同步多執行緒(Simultaneous Multithreading, SMT):基於多發射(Multiple-issue / Superscalar)且動態排程的處理器架構,允許在同一個時脈週期內從多個不同執行緒發射指令至不同的執行單元。
-
Flynn 分類法與能效比較(Flynn's Taxonomy & Energy Efficiency):
- SIMD(Single Instruction, Multiple Data):由單一控制單元(Control Unit)控制多個資料運算單元(ALUs)。指令擷取與解碼開銷分攤至大量資料,故具有極高能效(Energy Efficiency)。
- MIMD(Multiple Instruction, Multiple Data):每個處理核心皆擁有獨立的控制單元與指令擷取/解碼電路,處理平行任務時的控制邏輯功耗顯著高於 SIMD。
-
指令級平行(Instruction Level Parallelism, ILP):
- 泛指在單一處理器內重疊執行多條指令的技術。常見實作包含:指令管線化(Pipelining)、超純量(Superscalar)、亂序執行(Out-of-Order Execution, OoO)及動態排程(Dynamic Scheduling)。
解題方法
本題為觀念判斷題,解題切入點為比對電腦架構標準定義與硬體實作細節:
- 判斷粗粒度多執行緒切換時機與能掩蓋的停頓類型(Short Stalls vs. Long Stalls)。
- 檢查 SMT 的底層硬體基底(Multiple-issue 還是 Single-issue)。
- 比較 SIMD 與 MIMD 在控制邏輯硬體開銷上的能效表現。
- 確認 ILP 的範疇與具體硬體實現技術。
選項分析
(a) 正確
- 詳細說明:粗粒度多執行緒(Coarse-grained Multithreading)為了避免頻繁切換導致單一執行緒延遲過高,採用「僅在發生昂貴停頓(Expensive Stalls,如 L2/L3 Cache Miss 或訪問主記憶體)時才切換執行緒」的策略。由於切換執行緒需要清空(Flush)或填補管線,存在固定的硬體開銷。
第 4 題10 分
(10pts, no partial point, no penalty) Which of the following statement is/are TRUE? (10pts, no partial point, no penalty)
(a) CPU time is total time spent processing on a given job, including I/O time.
(b) In the IC design flow, the gate level implementation is the abstraction of the transistor level circuit
(c) Since CPI represents the average of how many cycles for a processor to execute an instruction, we can evaluate the performance of two CPUs by comparing the CPI when running the same program (compiled separately).
(d) Most tablet and smart phone use resistive touchscreen, since it allows multiple touches simultaneously
登入後即可作答並保存紀錄。
核心觀念
- CPU Time 與 Elapsed Time 的定義差異:CPU 執行時間(CPU Time)僅包含 CPU 處理該任務的實際運算時間,不包含等待 I/O 與其他程式交錯執行的時間。
- IC 設計抽象層級(Abstraction Levels):在積體電路設計中,邏輯閘層(Gate Level)為電晶體層(Transistor Level)的抽象化表示。
- CPU 效能三大要素公式:
衡量處理器效能需綜合評估指令數 ()、平均每指令週期數 () 與時脈週期時間(),單一指標無法決定整體效能。 - 硬體輸入介面特性:現代行動裝置(智慧型手機與平板)主流使用支援多點觸控(Multi-touch)的電容式觸控螢幕(Capacitive Touchscreen)。
解題方法
本題為計算機組織與結構基本概念的複選觀念題。解題切入點如下:
- 引用 CPU 效能標準量測公式,判斷效能評估指標是否嚴謹。
- 根據電腦系統抽象化層級架構,由底層半導體元件(Transistor)向高層邏輯(Gate/RTL)進行層級對應。
- 區分系統響應時間(Elapsed Time)與 CPU 執行時間(CPU Time)的範疇。
- 依據現行消費性電子硬體規範,審視 Touchscreen 技術原理。
選項分析
-
(a) 錯誤
- 題目原文:CPU time is total time spent processing on a given job, including I/O time.
- 詳解:CPU Time(CPU 執行時間)定義為 CPU 實際用於處理該程式指令的時間(可細分為 User CPU Time 與 System CPU Time),**明確不包含(excluding)**等待 I/O 運作或切換執行其他程式的時間。包含 I/O 等待時間與排程開銷的總時間稱為 Elapsed Time(或 Wall-clock Time / Response Time)。
-
(b) 正確
- 題目原文:In the IC design flow, the gate level implementation is the abstraction of the transistor level circuit
- 詳解:在 IC 設計流程中,階層化抽象由低至高依序為:電晶體層(Transistor Level / Switch Level) 邏輯閘層(Gate Level) 暫存器傳輸層(RTL) 系統/演算法層(System Level)。
第 5 題10 分
(10pts, no partial point, no penalty) Which of the following statement about RISC-V/MIPS instructions is/are TRUE? (10pts, no partial point, no penalty)
(a) Arithmetic instructions operands can be registers or memories.
(b) Stack pointer is a value denoting the most recently allocated address in a stack that shows where registers should be spilled or where old register values can be found.
(c) Programs are stored in memory to be read or written, but in a special format called machine sector, which is different from normal data stored in memory.
(d) A basic block is a sequence of instructions without branches.
登入後即可作答並保存紀錄。
核心觀念
本題考驗 RISC-V 與 MIPS 等 RISC(精簡指令集)指令集架構(ISA) 的基本屬性與作業系統/編譯器基礎觀念,包含以下四項核心知識:
- Load/Store 架構:RISC 架構中算術指令運算元(Operands)的存取限制。
- 堆疊指標(Stack Pointer)與暫存器溢位(Register Spilling):記憶體堆疊維護與函式呼叫協定。
- 馮·紐曼架構之儲存程式觀念(Stored-Program Concept):指令與資料在記憶體中的儲存型態與本質。
- 編譯器控制流程分析之基本區塊(Basic Block):程式指令區塊的定義與控制流屬性。
解題方法
針對各選項敘述,逐一比對 Patterson & Hennessy《Computer Organization and Design》經典教材中對 RISC-V / MIPS ISA 的標準定義與理論推導:
- 分析算術指令是否具備直接存取記憶體運算元的能力(區分 RISC 與 CISC 架構)。
- 核對堆疊指標()的定義與暫存器溢位(Register Spilling)之應用情境。
- 根據儲存程式觀念,檢視指令與資料於記憶體中儲存格式的異同。
- 依據編譯器理論檢視基本區塊(Basic Block)的進入、執行與離開條件屬性。
選項分析
-
(a) 錯誤
- 分析:RISC-V 與 MIPS 均屬於典型的 RISC(Load/Store 架構)。在 Load/Store 架構中,所有算術與邏輯指令(如
add,sub,and,or等)的運算元(Operands)只能是暫存器(Registers)或立即數(Immediates),絕不能直接以記憶體位址(Memory Operands)作為運算元。 - 補充:在 RISC 中,只有
load(如lw)與store(如sw)指令可以直接存取記憶體;若要對記憶體中的資料進行加法,必須先將資料 Load 入暫存器,經算術指令處理後,再 Store 回記憶體。直接允許算術指令存取記憶體運算元是 CISC(如 x86)架構的特徵。
- 分析:RISC-V 與 MIPS 均屬於典型的 RISC(Load/Store 架構)。在 Load/Store 架構中,所有算術與邏輯指令(如
-
(b) 正確
- 分析:堆疊指標(Stack Pointer, ) 是一個專用暫存器(RISC-V 中為
x2/sp,MIPS 中為$29/$sp),記錄目前堆疊頂端(Top of Stack)的位址,即堆疊中最新分配的記憶體空間位址(most recently allocated address)。
- 分析:堆疊指標(Stack Pointer, ) 是一個專用暫存器(RISC-V 中為
第 6 題10 分
(10pts, no partial point, no penalty) Which of the following statement about cache is/are TRUE? (10pts, no partial point, no penalty)
(a) Cache relies on the principle of locality to try to find the desired data in the higher levels of the memory hierarchy, which is different from the big idea of prediction.
(b) In a direct mapped cache, each memory location is mapped directly to two specific locations in the cache.
(c) A set associative cache reduces cache misses by more flexible placement of blocks.
(d) If the total cache size is kept the same, increasing the associativity raises the number of blocks per set, which is the number of simultaneous compares needed to perform the search in parallel.
登入後即可作答並保存紀錄。
核心觀念
本題考查計算機組織中**快取記憶體(Cache Memory)**的基本原理與硬體架構特質,包含以下重點:
- 計算機架構八大觀念(8 Great Ideas):記憶體階層(Hierarchy of Memories)設計建立於區域性原則(Principle of Locality);而預測(Prediction)為另一個獨立的核心設計觀念。
- 快取對映與放置策略(Block Placement Policy):
- 直接對映(Direct Mapped):實施 -to- 映射,每個區塊只能放置於恰好 1 個指定快取位置。
- 組連結(Set Associative):區塊對映至指定 Set 後,可彈性放置在該 Set 內的任一 Block,用以降低衝突失誤(Conflict Misses)。
- 組連結的平行硬體搜尋機制:
- 在總快取容量保持不變時,提高連結度(Associativity )會使每組的區塊數(Blocks per set)增加為 。
- 為在單一時脈週期內完成 Tag 尋找,硬體必須針對該 Set 內所有的 Block 同時進行 Tag 比較,故硬體平行比較器(Comparators)需求數量即等於 。
解題方法
本題為觀念判斷題,解題切入點如下:
- 釐清計算機架構設計哲學中「記憶體階層與區域性」與「預測」的定義差異。
- 代入 Cache 對映邏輯公式:。
- 比較不同 Block Placement 策略對 Cache Misses(特別是 Conflict Miss)的影響。
- 分析硬體實作細節:Associativity()與組內區塊數、平行比較器數量(Parallel Tag Comparison)之對應關係。
選項分析
-
(a) 正確
原文:Cache relies on the principle of locality to try to find the desired data in the higher levels of the memory hierarchy, which is different from the big idea of prediction.
分析:快取記憶體之能發揮作用,主要依賴區域性原則(Principle of Locality),包含時間區域性(Temporal Locality)與空間區域性(Spatial Locality)。根據 Patterson & Hennessy 的經典教材《Computer Organization and Design》,計算機架構的「八大核心觀念(8 Great Ideas)」中,「記憶體階層(Hierarchy of Memories)」與「透過預測提升效能(Performance via Prediction)」屬於兩個不同的設計觀念。因此,Cache 依賴區域性原則運作,這與「預測」觀念是不同的,敘述正確。 -
(b) 錯誤
原文:In a direct mapped cache, each memory location is mapped directly to two specific locations in the cache.
分析:在直接對映快取(Direct Mapped Cache)中,主記憶體的每一個區塊只能被直接對映到快取中**恰好 1 個(exactly one)**特定的位置。其對映公式為:
第 7 題10 分
(10pts) Assume we use a processor with 2 GHz clock rate to run a program which requires the following executions.
Instruction Type
of instructions
FP instructions
40 x 106
INT instructions
40 x 106
Load/Store instructions
30 x 106
branch instructions
20 x 106
CPI
2
1
5
5
By how much must we improve the CPI of FP instructions if we want the program to run two times faster?
登入後即可作答並保存紀錄。
原始執行週期
時脈 2 GHz ⇒ 每秒 2×10⁹ 個週期,原程式執行時間
欲使程式執行時間縮短為原來的 ½:
第 8 題10 分
(10pts) Using Booth's algorithm to do the following multiplication and answer the question.
How many additions/subtractions needed to be computed?
0111 11102 × 0111 1110
Number of additions =
Number of subtractions =
?
?
登入後即可作答並保存紀錄。
Booth 演算法以 、 兩位判斷:
- 、 → 無操作
- → 加上被乘數
- → 減去
設定
被乘數 (+126)
乘數 ,添上
寫出 各位(自 LSB 起):
| 位號 | ||
|---|---|---|
| 0 | 0 | 0 |
| 1 | 1 | 0 |
| 2 | 1 | 1 |
| 3 | 1 | 1 |
| 4 | 1 | 1 |
第 9 題10 分
(10pts) What's the value of x5/$t1 after the following RISC-V/MIPS instructions? (in decimal)
RISC-V------
x7 holds the value 0x0000000000011100hex.
blt x7, x0, ELSE
ori x5, x0, 8
jal x0, DONE
ELSE:
ori x5, x0, 4
DONE:
-MIPS
t0, t1, t1, $zero, 4
DONE:
登入後即可作答並保存紀錄。
核心觀念
- RISC-V / MIPS 條件跳躍指令(Branch Instruction):
blt(Branch if Less Than)用於比較兩個暫存器的有號數(Signed Integer)大小。若第一個暫存器的值嚴格小於第二個暫存器,則跳躍至指定標籤(Label);否則繼續順序執行下一條指令。 - 無條件跳躍指令(Unconditional Jump Instruction):
jal(Jump and Link)在 RISC-V 中將目標暫存器設為x0(零暫存器Zero Register),即可充當不需要儲存返回位址的無條件跳躍指令j。 - 邏輯或立即數運算(Bitwise OR Immediate):
ori指令將暫存器內容與立即數進行位元邏輯或(Bitwise OR)運算。將零暫存器與數值 進行ori運算(如ori x5, x0, 8),結果即為 。 - 二補數與數值符號判定(Two's Complement Representation):十六進位數值
0x0000000000011100的最高有效位元(MSB)為 ,在二補數系統中代表正數。
解題方法
本題為 RISC-V 與 MIPS 組合語言指令追蹤題,核心在於判定 blt 條件是否成立,並依據控制流程(Control Flow)推導暫存器 x5(RISC-V)與 $t1(MIPS)的最終十進位數值。
-
暫存器初始值數值分析:
暫存器x7(RISC-V)與$t0(MIPS)儲存的數值為:
將其換算為十進位:
因為最高有效位元(MSB)為 ,故 (為正數)。 -
條件跳躍
blt判定:
指令blt x7, x0, ELSE(與blt $t0, $zero, ELSE)的比較條件為:
條件不成立(False),因此不發生跳躍(Not Taken),程式繼續順序執行下一行指令。 -
執行順序指令與暫存器更新:
- 順序執行
ori x5, x0, 8(與ori $t1, $zero, 8):
位元運算過程:
- 順序執行
jal x0, DONE:
無條件跳躍至標籤DONE,跳過ELSE區塊中的ori x5, x0, 4。
- 順序執行
-
最終結果:
程式跳躍至DONE後結束,暫存器x5與$t1的十進位數值維持為 $8
第 10 題10 分
(10pts) Consider the following cache design with the following spec.
address size: 64 bits.
32 words of data in a line.
128 lines.
🖼️【此處有附圖,請對照原卷】
A~L are positive integers.
A=
B=
C=
D=
E=
F=
G=
H=
I =
J=
K=
L=
(-1 points for each incorrect answer)
登入後即可作答並保存紀錄。
這題考驗對快取記憶體(cache)設計的理解,包括位址切割(address decomposition)、快取結構(direct mapped, set-associative)、位址大小、行大小(line size)和快取行數(number of lines)之間的關係。
首先,我們需要根據題目提供的規格和快取結構圖來推導各個位址部分的位元數。
規格:
- Address size: 64 bits. 總位址大小是 64 位元。
- 32 words of data in a line. 一行(line)有 32 個字(word)。
- 128 lines. 快取總共有 128 行。
快取結構圖分析:
圖中顯示了 64 位元的位址被劃分成三個部分:Tag, Index, Block offset。
Tag: 標記部分,用於在快取中唯一識別一個主記憶體區塊。Index: 索引部分,用於定位快取中的哪個組(set)或哪一行(line)。Byte offset: 位元組偏移量,用於在選定的快取行內定位具體的位元組。
計算各部分位元數:
-
Byte offset (Block offset):
- 題目說明一行有 32 個字(words)。
- 在典型的電腦架構中,一個字(word)通常是 4 個位元組(bytes)。所以,一行有 。
- 要定址 128 個位元組,我們需要 位元。
- ,所以需要 7 位元來表示位元組偏移量。
- 圖中顯示
Byte offset有 7 位元。 - L = 7。
-
Index:
- 快取總共有 128 行(lines)。
- Index 的作用是選擇這 128 行中的哪一行。
- 要定址 128 行,我們需要 位元。
- ,所以需要 7 位元來作為 Index。
- 圖中顯示
Index有 7 位元。 - H = 7。
-
Tag:
- 總位址大小是 64 位元。
- 位址被分成 Tag, Index, Block offset 三部分。
- Tag 的位元數 = (總位址大小) - (Index 位元數) - (Block offset 位元數)。
- Tag 位元數 = 位元。
- 圖中顯示
Tag部分有 50 位元。 - F = 50。
根據圖中的標示推導 A 到 E:
圖中,位址的位元劃分如下:
- 最高位是 Tag 的最高位。
- Tag 部分從最高位開始,共有 50 位。
- Index 部分緊隨 Tag 之後,有 7 位。
- Block offset 部分是最低的 7 位。
位址從最高位到最低位的順序是:Tag (50 bits) | Index (7 bits) | Block offset (7 bits)。
總共 位元。
圖中的標示:
Tag部分標示為 50 bits。Index部分標示為 7 bits。Byte offset部分標示為 7 bits。
現在看圖中的 A, B, C, D, E, F, G, H, I, J, K, L。
這些字母代表位址的位元範圍或數量。
位址位元從 63 (最高位) 到 0 (最低位)。
-
Block offset 是最低的 7 位,即位址 0 到 6。
- 圖中
Byte offset標示為DEbits。這意味著D是Byte offset的位元數。 - D = 7。
- 圖中
-
Index 是緊接著 Block offset 的 7 位。
- Block offset 是位址 0-6。
- Index 應該是位址 7 到 。
- 圖中
Index部分標示為Cbits。這意味著C是Index的位元數。 - C = 7。
-
Tag 是剩餘的位元。
- Tag 的位元數是 50 位。
- 圖中
Tag部分標示為Bbits。這意味著B是Tag的位元數。 - B = 50。
-
總位址大小 是 64 位元。
- 圖中
Address標示為Abits。這意味著A是總位址大小。 - A = 64。
- 圖中
-
F, G, H, I, J, K, L 這些字母在圖中也標示在位址的劃分上。
F標示在Tag部分,表示 Tag 的位元數。我們已經推導出 F = 50。H標示在Index部分,表示 Index 的位元數。我們已經推導出 H = 7。L標示在Byte offset部分,表示 Byte offset 的位元數。我們已經推導出 L = 7。