免費詳解 / 交大 / 硬體 / 102

102 交大資工所考古題解答|硬體逐題詳解

102 交大資工所硬體考古題的逐題詳解,共 25 題,免費公開。

逐題詳解

14 分

According to the following program with fork() system call, explain what the output will be at Line A. Suppose all fork() system calls succeed.

#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
    int value = 5;
    pid_t pid;
    pid = fork();
    value += 10;
    pid = fork();
    value += 10;
    if (pid == 0) {
        value += 15;
        return 0;
    } else if (pid > 0) {
        wait(NULL);
        printf("%d\n", value);   /* LINE A */
        return 0;
    }
}

(a) 5. (b) 15. (c) 25. (d) 40. (e) 45.

每個 process 各自有一份 value,fork 不共用

第一次 fork 後 \(+10\),第二次 fork 後再 \(+10\) → 走到 if 前每個 process 的 value 都是 \(5+10+10=25\)

\(\text{pid}==0\) 的 process(第二次 fork 的 child)才 \(+15\),直接 return,沒有印

LINE A 只有 \(\text{pid}\gt0\) 的 process 會執行(第二次 fork 的 parent),value 是 25

原 parent 與第一次 fork 的 child 各有一個 child,各自 wait 完印一次,共印兩行,內容都是 25

(c)

24 分

The following program uses the Pthreads API. What would be the output from the program at LINE C. Suppose the system program executes in a Linux system (kernel 3.2.0, x86_64) and with a very light load.

#include <pthread.h>
#include <stdio.h>
int value = 0;
void *runner(void *param);
int main(int argc, char *argv[])
{
    int pid;
    pthread_t tid, tid2;
    pthread_attr_t attr;
    pid = fork();
    value++;
    if (pid == 0) {
        pthread_attr_init(&attr);
        pthread_create(&tid, &attr, runner, NULL);
        pthread_create(&tid2, &attr, runner, NULL);
        pthread_join(tid, NULL);
        pthread_join(tid2, NULL);
        printf("%d", value);   /* LINE C */
    } else if (pid > 0) {
        wait(NULL);
        return (0);
    }
}
void *runner(void *param)
{
    int temp = value;
    temp += 5;
    sleep(2);
    value = temp;
    pthread_exit(0);
}

(a) 1. (b) 5. (c) 11. (d) 6. (e) 10.

fork 之後 parent 與 child 各有一份 value;child 的 value++ 之後是 1

child 建立的兩個 thread 與 child 共用同一份 value

兩個 thread 都先執行 temp = value 讀到 1,\(\text{temp}=1+5=6\),然後 sleep(2)(輕載下另一個 thread 一定在這 2 秒內啟動)

醒來後各自寫回 value = 6,不是累加(兩個寫入同值) → 印出 6

兩個 thread 沒有互斥,是 lost update;若依序執行才會是 11(選項 (c)),這裡 sleep 讓兩者交錯

(d)

34 分

Which of the following statements is incorrect?

(a) The Mac OS X kernel is based on the Mach microkernel.

(b) Windows XP's architecture is more monolithic than microkernel.

(c) Linux kernel is based on the microkernel approach.

(d) The guest OS must be modified to run on the paravirtualized hardware.

(e) If a guest OS can be booted from an image file in the host operating system, we can simply copy the image file to another location and boot another guest OS.

(a) XNU 的底層是 Mach → T(敘述正確)

(b) Windows XP 偏 monolithic(hybrid) → T

(c) Linux 是 monolithic kernel,用 loadable module 增加彈性,不是 microkernel → F(敘述錯誤)

(d) paravirtualization 的 guest OS 要改(呼叫 hypercall) → T

(e) 複製 image 檔就能再開一台 guest → T

(c)

44 分

Which of the following statements is incorrect regarding disks?

(a) Performing a logical formatting on a disk means that we create a file system on it.

(b) A soft error of disk means that some data bits in a sector have been corrupted but can be corrected.

(c) The operation system can treat each partition of a disk as though it were a separate disk.

(d) A network-attached storage is a private network connecting servers and storage units.

(e) Compared with SCAN scheduling algorithm, C-SCAN provides a more uniform wait time.

(a) logical formatting = 建 file system → T

(b) soft error 可由 ECC 修正 → T

(c) partition 在 OS 眼中就是獨立的 disk → T

(d) 「專用網路連 server 與儲存裝置」是 SAN;NAS 走一般 LAN(NFS/CIFS) → F(敘述錯誤)

(e) C-SCAN 只單向服務,各位置等待時間較平均 → T

(d)

54 分

Which of the following statements is correct regarding allocating space to files?

(a) Indexed allocation supports direct access but suffers from external fragmentation.

(b) Linked allocation allows the blocks of a file to be scattered anywhere on the disk and is very efficient in performing random access in a file.

(c) Contiguous allocation suffers from internal fragmentation but is very efficient in performing random access in a file.

(d) The file-allocation table (FAT) can result in a significant number of disk head seeks, unless the FAT is cached.

(e) Regarding pointer overhead, linked allocation suffers from wasted space more severely than indexed allocation.

(a) indexed 以 block 為單位配置,沒有 external fragmentation → F

(b) linked 只能循序走 pointer,random access 很慢 → F

(c) contiguous 的缺點是 external fragmentation → F

(d) FAT 沒 cache 時,追 chain 每一步都要回頭讀 FAT 區,head 來回 seek → T

(e) index block 的 pointer overhead 才是較嚴重的那個(小檔案也要一整個 index block) → F

(d)

64 分

The ideal one way hash function is collision free. Given \(y=h(x)\). Suppose \(x\) is of infinite length and \(y\) is of 8 bits. What is the probability that two different inputs, \(x\) and \(x'\), of the hash function collide?

(a) 0 (b) 1 (c) 1/8 (d) 1/128 (e) 1/256

\(y\) 有 8 bits → \(2^8=256\) 種輸出,理想 hash 的輸出均勻分布

\(x'\) 的 hash 值與 \(h(x)\) 相同的機率 \(=\dfrac{1}{256}\)

(e)

74 分

Consider the following program:

#include <stdio.h>
#define BUFFER_SIZE 256
int main(int argc, char *argv[])
{
    char buffer[BUFFER_SIZE];
    if (argc < 2)
        return -1;
    else {
        ____________; /*fill in the right instruction herein*/
        return 0;
    }
}

To avoid the security problem, what will be the best choice of instruction to fill in the empty slot in the program?

(a) strcopy(buffer, argv[1]); (b) strcopy(buffer, argv[2]); (c) strncpy(buffer, argv[1], sizeof(buffer)); (d) strncpy(buffer, argv[1], sizeof(buffer)-1); (e) strncpy(buffer, argv[1], sizeof(buffer)+1);

(a)(b) strcopy 不是標準函式;argv[2] 也不一定存在 → F

(c) 複製 256 bytes,argv[1] 長度 \(\ge256\) 時 strncpy 不補 '\0',buffer 沒有結尾 → F

(d) 最多複製 255 bytes,留一格給 '\0'(再 buffer[255]=0 即安全) → T

(e) 複製 257 bytes,overflow → F

(d)

84 分

Which one of the following statements is TRUE?

(a) From the point of view of a network service provider, latency is a suitable metric to measure the performance of the network service server.

(b) Mini-computer has disappeared from the computer market since main-frame computers have been well designed to have much more computing power than mini-computers.

(c) The CPU operating clock rate has not been continuously and significantly improved these years because Moor's law has been invalidate since several years ago.

(d) CPU and RF/analog designs are generally regarded as two main streams/representatives that can represent the semiconductor technology level of a nation.

(e) With the fixed number of defects per area, a small die-area IC design has better manufacture yield than the big die-area one.

(a) 服務提供者在意單位時間服務量,看 throughput → F

(b) mini-computer 是被更便宜的 PC/server 取代,不是被 mainframe → F

(c) clock rate 停滯是 power wall,不是 Moore's law 失效 → F

(d) 不是公認的說法 → F

(e) \(\text{Yield}=\left(1+\dfrac{\text{defects/area}\times\text{die area}}{2}\right)^{-2}\),die 越小良率越高 → T

(e)

94 分

Which one of the following statements is incorrect?

(a) With the same ISA and circuit design, the CPU with higher clock rate does not necessarily run through a program in shorter runtime than the CPU with lower clock rate.

(b) Million Instructions Per Second (MIPS) is not a unfair metric to compare the performances of two computers because MIPS metric only counts the number of executed instructions but does not consider the CPU idle time for stalling CPU requested by cache miss.

(c) Programming languages and compilers heavily influence the number of executed machine instructions per operation.

(d) Algorithms determine the number of executed operations.

(e) Computer A runs through program B with 50 seconds, where 20 and 30 seconds are for integer and floating computations respectively. Computer A is promoted by replacing a new CPU running faster by two times and three times in integer and floating point operations respectively. New computer A can run through program B faster than the old one by 2.5 times.

(a) clock 拉高後,記憶體延遲(ns)不變,每次 cache miss 的 cycle 數變多、CPI 上升,總時間不一定變短 → T(敘述正確)

(b) MIPS 只數指令數、不管每道指令做多少事,本來就是不公平的指標;敘述說「不是 unfair」 → F(敘述錯誤)

(c) 語言與 compiler 決定每個 operation 展開成幾道指令 → T

(d) 演算法決定要做幾個 operation → T

(e) 新時間 \(=\dfrac{20}{2}+\dfrac{30}{3}=20\) s,\(\text{speedup}=\dfrac{50}{20}=2.5\) → T

(b)

104 分

Given the values of registers $t0 and $t1 in the table below, which of following statements is correct.

$t0 = 0xAAAAAAAA, $t1 = 0x22222222

(a) … the value of $t2 will become 0x55555552 after the execution of code sequence below. sll $t2, $t0, 3;or $t2, $t2, $t1

(b) … the value of $t2 will become 0x37777777 after the execution of code sequence below. srl $t2, $t0, 3;or $t2, $t2, $t1

(c) … the value of $t2 will become 0xF7777777 after the execution of code sequence below. srl $t2, $t0, 3;or $t2, $t2, $t1

(d) … the value of $t2 will become 0 after the execution of instruction below. slt $t2, $t0, $t1

(e) … the value of $t2 will become 1 after the execution of instruction below. sltu $t2, $t0, $t1

\(\text{0xAAAAAAAA}=1010\,1010\ldots1010_2\)

(a) sll 3:\(\text{0x55555550}\),or \(\text{0x22222222}\) 得 \(\text{0x77777772}\ne\text{0x55555552}\) → F

(b) srl 3(左補 0):\(\text{0x15555555}\),or \(\text{0x22222222}\) 得 \(\text{0x37777777}\) → T

(c) 同 (b) 的結果是 0x37777777,高位補 0 不會出現 F → F

(d) slt 是 signed:0xAAAAAAAA 為負 \(\lt\) 0x22222222,\(\$t2=1\) → F

(e) sltu 是 unsigned:0xAAAAAAAA \(\gt\) 0x22222222,\(\$t2=0\) → F

(b)

114 分

Suppose the program counter (PC) is at address 0x80000000, which of following statements is incorrect.

(a) it is possible to use one branch instruction to get to address 0x7fffff00

(b) it is possible to use one jump instruction to get to address 0x7fffff00

(c) it is possible to use one branch instruction to get to address 0x80000040

(d) it is possible to use one branch instruction to get to address 0x80010000

(e) it is possible to use one jump instruction to get to address 0x8fff0000

branch:16-bit 有號 offset(字數)加在 PC+4 上,範圍約 \(\pm2^{15}\) words \(=\pm128\text{ KB}\)

jump:26-bit 欄位左移 2 位,上接 \((\text{PC}+4)\) 的高 4 bits,只能在同一個 256 MB 區段內

(a) 0x7fffff00 與 PC 差 0x100 → T

(b) 0x7fffff00 高 4 bits = 0x7,PC+4 的高 4 bits = 0x8,不同區段 → F(敘述錯誤)

(c) 差 0x40 → T

(d) 差 0x10000 \(=64\) KB \(\lt128\) KB → T

(e) 高 4 bits = 0x8,同區段 → T

(b)

124 分

Consider the following sequence of actual outcomes for a branch, where T means the branch is taken, N means not taken, which of following statements is incorrect?

T-T-N-T-N-N-N-T-N

(a) It will be mispredicted five times if we always predict the branch outcomes as taken.

(b) It will be mispredicted four times if we always predict the branch outcomes as NOT taken.

(c) It will be mispredicted four times if a 1-bit predictor is used and this predictor is initialized as taken.

(d) It will be mispredicted five times if 1-bit predictor is used and this predictor is initialized as taken.

(e) It will be mispredicted four times if a 2-bit predictor is used and this predictor is initialized as taken.

序列中 N 有 5 個、T 有 4 個

(a) 全預測 T,錯在 5 個 N → T

(b) 全預測 N,錯在 4 個 T → T

1-bit(起始 T,預測=上一次的實際結果):

次序123456789
預測TTTNTNNNT
實際TTNTNNNTN
對錯○○×××○○××

共錯 5 次 → (c) 說 4 次 → F(敘述錯誤);(d) → T

(e) 2-bit(起始 strongly taken):計數 3,3,3→2,→3,→2,→1,→0 … 預測錯在第 3、5、6、8 次共 4 次 → T

2-bit 狀態:第 3 次 N:3→2(錯);第 4 次 T:預測 T 對,2→3;第 5 次 N:預測 T 錯,3→2;第 6 次 N:預測 T 錯,2→1;第 7 次 N:預測 N 對,1→0;第 8 次 T:預測 N 錯,0→1;第 9 次 N:預測 N 對

(c)

134 分

Which of the following statements are correct?

(a) Java interpreter interprets the java bytecode operations one at a time.

(b) The CLR is the implementation of the .NET virtual machine. It interprets the Microsoft intermediate language instructions one at a time.

(c) You can use printf() function in the Linux system call implementation.

(d) Normal instructions for the virtual machine can execute directly on the hardware and only the privileged instructions must be simulated.

(e) Named pipes are referred to as FIFOs in UNIX systems. Once created, they appear as typical files in the file system.

(a) interpreter 一次解釋一個 bytecode → T

(b) CLR 把 MSIL 用 JIT 編成 native code 再執行,不是逐道解釋 → F

(c) system call 在 kernel 內,用不了 user space 的 C library printf(kernel 用 printk) → F

(d) trap-and-emulate:一般指令直接跑,privileged 指令 trap 後由 VMM 模擬 → T

(e) named pipe = FIFO,在 file system 中是一個特殊檔案 → T

(a), (d), (e)

144 分

When implementing the monitor with the signal and wait execution method, which of the following statements are correct? Assume for each monitor, a semaphore mutex (initialized to 1) is provided. Two semaphore variables next and x_sem are initialized to 0 and two integers next_count and x_count are initialized to 0.

Each external procedure F is replaced by:
    wait(mutex);
    ...
    body of F
    ...
    if (next_count > 0)
        signal(next);
    else
        signal(mutex);

x.wait() is implemented as:          x.signal() is implemented as:
    x_count++;                           if (x_count > 0) {
    if (next_count > 0)                      next_count++;
        /* Line A */                         /* Line C */
    else                                     wait(next);
        /* Line B */                         next_count--;
    wait(x_sem);                         }
    x_count--;

(a) The statement of Line A is signal(mutex); (b) The statement of Line B is signal(next); (c) The statement of Line B is signal(mutex); (d) The statement of Line C is signal(x_sem); (e) The statement of Line A is wait(mutex);

x.wait():先把 monitor 讓出去,再睡在 x_sem 上

有人卡在 next(\(\text{next\_count}\gt0\),是剛 signal 完在等的 process) → Line A = signal(next)

沒有 → Line B = signal(mutex)

x.signal():叫醒睡在 x 上的 process,自己去等 next → Line C = signal(x_sem),接著 wait(next)

(a) F (b) F (c) T (d) T (e) F

(c), (d)

154 分

Which of the following statements are correct?

(a) Absolute code can be generated if we know where the process will reside in memory at compile time.

(b) A logical address is generated by CPU while a physical address is an address seen by the memory unit.

(c) Inverted page table is very efficient in searching for a match but inefficient in space used for storing page tables.

(d) Paging may suffer from external fragmentation while segmentation may suffer from internal fragmentation.

(e) Paging is a memory-management scheme that allows the physical address space of a process to be noncontiguous.

(a) compile time 就知道位置才產得出 absolute code → T

(b) logical address 由 CPU 產生,physical address 是 memory unit 看到的 → T

(c) inverted page table 省空間,代價是查表要搜尋(雜湊);敘述剛好反過來 → F

(d) paging 有 internal fragmentation、segmentation 有 external;敘述反了 → F

(e) paging 讓 process 的 physical memory 不必連續 → T

(a), (b), (e)

164 分

Which of the following statements are incorrect?

(a) CPU utilization is low when thrashing happens. Therefore, when thrashing happens, we should increase the degree of multiprogramming.

(b) The Optimal page-replacement algorithm results in the lowest page-fault rate of all algorithms but is difficult to implement because it requires future knowledge.

(c) The copy-on-Write mechanism decreases the used physical memory shared between two processes, of which one is parent and the other is child.

(d) For a memory-mapped file, we can use the memory read/write instructions to access its content.

(e) The page fault rate of a running process has nothing to do with the program structure of the running process.

(a) thrashing 時要降低 degree of multiprogramming,增加只會更糟 → F(敘述錯誤)

(b) OPT fault 最少,需知道未來 → T

(c) COW 讓 parent/child 共用 page,真的寫才複製,減少用掉的實體記憶體 → T

(d) memory-mapped file 用 load/store 存取 → T

(e) 程式結構(如陣列走訪順序)直接影響 locality 與 fault rate;敘述錯誤 → F

(a), (e)

174 分

Consider a group of \(n\) users and each user shares a secret key with every other user using a symmetric cryptosystem. In other words, each pair of users will share a unique key. Choose the correct ones in the following statements:

(a) Each user need to keep \(n-1\) keys. (b) Each user need to keep \(n\) keys. (c) The total number of different keys kept in the group is \(n(n-1)/2\). (d) The total number of different keys kept in the group is \(n(n-1)\). (e) The total number of keys kept in the group is \(n(n-1)\).

每人與其他 \(n-1\) 人各一把 → (a) T,(b) F

不同的金鑰:每一對一把 \(\binom n2=\dfrac{n(n-1)}{2}\) → (c) T,(d) F

全體保管的份數:\(n(n-1)\)(每把被兩個人各存一份) → (e) T

(a), (c), (e)

184 分

In the RSA asymmetric cryptosystem, \(n=p\cdot q\); \(ed \bmod (p-1)(q-1)=1\), where \(e\) is the public key, and \(d\) is the private key. Encrypting plaintext: \(C=M^e \bmod n\); Decrypting ciphertext: \(M=C^d \bmod n\). Choose the correct statements:

(a) \(n\) is public information (b) \(p\) is public information (c) \(q\) must be a prime number (d) \(M\) must be relatively prime to \(n\) (e) \((p-1)(q-1)\) is public information

(a) 公鑰是 \((e,n)\) → T

(b) \(p\) 洩漏就能分解 \(n\) 得 \(q\),再算出 \(d\) → F

(c) \(p,q\) 都要是質數 → T

(d) 只要 \(M\lt n\);\(M\) 與 \(n\) 不互質時 RSA 仍成立(CRT) → F

(e) \((p-1)(q-1)\) 公開等於送出 \(d=e^{-1}\bmod(p-1)(q-1)\) → F

(a), (c)

194 分

Each bit's carry out of a carry lookahead adder (CLA) is a function of each bit's generate, propagate, and carry in signals. Consider a two-level 9-bit CLA that is composed of several 3-bit CLA units with \(c_0\) as the carry in and \(c_1\) to \(c_9\) as the carry outs. Each CLA unit realizes 3-bit group generate and group propagate functions based on 3-bit inputs. A signal is regarded valid if its value is correct; or, it is regarded as invalid. Signals \(g_i\) and \(p_i\) are the generate and propagate signals at bit \(i\) while \(G_{i\text{-}j}\) and \(P_{i\text{-}j}\) are the group generate and group propagate signals associated with bits \(i\) to \(j\). Assume all input signals have been available, which ones of the following statements are correct?

(a) A number of 4 CLA units in total are required to assemble the two-level 9-bit CLA.

(b) Carry outs \(c_1\), \(c_2\) and \(c_3\) become valid earlier than other carry out signals.

(c) \(G_{0\text{-}2}=g_2+p_2g_1+p_2p_1g_0\) and \(P_{0\text{-}2}=p_2p_1p_0\).

(d) Carry outs \(c_4\) and \(c_5\) become valid earlier than \(c_6\).

(e) Assume the delays of each NOT, isolated AND, XOR, AND-OR structure gates are 1, 2, 2, and 3 time units respectively, and the sum is realized by 2 XOR gates while the propagate is realized by a XOR gate. Then the longest delay of the 2-level 9-bit CLA is the 12 time units.

(a) bits 0–2、3–5、6–8 各一顆 3-bit unit,再加第二層一顆 lookahead unit → 共 4 顆 → T

(b) \(c_1,c_2,c_3\) 由第一顆 unit 直接從 \(c_0\) 算出,不必等第二層 → T

(c) \(G_{0\text{-}2}=g_2+p_2g_1+p_2p_1g_0\);整組要傳遞須三位都 propagate,\(P_{0\text{-}2}=p_2p_1p_0\) → T

(d) \(c_4,c_5\) 要等第二層送出 \(c_3\) 之後在第二顆 unit 內才算出,晚於第二層直接產生的 \(c_6\) → F

(e) 臨界路徑:\(g_i,p_i\)(AND、XOR,2)→ 各組 \(G\)(AND-OR,3)→ 第二層產生 \(c_6\)(AND-OR,3)→ 最後一顆 unit 內部的 \(c_8\)(AND-OR,3)→ \(s_8=p_8\oplus c_8\)(XOR,2)

\(2+3+3+3+2=13\) time units → 照這個接法是 13,不是 12;官方答案把 (e) 算對(T)

(e) 題目只給了閘的延遲,沒說各層怎麼接。照最直接的接法(\(g,p\) 一層、group \(G\) 一層、第二層 lookahead 一層、組內 carry 一層、sum 的第二個 XOR 一層)得 13;把 \(g_i,p_i\) 當成已備妥的輸入則是 11,兩種都不是 12。官方答案認列 (e),本答案照官方,自己算的結果寫在這裡供參考

(a), (b), (c), (e)

204 分

Which ones of the following statements are correct?

(a) The biased exponents in IEEE standard 754 demand signed number exponent comparison.

(b) The number with all bits in exponent and fraction fields being 1 is referred to as infinity in IEEE standard 754.

(c) The fraction and exponent parts of the smallest positive single precision denormalized number in IEEE standard 754 are both 0.

(d) The right figure shows partial design for the first three steps of a floating-point adder. Assume \(N1=3.63\times10^{10}\) and \(N2=2.28\times10^{7}\). \((m1,m2,m3,m4)=(0,1,0,3)\). (圖:Small ALU 比較兩個 exponent → Exponent difference → control 送出 m1、m2、m3、m4;m1 選 exponent,m2 選要右移的 fraction,m3 選另一個 fraction,m4 是右移位數)

(e) Floating-point unit (FPU) was called co-processor before because CPU and FPU were manufactured into two independently chips. Currently modern CPU and FPU have been designed and integrated together in a single chip.

(a) 加 bias 後 exponent 當 unsigned 就能比大小,這正是 bias 的目的 → F

(b) exponent 全 1、fraction 全 1 是 NaN;infinity 的 fraction 全 0 → F

(c) 最小正 denormalized:exponent 全 0、fraction = 0…01 → F

(d) \(N1\) 的 exponent 10 較大,\(N2\) 的 exponent 7 較小:

m1 = 0(取大的 exponent,即 N1 的)、m2 = 1(要右移的是較小數 N2 的 fraction)、m3 = 0(N1 的 fraction 不動)、m4 = \(10-7=3\) → T

(e) FPU 早期是獨立的 co-processor 晶片,現在整合進 CPU → T

(d), (e)

214 分

Which ones of the following statements are correct?

(a) Consider the code sequence {\(k=10\); while (\(k\ge1\)) {\(Dat[k]=Dat[k]+2\); \(k\text{--}\);}}; spatial locality occurs on accessing variable \(k\).

(b) Consider the above code sequence; spatial locality occurs on accessing array \(Dat\).

(c) Assume a compiler does not have any optimization technique; Consider two sequential code sequences: Code 1: for (i=0; i<maxX; i++) for (j=0; j<maxY; j++) Dat[i][j]++; Code 2: for (j=0; j<maxY; j++) for (i=0; i<maxX; i++) Dat[i][j]++; The performances of two sequential codes are the same since modern cache design has very high cache hit rate (almost near 100%) and thus memory access time can be reduced significantly.

(d) Consider 32-bit word-addressing and a 32-word (only data) direct-mapped cache with 4-word blocks. The address sequence for data accessing is (0, 40, 80, 340, 56, 68, 172, 348, 48, 80). A conflict miss occurs for the last access (address 80).

(e) Continue statement (d). If the cache size is increased by 4 words (36 words in total), a cache hit occurs for the last access (address 80). As compared to the accessing result of 36-word cache, the miss for the last access to the 32-word cache (in statement (d)) can be regarded as a capacity miss.

(a) \(k\) 每圈都重複存取同一個變數 → temporal locality,不是 spatial → F

(b) \(Dat[k]\) 依序存取相鄰元素 → spatial locality → T

(c) Code 2 沿 column 走 row-major 陣列,每次跨一整列,miss 多很多,效能不同 → F

(d) 32 words ÷ 4 = 8 blocks,\(\text{index}=(\text{addr}/4)\bmod 8\)

位址0408034056681723484880
block0102085141743871220
index0245613744

48(block 12)與 80(block 20)都對應到 index 4,80 被 48 擠掉後再存取 80 → miss,且同樣大小的 fully associative 不會 miss → conflict miss → T

(e) 36 words = 9 blocks,\(\text{index}=\text{block}\bmod 9\):block 20→2、12→3,不再互擠,最後一次 80 hit

多 4 words 的容量就消除了這次 miss,從「容量不夠」的角度看,原 32-word 的 miss 可視為 capacity miss → T

(b), (d), (e)

224 分

A system has a 16-bit virtual address size with 256B pages and a 16-bit byte addressing physical memory with physically indexed 2-way set associative data cache (LRU replacement policy) of 512B cache size and 16B blocks. The first six accesses to the page table are: 0x1332, 0xad58, 0x0162, 0x2ea9, 0x813d, 0x9f5a. The system uses a single level page table. Assume the TLB and data cache are initially empty and their contents have been updated accordingly by the first six accesses (page table is shown below; VPN: virtual page number, PPN: physical page number). The CPU includes a fully associative TLB with 2 entries and an LRU replacement policy. Data reads from the following virtual addresses are performed (in the order listed): 0x813f, 0x136f, 0x2e5f, 0x9f50, 0x1370. Which ones of following statements are correct?

VPNPPNVPNPPN
0x010x270x810x8a
0x130x450x9f0xcd
0x2e0xe80xad0x7e

(a) The required numbers of bits for virtual page number and page offset in virtual address are all 8 bits.

(b) The required number of bits for index and tag in physical address are 4 and 8 bits respectively.

(c) Data access to 0x813f has access hit in TLB and cache.

(d) Data access to 0x9f50 has access miss in TLB and access hit in cache.

(e) Data access to 0x1370 has access miss in TLB and cache.

(a) 256B page → offset 8 bits;\(16-8=8\) bits VPN → T

(b) cache:\(512/16=32\) blocks,2-way → 16 sets;block offset 4、index 4、tag \(16-4-4=8\) bits → T

先走完前六次存取:TLB 只有 2 個 entry(LRU),留下最後兩次的 VPN 0x81、0x9f;cache 已有各自的 block

PA = PPN‖offset;\(\text{set}=\text{PA}[7:4]\),tag = PA[15:8]=PPN

存取VPNTLBPAsetcacheTLB 內容(LRU→MRU)
0x813f0x81hit0x8a3f3hit0x9f, 0x81
0x136f0x13miss0x456f6miss0x81, 0x13(擠掉 0x9f)
0x2e5f0x2emiss0xe85f5miss0x13, 0x2e(擠掉 0x81)
0x9f500x9fmiss0xcd505hit0x2e, 0x9f(擠掉 0x13)
0x13700x13miss0x45707miss0x9f, 0x13

(c) 0x813f:TLB hit,set 3 內有 0x8a3d 同一 block(0x813d→PA 0x8a3d,block 0x8a3) → cache hit → T

(d) 0x9f50:TLB miss(0x9f 在 0x136f 進來時被擠掉);set 5 原有 0x7e、0xcd 兩個 tag(0xad58、0x9f5a 載入),0x2e5f 進來時擠掉 LRU 的 0x7e,剩 0xcd、0xe8;0x9f50 的 tag 是 0xcd → cache hit → T

(e) 0x1370:0x13 在 0x9f50 進來時被擠掉 → TLB miss;PA 0x4570 在 set 7,set 7 還是空的 → cache miss → T

(a), (b), (c), (d), (e)

234 分

For the Single-Cycle MIPS CPU shown below, which of following statements are correct?

(圖:標準 single-cycle datapath;線 A 是 register file 的 Read data 2 接到 data memory 的 Write data 的那條線,線 B 是 Sign-extend 輸出 32 bits 接到 ALUSrc mux 與 Shift left 2 的那條線)

(a) If the path labeled A has been cut, the instructions add, slt, and sw still can run correctly.

(b) If the path labeled B has been cut, the instructions lw, sw and beq may fail.

(c) If the control signal ALUSrc is stuck on 0, the instructions lw, sw, and beq may fail to run correctly.

(d) If the control signal RegDst is stuck on 0, the instructions lw and sw still can run correctly.

(e) If the control signal MemToReg is stuck on 1, the instructions add, sub, lw, and slt may fail to run correctly.

(a) A 斷掉:sw 要寫進 memory 的 rt 內容送不過去 → sw 失敗 → F

(b) B 斷掉:lw、sw 的 offset 進不了 ALU,beq 的 branch 位移也到不了 Shift left 2 → T

(c) ALUSrc 固定 0 = 永遠選 register;lw、sw 要選 immediate 會錯,beq 本來就選 register → \(\text{lw, sw}\) 會失敗但 beq 不會,敘述把 beq 也算進去 → F

(d) RegDst 固定 0:寫入 rt;lw 的目的暫存器正是 rt,sw 不寫 register → lw、sw 都正常 → T

(e) MemToReg 固定 1:寫回的是 memory 讀出的資料,add、sub、slt 會錯,lw 本來就是 1,不會錯 → F

(b), (d)

244 分

Given the pipelined MIPS CPU below where assume both forwarding and stall mechanisms have been designed, which of following statements are correct?

(圖:標準 forwarding+hazard detection 的 pipeline;A 是 MEM/WB 回到 EX 的 forwarding 路徑,B 是 EX/MEM 回到 EX 的 forwarding 路徑)

(a) Assume the path labeled A has been cut, the following code snippet will fail. add $s2,$s0,$s1;add $s3,$s0,$s2

(b) Assume the path labeled A has been cut, the following code snippet will fail. add $t1,$t1,$s2;add $t1,$t0,$t2;add $s2,$s1,$t1

(c) Assume the path labeled B has been cut, the following code snippet will fail. add $t1,$t1,$s2;add $t1,$t0,$t2;add $s2,$s1,$t1

(d) Assume the path labeled A has been cut, the following code snippet will fail. lw $s0,4($t1);add $s2,$s0,$s1

(e) Assume the path labeled B has been cut, the following code snippet will fail. lw $s0,4($t1);add $s2,$s0,$s1

A:MEM/WB → EX(距離 2 的相依);B:EX/MEM → EX(距離 1 的相依)

(a) \(\$s2\) 由第 1 道產生、第 2 道馬上用,距離 1,走 B;A 斷了沒影響 → F

(b) 第 3 道的 \(\$t1\) 取最近的寫入者(第 2 道,距離 1)走 B;第 1 道(距離 2)的值已被蓋掉,A 用不到 → F

(c) B 斷了,第 3 道拿不到第 2 道的 \(\$t1\) → T

(d) lw → add 的 load-use hazard:stall 一個 cycle,之後 add 在 EX 時 lw 在 WB,資料從 MEM/WB 轉出,要走 A,A 斷了就錯 → T

(e) 同一段程式用的是 A,B 斷了不影響 → F

(c), (d)

254 分

Consider the code sequence below, where we predict beq as taken, but actually it is NOT taken, which of following statements are correct?

lw  $s0, 0($t0)
lw  $s1, 0($t0)
beq $s0, $s1, L1
add $s2, $s0, $s1

(a) For the pipelined MIPS CPU which has data forwarding mechanism and the branch outcome is determined in MEM stage, it takes 8 cycles to complete the execution of the above code sequence.

(b) … determined in MEM stage, it takes 12 cycles …

(c) … determined in ID stage, it takes 7 cycles …

(d) … determined in ID stage, it takes 11 cycles …

(e) … determined in ID stage, it takes 10 cycles …

四道指令、不 stall 也不 flush:\((5-1)+4=8\) cycles

beq 的 \(\$s1\) 是前一道 lw 剛讀的 → load-use,beq 要多等 1 cycle

MEM 決定 branch:beq 在 cycle 3 IF,stall 後 EX 在 cycle 6、MEM 在 cycle 7 才知道猜錯

猜錯時跟在 beq 後面抓進來的 3 道錯誤指令清掉,cycle 8 重新 fetch add

cycle     1  2  3  4  5  6  7  8  9  10 11 12
lw s0     IF ID EX ME WB
lw s1        IF ID EX ME WB
beq             IF ID ID EX ME
(錯誤路徑)         IF IF -- -- --   ← 7 結束時清掉
add                             IF ID EX ME WB

add 在 cycle 8–12 完成 → 12 cycles → (b) T,(a) F

ID 決定 branch:比較在 ID 做,\(\$s1\) 要等 lw 的 MEM 結束才能轉進 ID,beq 在 ID 停 2 cycle(cycle 4、5),cycle 6 比較

猜錯時只清掉 1 道錯誤指令,cycle 7 重新 fetch add → add 在 cycle 7–11 完成 → 11 cycles → (d) T,(c)(e) F

(b), (d)

109–115 的詳解也是這樣寫的。

國立陽明交通大學 109–115 的詳解收錄在付費版;106–115 全年度完整詳解共 579 頁,逐題推導。

購買 · NT$ 850 看交大其他免費詳解

其他年度與考科

同一年的其他科

同一科的其他年度

聯絡我們

題目有錯、詳解看不懂,都歡迎來信

想許願補哪一份、對購買有疑問也可以,收到後會盡快回覆。

william.chou.123123@gmail.com