Home › Practice › RTL Design › Which way to evict?
Which way to evict?
EasyRTLsequentialarchitecture
A cache set has four slots (ways) for memory blocks. When all four are full and a new block arrives, one old block must be thrown out. Which one?
Concept first. The best victim is the least recently used way (LRU), but tracking the exact order of four ways needs extra state and a lot of update logic. Tree pseudo-LRU is a cheap approximation that uses only 3 bits arranged as a small binary tree. The root bit says which half to evict from (ways 0-1 or ways 2-3). One leaf bit per half says which of the two ways inside that half. Every time a way is used, the bits along its path are set to point away from it, so recently used ways are protected. Draw the tree, use way 1, then way 2, and follow the arrows to see who becomes the victim.
What to build.
- Ports:
clk, rst, access, way[1:0]; outputvictim[1:0]. - State bits:
b0(which half: 0 means ways 0-1, 1 means ways 2-3),b1(which way inside ways 0-1: 0 means way 0, 1 means way 1),b2(which way inside ways 2-3: 0 means way 2, 1 means way 3). All are 0 on reset (synchronous, active-highrst). - On a rising edge with
access = 1: ifwayis 0 or 1, setb0 = 1(point away, to ways 2-3) andb1 = ~way[0]. Ifwayis 2 or 3, setb0 = 0andb2 = ~way[0]. Bits not named stay unchanged. victimfollows the state: ifb0is 1 the victim is in ways 2-3 and its low bit isb2; otherwise it is in ways 0-1 and its low bit isb1.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.