cache.c - #include#include#include#include ...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <assert.h> #include <stdio.h> #include <stdlib.h> #include "cache.h" // initialize the cache by allocating space for all of the cache // blocks and initializing them to be invalid and with 0 last access // times. void init_cache(cache_t *cache) { // initialize the cache blocks to invalid for (int i = 0 ; i < NUM_SETS ; i ++) { for (int j = 0 ; j < 2 ; j ++) { cache->sets[i].blocks[j].valid = false; } cache->sets[i].lru = 0; } cache->accesses = 0; cache->hits = 0; cache->writebacks = 0; } // given an address, extract the tag field unsigned address_to_tag(unsigned address) { return (address >> (OFFSET_SZ+INDEX_SZ)); } // given an address, extract the index field unsigned address_to_index(unsigned address) { unsigned mask = (1 << INDEX_SZ) - 1; return (address >> OFFSET_SZ) & mask; } // Given an address, look up in cache "cache" to see if that // address hits. If it does update the LRU. // Include necessary updates to the access, hit, writeback counters
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/09/2011 for the course CS 232 taught by Professor Kumar during the Spring '08 term at University of Illinois, Urbana Champaign.

Page1 / 2

cache.c - #include#include#include#include ...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online