1 # gt_combiner returns results that are in the wrong order from how
2 # they need to be. Specifically, if the partition gates are open, the
3 # bits need to be reversed through the width of the partition. This
5 from nmigen
import Signal
, Module
, Elaboratable
, Mux
8 class ReorderResults(Elaboratable
):
9 def __init__(self
, width
):
11 self
.results_in
= Signal(width
, reset_less
=True)
12 self
.gates
= Signal(width
-1, reset_less
=True)
14 self
.output
= Signal(width
, reset_less
=True)
16 def elaborate(self
, platform
):
21 current_result
= self
.results_in
[-1]
23 for i
in range(width
-2, -1, -1): # counts down from width-1 to 0
25 comb
+= cur
.eq(current_result
)
26 comb
+= self
.output
[i
+1].eq(cur
)
27 current_result
= Mux(self
.gates
[i
], self
.results_in
[i
], cur
)
29 comb
+= self
.output
[0].eq(current_result
)