diff --git a/main.py b/main.py index 801a73959cfc6eaf029dd4228ed41cd5433c955b..c0e997458a0a622721e453d3217b8994bc4f292e 100644 --- a/main.py +++ b/main.py @@ -39,7 +39,7 @@ def main(set_identifier_bit_count, line_count, block_identifier_bit_count, file_ s = set_identifier_bit_count S = set_count = int(math.pow(2, s)) E = line_count - e = line_identifier_bit_count = math.log2(E) + e = line_identifier_bit_count = math.log2(E) b = block_identifier_bit_count B = block_size = int(math.pow(2, b)) m = address_identifier_bit_count = E * S @@ -58,7 +58,7 @@ def main(set_identifier_bit_count, line_count, block_identifier_bit_count, file_ cache[len(cache) - 1].append({ 'valid': False, 'tag': 0, - 'block': 0, + 'block': [], }) # print('Address Bit Count: {0}'.format(address_identifier_bit_count)) @@ -148,9 +148,9 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions): set = (address & set_mask) >> block_offset tag = (address & tag_mask) >> (block_offset + set_offset) - # print('block: {0:b}'.format(block)) - # print('set: {0:b}'.format(set)) - # print('tag: {0:b}'.format(tag)) + # print('block: {0} As Bits: {0:b}'.format(block)) + # print('set: {0} As Bits: {0:b}'.format(set)) + # print('tag: {0} As Bits: {0:b}'.format(tag)) # We have our values. Now compare against the all entries in the cache. for index in range(len(cache[set])): @@ -169,6 +169,12 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions): cache[set][index]['valid'] = True cache[set][index]['tag'] = tag + # Set block values that are "loaded" into memory. + offset = int(block_offset * (address / block_offset)) + cache[set][index]['block'] = [] + for i in range(B): + cache[set][index]['block'].append(offset + i) + return (cache, hits, misses, evictions) @@ -178,6 +184,12 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions): evictions += 1 cache[set][0]['tag'] = tag + # Set block values that are "loaded" into memory. + offset = int(block_offset * (address / block_offset)) + cache[set][0]['block'] = [] + for i in range(B): + cache[set][0]['block'].append(offset + i) + return (cache, hits, misses, evictions)