SHARE
TWEET

Untitled

a guest Nov 19th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cache_size = 8 * 1024
  2. associativity = 1
  3. block_size = 32
  4. num_blocks = cache_size // block_size
  5. num_sets = cache_size // (block_size * associativity)
  6.  
  7. misses = 0
  8. accesses = 0
  9.  
  10. cache = [[-1 for x in range(associativity)] for y in range(num_sets)]
  11. def simulator(address):
  12.     global misses
  13.     global accesses
  14.     block_offset = address % block_size
  15.     index = (address // block_size) % num_sets
  16.     tag = address // (block_size * num_sets)
  17.  
  18.     accesses += 1
  19.     curr = cache[index]
  20.     for i in range(len(curr)):
  21.         if curr[i] == tag:
  22.             curr.pop(i)
  23.             curr.insert(0, tag)
  24.             return
  25.  
  26.     curr.pop(len(curr) - 1)
  27.     curr.insert(0, tag)
  28.     misses += 1
  29.  
  30.  
  31. data_size = 8
  32. N = 64
  33. M = 4
  34. addressA = 0XFBDCE8
  35. for row in range(N):
  36.     col = row
  37.     while col < 64 - row:
  38.         simulator(addressA + col * N * data_size + row * data_size)
  39.         simulator(addressA + row * N * data_size + col * data_size)
  40.         simulator(addressA + row * N * data_size + col * data_size)
  41.         col+=1
  42.     col = 64 - row
  43.     while col < row:
  44.         simulator(addressA + col * N * data_size + row * data_size)
  45.         simulator(addressA + row * N * data_size + col * data_size)
  46.         simulator(addressA + row * N * data_size + col * data_size)
  47.         col+=1
  48.  
  49.  
  50. print (misses)
  51. print(accesses)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top