//==================================================================== // Patitz, Zachary // CS 5113 // Programming assignment #2 // // Cache performance simulator: // This simulator simulates the performance of different cache setups. // First it simulates different combinations of block size and cache // size (30 combinations) in a fully associative environment. // Second it simulates different size caches using differnet set // associations with a constant block size (32bytes). // The program outputs the current cache setup and it's miss rate // and average access time. // // output goes to standard out (monitor) redirect to output file if // desired. //==================================================================== #include #include #include #include const float READ_PROB=0.90f; //prob of going to next address const int MEM_OFFSET=500; //the mem offset if not next address const int OFFSET_RANGE=500; //the range of the offset const long int CacheSizes[] = {1024, 4*1024, 16*1024, 64*1024, 256*1024, 512*1024}; const int NUM_C_SIZES = 6; //corresponds to CacheSizes const int BlockSizes[] = {16, 32, 64, 128, 256}; const int NUM_B_SIZES = 5; //corresponds to BlockSizes const long int CacheSizes2[] = {1024, 2*1024, 4*1024, 8*1024, 16*1024, 32*1024, 64*1024, 128*1024, 256*1024}; const int NUM_C_SIZES2 = 9; //corresponds to CacheSizes2 const int Associativity[] = {1, 2, 4, 8}; const int NUM_ASSOC = 4; const int AssocBlockSize = 32; //struct to represent an instruction struct Instruction{ long int address; long int next; }; const long int MEM_SIZE = 1024*1024; //size of MM in bytes //=========================================================== //class CMemory definitions class CMemory { public: CMemory::CMemory(void); CMemory::CMemory(long int msize); CMemory::~CMemory(void); void CMemory::GenerateMemory(void); struct Instruction* Instructions; private: long int MemSize; //the size of the memory IN BLOCKS long int CMemory::genBranchAddress(long int curraddr); }; //=========================================================== //class CCache definitions class CCache { public: CCache::CCache(void); CCache::CCache(long int csize, int bsize); CCache::~CCache(void); struct Instruction* CacheInstr; CCache::ExcecuteNCycles(long int N, CMemory* memory, int associativity); private: long int CacheSize; int BlockSize; bool IsFull; long int CCache::findAddress(long int addr, int accosiativity); long int CCache::addAddress(long int addr, CMemory* memory, int associativity); };