#ifndef MEM_H
#define MEM_H
using namespace std;
// Function to return the log to the base 2
unsigned lg(unsigned n);
class mem{
private:
short unsigned blocksize;
short unsigned assoc;
long unsigned sets;
long unsigned size;
// size = blocksize * assoc * sets
short unsigned policy_rep;
// Replacement Policy: 0=LRU, 1=LFU
short unsigned policy_wr;
// Write Policy: 0=WBWA, 1=WTNA
//unsigned char **arr_data;
long unsigned **arr_tag;
bool **arr_tag_valid;
//unsigned int *arr_set_count;
long unsigned **arr_block_count;
bool **arr_block_dirty;
long unsigned read_access;
long unsigned read_misses;
long unsigned write_access;
long unsigned write_misses;
long unsigned writebacks;
float hit_time;
float miss_penalty;
float aat;
class mem *next;
class vcache *vc;
long unsigned vc_blocks;
void block_count_update(long unsigned index,short unsigned assoc);
// Updates the block-counter
short unsigned block_replace(long unsigned index);
// Finds and returns the block to be replaced
public:
string name;
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);
bool read(long unsigned addr);
void write(long unsigned addr);
friend float meminfo(class mem *,short unsigned state);
};
class vcache{
private:
short unsigned blocksize;
unsigned assoc;
// Full Associativity <==> no. of sets = 1
long unsigned *arr_tag;
bool *arr_tag_valid;
unsigned *arr_block_count;
bool *arr_block_dirty;
// Counters
long unsigned read_access;
long unsigned read_misses;
long unsigned write_access;
long unsigned write_misses;
void block_count_update(unsigned block);
// Updates the count of the block depending upon the replacement policy
public:
string name;
vcache(short unsigned blocksize,unsigned assoc);
// assoc is number of blocks in vcache. As victim caches have full associativity, size = blocksize * assoc
int find(long unsigned addr);
// Finds if a block with the given addr is present and returns its block address or -1 if absent
unsigned find();
// Finds the block to be replaced according to the replacement policy
long unsigned swap(long unsigned addr,bool dirty,int vc_block_rep);
// vc_block_rep is the address of the block to be swapped
//friend float meminfo(class vcache *);
};
// Memory Info
float meminfo(class mem*,short unsigned var);
#endif