Commit 1a518fb8 authored by Yuxiao Mao's avatar Yuxiao Mao
Browse files

RegmapUtil: rewrite countEvent with when-otherwise insteed of mux

parent cc0664b9
......@@ -13,11 +13,15 @@ class RegmapUtilCountEvent(regName: String)(implicit mp: MatanaParams) {
val in = Wire(new RegmapUtilCountEventIn())
val countEvent = RegInit(0.U(mp.counterWidth.W)).suggestName("count" + regName)
countEvent := Mux(in.reset,
0.U,
Mux(in.decrement && in.event,
Mux(countEvent >= 1.U, countEvent - in.event, 0.U), // decrement do not below 0
countEvent + in.event))
when (in.reset) {
countEvent := 0.U
} .otherwise {
when (in.decrement && in.event) {
countEvent := Mux(countEvent >= 1.U, countEvent - in.event, 0.U), // decrement should not below 0
} .otherwise {
countEvent := countEvent + in.event // TODO? increment should not overflow
}
}
// max: track count evolution when decrement exists
val maxEvent = RegInit(0.U(mp.counterWidth.W)).suggestName("max" + regName)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment