/// <summary> /// Construct an L1Cache given a cache settings /// </summary> /// <param name="mb">reference to main memory block</param> /// <param name="cs">instruction cache preferences</param> public L1Cache(MemoryBlock mb, InstructionCachePreferences cs) { memBlock = mb; //Only if this cache is enabled do we create all these items if (cs.Enabled) { replaceStrategy = cs.ReplaceStrategy; wordsPerBlock = cs.BlockSize / 4; uint numberBlocks = cs.NumberBlocks; uint blocksPerSet = cs.BlocksPerSet; //determine the number of sets in the cache uint numSets = numberBlocks / blocksPerSet; //and allocate the collection of sets Sets = new CacheSet[numSets]; //create and init each set uint blockNumber = 0; for (uint ii = 0; ii < numSets; ii++) { Sets[ii] = new CacheSet(mb, wordsPerBlock, blocksPerSet, blockNumber, replaceStrategy); blockNumber += blocksPerSet; } //for ii } //if ResetStats(); }//L1Cache ctor
/// <summary> /// Create a CacheSet with blocksPerSet lines. Create each line in the set and reset the /// statisitcs. /// </summary> /// <param name="mb">reference to main memory block</param> /// <param name="wordsPerBlock">number of words per block</param> /// <param name="blocksPerSet">number of blocks per set</param> /// <param name="startBlock">starting block of this set</param> /// <param name="replaceStrategy">which replacement strategy to use</param> public CacheSet(MemoryBlock mb, uint wordsPerBlock, uint blocksPerSet, uint startBlock, ReplaceStrategiesEnum replaceStrategy) { memBlock = mb; _replaceStrategy = replaceStrategy; rand = new Random(4); Blocks = new CacheBlock[blocksPerSet]; for (uint ii = 0; ii < blocksPerSet; ii++) { Blocks[ii] = new CacheBlock(mb, wordsPerBlock, startBlock++); } //for ii ResetStats(); }//CacheSet ctor