#include "cache.h" #include "DRWUsim.h" //************************************************************* CCache::CCache(void): BlockSize(BlockSize), CacheSize(0), CurrAddress(0), Blocks(NULL), Full(false) {} //************************************************************* //************************************************************* CCache::CCache(long int bsize, long int csizekb): BlockSize(bsize), CacheSize(csizekb), CurrAddress(0), Full(false), NumBlocks((int)((csizekb*1024)/BlockSize/WORD_SIZE)) { Blocks = new CBlock[NumBlocks]; } //************************************************************* //initialize Cache for use CCache::InitializeCache(long int bsize, long int csizekb) { BlockSize=bsize; CacheSize=csizekb; CurrAddress=0; Full=false; NumBlocks=(int)((csizekb*1024)/BlockSize/WORD_SIZE); Blocks = new CBlock[NumBlocks]; } //************************************************************* //input block number and processor number //return the index of the block in cache -1 if block is not //present int CCache::isCached(long int block, int penum) { int i=0; int startblock=(int)(block%NumBlocks); int startNextSet=startblock+ASSOCIATIVITY; for(i=startblock; i0) { Blocks[rnum].decProcCount(); Blocks[rnum].setC(penum, 0); } //add the block Blocks[rnum]=addblock; Blocks[rnum].setC(penum, C); return 0; } //************************************************************* void CCache::setCurrAddress(long int addr) { CurrAddress=addr; } //************************************************************* long int CCache::getCurrAddress(void) { return CurrAddress; } //************************************************************* long int CCache::getCurrBlock(void) { return CurrBlock; } long int CCache::getCurrBIndex(void) { return CurrBIndex; }