2012-02-26 02:09:26 +01:00
|
|
|
package rocket
|
2011-11-09 23:52:17 +01:00
|
|
|
|
|
|
|
import Chisel._
|
2012-01-14 00:55:56 +01:00
|
|
|
|
2012-10-12 01:48:51 +02:00
|
|
|
object Util
|
2011-12-09 09:42:43 +01:00
|
|
|
{
|
2012-10-12 01:48:51 +02:00
|
|
|
implicit def intToUFix(x: Int): UFix = UFix(x)
|
|
|
|
implicit def intToBoolean(x: Int): Boolean = if (x != 0) true else false
|
|
|
|
implicit def booleanToInt(x: Boolean): Int = if (x) 1 else 0
|
2012-11-17 15:48:44 +01:00
|
|
|
|
|
|
|
implicit def wcToUFix(c: WideCounter): UFix = c.value
|
|
|
|
}
|
|
|
|
|
2012-11-25 03:19:28 +01:00
|
|
|
object AVec
|
|
|
|
{
|
|
|
|
def apply[T <: Data](elts: Seq[T]): Vec[T] = {
|
|
|
|
require(elts.tail.forall(elts.head.getClass == _.getClass))
|
|
|
|
Vec(elts) { elts.head.clone }
|
|
|
|
}
|
|
|
|
def apply[T <: Data](elt0: T, elts: T*): Vec[T] = apply(elt0 :: elts.toList)
|
|
|
|
}
|
|
|
|
|
2012-11-17 15:48:44 +01:00
|
|
|
// a counter that clock gates most of its MSBs using the LSB carry-out
|
|
|
|
case class WideCounter(width: Int, inc: Bool = Bool(true))
|
|
|
|
{
|
|
|
|
private val isWide = width >= 4
|
|
|
|
private val smallWidth = if (isWide) log2Up(width) else width
|
|
|
|
private val small = Reg(resetVal = UFix(0, smallWidth))
|
|
|
|
private val nextSmall = small + UFix(1, smallWidth+1)
|
|
|
|
when (inc) { small := nextSmall(smallWidth-1,0) }
|
|
|
|
|
|
|
|
private val large = if (isWide) {
|
|
|
|
val r = Reg(resetVal = UFix(0, width - smallWidth))
|
|
|
|
when (inc && nextSmall(smallWidth)) { r := r + UFix(1) }
|
|
|
|
r
|
|
|
|
} else null
|
|
|
|
|
|
|
|
val value = Cat(large, small)
|
|
|
|
|
|
|
|
def := (x: UFix) = {
|
|
|
|
val w = x.getWidth
|
|
|
|
small := x(w.min(smallWidth)-1,0)
|
|
|
|
if (isWide) large := (if (w < smallWidth) UFix(0) else x(w.min(width)-1,smallWidth))
|
|
|
|
}
|
2011-12-09 09:42:43 +01:00
|
|
|
}
|