【发布时间】:2011-01-23 20:58:24
【问题描述】:
我的教授编写了一个程序来模拟内存写入 L2 缓存的方式。它有几个地方我应该填写空白。我应该做的第一件事是清除每个缓存条目的有效位。他给了我们以下内容:
//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 与它的关系。
谁能给我解释一下?
【问题讨论】:
-
你的问题和你的标题有什么关系?
-
好吧,我很确定我对代码的不理解与 typedef 设置有关,我不知道如何简洁地表达我的问题的细节以获得标题,所以我就去了。抱歉,如果我违反了礼仪,那不是我的本意——我只是不知道我在说什么。 ^^;