GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Apr-2008, 03:32
NatsoumiMaya NatsoumiMaya is offline
New Member
 
Join Date: Feb 2008
Posts: 2
NatsoumiMaya is on a distinguished road

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.

the variable cache is an array of SETS

oh, this code is written in the "main" function

CPP / C++ / C 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:


CPP / C++ / C 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 and all help provided
Last edited by LuciWiz : 30-Apr-2008 at 12:16. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cache size for PDA and mobile devices FarAway Computer Hardware Forum 0 24-Oct-2007 09:22
C program for Cache Memory Simulation based on UNIX C ravi119 C Programming Language 2 30-Nov-2006 14:01
Re: Alternative PHP Cache (APC) admin Web Hosting Forum 0 04-May-2006 23:41
help direct mapped cache lovec++ Computer Software Forum - Windows 0 18-May-2004 21:11
what is the use of L1 and L2 cache? meet_raman Computer Hardware Forum 4 01-May-2004 12:45

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:55.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.