diff options
| author | Jack | 2022-01-12 04:27:19 +0000 |
|---|---|---|
| committer | Jack | 2022-01-12 04:27:19 +0000 |
| commit | 29df513e348cc809876893f650af8180f0190496 (patch) | |
| tree | 06daaea954b4e5af7113f06e4bdbb78b33515cb3 /src/main/scala/chisel3/util/Mux.scala | |
| parent | 5242ce90659decb9058ee75db56e5c188029fbf9 (diff) | |
| parent | 747d16311bdf185d2e98e452b14cb5d8ccca004c (diff) | |
Merge branch 'master' into 3.5-release
Diffstat (limited to 'src/main/scala/chisel3/util/Mux.scala')
| -rw-r--r-- | src/main/scala/chisel3/util/Mux.scala | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/main/scala/chisel3/util/Mux.scala b/src/main/scala/chisel3/util/Mux.scala index 946de461..e84b86a4 100644 --- a/src/main/scala/chisel3/util/Mux.scala +++ b/src/main/scala/chisel3/util/Mux.scala @@ -23,8 +23,8 @@ import chisel3._ */ object Mux1H { def apply[T <: Data](sel: Seq[Bool], in: Seq[T]): T = - apply(sel zip in) - def apply[T <: Data](in: Iterable[(Bool, T)]): T = SeqUtils.oneHotMux(in) + apply(sel.zip(in)) + def apply[T <: Data](in: Iterable[(Bool, T)]): T = SeqUtils.oneHotMux(in) def apply[T <: Data](sel: UInt, in: Seq[T]): T = apply((0 until in.size).map(sel(_)), in) def apply(sel: UInt, in: UInt): Bool = (sel & in).orR @@ -44,8 +44,8 @@ object Mux1H { * Returns the output of the Mux tree. */ object PriorityMux { - def apply[T <: Data](in: Seq[(Bool, T)]): T = SeqUtils.priorityMux(in) - def apply[T <: Data](sel: Seq[Bool], in: Seq[T]): T = apply(sel zip in) + def apply[T <: Data](in: Seq[(Bool, T)]): T = SeqUtils.priorityMux(in) + def apply[T <: Data](sel: Seq[Bool], in: Seq[T]): T = apply(sel.zip(in)) def apply[T <: Data](sel: Bits, in: Seq[T]): T = apply((0 until in.size).map(sel(_)), in) } @@ -57,12 +57,13 @@ object PriorityMux { * }}} */ object MuxLookup { + /** @param key a key to search for * @param default a default value if nothing is found * @param mapping a sequence to search of keys and values * @return the value found or the default if not */ - def apply[S <: UInt, T <: Data] (key: S, default: T, mapping: Seq[(S, T)]): T = { + def apply[S <: UInt, T <: Data](key: S, default: T, mapping: Seq[(S, T)]): T = { /* If the mapping is defined for all possible values of the key, then don't use the default value */ val (defaultx, mappingx) = key.widthOption match { case Some(width) => @@ -77,7 +78,7 @@ object MuxLookup { case None => (default, mapping) } - mappingx.foldLeft(defaultx){ case (d, (k, v)) => Mux(k === key, v, d) } + mappingx.foldLeft(defaultx) { case (d, (k, v)) => Mux(k === key, v, d) } } } @@ -89,12 +90,14 @@ object MuxLookup { * }}} */ object MuxCase { + /** @param default the default value if none are enabled * @param mapping a set of data values with associated enables - * @return the first value in mapping that is enabled */ - def apply[T <: Data] (default: T, mapping: Seq[(Bool, T)]): T = { + * @return the first value in mapping that is enabled + */ + def apply[T <: Data](default: T, mapping: Seq[(Bool, T)]): T = { var res = default - for ((t, v) <- mapping.reverse){ + for ((t, v) <- mapping.reverse) { res = Mux(t, v, res) } res |
