Arm/cachetag

From ASMBits

Consider the following cache:

  • Capacity of C bytes
  • Associativity of 2W ways

Write a function that will determine whether the cache blocks holding two addresses will have the same tag, for the above cache. Your function will be provided C, W, and two addresses. It must return 1 or 0 to indicate whether the cache blocks holding the two addresses would have the same tag field. C and W will be valid values for a 32-bit address, and will correspond to a cache where the block size and number of sets are powers of two.

int cachetag(unsigned int C, unsigned int W, unsigned int addr1, unsigned int addr2);

Expected solution length: Around 10 lines.

Sample Input

cachetag(16384, 2, 0, 2) (16 KB, 4-way)

Sample Output

r0=1

Write your solution here

Upload a source file...