Skip to content

Commit

Permalink
Make PriorityEncoder interface more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
aswaterman committed Dec 9, 2013
1 parent 7c5733d commit 22ab4ef
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/scala/ChiselUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -558,23 +558,23 @@ object Pipe
*/
object PriorityMux
{
def apply[T <: Bits](in: Seq[(Bool, T)]): T = {
def apply[T <: Bits](in: Iterable[(Bool, T)]): T = {
if (in.size == 1) {
in.head._2
} else {
Mux(in.head._1, in.head._2, apply(in.tail))
}
}
def apply[T <: Bits](sel: Seq[Bool], in: Seq[T]): T = apply(sel zip in)
def apply[T <: Bits](sel: Bits, in: Seq[T]): T = apply((0 until in.size).map(sel(_)), in)
def apply[T <: Bits](sel: Iterable[Bool], in: Iterable[T]): T = apply(sel zip in)
def apply[T <: Bits](sel: Bits, in: Iterable[T]): T = apply((0 until in.size).map(sel(_)), in)
}

/** Returns the bit position of the trailing 1 in the input vector
with the assumption that multiple bits of the input bit vector can be set
*/
object PriorityEncoder
{
def apply(in: Seq[Bool]): UInt = PriorityMux(in, (0 until in.size).map(UInt(_)))
def apply(in: Iterable[Bool]): UInt = PriorityMux(in, (0 until in.size).map(UInt(_)))
def apply(in: Bits): UInt = apply((0 until in.getWidth).map(in(_)))
}

Expand Down

0 comments on commit 22ab4ef

Please sign in to comment.