110 年 國立臺灣聯合大學系統(清華、政治、陽明交通、中央四校聯招)研究所電機類《計算機系統(計算機組織)》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊

第 1 題10 分

  1. (10%) The importance of having a good branch predictor depends on how often conditional
    branches are executed. Together with branch predictor accuracy, this will determine how much
    time is spent stalling due to mispredicted branches. In this problem, assume a 5-stage pipeline
    RISC processor with the breakdown of dynamic instructions into various instruction categories is
    as follows:
    Instruction Type | Percentage
    -----------------|------------
    R-type | 40%
    BEQ | 25%
    JUMP | 5%
    LW | 25%
    SW | 5%

Also, assume the following branch predictor accuracies:

Predictor TypeAccuracy
Always-Taken45%
Always-Not-Taken55%
2-Bit Predictor85%

(a) (2%) Stall cycles due to mispredicted branches increase the CPI. What is the extra CPI due
to mispredicted branches with the always-taken predictor? Assume that branch outcomes are
determined in the EX stage, that there are no data hazards, and that no delay slots are used.
(b) (2%) Repeat (a) for the "always-not-taken" predictor.
(c) (2%) Repeat (a) for the 2-bit predictor.
(d) (2%) With the 2-bit predictor, what speedup would be achieved if we could convert half of
the branch instructions in a way that replaces a branch instruction with an ALU instruction?
Assume that correctly and incorrectly predicted instructions have the same chance of being
replaced.
(e) (2%) Some branch instructions are much more predictable than others. If we know that 80%
of all executed branch instructions are easy-to-predict loop-back branches that are always
predicted correctly, what is the accuracy of the 2-bit predictor on the remaining 20% of the
branch instructions?

登入後即可作答並保存紀錄。

這一題的完整詳解

(a) always‑taken

分支指令比例 = 25 % = 0.250.25
預測正確率 = 45 % → 錯誤率 =1−0.45=0.55=1-0.45=0.55
每次錯誤產生的停頓週期 = 2

額外 CPI=0.25×0.55×2=0.275\text{額外 CPI}=0.25 \times 0.55 \times 2 = 0.275

(b) always‑not‑taken

錯誤率 =1−0.55=0.45=1-0.55=0.45

額外 CPI=0.25×0.45×2=0.225\text{額外 CPI}=0.25 \times 0.45 \times 2 = 0.225

(c) 2‑bit predictor

錯誤率 =1−0.85=0.15=1-0.85=0.15

額外 CPI=0.25×0.15×2=0.075\text{額外 CPI}=0.25 \times 0.15 \times 2 = 0.075

(d) 轉換一半分支為 ALU 指令(使用 2‑bit predictor)

原始分支比例 0.250.25 → 轉換後分支比例 0.25×0.5=0.1250.25 \times 0.5 = 0.125

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 2 題8 分

  1. (8%) In this problem, we examine how pipelining affects the clock cycle time of the processor.
    Assume the individual stages of the datapath have the following latencies:
    Stage | Latency
    ------|---------
    IF | 300ps
    ID | 100ps
    EXE | 600ps
    MEM | 350ps
    WB | 100ps

And, assume that instructions executed by the processor are broken down as follows:

Instruction TypePercentage
ALU35%
Beq30%
LW20%
SW15%

(a) (2%) What is the clock cycle time in a pipelined and non-pipelined processor?
(b) (2%) If we can split one stage of the pipelined datapath into two new stages, each with half
the latency of the original stage, which stage would you split and what is the new clock
cycle time of the processor?
(c) (2%) Assuming there are no stalls or hazards, what is the utilization of the data memory?
(d) (2%) Assuming there are no stalls or hazards, what is the utilization of the write-register
port of the "Registers" unit?

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

  1. 處理器時脈週期(Clock Cycle Time, TcT_c)定義:

    • 非流水線處理器(Non-pipelined / Single-Cycle Processor):時脈週期必須能滿足執行時間最長的指令所需之總延遲(Total Latency)。其計算公式為:
      Tc,non-pipelined=max⁡all instructions(∑Stage Latencies of Instruction)T_{c, \text{non-pipelined}} = \max_{\text{all instructions}} \left( \sum \text{Stage Latencies of Instruction} \right)
    • 流水線處理器(Pipelined Processor):時脈週期受限於延遲最長的單一階段(Bottleneck Stage)。其計算公式為:
      Tc,pipelined=max⁡(IF,ID,EXE,MEM,WB)T_{c, \text{pipelined}} = \max(\text{IF}, \text{ID}, \text{EXE}, \text{MEM}, \text{WB})
  2. 流水線拆分(Stage Splitting)效能優化:

    • 若可將某一個階段拆分為等延遲的兩個子階段,欲最大化降低時脈週期,應優先拆分當前的瓶頸階段(最大延遲階段)。拆分後的新時脈週期將由剩餘階段中的最大延遲決定。
  3. 硬體資源利用率(Hardware Resource Utilization):

    • 利用率定義為「該硬體單元在執行指令過程中有被存取的時間區段佔總時間(或總指令數)的比例」。在無停頓(Stall)與冒險(Hazard)理想狀況下,處理器每個時脈週期皆順利發射(Issue)並執行一筆指令。
    • 資料記憶體(Data Memory):僅在 MEM 階段被存取,包含載入指令(LW,讀取)與儲存指令(SW,寫入)。
    • 暫存器檔案寫入埠(Write-Register Port of Registers):僅在 WB 階段被使用,包含需要將運算或載入結果寫回暫存器的指令(ALU 與 LW)。

解題方法

(a) 計算 Pipelined 與 Non-pipelined 處理器的時脈週期

  1. 非流水線處理器(Non-pipelined):
    分析各類指令通過資料通路所需的總延遲:

    • ALU 指令:經過 IF、ID、EXE、WB 階段,延遲為 300+100+600+100=1100 ps300 + 100 + 600 + 100 = 1100\text{ ps}。
    • Beq 指令:經過 IF、ID、EXE 階段,延遲為 300+100+600=1000 ps300 + 100 + 600 = 1000\text{ ps}。
    • LW 指令:經過 IF、ID、EXE、MEM、WB 階段,延遲為 300+100+600+350+100=1450 ps300 + 100 + 600 + 350 + 100 = 1450\text{ ps}。
    • SW 指令:經過 IF、ID、EXE、MEM 階段,延遲為 300+100+600+350=1350 ps300 + 100 + 600 + 350 = 1350\text{ ps}。

    單時脈週期處理器必須滿足延遲最長的指令(LW):
    Tc,non-pipelined=1450 psT_{c, \text{non-pipelined}} = 1450\text{ ps}

  2. 流水線處理器(Pipelined):
    時脈週期取各階段延遲的最大值:
    Tc,pipelined=max⁡(300,100,600,350,100)=600 ps(由 EXE 階段決定)T_{c, \text{pipelined}} = \max(300, 100, 600, 350, 100) = 600\text{ ps} \quad (\text{由 EXE 階段決定})

(b) 拆分階段與新時脈週期

  1. 當前流水線瓶頸為 EXE 階段(延遲 600 ps600\text{ ps})。
  2. 將 EXE 階段拆分為 EXE1\text{EXE}_1 與 EXE2\text{EXE}_2 兩個子階段,各自延遲為:
    Latency(EXE1)=Latency(EXE2)=600 ps2=300 ps\text{Latency}(\text{EXE}_1) = \text{Latency}(\text{EXE}_2) = \frac{600\text{ ps}}{2} = 300\text{ ps}
  3. 拆分後各階段延遲分別為:
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 3 題8 分

  1. (8%) Assume that logic blocks needed to implement a processor's datapath have the following latencies:
    Logic Block | Latency
    ------------|---------
    Instruction-Memory | 200ps
    Add | 100ps
    Mux | 10ps
    ALU | 250ps
    Registers | 100ps
    Data-Memory | 250ps
    Sign-Extend | 15ps
    Shift-left-2 | 10ps

(a) (2%) Consider a datapath similar to the one in the textbook shown below, but for a processor
that only has one type of instruction: unconditional PC-relative branch. What would the cycle
time be for this datapath?
🖼️【此處有附圖,請對照原卷】
(b) (2%) Repeat (a), but this time we need to support only conditional PC-relative branches.
The remaining three problems refer to the datapath element Shift-left-2:
(c) (2%) For which kind of instructions (if any) requires this resource on the critical path?
(d) (2%) Assuming that we only support beq and add instructions, discuss how changes in the
given latency of this resource affect the cycle time of the processor. Assume that the latencies
of other resources do not change.

🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 2 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

單周期處理器的時脈週期必須涵蓋該指令所需的最長路徑。元件串接時延遲相加;平行路徑則要等較晚到達的一路,因此取兩者的最大值。最後由 Mux 選出的結果,還要計入 Mux 延遲。

解題方法與計算

圖中 PC 同時送往指令記憶體與計算 PC+4PC+4 的加法器;分支立即值經過 Sign-Extend、Shift-left-2,再與 PC+4PC+4 相加,最後由 PCSrc Mux 選出下一個 PC。條件分支另由暫存器讀出兩個運算元,其中 Read data 2 會經過 ALUSrc Mux,再進入 ALU 比較。

(a) 只有無條件 PC-relative branch

無條件分支不需要暫存器讀取或 ALU 比較,只需計算分支目標位址。PC+4PC+4 與指令立即值的處理是平行進行的:

  • PC+4PC+4 路徑:100100 ps。
  • 立即值路徑:指令記憶體 200200 ps、Sign-Extend 1515 ps、Shift-left-2 1010 ps,共 225225 ps。

分支目標加法器要等兩路輸入都到達,因此等待 225225 ps,再經過加法器與 PCSrc Mux:

Ta=max⁡(100, 200+15+10)+100+10=335 psT_a=\max(100,\ 200+15+10)+100+10=335\text{ ps}

(b) 只有 conditional PC-relative branch

分支目標位址路徑仍為 335335 ps。條件判斷路徑則需先取得指令,再讀取暫存器;Read data 2 經過 ALUSrc Mux 後進入 ALU,最後由 PCSrc Mux 選擇下一個 PC:

T判斷=200+100+10+250+10=570 psT_{\text{判斷}}=200+100+10+250+10=570\text{ ps}

因此整體時脈週期取兩條路徑的較大值:

Tb=max⁡(335, 570)=570 psT_b=\max(335,\ 570)=570\text{ ps}

(c) Shift-left-2 何時位於關鍵路徑?

PC-relative branch 會使用 Shift-left-2 來計算分支目標位址。

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 4 題8 分

  1. (8%) Assume that we would like to expand the MIPS register file from 32 registers to 128 registers
    and expand the instruction set to contain four times as many instructions.
    (a) (4%) How would this affect the size of each of the bit fields in the R-type, and I-type,
    respectively, instructions?
    (b) (4%) How could each of the two proposed changes decrease the size of an MIPS assembly
    program? On the other hand, how could the proposed change increase the size of an MIPS
    assembly program?

登入後即可作答並保存紀錄。

這一題的完整詳解

(a) 位元欄位變化

  • R‑type

    • 原本 rs,rt,rdrs,rt,rd 為 55 位元(可編碼 25=322^5=32 個暫存器),擴增至 128128 個暫存器需 77 位元。
    • opcode 與 funct 仍屬指令集編碼,指令數量成 44 倍,需再加 22 位元 → opcodeopcode 從 66 位元變 88 位元(functfunct 亦可同樣擴展 22 位元),若只增 opcodeopcode 亦可滿足 4×4\times。
    • 其它欄位 (shamtshamt) 保持 55 位元。
  • I‑type

    • rs,rtrs,rt 同樣由 55 位元擴至 77 位元。
    • opcodeopcode 加 22 位元,從 66 位元變 88 位元。
    • 32 位元指令長度固定,故剩餘給 immediateimmediate 的位元數減少:
      immediate=32−opcode−rs−rt=32−8−7−7=10 位元\text{immediate}=32-\text{opcode}-rs-rt=32-8-7-7=10\ \text{位元}
      原先 1616 位元減少 66 位元。

(b) 程式大小的增減

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 5 題12 分

  1. (12%) Translate the following C code to MIPS assembly code. Please use a minimum number of
    instructions. Assume that the values of a, b, i and j are in registers s0,s0, s1, t0,andt0, and t1,
    respectively. Also, assume that register $s2 holds the base address of the array D.
    for(i=0; i<a; i++)
    for(j=0; j<b; j++)
    D[4*j] = i + j;

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考查三個重點:

  1. 巢狀迴圈的 MIPS 轉換

    • 外層迴圈控制變數為 ii。
    • 內層迴圈控制變數為 jj。
    • 每次外層 ii 增加前,必須將 jj 重新設為 00。
  2. 陣列位址計算

    若 D 為整數陣列,且每個元素佔 4 bytes,則:

    Address(D[k])=base(D)+4k\text{Address}(D[k])=\text{base}(D)+4k

    題目存取的是 D[4*j],因此:

Address(D[4j])=base(D)+4(4j)=base(D)+16j\text{Address}(D[4j])=\text{base}(D)+4(4j) =\text{base}(D)+16j

因此可將 jj 左移 4 位:

16j=j×24=j≪416j=j\times 2^4=j\ll 4

  1. 迴圈條件的實作

    C 語言條件為:

    i<a,j<bi<a,\qquad j<b

    MIPS 可使用 slt 判斷小於關係:

    slt $t2, $t0, $s0
    

    若 i<ai<a,則 $t2 = 1;否則 $t2 = 0。


解題方法

按照原始 C 程式的結構翻譯:

for (i = 0; i < a; i++) {
    for (j = 0; j < b; j++) {
        D[4*j] = i + j;
    }
}

暫存器配置如下:

C 變數MIPS 暫存器
aa$s0
bb$s1
ii$t0
jj$t1
D 的 base address$s2

另使用:

  • $t2:條件判斷結果或位移後的位址偏移量
  • $t3:要寫入陣列的值 i+ji+j
  • `
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 6 題4 分

  1. (4%) SISD, SIMD, MISD, and MIMD are one categorization of parallel hardware architectures
    proposed in the 1960s and still used today. What are SISD, SIMD, MISD, and MIMD? Please
    give a brief explanation and one example for each architecture.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考驗計算機系統架構中的平行硬體分類法——費林分類法(Flynn's Taxonomy)。1966 年由 Michael J. Flynn 提出,依據電腦運作時的**指令流(Instruction Stream)與資料流(Data Stream)**數量(單一 Single 或多重 Multiple),將所有計算機硬體架構劃分為四大類:

  1. SISD:Single Instruction Stream, Single Data Stream
  2. SIMD:Single Instruction Stream, Multiple Data Stream
  3. MISD:Multiple Instruction Stream, Single Data Stream
  4. MIMD:Multiple Instruction Stream, Multiple Data Stream

解題方法

本題為標準觀念簡答題(佔 4 分)。解題切入點需針對 SISD、SIMD、MISD、MIMD 四種架構分別說明:

  1. 全稱與核心定義:說明指令流與資料流的數量搭配關係。
  2. 運作特徵:說明控制單元(Control Unit)與算術邏輯單元(ALU)如何合作。
  3. 代表性實體範例:列舉一項業界或計算機結構中標準的硬體範例。

分類公式矩陣如下:

Flynn’s Taxonomy單一資料流 (Single Data)多重資料流 (Multiple Data)單一指令流 (Single Instruction)SISDSIMD多重指令流 (Multiple Instruction)MISDMIMD\begin{array}{|c|c|c|} \hline \text{Flynn's Taxonomy} & \text{單一資料流 (Single Data)} & \text{多重資料流 (Multiple Data)} \\ \hline \text{單一指令流 (Single Instruction)} & \text{SISD} & \text{SIMD} \\ \hline \text{多重指令流 (Multiple Instruction)} & \text{MISD} & \text{MIMD} \\ \hline \end{array}

架構詳細分析

1. SISD (Single Instruction Stream, Single Data Stream)

  • 定義與運作:單指令流單資料流。在同一個時脈週期內,處理器僅讀取單一指令流,並對單一資料流進行運算處理。此為最傳統的馮·紐曼(Von Neumann)架構,不具備資料級或任務級的平行硬體處理能力。
  • 代表範例:早期的單核心微處理器(例如 Intel 8086、Intel Pentium 早期的單核 CPU)。

2. SIMD (Single Instruction Stream, Multiple Data Stream)

  • 定義與運作:單指令流多資料流。在同一個時脈週期內,單一控制單元發射同一條指令給多個不同的處理單元(Processing Elements / ALUs),同時對多筆不同的資料執行相同的運算操作。具備極高的「資料級平行性(Data-Level Parallelism, DLP)」。
  • 代表範例:繪圖處理器(GPU)、向量處理器(Vector Processor),或 CPU 中的 SIMD 擴充指令集硬體(如 Intel AVX-512、ARM NEON)。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 7 題9 分

  1. [9%] Consider two different implementations, M1 and M2, of the same instruction set. There are
    three classes of instructions (A, B, and C) in the instruction set. M1 has a clock rate of 100MHz
    and M2 has a clock rate of 150MHz. The average number of cycles for each instruction class and
    their frequencies (for a typical program) are as the table below. (Note, the MIPS in these
    statements stand for Millions of Instruction Per Second)
    Instruction | Machine M1- | Machine M2- | Frequency
    class | Cycles/instruction class | Cycles/instruction class |
    A | 1 | 2 | 60%
    B | 3 | 3 | 30%
    C | 5 | 4 | 10%
    (a) [3%] What is the CPI for M1 and M2?
    (b) [3%] What is the MIPS rating for MIPSM1 and MIPSM2?
    (c) [3%] A favorite program runs in 10 seconds on machine M1. If we want to build a new
    machine M3, which will run this program in 6 seconds. But it require 1.2 times as many clock
    cycles as M1 for this program. What is the clock rate of M3?

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題為典型的效能評估(Performance Assessment)題目,重點考查計算機架構中**CPU 效能方程式(CPU Performance Equation)**及相關效能指標(CPI 與 MIPS)的定義與計算。

關鍵公式如下:

  1. 加權平均 CPI(Cycles Per Instruction):
    若指令集包含多種類型的指令,每種指令出現的頻率為 FiF_i,對應的時脈週期數為 CPIi\text{CPI}_i,則平均 CPI 為:
    CPI=∑i(CPIi×Fi)\text{CPI} = \sum_{i} (\text{CPI}_i \times F_i)
  2. MIPS(Millions of Instructions Per Second):
    衡量 CPU 每秒執行多少百萬條指令,計算公式為:
    MIPS=Clock RateCPI×106\text{MIPS} = \frac{\text{Clock Rate}}{\text{CPI} \times 10^6}
  3. CPU 執行時間(CPU Execution Time):
    程式在機器上的執行時間 TT 與總時脈週期數(Clock Cycles, NcyclesN_{\text{cycles}})及時脈頻率(Clock Rate, ff)關係為:
    T=Ncyclesf=I×CPIfT = \frac{N_{\text{cycles}}}{f} = \frac{I \times \text{CPI}}{f}
    其中 II 為指令總數(Instruction Count)。

解題方法

(a) 計算 M1 與 M2 的 CPI

根據表列之各類指令週期數與出現頻率 FA=0.6F_A = 0.6、FB=0.3F_B = 0.3、FC=0.1F_C = 0.1:

  • 機器 M1 的 CPI:
    CPIM1=(1×0.6)+(3×0.3)+(5×0.1)=0.6+0.9+0.5=2.0\text{CPI}_{\text{M1}} = (1 \times 0.6) + (3 \times 0.3) + (5 \times 0.1) = 0.6 + 0.9 + 0.5 = 2.0

  • 機器 M2 的 CPI:
    CPIM2=(2×0.6)+(3×0.3)+(4×0.1)=1.2+0.9+0.4=2.5\text{CPI}_{\text{M2}} = (2 \times 0.6) + (3 \times 0.3) + (4 \times 0.1) = 1.2 + 0.9 + 0.4 = 2.5


(b) 計算 M1 與 M2 的 MIPS 評等

已知時脈頻率 fM1=100 MHz=100×106 Hzf_{\text{M1}} = 100 \text{ MHz} = 100 \times 10^6 \text{ Hz},fM2=150 MHz=150×106 Hzf_{\text{M2}} = 150 \text{ MHz} = 150 \times 10^6 \text{ Hz}:

  • 機器 M1 的 MIPS:
    MIPSM1=100×1062.0×106=50\text{MIPS}_{\text{M1}} = \frac{100 \times 10^6}{2.0 \times 10^6} = 50

  • 機器 M2 的 MIPS:
    MIPSM2=150×1062.5×106=60\text{MIPS}_{\text{M2}} = \frac{150 \times 10^6}{2.5 \times 10^6} = 60


(c) 計算 M3 的時脈頻率(Clock Rate)

已知條件:

  • 在 M1 上的執行時間 TM1=10 秒T_{\text{M1}} = 10 \text{ 秒}。
  • 在 M3 上的目標執行時間 TM3=6 秒T_{\text{M3}} = 6 \text{ 秒}。
  • M3 執行此程式所需的總時脈週期數為 M1 的 1.21.2 倍,即 Ncycles, M3=1.2×Ncycles, M1N_{\text{cycles, M3}} = 1.2 \times N_{\text{cycles, M1}}。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 8 題13 分

  1. [13%]
    (a) [3%] Assume 185 and 169 are signed 8-bit decimal integers store in sign-magnitude format.
    Calculate 185+169. The result should be written in decimal.
    (b) [3%] Assume 185 and 169 are signed 8-bit decimal integers store in two's complement
    format. Calculate 185+169. The result should be written in decimal.
    (c) [3%] What decimal number does the bit pattern 0x0E000000 represent if it is a floating point
    number? Use the IEEE 754 standard.
    (d) [4%] Calculate the binary number (1.1100)*(-0.1101) step by step. You should use guard,
    round and sticky bit in rounding step. The result should store in IEEE 754 with 5 bits
    mantissa.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題涵蓋計算機組織與資料表示法(Data Representation)的四大核心主題:

  1. 符號大小表示法(Sign-Magnitude Representation):
    • 8 位元格式中,最高位元(MSB, Bit 7)為符號位元(0 代表正、1 代表負),其餘 7 位元(Bits 6~0)表示絕對值大小(Magnitude)。
    • 表示範圍為 [−127,+127][-127, +127]。
  2. 二補數表示法(Two's Complement Representation):
    • 8 位元格式中,MSB 權重為 −27=−128-2^7 = -128,其餘位元權重為正。
    • 正數轉負數(或負數轉真值)之公式為:取反+1\text{取反} + 1(Invert and add 1)。
    • 表示範圍為 [−128,+127][-128, +127]。若兩同號數相加得到異號數,即發生算術溢位(Arithmetic Overflow)。
  3. IEEE 754 單精確度浮點數標準(Single-Precision Floating-Point Standard):
    • 格式為 32 位元:1 位元符號(SS)、8 位元偏差指數(Biased Exponent, EE)、23 位元小數部分(Fraction/Mantissa, FF)。
    • 當 1≤E≤2541 \le E \le 254 時為常態化數(Normalized Number),真值為:
      (−1)S×(1.F)2×2E−127(-1)^S \times (1.F)_2 \times 2^{E - 127}
  4. 浮點數乘法與捨入機制(Floating-Point Multiplication and IEEE 754 Rounding):
    • 有效數相乘後進行正規化,並利用三位元輔助捨入判斷:
      • Guard bit (GG):Mantissa 規定長度後的第一個額外位元。
      • Round bit (RR):Guard bit 後的第二個額外位元。
      • Sticky bit (SS):Round bit 之後所有剩餘位元的邏輯或(Logical OR)。
    • 向最近偶數捨入(Round to Nearest, Ties to Even):當 G=1G=1 且 R=S=0R=S=0(剛好在正中間 Tie)時,若 Mantissa 最低有效位元(LSB)為 11(奇數)則需進位 +1+1 使其變為偶數 00;若 LSB 為 00(偶數)則直接捨去。

解題方法與推導

(a) 8-bit 符號大小表示法計算 185+169185 + 169

  1. 將十進制位元樣式轉為 8 位元二進制:

    • 18510=(10111001)2185_{10} = (10111001)_2
    • 16910=(10101001)2169_{10} = (10101001)_2
  2. 解讀符號大小表示法之真值:

    • 對於 18510=(10111001)2185_{10} = (10111001)_2:
      • 符號位元 Bit 7=1\text{Bit } 7 = 1(負數)
      • 大小數值 Bits 6~0=(0111001)2=32+16+8+1=5710\text{Bits } 6\text{~}0 = (0111001)_2 = 32 + 16 + 8 + 1 = 57_{10}
      • 故代表數值為 −57-57。
    • 對於 16910=(10101001)2169_{10} = (10101001)_2:
      • 符號位元 Bit 7=1\text{Bit } 7 = 1(負數)
      • 大小數值 Bits 6~0=(0101001)2=32+8+1=4110\text{Bits } 6\text{~}0 = (0101001)_2 = 32 + 8 + 1 = 41_{10}
      • 故代表數值為 −41-41。
  3. 計算相加結果:
    (−57)+(−41)=−98(-57) + (-41) = -98

    • 檢查:∣−98∣=9810=(1100010)2|-98| = 98_{10} = (1100010)_2(7 位元),未超出 8-bit Sign-Magnitude 範圍 [−127,+127][-127, +127]。
    • 最終十進制結果為 −98-98。

(b) 8-bit 二補數表示法計算 185+169185 + 169

  1. 解讀二補數之真值:

    • 對於 18510=(10111001)2185_{10} = (10111001)_2:
      • MSB 為 11(負數)。
      • 求真值:取反加一 ∼(10111001)2+1=(01000110)2+1=(01000111)2=7110\sim(10111001)_2 + 1 = (01000110)_2 + 1 = (01000111)_2 = 71_{10},故真值為 −71-71。
    • 對於 16910=(10101001)2169_{10} = (10101001)_2:
      • MSB 為 11(負數)。
      • 求真值:取反加一 ∼(10101001)2+1=(01010110)2+1=(01010111)2=8710\sim(10101001)_2 + 1 = (01010110)_2 + 1 = (01010111)_2 = 87_{10},故真值為 −87-87。
  2. 計算數學真值與溢位分析:

    • 數學相加真值為:
      (−71)+(−87)=−158(-71) + (-87) = -158
    • 由於 8-bit 二補數可表示範圍為 [−128,+127][-128, +127],−158<−128-158 < -128,產生算術溢位(Overflow)。
  3. 硬體暫存器運算結果:

    • 執行 8 位元二進制加法:

\begin{array}{r@{\quad}l}
10111001_2 & (-71) \
+; 10101001_2 & (-87) \
\hline
(1)01100010_2 &
\end{array}
$$

  • 捨棄第 9 位元進位後,暫存器保留值為 (01100010)2=+9810(01100010)_2 = +98_{10}。
  • 答題規範:完整寫出數學真值 −158-158(發生溢位),以及硬體 8-bit 二補數截斷值 +98+98。

(c) 浮點數位元樣式 0x0E000000 之十進制值

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 9 題16 分

  1. [16%] For a direct-mapped cache design with 32-bit address, the following bits of the address are
    used to access the cache:
    Address Field | Case I | Case II
    --------------|----------|---------
    Tag field | [31–10] | [31–12]
    Index field | [9–4] | [11–5]
    Offset field | [3–0] | [4–0]

(a) [3%] What is the block size (in words) of each case?
(b) [3%] For the total of two cases, how many entries does the cache have??
Starting from power on, the following byte-addressed cache references are recorded.
Address: 0, 4, 16, 132, 232, 160, 1024, 30, 140, 3100

(c) [3%] For Case I, how many blocks are replaced?
(d) [3%] For Case I, what is the hit ratio?
(e) [4%] For Case I as the final state of the cache, how many valid entries in this cache? Show
the index for each valid entry.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

直接對映快取(direct-mapped cache)將 32 位元位址分成:

Tag∣Index∣Offset\text{Tag} \mid \text{Index} \mid \text{Offset}

其中:

  • Offset 決定資料在一個 block 內的位元組位置。
  • Index 決定存取哪一個 cache entry。
  • Tag 用來判斷該 entry 中的 block 是否就是目前要求的 block。
  • 題目採 byte-addressed,且 11 word =4=4 bytes。

重要公式如下:

Block size=2Offset bits bytes\text{Block size}=2^{\text{Offset bits}}\text{ bytes} Cache entries=2Index bits\text{Cache entries}=2^{\text{Index bits}}

對 Case I 而言:

Block number=⌊Address16⌋\text{Block number}=\left\lfloor\frac{\text{Address}}{16}\right\rfloor Index=Block number mod 64\text{Index}=\text{Block number}\bmod 64

(a) 每個 case 的 block size

Case I

Offset field 為 bits [3–0][3\text{–}0],共有 44 bits,因此:

Block size=24=16 bytes\text{Block size}=2^4=16\text{ bytes}

換算成 word:

164=4 words\frac{16}{4}=4\text{ words}

Case II

Offset field 為 bits [4–0][4\text{–}0],共有 55 bits,因此:

Block size=25=32 bytes\text{Block size}=2^5=32\text{ bytes}

換算成 word:

324=8 words\frac{32}{4}=8\text{ words}

(b) Cache entries 數量

Case I

Index field 為 bits [9–4][9\text{–}4],共有 66 bits:

Entries=26=64\text{Entries}=2^6=64

Case II

Index field 為 bits [11–5][11\text{–}5],共有 77 bits:

Entries=27=128\text{Entries}=2^7=128

因此:

  • Case I:6464 entries
  • Case II:128128 entries
  • 若題意要求兩種設計數量相加,總數為:
64+128=192 entries64+128=192\text{ entries}

Case I 的位址分析

Case I 的欄位如下:

  • Tag:bits [31–10][31\text{–}10]
  • Index:bits [9–4][9\text{–}4]
  • Offset:bits [3–0][3\text{–}0]

因此每個 block 大小為 1616 bytes,每個 cache 有 6464 個 entries。

計算時使用:

Block number=⌊Address16⌋\text{Block number}=\left\lfloor\frac{\text{Address}}{16}\right\rfloor Index=Block number mod 64\text{Index}=\text{Block number}\bmod 64 Tag=⌊Block number64⌋\text{Tag}=\left\lfloor\frac{\text{Block number}}{64}\right\rfloor

位址 00、44、1616 等均以 byte address 解讀。

存取位址Block numberIndexTag結果說明
00000000Miss初始 cache 為空
44000000Hit與位址 00 位於同一 block
1616111100Miss存入 index 11
132132888800Miss存入 index 88
2322321414141400Miss存入 index 1414
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 10 題6 分

  1. [6%]
    (a) [3%] Assume the miss rate of an instruction cache is 2% and the miss rate of the data cache
    is 4%. If a processor has a CPI of 2 without any memory stalls and the miss penalty is 200
    cycles for all misses. Assume the frequency of all loads and stores is 36%. Determine how
    much faster a processor would run with a perfect cache that never missed.
    (b) [3%] If the processor has a base CPI of 1, and clock rate of 4 GHz. Assume the memory
    access time is 100 ns, including al the miss handling. Suppose the miss rate per instruction
    at the primary cache is 3%. Now we add a secondary data cache that has a 5 ns access time
    for either a hit or a miss, and is large enough to reduce the miss rate to main memory to
    0.5%. What is the total CPI of this two-level cache?

登入後即可作答並保存紀錄。

這一題的完整詳解

(a)
指令快取未命中額外週期:0.02×200=40.02 \times 200 = 4
資料快取未命中機率=0.36×0.04=0.01440.36 \times 0.04 = 0.0144,額外週期:0.0144×200=2.880.0144 \times 200 = 2.88

總 CPI

CPI實際=2+4+2.88=8.88\text{CPI}_{\text{實際}} = 2 + 4 + 2.88 = 8.88

完美快取無未命中,CPI = 基礎 22。
速度提升(Speedup)

Speedup=8.882=4.44\text{Speedup}= \frac{8.88}{2}=4.44

(b)

  • 時鐘週期 T=14GHz=0.25 nsT = \frac{1}{4\text{GHz}} = 0.25\text{ ns}
  • L2 (次級快取) 存取 5 ns → 5 ns/0.25 ns=205\text{ ns}/0.25\text{ ns}=20 cycles
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 11 題6 分

  1. [6%] Listed below are key page table parameters.
    Parameter | Value
    ---------------|-------
    Virtual address size | 42 bits
    Physical DRAM size | 8GiB
    Page size | 4 KiB
    PTE size | 4 bytes

(a) [3%] For a single-level page table, how much physical memory is needed for storing the
page table?
(b) [3%] In a memory hierarchy system, we can integrate virtual memory, TLB and cache. A
memory reference can encounter three different types of misses: a TLB miss, a page fault
and a cache miss. Considering all the combinations of these three events with one or more
occurring. Identify the number for the three events which is impossible.

登入後即可作答並保存紀錄。

這一題的完整詳解

(a) 單階頁表所需的實體記憶體大小

核心觀念
本題考查虛擬記憶體(Virtual Memory)中「單階頁表(Single-Level Page Table)」的大小計算。關鍵觀念與公式如下:

  1. 虛擬位址空間大小(Virtual Address Space Size):若虛擬位址位元數為 nn bits,則虛擬位址空間大小為 2n bytes2^n\text{ bytes}。
  2. 頁面大小(Page Size):設頁面大小為 P=2p bytesP = 2^p\text{ bytes},其中 pp bits 為頁內偏移量(Page Offset)。
  3. 頁表項數目(Number of Page Table Entries, PTEs):
    虛擬頁號位元數(VPN bits)=n−p\text{虛擬頁號位元數(VPN bits)} = n - p
    頁表項總數(Total PTEs)=2n−p=虛擬位址空間大小頁面大小\text{頁表項總數(Total PTEs)} = 2^{n - p} = \frac{\text{虛擬位址空間大小}}{\text{頁面大小}}
  4. 頁表總容量(Page Table Size):
    頁表容量=頁表項總數×單一頁表項大小(PTE Size)\text{頁表容量} = \text{頁表項總數} \times \text{單一頁表項大小(PTE Size)}

解題方法

  1. 提取已知條件:
    • 虛擬位址長度 n=42 bitsn = 42\text{ bits}。
    • 實體記憶體大小(Physical DRAM Size)=8 GiB= 8\text{ GiB}(註:單階頁表必須涵蓋整體虛擬位址空間,因此頁表大小僅取決於虛擬位址空間與頁面大小,實體 DRAM 大小在此題為干擾資訊)。
    • 頁面大小 P=4 KiB=4×210 bytes=212 bytesP = 4\text{ KiB} = 4 \times 2^{10}\text{ bytes} = 2^{12}\text{ bytes}。
    • 單一頁表項大小(PTE Size)=4 bytes= 4\text{ bytes}。
  2. 推導關鍵步驟:
    • 頁內偏移量位元數 p=log⁡2(4 KiB)=12 bitsp = \log_2(4\text{ KiB}) = 12\text{ bits}。
    • 虛擬頁號位元數(Virtual Page Number, VPN bits)=42−12=30 bits= 42 - 12 = 30\text{ bits}。
    • 單階頁表需為每個虛擬頁面建立一個頁表項,故頁表項總數為 2302^{30} 個。
    • 儲存該單階頁表所需的實體記憶體容量為:
      Page Table Size=230×4 bytes=4×230 bytes=4 GiB\text{Page Table Size} = 2^{30} \times 4\text{ bytes} = 4 \times 2^{30}\text{ bytes} = 4\text{ GiB}

(b) TLB Miss、Page Fault 與 Cache Miss 之組合可行性分析

核心觀念
本題考查記憶體階層(Memory Hierarchy)中 TLB、頁表/主記憶體(Virtual Memory / DRAM)與快取(Cache)三者間的協同運作機制與邏輯約束:

  1. TLB(Translation Lookaside Buffer):頁表的快取。TLB Hit 代表該頁面的轉譯位址已在 TLB 中,隱含該頁面必定已存在於實體主記憶體(DRAM)中。
  2. Page Fault(缺頁中斷):代表欲存取的頁面不在實體主記憶體(DRAM)中,必須從輔助記憶體(如磁碟)載入。
  3. Cache(快取記憶體):主記憶體資料的快取。若發生 Page Fault,代表該頁面資料根本不在 DRAM 中,因此快取中絕不可能存在該頁面的有效資料。

由上述運作機制可得出兩項關鍵邏輯約束:

  • 約束一:若發生 TLB Hit,則絕不可能發生 Page Fault(TLB Hit 代表頁面已在 DRAM 中)。
  • 約束二:若發生 Page Fault,則絕不可能發生 Cache Hit(頁面不在 DRAM 中,快取無法命中)。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

其他考古題