diff --git a/main.py b/main.py index 25fd634f70937c891e906d589e3cf825f23faa75..80a669339562ebcf147cd7613a6e4715cd158e1e 100644 --- a/main.py +++ b/main.py @@ -107,9 +107,10 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions): # Check if instruction load. If so, we can skip line. if split_line[0] == 'I': # Found instruction load. Returning. - return + return (hits, misses, evictions) else: line = line.strip() + conflict_miss = -1 # print('\n') # print('handle_line():') # print(' line: {0}'.format(line)) @@ -144,28 +145,33 @@ def handle_line(cache, line, M, B, S, hits, misses, evictions): # print('set: {0:b}'.format(set)) # print('tag: {0:b}'.format(tag)) - # We have our values. Now compare against the cache. - # print('cache[set]: {0}'.format(cache[set])) - if cache[set][0]['valid'] == True and cache[set][0]['tag'] == tag: - # Match found. - print('{0} hit'.format(line)) - hits += 1 - else: - # Not a match. Examine why. - misses += 1 - if cache[set][0]['valid'] == True: - # Cache location was set, but tag did not match. Conflict miss. - print('{0} miss eviction'.format(line)) - cache[set][0]['tag'] = tag + # We have our values. Now compare against the all entries in the cache. + for index in range(len(cache[set])): + # Check if match. + if cache[set][index]['valid'] == True and cache[set][index]['tag'] == tag: + # Match found. + print('{0} hit'.format(line)) + hits += 1 + return (cache, hits, misses, evictions) else: - # Cache location was not set. Cold miss. - print('{0} miss'.format(line)) - cache[set][0]['valid'] = True - cache[set][0]['tag'] = tag - evictions += 1 - # print('cache: {0}'.format(cache)) - - return (cache, hits, misses, evictions) + # Not a match. Examine why. + if cache[set][index]['valid'] == False: + # Cache location was not set. Cold miss. We can just set and return. + print('{0} miss'.format(line)) + misses += 1 + cache[set][index]['valid'] = True + cache[set][index]['tag'] = tag + + return (cache, 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 + + return (cache, hits, misses, evictions) diff --git a/run.sh b/run.sh index 7a5ab47a328aae5d48204fc28fc82044f34050a2..5373cb0c3b692cbe4e4b881f813e19f7d8d59954 100755 --- a/run.sh +++ b/run.sh @@ -62,14 +62,16 @@ function execute_single_file () { # Run input file on example cache simulator file. echo "" echo -e "${color_blue}Running input file on \"wmucachelab/csim-ref\". Runtime args:${color_reset}" - echo -e "${color_blue} -v -s 4 -E 1 -b 4 -t $file${color_reset}" - ./wmucachelab/csim-ref -v -s 4 -E 1 -b 4 -t $file + echo -e "${color_blue} -v -s 1 -E 2 -b 1 -t $file${color_reset}" +# ./wmucachelab/csim-ref -v -s 2 -E 1 -b 1 -t $file + ./wmucachelab/csim-ref -v -s 1 -E 2 -b 1 -t $file # Run input file on compiled C code. echo "" echo -e "${color_blue}Running input file on Python code. Runtime args:${color_reset}" - echo -e "${color_blue} -v -s 4 -E 1 -b 4 -t $file${color_reset}" - python3 main.py -v -s 4 -E 1 -b 4 -t $file + echo -e "${color_blue} -v -s 1 -E 2 -b 1 -t $file${color_reset}" +# python3 main.py -v -s 2 -E 1 -b 1 -t $file + python3 main.py -v -s 1 -E 2 -b 1 -t $file else echo -e "${color_red}Failed to determine absolute path for input file.${color_reset}"