All problems
Cache Tag Compare
Problem
Check whether an address hits in a set-associative cache.
cache is a list of sets, each holding recently used tags for that set. block_size and num_sets define the address split; the address hits when its tag is present in the indexed set.
Return [hit, tag].
Hint
Only the tags stored in the selected set are compared.
Test cases
case 1
in: [[[1,2],[3]],4,2,8]
expected: [true,1]
case 2
in: [[[1,2],[3]],4,2,4]
expected: [false,0]
case 3
in: [[[],[]],4,2,0]
expected: [false,0]
case 4
in: [[[5],[5]],4,2,20]
expected: [false,2]
Starter codePython
def cache_tag_compare(cache, block_size, num_sets, address):
# Your code here
pass4 test cases · run your code against them in the editor