113 年 國立中正大學電機工程學系碩士班晶片系統組《計算機組織》
第 1 題20 分
- (20%) Assume compiler A runs a program with a dynamic instruction count of and spends 1.1 s, and compiler B runs the same program with a dynamic instruction count of and computing time of 1.2 s.
(a). (10%) What is the average CPI for each compiler with a clock cycle time of 0.5 ns.
(b). (10%) A new compiler is that uses only instructions and has an average CPI of 1.2. What is the speedup of this new compiler comparing to compilers A and B?
登入後即可作答並保存紀錄。
核心觀念
本題考查 CPU 執行時間、動態指令數、平均 CPI 與時脈週期時間的關係:
因此:
加速比定義為:
時脈週期時間為:
解題方法
先利用已知的執行時間、動態指令數與時脈週期時間求出 A、B 的平均 CPI;再利用新編譯器的指令數與 CPI 求出新執行時間,最後分別與 A、B 的執行時間相比。
(a) 求各編譯器的平均 CPI
編譯器 A:
編譯器 B:
所以:
第 2 題30 分
- (30%) As in the table, an MIPS CPU is designed with instructions and latencies. Assume the multiplexors, control unit, PC accesses, and sign extension unit have no delay.
(a). (10%) What is the critical path if the CPU is working as a single-cycle processor? Why?
(b). (10%) What is the minimum clock speed of the single-cycle processor?
(c). (10%) What is the minimum clock speed if the CPU is working as a multi-cycle processor?
| Instructions | Instruction fetch | Register read | Control | Memory access | Register write | ALU |
|---|---|---|---|---|---|---|
| sub | 300ps | 100 ps | 200ps | 100 ps | 100ps | |
| sw | 300ps | 100 ps | 200ps | 300ps | 100ps | |
| add | 300ps | 100 ps | 200ps | 100 ps | 100ps | |
| beq | 300ps | 100 ps | 200ps | 250ps |
登入後即可作答並保存紀錄。
核心觀念
單週期處理器中,每一條指令都必須在同一個 clock cycle 內完成,因此:
多週期處理器會將指令拆成多個階段,每一個階段使用一個 clock cycle,因此:
時脈頻率與週期的關係為:
題目同時列出 Control = 200 ps,又明定 control unit 沒有延遲,兩者互相矛盾。本詳解依題幹的明文假設,將 control unit 的有效延遲視為 ,因此不將表格中的 加入路徑。
解題方法
在單週期處理器中,只需將同一條指令實際依序經過的元件延遲相加。平行執行的路徑不相加,而是取較慢者。
| 指令 | 實際資料路徑 | 總延遲 |
|---|---|---|
add | Instruction fetch → Register read → ALU → Register write | |
sub | Instruction fetch → Register read → ALU → Register write | |
sw | Instruction fetch → Register read → ALU → Memory access | |
beq | Instruction fetch → Register read → ALU(比較) |
(a)單週期處理器的 critical path
sw 指令的路徑為:
其延遲為:
比較所有指令:
因此,critical path 是 sw 指令的資料寫入路徑。原因是 sw 必須先讀取暫存器,再由 ALU 計算記憶體位址,最後完成資料記憶體存取;這條路徑比其他指令更長。
(b)單週期處理器的最低 clock speed
第 3 題20 分
- (20%) Consider a segment MIPS code as below.
(a). (10%) Find the hazards in the preceding code segment.
(b). (10%) Reorder the instructions to avoid any pipeline stalls.
lw $s1, 0($t0)
lw $s2, 4($t0)
add $a3, $s1, $s2
sw $a3, 12($t0)
lw $s5, 8($t0)
add $a5, $s1, $s5
sw $a5, 16($t0)
登入後即可作答並保存紀錄。
(a) 資料危險 (RAW)
- a3 : s1,…
產生,緊接的add s1,$s2` 需使用,形成 load‑use hazard。 - a3 : 同上,
lw $s2,…→add $a3,…產生 load‑use hazard。 - a5 :
lw $s1,…→add $a5,$s1,$s5形成 load‑use hazard(在add $a5前未插入其他指令)。 - a5 :
lw $s5,…→add $a5,…形成 load‑use hazard。
sw $a3,… 與 sw $a5,… 皆只讀取前一條 add 的結果,可用 forwarding 把 ALU 結果直接送至 MEM 階段,不需額外停頓。
(b) 重新排程避免停頓
第 4 題30 分
- (30%) Assume an adder-subtractor CPU circuit is composed of full-adder (FA) as in the figure. Please find the value for:
(a). (10%) Find value at for A-B = 0-0.
(b). (10%) Find value at for A-B = -1-(-2).
(c). (10%) Find value at for A-B = 0-2.
🖼️【此處有附圖,請對照原卷】
Figure: a 4-bit adder-subtractor built from four full adders (FA). Each passes through an XOR gate with the control line to give ; the FA of bit takes , and carry-in , and outputs and carry-out (). is also connected to ; the output is , and is the XOR of and .
登入後即可作答並保存紀錄。
核心觀念
此電路以控制訊號 選擇加法或減法:
- 時, 且 ,執行 。
- 時, 且 ,執行二補數減法:
每一位全加器的輸入為 ,輸出為 。有號溢位旗標為:
題目中的負數以 4 位元二補數表示:、。
解題方法
三小題都是減法,因此皆取 ,將 逐位反相,並令 。由最低位 起逐位計算進位與和位。
(a)
、,所以 ,且 。
逐位計算可得 ,因此 。所需值為:
因此 。
(b)
、,所以 ,且 。