forked from chipsalliance/rocket-chip
-
Notifications
You must be signed in to change notification settings - Fork 1
Chisel tips&tricks
erling edited this page Sep 23, 2019
·
7 revisions
To prevent the FIRRTL compiler to optimize your structures away wrap them in dontTouch()'s
object WrapInc
{
// "n" is the number of increments, so we wrap at n-1.
def apply(value: UInt, n: Int): UInt = {
if (isPow2(n)) {
(value + 1.U)(log2Ceil(n)-1,0)
} else {
val wrap = (value === (n-1).U)
Mux(wrap, 0.U, value + 1.U)
}
}
}