diff --git a/documents/references.md b/documents/references.md index 5f41f9490b9d1b7e362fbadddf9230d59c109e2b..46bacf7576e18bc81a07180da202a832aa1b4870 100644 --- a/documents/references.md +++ b/documents/references.md @@ -23,6 +23,9 @@ Includes anything from stack overflow links to notes about logic from previous w ### Bitwise Operations <https://www.tutorialspoint.com/python/bitwise_operators_example.htm> +### Character to Int +<https://stackoverflow.com/a/704160> + ## Makefile * Purpose of ".PHONY" - <https://stackoverflow.com/a/2145605> diff --git a/main.py b/main.py index e4ff531d4411b9611712a220adaf055df58e7ae4..d88e376c53af17be325864d618d94ae06780700d 100644 --- a/main.py +++ b/main.py @@ -67,9 +67,11 @@ class CacheSimulator(): self.b = b self.B = int(math.pow(2, self.b)) self.m = self.E * self.S - # M = total_bytes = int(math.pow(2, m)) + # self.M = int(math.pow(2, self.m)) self.M = int(math.pow(2, 64)) + # self.debug_print() + # Create cache object. self.cache = [] self.access_log = [] @@ -92,6 +94,18 @@ class CacheSimulator(): # Run simulation on cache, using file. self.run_simulation(file_name) + def debug_print(self): + print('\n') + print('Debug Info:') + print(' s: {0}'.format(self.s)) + print(' S: {0}'.format(self.S)) + print(' e: {0}'.format(self.e)) + print(' E: {0}'.format(self.E)) + print(' b: {0}'.format(self.b)) + print(' B: {0}'.format(self.B)) + print(' verbose: {0}'.format(self.verbose)) + print('') + def run_simulation(self, file_name): """ Runs full simulation of cache, using given input file. @@ -129,7 +143,10 @@ class CacheSimulator(): # Not an instruction load. Keep processing. Start by parsing line info. parsed_data = {} - address = int(split_line[2]) + try: + address = int(split_line[2]) + except ValueError: + address = int(ord(split_line[2])) parsed_data['address'] = address parsed_data['value_size'] = int(split_line[3]) @@ -139,6 +156,10 @@ class CacheSimulator(): set_mask = ((self.S << block_offset) - 1) ^ block_mask set_offset = self.s tag_mask = (self.M - 1) ^ set_mask ^ block_mask + # print('full_mask: {0} As Bits: {0:b}'.format(self.M - 1)) + # print('block_mask: {0} As Bits: {0:b}'.format(block_mask)) + # print('set_mask: {0} As Bits: {0:b}'.format(set_mask)) + # print('tag_mask: {0} As Bits: {0:b}'.format(tag_mask)) # Use masks to get address chunks. parsed_data['block'] = address & block_mask @@ -146,6 +167,10 @@ class CacheSimulator(): parsed_data['set'] = set tag = (address & tag_mask) >> (block_offset + set_offset) parsed_data['tag'] = tag + # print('address: {0} As Bits: {0:b}'.format(address)) + # print('block: {0} As Bits: {0:b}'.format(parsed_data['block'])) + # print('set: {0} As Bits: {0:b}'.format(parsed_data['set'])) + # print('tag: {0} As Bits: {0:b}'.format(parsed_data['tag'])) # We have our values. Now compare against the all entries in the cache. for index in range(len(self.cache[set])): @@ -219,9 +244,14 @@ class CacheSimulator(): self.cache[set][index]['tag'] = tag # Set block values that are "loaded" into memory. + # print('b: {0} As Bits: {0:b}'.format(self.b)) + # print('B: {0} As Bits: {0:b}'.format(self.B)) lower_offset = int(address / self.B) * self.B upper_offset = (int(address / self.B) + 1) * self.B value_offset = address + value_size + # print('lower_offset: {0}'.format(lower_offset)) + # print('upper_offset: {0}'.format(upper_offset)) + # print('value_offset: {0}'.format(value_offset)) self.cache[set][index]['block'] = [] for i in range(self.B): self.cache[set][index]['block'].append(lower_offset + i) @@ -229,7 +259,7 @@ class CacheSimulator(): self.update_access_log(set, index) # Check if size sets address outside of current cache block. - if value_offset >= upper_offset: + if value_offset > upper_offset: # Size sets address outside of current cache block. Update additional blocks as needed. # Start by getting our new size. new_size = value_offset - upper_offset