Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Set{
- //int order; //NOTE: We may not need this.
- long unsigned setIndex;
- struct Line *cacheLine;
- };
- struct Line{
- int valid;
- long unsigned tag;
- };
- if(strcmp(assoc, "direct") == 0 ){
- numOfLines = 1;
- numOfSets = cacheSize/(blockSize*numOfLines);
- int k = log2n(numOfSets);
- int offset = log2n(blockSize);
- struct Set *cache = (struct Set *) malloc(sizeof(struct Set)*numOfSets);
- while(readLine() != EXIT_FAILURE){
- int hit = 0;
- int preHit = 0;
- blockIdentifier = address>>offset;
- tempSetIndex = ((blockIdentifier) & ((1<<k)-1));
- tempTag = address>> k;
- tempTag = tempTag >> offset;
- for(i = 0; (hit == 0) && (i < numOfSets-1); i++){
- if((cache[i].setIndex == tempSetIndex) && (cache[i].cacheLine->tag == tempTag)){
- hit = 1;
- numHits++;
- if(operation == 'W'){
- numWrites++;
- }
- }
- }
- if(hit == 0){
- cache[fifo].setIndex = tempSetIndex;
- cache[fifo].cacheLine->tag = tempTag;
- cache[fifo].cacheLine->valid = 1;
- hit = 1;
- if(fifo == numOfSets-2){
- fifo = 0;
- }
- else{
- fifo++;
- }
- if(operation == 'R'){
- numMisses++;
- numReads++;
- }
- if(operation == 'W'){
- numMisses++;
- numReads++;
- numWrites++;
- }
Add Comment
Please, Sign In to add comment