diff options
| author | Andrew Waterman | 2015-07-29 00:23:59 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-07-29 00:23:59 -0700 |
| commit | 75f54a3f873f168a7811da88ba1d3d59c9844659 (patch) | |
| tree | 9f6d0aa9c3e61871d821a048289013764bb045fe /src/main/scala/Chisel/utils.scala | |
| parent | d034f40b02e40d8a919596c7554bc0662db62001 (diff) | |
Use Seq, not Iterable, when traversal order matters
Diffstat (limited to 'src/main/scala/Chisel/utils.scala')
| -rw-r--r-- | src/main/scala/Chisel/utils.scala | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/main/scala/Chisel/utils.scala b/src/main/scala/Chisel/utils.scala index 7f9811fd..c2e88bd2 100644 --- a/src/main/scala/Chisel/utils.scala +++ b/src/main/scala/Chisel/utils.scala @@ -84,18 +84,16 @@ object RegEnable */ object Mux1H { - def apply[T <: Data](sel: Iterable[Bool], in: Iterable[T]): T = { - if (in.tail.isEmpty) in.head + def apply[T <: Data](sel: Seq[Bool], in: Seq[T]): T = + apply(sel zip in) + def apply[T <: Data](in: Iterable[(Bool, T)]): T = { + if (in.tail.isEmpty) in.head._2 else { - val masked = (sel, in).zipped map ((s, i) => Mux(s, i.toBits, Bits(0))) - in.head.fromBits(masked.reduceLeft(_|_)) + val masked = in map {case (s, i) => Mux(s, i.toBits, Bits(0))} + in.head._2.fromBits(masked.reduceLeft(_|_)) } } - def apply[T <: Data](in: Iterable[(Bool, T)]): T = { - val (sel, data) = in.unzip - apply(sel, data) - } - def apply[T <: Data](sel: Bits, in: Iterable[T]): T = + def apply[T <: Data](sel: Bits, in: Seq[T]): T = apply((0 until in.size).map(sel(_)), in) def apply(sel: Bits, in: Bits): Bool = (sel & in).orR } @@ -107,15 +105,15 @@ object Mux1H */ object PriorityMux { - def apply[T <: Bits](in: Iterable[(Bool, T)]): T = { + def apply[T <: Bits](in: Seq[(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: 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) + 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) } object unless { |
