hi:
I have two methods to write in this cache simulator:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
struct cache_blk_t {
unsigned long tag;
char valid;
char dirty;
cache_blk_t *way_next;
cache_blk_t *way_prev;
};
struct cache_set_t {
cache_blk_t *way_head;
cache_blk_t *way_tail;
unsigned int FIFO_counter;
};
enum cache_policy {
LRU,
Random,
FIFO
};
struct cache_t {
int nsets; // # sets
int bsize; // block size
int assoc; // associativity
enum cache_policy policy;
// statistics
unsigned long accesses;
unsigned long hits;
unsigned long misses;
unsigned long replacements;
unsigned long writebacks;
struct cache_set_t *sets;
};
void
cache_create(int A, int B, int C, enum cache_policy policy)
{
create cache based on A, B, and C
allocate sets
allocate blocks in each set
remember the replacement policy setting
initialize statistics data
}
int
cache_access(struct cache_t *cp, unsigned long address, char access_type)
{
based on address determine the set to access in cp
examine blocks in the set to check hit/miss
if miss, determine the victim in the set to replace
if LRU is used, update the block list
}
In the Cache create, and cache access method, can anyone help translate my sudo code?
Thanks,