2014-06-11 34 views
8

我在努力解決這個問題,我環顧四周,但所有類似的問題比我的更先進,利用日誌,這比我們在課堂上做得更先進。這裏的問題:設置關聯緩存:計算標記的大小?

Suppose you have a 4-way set associative cache which has in total 4096 bytes of cache memory and each cache line is 128 bytes. How many sets are there is this cache? If memory is byte addressable and addresses are 16 bits then how many bytes are used for the tag?

這是我到目前爲止有:

4096/128 = num lines

4096/128/4 = 8 = num sets (each set is 4 lines in 4-way set assoiative)

So, need 3 bits to choose set (2^3=8)

We have 16-3 = 13 bits left for the tag and word.

由於問題說內存是字節可尋址的,我認爲這意味着該字長爲8位(= 1字節),因此標記長度爲16-3-8 = 5位。

雖然我對此不太確定。有沒有人有解決這個問題?

謝謝。

回答

6

如果內存字節尋址

這種說法只是告訴我們,主存儲器是不論寬度的字節尋址即,架構,其中的數據可以在同一時間內訪問8位,數據和地址總線。

這不會影響標籤的位數。

解決方案:

4路組關聯

總高速緩衝存儲器= 4096字節

塊大小(高速緩存行)= 128字節

高速緩存行的數目= 4096/128 = 32行

高速緩存中的集數= 32/4 = 8集

╔════════════════════════════╗ 
║  16 bit address  ║ 
╠══════════╤════════╤════════╣ 
║ tag bit? │ 3 bits │ 7 bits ║ 
╚══════════╧════════╧════════╝ 

字偏移=登錄 8 = 3比特

集偏移=登錄 128 = 7比特

答案:

標籤位= 16 - (3 + 7)= 6位

╔══════════════════════════╗ 
║  16 bit address  ║ 
╠════════╤════════╤════════╣ 
║ 6 bits │ 3 bits │ 7 bits ║ 
╚════════╧════════╧════════╝