#include "prog2.h" void BSizeCSizeSim(CMemory* Memory); void AssocSim(CMemory* Memory); //=========================================================== //main method int main(void) { //seed the random number generator srand((unsigned)time(NULL)); //memory will remain constant through the simulations CMemory Memory(MEM_SIZE); Memory.GenerateMemory(); BSizeCSizeSim(&Memory); printf("\n\n"); AssocSim(&Memory); return 0; } //=========================================================== //=========================================================== //simulate different cache sizes with different cache sizes void BSizeCSizeSim(CMemory* Memory) { int i=0, j=0; int associativity=0; printf("Cache Size:\tBlock Size:\tMiss Rate:\tAveAccess Time:\t\tMisses:\n"); for(i=0; iExcecuteNCycles(100000, Memory, Associativity[j]); delete Cache; } } } //=========================================================== //=========================================================== //CCache functions CCache::CCache(void) {} CCache::CCache(long int csize, int bsize): CacheSize(csize), BlockSize(bsize), IsFull(false) { CacheInstr = new struct Instruction[csize]; for(long int i=0; iInstructions[currindex].address; CacheInstr[i].next=memory->Instructions[currindex].next; currindex++; } cc+=misspenalty; currindex=0; //go through N cycles for(instrExec=0; ccInstructions[blockaddr+j].address; CacheInstr[i+j].next=memory->Instructions[blockaddr+j].next; } return i+bindex; } } } //if there is no empty spot if(IsFull) { long int rnum=rand()%((CacheSize/BlockSize)/numsets); rnum=(blockset*blocksperset+rnum)*BlockSize;//(rnum%BlockSize); for(j=0; jInstructions[blockaddr+j]; return rnum+bindex; } IsFull=false; return -1; } //destructor CCache::~CCache(void) { delete[] CacheInstr; } //=========================================================== //=========================================================== //CMemory fcns CMemory::CMemory(void): MemSize(MEM_SIZE) { Instructions = new struct Instruction[MEM_SIZE]; } CMemory::CMemory(long int msize): MemSize(msize) { Instructions = new struct Instruction[msize]; } CMemory::~CMemory(void) { delete[] Instructions; } //=========================================================== //generate the Central Memory instructions according to //specifications void CMemory::GenerateMemory(void) { long int i=0; int j=0, branches=0, reads=0, writes=0; int rnum = 0; float rprob = 0; printf("Randomly generating Central Memory Instructions...\n"); for(i=0; i=MemSize) newaddress -= MemSize; else if(newaddress<0) newaddress += MemSize; else; //don't do anything to newaddress, it's okay! return newaddress; }