Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plru Docs #249

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
68 changes: 68 additions & 0 deletions source/SpinalHDL/Libraries/Misc/Plru.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.. role:: raw-html-m2r(raw)

Check warning on line 1 in source/SpinalHDL/Libraries/Misc/Plru.rst

View workflow job for this annotation

GitHub Actions / test

document isn't included in any toctree

Check warning on line 1 in source/SpinalHDL/Libraries/Misc/Plru.rst

View workflow job for this annotation

GitHub Actions / build

document isn't included in any toctree
:format: html

Plru
==========================

Introduction
--------------------
- Pseudo least recently used combinatorial logic
- io.context.state need to be handled externaly.
- When you want to specify a access to a entry, you can use the io.update interface to get the new state value.
- plru.io.evict.id tells you the id of the next block to be evicted
- plru.io.update.id lets you update what you recently used


PLRU Code

.. code-block:: scala

val io = new Bundle{
val context = new Bundle{
//user -> plru, specify the current state
val state = Plru.State(entries)
//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"
val valids = withEntriesValid generate Bits(entries bits)
}
val evict = new Bundle{
//PLRU -> user, Tells you the least recently used entry for the given context provided above
val id = UInt(log2Up(entries) bits)
}
val update = new Bundle{
// user -> PLRU specify which entry the user want to mark as most recently used
val id = UInt(log2Up(entries) bits)
// PLRU -> user specfy what should then be the new value of the PLRU status
val state = Plru.State(entries)
}
}


Example usage in a cache

.. code-block:: scala

val plru = new Area {
// Define a Mem, to track the state of each set
val ram = Mem.fill(nSets)(Plru.State(wayCount))
val write = ram.writePort
val fromLoad, fromStore = cloneOf(write)
write.valid := fromLoad.valid || fromStore.valid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say, this is when you have two pipeline (one load and one store) which want to update the PLRU state.
For the doc itself, we shouldn't have that complexity.

There is two example of PLRU usage you may haven't seen :

write.payload := fromLoad.valid.mux(fromLoad.payload, fromStore.payload)
}


Get the ID of the way to evict from

.. code-block:: scala

val replacedWay = plru.io.evict.id

Update recently used way

.. code-block:: scala

plru.update.id := refillWay




Loading