summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAndrew Waterman2016-01-25 15:35:03 -0800
committerAndrew Waterman2016-01-25 15:35:03 -0800
commit9017ec37d0eb7bb3bd10ed7863c0706ff1020cd9 (patch)
tree3cf9071891268ca30c6d5e0cbc83fa120ecb418d /src/main
parentf856d44b1f7c00ecee0b13021b4723c89debd250 (diff)
Emit FIRRTL muxes for aggregates
Diffstat (limited to 'src/main')
-rw-r--r--src/main/scala/Chisel/Bits.scala14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/main/scala/Chisel/Bits.scala b/src/main/scala/Chisel/Bits.scala
index 739e6c1b..fbc1586f 100644
--- a/src/main/scala/Chisel/Bits.scala
+++ b/src/main/scala/Chisel/Bits.scala
@@ -527,24 +527,20 @@ object Mux {
case (c: UInt, a: Bool) => doMux(cond, c, a << 0).asInstanceOf[T]
case (c: Bool, a: UInt) => doMux(cond, c << 0, a).asInstanceOf[T]
case (c: Bits, a: Bits) => doMux(cond, c, a).asInstanceOf[T]
- // FIRRTL doesn't support Mux for aggregates, so use a when instead
- case _ => doWhen(cond, con, alt)
+ case _ => doAggregateMux(cond, con, alt)
}
- private def doMux[T <: Bits](cond: Bool, con: T, alt: T): T = {
+ private def doMux[T <: Data](cond: Bool, con: T, alt: T): T = {
require(con.getClass == alt.getClass, s"can't Mux between ${con.getClass} and ${alt.getClass}")
val d = alt.cloneTypeWidth(con.width max alt.width)
pushOp(DefPrim(d, MultiplexOp, cond.ref, con.ref, alt.ref))
}
- // This returns an lvalue, which it most definitely should not
- private def doWhen[T <: Data](cond: Bool, con: T, alt: T): T = {
+
+ private def doAggregateMux[T <: Data](cond: Bool, con: T, alt: T): T = {
require(con.getClass == alt.getClass, s"can't Mux between ${con.getClass} and ${alt.getClass}")
for ((c, a) <- con.flatten zip alt.flatten)
require(c.width == a.width, "can't Mux between aggregates of different width")
-
- val res = Wire(t = alt.cloneTypeWidth(con.width max alt.width), init = alt)
- when (cond) { res := con }
- res
+ doMux(cond, con, alt)
}
}