Cache step by step

Type a sequence of addresses, choose what the cache is like and watch it work access by access: how each address is split, which line or set it falls into, which block leaves and whether each miss is compulsory, capacity or conflict. The miss rate, the total size and the AMAT come out on their own. It runs in your browser, on your phone too.

How to use it

  1. Type the byte addresses in accesses.txt, in decimal or hexadecimal (0x…), separated by spaces or commas. Put a W in front of writes (W32). Or pick an example: the exam-style questions from the cache topics, two clashing arrays, the spatial locality of an array or a mix of reads and writes.
  2. Choose the organisation (direct, 2-way, 4-way or fully associative), the number of lines and words per block, the replacement (LRU or FIFO) and the write policy.
  3. Press Step to move access by access, or Run to watch it all. At each step you see the address split into its fields with the maths, the cache state (valid bit, tag, block and, with write-back, the dirty bit) and why it was a hit or a miss.
  4. Below, the access-by-access evolution (the same table as in the exam), the results, the cache size, the AMAT with your hit time and miss penalty, and a comparison of the organisations with the same accesses.

How to read the table

Each column is an access (the address on top) and each row a line (or a way of a set). In coral, the block that has just come in on a miss; in green, the one that was already there (a hit). The type row says what each access was and the out row, the block that was evicted. With write-back, an asterisk marks dirty blocks.

The maths: block = address ÷ (4 · words per block), line (or set) = block mod lines (or sets) and tag = block ÷ lines (or sets). The size adds, per line, the valid bit, the tag and the data (and the dirty bit with write-back). AMAT = hit time + miss rate × miss penalty.

The rules it follows

  • Byte addresses and 4-byte words, as in the course notes.
  • Within a set, the new block takes the first free way or its victim’s. LRU evicts the one unused the longest; FIFO, the first to arrive.
  • A miss is compulsory if the block had never been in; capacity if a fully associative cache of the same size would also miss; conflict otherwise.
  • Write-through without write-allocate: a write miss does not bring the block in. Write-back with write-allocate: it brings it in, marks it dirty and writes it to memory when it leaves.

For the exam

The cache question in the exam gives a cache and a sequence of addresses and asks for the table with every hit and miss type, the miss rate and the size. Do the table on paper and compare it with the simulator’s; the challenge below gives you new sequences. The theory is in the direct-mapped cache and associative cache topics.