functional style on MuxBundle
This commit is contained in:
parent
f249da1803
commit
f7b1e23ead
@ -5,11 +5,7 @@ import Chisel._
|
|||||||
|
|
||||||
object MuxBundle {
|
object MuxBundle {
|
||||||
def apply[T <: Data] (default: T, mapping: Seq[(Bool, T)]): T = {
|
def apply[T <: Data] (default: T, mapping: Seq[(Bool, T)]): T = {
|
||||||
var res = default;
|
mapping.reverse.foldLeft(default)((b, a) => Mux(a._1, a._2, b))
|
||||||
for ((t, v) <- mapping.reverse){
|
|
||||||
res = Mux(t, v, res);
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user