伪最近最少使用逻辑(Plru)
简介
伪最近最少使用组合逻辑
io.context.state 需由外部逻辑处理。
当需要指定对某表项的访问时,可通过 io.update 接口获取新的状态值。
plru.io.evict.id 指示下一个将被淘汰的块 ID
plru.io.update.id 用于更新最近使用的表项
伪LRU 代码
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)
}
}
缓存中使用示例
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
write.payload := fromLoad.valid.mux(fromLoad.payload, fromStore.payload)
}
获取待淘汰路(way)的ID
val replacedWay = plru.io.evict.id
更新最近使用的路
plru.update.id := refillWay