From 41d0d4cd075130cb6b4e41a7c7b6183830b5b9bc Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Wed, 7 Dec 2022 00:41:55 +0000 Subject: Make PriorityMux stack safe (backport #2854) (#2855) * Make PriorityMux stack safe (#2854) It used to be implemented with recursion, now it's implemented with a stack safe reverse and foldLeft. Also there were no tests for PriorityMux so I added one which helps prove the change is functionally correct. (cherry picked from commit 269ce472e9aa0c242fc028871a1fd5b045c82f83) # Conflicts: # src/test/scala/chiselTests/util/PipeSpec.scala * Resolve backport conflicts Co-authored-by: Jack Koenig Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>--- core/src/main/scala/chisel3/SeqUtils.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core/src') diff --git a/core/src/main/scala/chisel3/SeqUtils.scala b/core/src/main/scala/chisel3/SeqUtils.scala index b1136120..9d975349 100644 --- a/core/src/main/scala/chisel3/SeqUtils.scala +++ b/core/src/main/scala/chisel3/SeqUtils.scala @@ -64,7 +64,10 @@ private[chisel3] object SeqUtils { if (in.size == 1) { in.head._2 } else { - Mux(in.head._1, in.head._2, priorityMux(in.tail)) + val r = in.view.reverse + r.tail.foldLeft(r.head._2) { + case (alt, (sel, elt)) => Mux(sel, elt, alt) + } } } -- cgit v1.2.3