1 from nmigen
import Signal
, Module
, Elaboratable
, Mux
2 from ieee754
.part_mul_add
.partpoints
import PartitionPoints
3 from ieee754
.part_cmp
.experiments
.eq_combiner
import Twomux
6 # This is similar to EQCombiner, except that for a greater than
7 # comparison, it needs to deal with both the greater than and equals
8 # signals from each partition. The signals are combined using a
9 # cascaded AND/OR to give the following effect:
10 # When a partition is open, the output is set if either the current
11 # partition's greater than flag is set, or the current partition's
12 # equal flag is set AND the previous partition's greater than output
14 class GTCombiner(Elaboratable
):
15 def __init__(self
, width
):
17 self
.mux_input
= Signal(reset_less
=True) # right hand side mux input
18 self
.eqs
= Signal(width
, reset_less
=True) # the flags for EQ
19 self
.gts
= Signal(width
, reset_less
=True) # the flags for GT
20 self
.gates
= Signal(width
-1, reset_less
=True)
21 self
.outputs
= Signal(width
, reset_less
=True)
23 def elaborate(self
, platform
):
27 previnput
= self
.gts
[-1] |
(self
.eqs
[-1] & self
.mux_input
)
28 for i
in range(self
.width
-1, 0, -1): # counts down from width-1 to 1
29 m
.submodules
["mux{}".format(i
)] = mux
= Twomux()
31 comb
+= mux
.ina
.eq(previnput
)
32 comb
+= mux
.inb
.eq(self
.mux_input
)
33 comb
+= mux
.sel
.eq(self
.gates
[i
-1])
34 comb
+= self
.outputs
[i
].eq(mux
.outb
)
35 previnput
= self
.gts
[i
-1] |
(self
.eqs
[i
-1] & mux
.outa
)
37 comb
+= self
.outputs
[0].eq(previnput
)
42 return [self
.eqs
, self
.gts
, self
.gates
, self
.outputs
]