Want more features on Pastebin? Sign Up, it's FREE!
Guest

cache.h

By: Ronin420 on Sep 25th, 2011  |  syntax: C++  |  size: 2.99 KB  |  views: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #ifndef MEM_H
  2. #define MEM_H
  3.  
  4.  
  5. using namespace std;
  6.  
  7. // Function to return the log to the base 2
  8. unsigned lg(unsigned n);
  9.  
  10.  
  11. class mem{
  12.     private:
  13.         short unsigned blocksize;
  14.         short unsigned assoc;
  15.         long unsigned  sets;
  16.         long unsigned  size;
  17.             // size = blocksize * assoc * sets
  18.  
  19.         short unsigned policy_rep;
  20.             // Replacement Policy: 0=LRU, 1=LFU
  21.         short unsigned policy_wr;
  22.             // Write Policy: 0=WBWA, 1=WTNA
  23.  
  24.         //unsigned char **arr_data;
  25.         long unsigned **arr_tag;
  26.         bool **arr_tag_valid;
  27.  
  28.         //unsigned int *arr_set_count;
  29.         long unsigned **arr_block_count;
  30.         bool **arr_block_dirty;
  31.  
  32.         long unsigned read_access;
  33.         long unsigned read_misses;
  34.         long unsigned write_access;
  35.         long unsigned write_misses;
  36.         long unsigned writebacks;
  37.  
  38.         float hit_time;
  39.         float miss_penalty;
  40.         float aat;
  41.  
  42.         class mem *next;
  43.         class vcache *vc;
  44.  
  45.         long unsigned vc_blocks;
  46.        
  47.         void block_count_update(long unsigned index,short unsigned assoc);
  48.             // Updates the block-counter
  49.         short unsigned block_replace(long unsigned index);
  50.             // Finds and returns the block to be replaced
  51.  
  52.     public:
  53.         string name;
  54.  
  55.         mem(string name,class mem *next,short unsigned blocksize,long unsigned size,short unsigned assoc,short unsigned policy_rep,short unsigned policy_wr,long unsigned vc_blocks);
  56.         bool read(long unsigned addr);
  57.         void write(long unsigned addr);
  58.  
  59.         friend float meminfo(class mem *,short unsigned state);
  60.        
  61.        
  62.  
  63. };
  64.  
  65.  
  66. class vcache{
  67.    
  68.     private:
  69.         short unsigned blocksize;
  70.         unsigned assoc;
  71.         // Full Associativity <==> no. of sets = 1
  72.  
  73.         long unsigned *arr_tag;
  74.         bool *arr_tag_valid;
  75.  
  76.         unsigned *arr_block_count;
  77.         bool *arr_block_dirty;
  78.  
  79.         // Counters
  80.         long unsigned read_access;
  81.         long unsigned read_misses;
  82.         long unsigned write_access;
  83.         long unsigned write_misses;
  84.  
  85.         void block_count_update(unsigned block);
  86.             // Updates the count of the block depending upon the replacement policy
  87.  
  88.     public:
  89.         string name;
  90.  
  91.         vcache(short unsigned blocksize,unsigned assoc);
  92.             // assoc is number of blocks in vcache. As victim caches have full associativity, size = blocksize * assoc
  93.         int find(long unsigned addr);
  94.             // Finds if a block with the given addr is present and returns its block address or -1 if absent
  95.         unsigned find();
  96.             // Finds the block to be replaced according to the replacement policy
  97.         long unsigned swap(long unsigned addr,bool dirty,int vc_block_rep);
  98.             // vc_block_rep is the address of the block to be swapped
  99.  
  100.         //friend float meminfo(class vcache *);
  101.  
  102. };
  103.  
  104.  
  105. // Memory Info
  106. float meminfo(class mem*,short unsigned var);
  107.  
  108.  
  109. #endif
clone this paste RAW Paste Data