1
0

Merge pull request #314 from ucb-bar/widecounter-reset

Allow WideCounter to not be reset
This commit is contained in:
Andrew Waterman 2016-09-18 22:37:40 -07:00 committed by GitHub
commit f0debb89e4

View File

@ -127,16 +127,16 @@ object Split
} }
// a counter that clock gates most of its MSBs using the LSB carry-out // a counter that clock gates most of its MSBs using the LSB carry-out
case class WideCounter(width: Int, inc: UInt = UInt(1)) case class WideCounter(width: Int, inc: UInt = UInt(1), reset: Boolean = true)
{ {
private val isWide = width > 2*inc.getWidth private val isWide = width > 2*inc.getWidth
private val smallWidth = if (isWide) inc.getWidth max log2Up(width) else width private val smallWidth = if (isWide) inc.getWidth max log2Up(width) else width
private val small = Reg(init=UInt(0, smallWidth)) private val small = if (reset) Reg(init=UInt(0, smallWidth)) else Reg(UInt(width = smallWidth))
private val nextSmall = small +& inc private val nextSmall = small +& inc
small := nextSmall small := nextSmall
private val large = if (isWide) { private val large = if (isWide) {
val r = Reg(init=UInt(0, width - smallWidth)) val r = if (reset) Reg(init=UInt(0, width - smallWidth)) else Reg(UInt(width = width - smallWidth))
when (nextSmall(smallWidth)) { r := r + UInt(1) } when (nextSmall(smallWidth)) { r := r + UInt(1) }
r r
} else null } else null