RTL Design #14 · 2026-10-07 · Caches · Medium · about 15 min

An LRU tracker that forgets the oldest way

lru4 watches a 4-way cache set and reports which way to evict: the one that was used least recently.

  • A cycle with access = 1 uses way. That way becomes the most recently used; the other three keep their order relative to each other.
  • A cycle with access = 0 changes nothing.
  • lru is the least recently used way. It's registered: it reflects every access up to the previous cycle.
  • After reset the order is 3, 2, 1, 0 from most to least recently used, so lru is 0.

For example, after reset: using way 0 makes lru 1. Using way 3 next leaves lru at 1, because way 1 still hasn't been touched.

The current design gets the first few evictions right, then starts naming ways that were used a moment ago. Fix lru.sv.

Write and run your answer in the browser. The hidden tests check it, and it’s free.