Arm/cachehit
From ASMBits
arm/cachetagPrevious
Nextarm/cachehits
Consider the following cache:
- Direct-mapped (i.e., 1-way set-associative)
- 2B block size
- 2S sets
Write a function that will determine whether the cache block for a given address is in a cache (i.e., will hit). Your function will be provided B, S, an array of tags (one for each cache block), and one address.
Assume every cache block in the cache is valid. The array of tags contains exactly 2S words, one for each set. Each entry in the array is a 32-bit word, but only the tag bits are valid (the lower bits that correspond to the set number and offset are undefined).
Your function should return 1 or 0, indicating whether the cache block containing the given address is located in the cache.
int cachehit(unsigned int B, unsigned int S, unsigned int *cachetags, unsigned int addr);
Expected solution length: Around 15 lines.
Sample Input
[See below]
Sample Output
r0=1
arm/cachetagPrevious
Nextarm/cachehits