CircularBufferMulti replace when with Mux
'when' replaced with 'Mux' in CircularBufferMulti in order to make the
code safer (all states are defined) and more concise. In this case
hardware generated should be identical.
Change-Id: I3df562801341274778443b80ca00c57c43a0d69d
diff --git a/hdl/chisel/src/common/CircularBufferMulti.scala b/hdl/chisel/src/common/CircularBufferMulti.scala
index 5dbbef2..81ef625 100644
--- a/hdl/chisel/src/common/CircularBufferMulti.scala
+++ b/hdl/chisel/src/common/CircularBufferMulti.scala
@@ -63,17 +63,10 @@
buffer(i) := Mux(rotatedInput(i).valid, rotatedInput(i).bits, buffer(i))
}
-
var nEnqueued = RegInit(0.U(io.nEnqueued.getWidth.W))
- when(io.flush) {
- enqPtr := 0.U
- deqPtr := 0.U
- nEnqueued := 0.U
- } .otherwise {
- enqPtr := enqPtr + io.enqValid
- deqPtr := deqPtr + io.deqReady
- nEnqueued := nEnqueued + io.enqValid - io.deqReady
- }
+ enqPtr := Mux(io.flush, 0.U, enqPtr + io.enqValid)
+ deqPtr := Mux(io.flush, 0.U, deqPtr + io.deqReady)
+ nEnqueued := Mux(io.flush, 0.U, nEnqueued + io.enqValid - io.deqReady)
io.nEnqueued := nEnqueued
io.nSpace := capacity.U - nEnqueued
@@ -82,4 +75,4 @@
for (i <- 0 until n) {
io.dataOut(i) := outputBufferView(i)
}
-}
\ No newline at end of file
+}