Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Cache Simulator...PLZ HELP!! (http://www.go4expert.com/forums/cache-simulatorplz-help-t10234/)

Natsoumi_Maya 25Apr2008 14:34

Cache Simulator...PLZ HELP!!
 
What im trying to do is implement the cache using C. I have to find out the hit and miss rate of the cache. my code is pretty long so i'll just show u the parts i've implemented and the parts i need help with. If u have any inqueries PLZ feel free to ask. Thank you in advance for any help provided.
This is the part i have implemented. The code basically implements the Full associative, set associative and direct mapped cache.

cache - array of SETS

Code:

int i;
if(MAX_SET==1)        // Fully Associative Cache
{
    i = 0;
    while (i <=BLOCKS_PER_SET)  // Dividing the SET into
                                                      //Blocks of size "BYTES_PER_BLOCK"
    {
        cache[i].block = (struct BLOCK *)malloc(BYTES_PER_BLOCK)    // Not Sure about "  cache[i].block " 
        i ++;
      }
      cache --;
}
else
{
    while (cache )  //THINK OF CONDITION: while the array of SETS is not FULL
    {
        if (MAX_SET == BLOCKS_PER_SET) //Direct Mapped Cache
        {
            while (MAX_SET != 0)
            {
                i = 0;
        while (i <=BLOCKS_PER_SET) // Dividing the SET into BLOCKS
                                                              //of size "BYETS_PER_BLOCK"
        {
            cache[i].block = (struct BLOCK *)malloc
                    BYTES_PER_BLOCK)    //CHECK the "cache[i].block"
            i ++;
        }
        MAX_SET --;
            }
        }
        else // Set Associative Cache
        {
            while (MAX_SET != 0)
            {
        i = 0;
        while (i <=BLOCKS_PER_SET) // Dividing the SET into BLOCKS of
                                                              //size "BYTES_PER_BLOCK"
        {
            cache[i].block = (struct BLOCK *)malloc(BLOCKS_PER_SET)                        i ++;
        }
        MAX_SET --;
              }
          }
          cache --;
        }
}int i;
if(MAX_SET==1)        // Fully Associative Cache
{
    i = 0;
    while (i <=BLOCKS_PER_SET)  // Dividing the SET into
                                                      //Blocks of size "BYTES_PER_BLOCK"
    {
        cache[i].block = (struct BLOCK *)malloc(BYTES_PER_BLOCK)    // Not Sure about "  cache[i].block " 
        i ++;
      }
      cache --;
}
else
{
    while (cache )  //THINK OF CONDITION: while the array of SETS is not FULL
    {
        if (MAX_SET == BLOCKS_PER_SET) //Direct Mapped Cache
        {
            while (MAX_SET != 0)
            {
                i = 0;
        while (i <=BLOCKS_PER_SET) // Dividing the SET into BLOCKS
                                                              //of size "BYETS_PER_BLOCK"
        {
            cache[i].block = (struct BLOCK *)malloc
                    BYTES_PER_BLOCK)    //CHECK the "cache[i].block"
            i ++;
        }
        MAX_SET --;
            }
        }
        else // Set Associative Cache
        {
            while (MAX_SET != 0)
            {
        i = 0;
        while (i <=BLOCKS_PER_SET) // Dividing the SET into BLOCKS of
                                                              //size "BYTES_PER_BLOCK"
        {
            cache[i].block = (struct BLOCK *)malloc(BLOCKS_PER_SET)                        i ++;
        }
        MAX_SET --;
              }
          }
          cache --;
        }
}

Since my program is incomplete, im not able to test it, SO i was wondering if In the part i implemented
Code:

cache[i].block = (struct BLOCK *)malloc(BLOCKS_PER_SET)
is correct (Syntax wise).

This is the part i need help with. I have the algorithim down but im not sure how to implement. Again, any help is most appreciated:


Code:

BOOL simulate(unsigned int address)
{
        /* Algorithm:
                * - Find the index for current address
        * - For that set, search all valid blocks for matching tags
        * - If a match is found, you have a hit:
          *  + update timestamp of block and LRU of set
        *  + return true
        * - If there is no match, you have a miss:
        *  + Search for an invalid block and use it to store new block
        *  + If there are no invalid blocks, replace the LRU block
        *  + update timestamp of block and LRU of set
        *  + return false
        */
        /******* Fully Associative Cache*******/
       
        /********* Direct Mapped Cache*********/
        /******** SET Associative Cache********/
}

Again, thank you in advance for any help provided :)


All times are GMT +5.5. The time now is 09:06.