7 void flush_cache( struct cache_t
* c
)
9 for (int k
=0; k
<c
->ways
; k
++)
10 memset((char*)c
->tags
[k
], 0, c
->ways
*sizeof(struct tag_t
));
11 memset((char*)c
->states
, 0, c
->rows
*sizeof(unsigned short));
14 void init_cache( struct cache_t
* c
, struct lru_fsm_t
* fsm
, int writeable
)
16 c
->fsm
= fsm
; /* note purposely point to [-1] */
17 c
->line
= 1 << c
->lg_line
;
18 c
->rows
= 1 << c
->lg_rows
;
20 c
->row_mask
= c
->rows
-1;
21 c
->tags
= (struct tag_t
**)malloc(c
->ways
*sizeof(struct tag_t
**));
22 for (int k
=0; k
<c
->ways
; k
++)
23 c
->tags
[k
] = (struct tag_t
*)malloc(c
->rows
*sizeof(struct tag_t
));
24 c
->states
= (unsigned short*)malloc(c
->rows
*sizeof(unsigned short));
27 c
->evicted
= writeable
? &place
: 0;
28 c
->refs
= c
->misses
= 0;
29 c
->updates
= c
->evictions
= 0;
33 void show_cache( struct cache_t
* c
)
35 fprintf(stderr
, "lg_line=%ld lg_rows=%ld line=%ld rows=%ld ways=%ld row_mask=0x%lx\n",
36 c
->lg_line
, c
->lg_rows
, c
->line
, c
->rows
, c
->ways
, c
->row_mask
);