#include #include "bool.h" #include "memory.h" /* incremented at each cache access; used to implement LRU associative cache entry replacement. The last used time of a block should be the access count AFTER incrementation. Remember that ALL of the cache access functions should increment the access count by exactly one. */ static int accessCount = 0; /* Create a new cache. Be sure to initialize all the words in your cache to 0. */ Cache newCache (int associativity, int nsets, int blocksize, bool printingCache, bool debugging) { Cache cache; cache = (struct cache *) malloc (sizeof(struct cache)); cache->associativity = associativity; cache->nsets = nsets; cache->blocksize = blocksize; cache->printingCache = printingCache; cache->debugging = debugging; cache->sets = (struct set *) malloc (nsets * sizeof(struct set)); /* YOU FILL IN MORE CODE HERE. */ return cache; } /* Return true if the cache contains the entry at the given address. Should increment the access count (and the lastUsedTime), if there is a cache hit. Should not increment the access count if the cache is missed. */ bool cacheContains (Cache cache, unsigned int address) { return FALSE; /* YOU PROVIDE THE BODY OF THIS FUNCTION. */ } /* The cache contains an entry at the given address. Return the cached memory contents. Should increment the access count. */ int cacheContents (Cache cache, unsigned int address) { return 0; /* YOU PROVIDE THE BODY OF THIS FUNCTION. */ /* if (Cannot find the specified address in the cache) { printf ("CacheContents didn't find address %8.8x!\n", address); exit (-1); } */ } /* The cache contains an entry at the given address, and the corresponding memory contents is being changed (by memory.c) to the given value. Update the cache entry to match. THIS FUNCTION MUST NOT MODIFY THE MEMORY. Should increment the access count. */ void updateCacheContents (Cache cache, unsigned int address, int contents) { /* YOU PROVIDE THE BODY OF THIS FUNCTION. */ /* if (Cannot find the specified address in the cache) { printf ("UpdateCacheContents didn't find address %8.8x!\n", address); exit (-1); } */ } /* Add an entry in the cache for the given address by copying it from memory. The cache currently does not contain an entry for the given address. THIS FUNCTION MUST NOT MODIFY THE MEMORY. Should increment the access count. */ void addEntry (Cache cache, Memory mipsMem, unsigned int address) { /* YOU PROVIDE THE BODY OF THIS FUNCTION. */ }