include: deprecate syscalls leftovers
[cavatools.git] / pipesim / cache.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4
5 #include "cache.h"
6
7 void flush_cache( struct cache_t* c )
8 {
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));
12 }
13
14 void init_cache( struct cache_t* c, struct lru_fsm_t* fsm, int writeable )
15 {
16 c->fsm = fsm; /* note purposely point to [-1] */
17 c->line = 1 << c->lg_line;
18 c->rows = 1 << c->lg_rows;
19 c->ways = fsm->way;
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));
25 flush_cache(c);
26 static long place =0;
27 c->evicted = writeable ? &place : 0;
28 c->refs = c->misses = 0;
29 c->updates = c->evictions = 0;
30 }
31
32
33 void show_cache( struct cache_t* c )
34 {
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);
37 }
38