|
| 1 | +.. role:: raw-html-m2r(raw) |
| 2 | + :format: html |
| 3 | + |
| 4 | +Plru |
| 5 | +========================== |
| 6 | + |
| 7 | +Introduction |
| 8 | +-------------------- |
| 9 | +- Pseudo least recently used combinatorial logic |
| 10 | +- io.context.state need to be handled externaly. |
| 11 | +- When you want to specify a access to a entry, you can use the io.update interface to get the new state value. |
| 12 | +- plru.io.evict.id tells you the id of the next block to be evicted |
| 13 | +- plru.io.update.id lets you update what you recently used |
| 14 | + |
| 15 | + |
| 16 | +PLRU Code |
| 17 | + |
| 18 | +.. code-block:: scala |
| 19 | +
|
| 20 | + val io = new Bundle{ |
| 21 | + val context = new Bundle{ |
| 22 | + //user -> plru, specify the current state |
| 23 | + val state = Plru.State(entries) |
| 24 | + //user -> plru, allow to specify prefered entries to remove. each bit set mean : "i would prefer that way to not to be selected by PLRU" |
| 25 | + val valids = withEntriesValid generate Bits(entries bits) |
| 26 | + } |
| 27 | + val evict = new Bundle{ |
| 28 | + //PLRU -> user, Tells you the least recently used entry for the given context provided above |
| 29 | + val id = UInt(log2Up(entries) bits) |
| 30 | + } |
| 31 | + val update = new Bundle{ |
| 32 | + // user -> PLRU specify which entry the user want to mark as most recently used |
| 33 | + val id = UInt(log2Up(entries) bits) |
| 34 | + // PLRU -> user specfy what should then be the new value of the PLRU status |
| 35 | + val state = Plru.State(entries) |
| 36 | + } |
| 37 | + } |
| 38 | +
|
| 39 | +
|
| 40 | +Example usage in a cache |
| 41 | + |
| 42 | +.. code-block:: scala |
| 43 | +
|
| 44 | + val plru = new Area { |
| 45 | + // Define a Mem, to track the state of each set |
| 46 | + val ram = Mem.fill(nSets)(Plru.State(wayCount)) |
| 47 | + val write = ram.writePort |
| 48 | + val fromLoad, fromStore = cloneOf(write) |
| 49 | + write.valid := fromLoad.valid || fromStore.valid |
| 50 | + write.payload := fromLoad.valid.mux(fromLoad.payload, fromStore.payload) |
| 51 | + } |
| 52 | +
|
| 53 | +
|
| 54 | +Get the ID of the way to evict from |
| 55 | + |
| 56 | +.. code-block:: scala |
| 57 | +
|
| 58 | + val replacedWay = plru.io.evict.id |
| 59 | +
|
| 60 | +Update recently used way |
| 61 | + |
| 62 | +.. code-block:: scala |
| 63 | +
|
| 64 | + plru.update.id := refillWay |
| 65 | +
|
| 66 | +
|
| 67 | +
|
| 68 | +
|
0 commit comments