1. [20%] Consider a MIPS processor with an additional floating point unit. Assume functional unit delays in the processor are as follows: memory (2 ns), ALU and adders (2 ns), register file access (1 ns), FPU add (8 ns), FPU multiply (16 ns), and the remaining units (0 ns). Also assume instruction mix as follows: loads (31%), stores (21%), R-format instructions (27%), branches (5%), jumps (2%), FP adds and subtracts (7%), and FP multiplies and divides (7%).
(a) What is the delay in nanosecond to execute a load, store, R-format, branch, jump, FP add/subtract, and FP multiply/divide instruction in a single MIPS design?
(b) What is the averaged delay in nanosecond to execute a Load, store, R-format, branch, jump, FP add/subtract, and FP multiply/divide instruction in a multicycle MIPS design?
(a) 先算每一種指令自己的路徑延遲(只加有經過的元件):
| 指令 | 取指令 mem | reg 讀 | ALU | data mem | reg 寫 | FPU | 合計 (ns) |
|---|---|---|---|---|---|---|---|
| load | 2 | 1 | 2 | 2 | 1 | — | 8 |
| store | 2 | 1 | 2 | 2 | — | — | 7 |
| R-format | 2 | 1 | 2 | — | 1 | — | 6 |
| branch | 2 | 1 | 2 | — | — | — | 5 |
| jump | 2 | — | — | — | — | — | 2 |
| FP add/sub | 2 | 1 | — | — | 1 | 8 | 12 |
| FP mul/div | 2 | 1 | — | — | 1 | 16 | 20 |
single-cycle 的 clock 要容納最慢的指令(FP mul/div,20 ns),每條指令都占一個 cycle → 每一條指令都是 20 ns(load 8、store 7、R-format 6、branch 5、jump 2、FP add/sub 12 的路徑都會被拉長到 20)
(b) multicycle:每個 cycle 只做一件事(取指令、讀 reg、ALU 或 FPU、存取資料記憶體、寫 reg),clock 要容納最慢的單一步驟 = FPU multiply 的 16 ns
各指令用幾個 cycle(IF、ID、EX、MEM、WB;branch 在 EX 完成,jump 在第 3 cycle 完成,FP 指令沒有 MEM):
| 指令 | cycles | 比例 |
|---|---|---|
| load | 5 | 0.31 |
| store | 4 | 0.21 |
| R-format | 4 | 0.27 |
| branch | 3 | 0.05 |
| jump | 3 | 0.02 |
| FP add/sub | 4 | 0.07 |
| FP mul/div | 4 | 0.07 |
平均 CPI \(=0.31\times5+0.21\times4+0.27\times4+0.05\times3+0.02\times3+0.07\times4+0.07\times4=1.55+0.84+1.08+0.15+0.06+0.28+0.28=4.24\)
平均延遲 \(=4.24\times16=67.84\) ns
multicycle 的 67.84 ns 比 single-cycle 的 20 ns 還慢:16 ns 的 FPU 步驟把每一個 cycle 都拉長到 16 ns,其他步驟只要 1~2 ns。若把 FPU 做成多個 2 ns 的 cycle(clock 2 ns),則 FP add 4、FP mul 8 個 EX cycle,平均約 9.88 ns
(a) 單週期:每條都是 20 ns(各路徑 8、7、6、5、2、12、20) (b) 多週期:CPI 4.24 × 16 ns \(=67.84\) ns