Skip to content

Commit

Permalink
Make Mux1H interface more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
aswaterman committed Nov 25, 2013
1 parent 76f5683 commit 8dc0a8e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/scala/ChiselUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ object UIntToOH
*/
object Mux1H
{
def apply[T <: Data](sel: Seq[Bool], in: Seq[T]): T = {
if (in.size == 1) in(0)
def apply[T <: Data](sel: Iterable[Bool], in: Iterable[T]): T = {
if (in.tail.isEmpty) in.head
else {
val masked = (sel, in).zipped map ((s, i) => Mux(s, i.toBits, Bits(0)))
in(0).fromBits(masked.reduceLeft(_|_))
in.head.fromBits(masked.reduceLeft(_|_))
}
}
def apply[T <: Data](in: Seq[(Bool, T)]): T = {
def apply[T <: Data](in: Iterable[(Bool, T)]): T = {
val (sel, data) = in.unzip
apply(sel, data)
}
def apply[T <: Data](sel: Bits, in: Seq[T]): T =
def apply[T <: Data](sel: Bits, in: Iterable[T]): T =
apply((0 until in.size).map(sel(_)), in)
}

Expand Down

0 comments on commit 8dc0a8e

Please sign in to comment.