Question

J'ai un programme écrit mon professeur qui simule la façon dont la mémoire écrit dans le cache L2. Il a deux ou trois endroits où je suis censé remplir le vide. La première chose que je suis censé faire est clair que le bit valide de chaque entrée du cache. Il nous a donné ce qui suit:

//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];

Alors, si je comprends bien, effaçant le bit valide signifie simplement la mise à zéro. Le bit est valide bit 31 de v_d_tag, donc je devrais utiliser un masque de bits - Je veux faire quelque chose le long des lignes de « v_d_tag ??= v_d_tag ??& 0x80000000; », je pense? Mais ce que je ne comprends pas comment je peux passer et faire pour chaque entrée de cache. Je vois le tableau des entrées du cache (de l2_cache), mais je ne vois pas comment l'v_d_tag ??est liée à cela.

Quelqu'un peut-il me l'expliquer?

Était-ce utile?

La solution

typedef struct is redundant in C++, as are the #define I'm seeing, they could be static const int.

In order to clear them all, you would want to do

for(int i = 0; i < L2_NUM_CACHE_ENTRIES; i++)
    l2_cache[i].v_d_tag &= 0x80000000;

Autres conseils

The struct is defined in a C fashion, since in C it is a common idiom to typedef declare a struct so that it can be used as a type without having to write struct L2_CACHE_ENTRY on every reference. This idiom is no longer needed in C++, since the struct tag will work as an individual type.

In short, in C++ you can treat

typedef struct {

uint32_t v_d_tag;

uint32_t cache_line[WORDS_PER_CACHE_LINE];

} L2_CACHE_ENTRY;

exactly the same as

struct L2_CACHE_ENTRY{

uint32_t v_d_tag;

uint32_t cache_line[WORDS_PER_CACHE_LINE];

};
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top