Пример #1
0
 public FrameSet()
 {
     for(int i = 0;i<Memory.frameSetSize;i++)
     {
         frames[i] = new Frame();
     }
 }
Пример #2
0
        public void printCache(Frame[] cache)
        {
            if (BlockHolds1)
            {
                if (DirectCache)
                {
                    Console.WriteLine("Frame Tag Value Dirty Empty");
                    for (int i = 0; i < cacheSize; i++)
                    {
                        Console.WriteLine(i + "      " + cache[i].tag + "     " + cache[i].value + "    " + cache[i].dirty + "   " + cache[i].empty);
                    }
                }
                else // 2-way set
                {
                    Console.WriteLine("Set Tag    Value   Dirty     Empty");

                    for (int i = 0; i < numOfSets; i++)
                    {
                        Console.WriteLine(i + "    " + cache2[i].frame1.tag + "      " + cache2[i].frame1.value + "      " + cache2[i].frame1.dirty + "      " + cache2[i].frame1.empty);
                        Console.WriteLine(i + "    " + cache2[i].frame2.tag + "      " + cache2[i].frame2.value + "      " + cache2[i].frame2.dirty + "      " + cache2[i].frame2.empty);
                    }
                }
            }
            else
            {
                if (DirectCache)
                {
                    Console.WriteLine("Frame Tag Value1 Value2 Dirty Empty");
                    for (int i = 0; i < cacheSize; i++)
                    {
                        Console.WriteLine(i + "      " + cache2B[i].tag + "     " + cache2B[i].value[0] + "    " + cache2B[i].value[1] + "    " + cache2B[i].dirty + "   " + cache2B[i].empty);
                    }
                }
                else // 2-way set
                {
                    Console.WriteLine("Set Tag    Value1    Value2   Dirty     Empty");

                    for (int i = 0; i < numOfSets; i++)
                    {
                        Console.WriteLine(i + "    " + cache22B[i].frame1.tag + "      " + cache22B[i].frame1.value[0] + "      " + cache22B[i].frame1.value[1] + "       " + cache22B[i].frame1.dirty + "      " + cache22B[i].frame1.empty);
                        Console.WriteLine(i + "    " + cache22B[i].frame2.tag + "      " + cache22B[i].frame2.value[0] + "      " + cache22B[i].frame2.value[1] + "      " + cache22B[i].frame2.dirty + "      " + cache22B[i].frame2.empty);
                    }
                }
            }
        }
Пример #3
0
 public Set(Frame frame1, Frame frame2)
 {
     this.frame1 = frame1;
     this.frame2 = frame2;
 }
Пример #4
0
 public void writeToMem(Frame replaceable, short address)
 {
     for (int i = 0; i < blockSize; i++)
     {
         stack[(address - (address % blockSize)) + i] = replaceable.data[i];
     }
 }
Пример #5
0
 public short randomReplace(int setNum, Frame newFrame, short address)
 {
     Random rnd = new Random();
     int randNum = rnd.Next(frameSetSize);
     Frame replaceable = cache[setNum].frames[randNum];
     if (replaceable.dirtyBit)
     {
         writeToMem(replaceable, (short)(replaceable.tag*blockSize));
     }
     cache[setNum].frames[randNum] = newFrame;
     return newFrame.data[address % blockSize];
 }
Пример #6
0
 public short loadMemBlk(int setNum, short address)
 {
     int blkNum = getBlkNum(address);
     Frame newFrame = new Frame();
     newFrame.dirtyBit = false;
     newFrame.tag = blkNum;
     for (int i = 0; i < blockSize; i++)
     {
         newFrame.data[i] = stack[blkNum * blockSize + i];
     }
     int emptySpot = lookForEmptySpot(setNum);
     //if there's an empty spot
     if (emptySpot != -1)
     {
         cache[setNum].frames[emptySpot] = newFrame;
         return newFrame.data[address % blockSize];
     }
     //no free spot
     else
     {
         return randomReplace(setNum, newFrame, address);
     }
 }