Skip to content
Snippets Groups Projects
Commit 0c5fd283 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Further correct masking caclulations

parent 70d08548
Branches
No related merge requests found
......@@ -67,6 +67,7 @@ def main(set_identifier_bit_count, line_count, block_identifier_bit_count, file_
# print('E: {0}'.format(E))
# print('Tag Bits: {0}'.format(tag_identifier_bit_count))
print('Cache: {0}'.format(cache))
print('\n\n')
run_simulation(cache, file_name, M, B, S)
......@@ -87,6 +88,8 @@ def run_simulation(cache, file_name, M, B, S):
for line in file:
# print('Line: {0}'.format(line))
cache, hits, misses, evictions = handle_line(cache, line, M, B, S, hits, misses, evictions)
# print('Cache: {0}'.format(cache))
# print('')
# print('M: {0} As Bits: {1:b}'.format(M, M - 1))
# print('B: {0} As Bits: {1:b}'.format(B, B - 1))
......@@ -127,9 +130,12 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions):
# Get mask values.
full_mask = M - 1
block_mask = B - 1
set_mask = ((S - 1) << 1)
block_offset = int(math.log2(B))
set_mask = ((S << block_offset) - 1) ^ block_mask
set_offset = int(math.log2(S))
tag_mask = (M - 1) ^ set_mask ^ block_mask
# print('')
# print('Address: {0} As Bits: {0:b}'.format(address))
# print('full_mask: {0} As Bits: {0:b}'.format(full_mask))
# print('block_mask: {0} As Bits: {0:b}'.format(block_mask))
......@@ -139,8 +145,8 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions):
# Use masks to get address chunks.
block = address & block_mask
set = (address & set_mask) >> 1
tag = address & tag_mask
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))
......@@ -168,9 +174,9 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions):
# If we made it this far, cache locations were set, but tags did not match. Conflict miss.
print('{0} miss eviction'.format(line))
cache[set][0]['tag'] = tag
misses += 1
evictions += 1
cache[set][0]['tag'] = tag
return (cache, hits, misses, evictions)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment