summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Waterman2015-07-28 13:56:10 -0700
committerAndrew Waterman2015-07-28 13:56:10 -0700
commita2c0b84450e189807009e1a200e07e900f20844f (patch)
tree7ec8bb15a668c5d9c9e2fef1d288708d1a0cd733
parent344978a378e5297d43a4159f6ae6f81ab4eede6b (diff)
Simplify Cat
-rw-r--r--src/main/scala/Chisel/Core.scala31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala
index 22bb555c..508ae4cb 100644
--- a/src/main/scala/Chisel/Core.scala
+++ b/src/main/scala/Chisel/Core.scala
@@ -919,25 +919,20 @@ object Mux {
}
object Cat {
- def apply[T <: Bits](a: T, r: T*): T = apply(a :: r.toList)
- def apply[T <: Bits](r: Seq[T]): T = doCat(r)
- private def doCat[T <: Data](r: Seq[T]): T = {
- if (r.tail.isEmpty)
- r.head
+ def apply[T <: Bits](a: T, r: T*): UInt = apply(a :: r.toList)
+ def apply[T <: Bits](r: Seq[T]): UInt = {
+ if (r.tail.isEmpty) r.head.asUInt
else {
- val l = doCat(r.slice(0, r.length/2))
- val h = doCat(r.slice(r.length/2, r.length))
- val isConst = (l.isLit() && h.isLit())
- val w = if (isConst) l.getWidth + h.getWidth else if (l.getWidth >= 0 && h.getWidth >= 0) l.getWidth + h.getWidth else -1
- val d = l.cloneTypeWidth(w)
- if (isConst) {
- val c = (l.litValue() << h.getWidth) | h.litValue()
- // println("DO-CAT L = " + l.litValue() + " LW = " + l.getWidth + " H = " + h.litValue() + " -> " + c)
-
- d.setLitValue(ULit(c, w))
- } else
- pushCommand(DefPrim(d.cid, d.toType, ConcatOp, Array(l.ref, h.ref), NoLits))
- d
+ val left = apply(r.slice(0, r.length/2))
+ val right = apply(r.slice(r.length/2, r.length))
+ val w = left.sumWidth(right, 0)
+ if (left.isLit && right.isLit) {
+ UInt((left.litValue() << right.getWidth) | right.litValue(), w)
+ } else {
+ val d = UInt(width = w)
+ pushCommand(DefPrim(d.cid, d.toType, ConcatOp, Array(left.ref, right.ref), NoLits))
+ d
+ }
}
}
}