#include #include "byutr.h" #define TRUE 1 #define FALSE 0 #define ismem(cnt) ((cnt == MEMREAD) || (cnt == MEMREADINV) || (cnt == MEMWRITE) || (cnt == FETCH)) #define isdata(cnt) ((cnt == MEMREAD) || (cnt == MEMREADINV) || (cnt == MEMWRITE)) #define iswrite(cnt) (cnt == MEMWRITE) unsigned long addr; unsigned char control; typedef struct cache { unsigned long time; unsigned long tag; unsigned char valid; unsigned char dirty; } cache; int big, line_size, num_sets, num_cols; unsigned long references, reads, writes, oldmisses; unsigned long instructions, misses, dirty; void determine_endian() { unsigned long *a; unsigned char p[4]; a = (unsigned long *)p; *a = 0x12345678; if(*p == 0x12) { big = TRUE; fprintf(stderr,"Big Endian System\n"); } else { big = FALSE; fprintf(stderr,"Little Endian System\n"); } } void print_stats() { printf("Size (KBytes) = %5d\n",(num_sets*num_cols*line_size)/1024); printf("Assoc = %2d\n",num_cols); printf("Line size = %3d\n\n",line_size); printf("references = %d\n",references); printf("instructions = %d\n",instructions); printf("reads = %d\n",reads); printf("writes = %d\n",writes); printf("dirty replace = %d\n",dirty); printf("misses = %d\n",misses); printf("miss rate = %5.2f%%\n",100.0*(float)misses/references); } cache *build_cache(s, a, ls) int s, a, ls; { cache *c; int i, j, size; size = s*1024; num_sets = size / ls / a; num_cols = a; line_size = ls; if((c = (cache *)malloc(num_sets * num_cols * sizeof(cache))) == NULL) { fprintf(stderr,"cannot malloc space for cache\n"); exit(-1); } for(i=0;i> 1; } return(cnt); } unsigned long l2b(unsigned long l) { unsigned long tmp; tmp = l; tmp = (tmp << 8) | ((l >> 8) & 0x000000ff); tmp = (tmp << 8) | ((l >> 16) & 0x000000ff); tmp = (tmp << 8) | ((l >> 24) & 0x000000ff); return(tmp); } void do_cache_lookup(c) cache *c; { unsigned long set, tag, old, col; int found, i; addr = addr >> mylog2(line_size); set = addr & (~(0xffffffff << mylog2(num_sets))); tag = addr >> mylog2(num_sets); if(isdata(control)) { if(iswrite(control)) writes++; else reads++; } else { instructions++; } found = FALSE; for(i=0;i