Consider the following cache:
- Direct-mapped (i.e., 1-way set-associative)
- 2B block size
- 2S sets
Your function will be provided B, S, an array of tags (one for each cache block), and a list of addresses. Write a function that will determine how many of those addresses would hit in the above cache. This problem counts the number of hits assuming the cache state does not change (i.e., it's the same problem as nios/cachehit, but run multiple times on a list of addresses. You may wish to reuse your solution from that problem).
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).
The address list contains an array of 32-bit addresses, and is terminated with -1. Do not process the -1 as if it were an address.
Your function should return the number of addresses in the address list that would hit in the cache.
int cachehits(unsigned int B, unsigned int S, unsigned int *cachetags, unsigned int *addrlist);
Expected solution length: Around 40 lines.
Write your solution here