Domanda

Ho un programma mio professore ha scritto che simula il modo in cui la memoria scrive alla cache L2. Ha un paio di posti dove dovrei per riempire il vuoto. La prima cosa che dovrei fare è cancellare il bit valido di ogni voce di cache. Egli ci ha dato il seguente:

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

Quindi, se ho capito bene, aprendo la bit valido significa solo impostandolo a zero. Il bit valido è il bit 31 di v_d_tag, quindi dovrei essere usando una maschera di bit - Voglio fare qualcosa sulla falsariga di "v_d_tag ??= v_d_tag ??& 0x80000000,", penso? Ma quello che non capisco è come posso passare il turno e farlo per ogni voce della cache. Vedo la serie di voci di cache (l2_cache), ma io non vedo come il v_d_tag ??è legata a quella.

Qualcuno può spiegare a me?

È stato utile?

Soluzione

typedef struct è ridondante in C ++, come lo sono il #define sto vedendo, potrebbero essere static int const.

Al fine di eliminarli tutti, si vorrebbe fare

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

Altri suggerimenti

Lo struct è definita in modo C, poiché in C è un linguaggio comune typedef struct dichiarare un modo che possa essere usato come un tipo senza dover struct L2_CACHE_ENTRY scrittura su ogni riferimento. Questo linguaggio non è più necessaria in C ++, dal momento che il tag struct funzionerà come un medesimo gruppo.

In breve, in C ++ è possibile trattare

typedef struct {

uint32_t v_d_tag;

uint32_t cache_line[WORDS_PER_CACHE_LINE];

} L2_CACHE_ENTRY;

esattamente come

struct L2_CACHE_ENTRY{

uint32_t v_d_tag;

uint32_t cache_line[WORDS_PER_CACHE_LINE];

};
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top