我有一個教授寫的程序模擬了內存寫入L2緩存的方式。它有幾個地方我應該填補空白。我應該做的第一件事是清除每個緩存條目的有效位。他給了我們以下幾點:對C++中typedef結構的混淆
//number of cache entries (2^11)
#define L2_NUM_CACHE_ENTRIES (1<<11)
/***************************************************
This struct defines the structure of a single cache
entry in the L2 cache. It has the following fields:
v_d_tag: 32-bit unsigned word containing the
valid (v) bit at bit 31 (leftmost bit),
the dirty bit (d) at bit 30, and the tag
in bits 0 through 15 (the 16 rightmost bits)
cache_line: an array of 8 words, constituting a single
cache line.
****************************************************/
Typedef struct {
uint32_t v_d_tag;
uint32_t cache_line[WORDS_PER_CACHE_LINE];
} L2_CACHE_ENTRY;
//The L2 is just an array cache entries
L2_CACHE_ENTRY l2_cache[L2_NUM_CACHE_ENTRIES];
所以,據我瞭解,清除有效位只是意味着將其設置爲零。有效位是v_d_tag的第31位,所以我應該使用位掩碼 - 我想按照「v_d_tag = v_d_tag & 0x80000000;」的方式做一些事情,我想?但我不明白的是,我如何通過併爲每個緩存條目執行此操作。我看到緩存條目數組(l2_cache),但我看不到v_d_tag與此有關。
有人可以解釋給我嗎?
什麼是你的問題與你的標題呢? – 2011-01-23 21:01:23
好吧,我相當肯定,我對代碼不瞭解的內容與typedef設置有關,我不確定如何簡潔地將我的問題的具體內容用於標題,因此我隨它一起去了。對不起,如果我違反了禮儀,這不是我的意圖 - 我只是不知道我在說什麼。 ^^; – amb691 2011-01-24 05:34:28