06046fa2a182d1cfbcb3b1f73b4c2f1c165f763d
1 from nmigen
import Signal
, Module
, Elaboratable
, Mux
2 from ieee754
.part_mul_add
.partpoints
import PartitionPoints
4 class Combiner(Elaboratable
):
11 def elaborate(self
, platform
):
15 comb
+= self
.outa
.eq(Mux(self
.sel
, self
.inb
, self
.ina
))
16 comb
+= self
.outb
.eq(self
.sel
& self
.ina
)
20 # This is similar to EQCombiner, except that for a greater than
21 # comparison, it needs to deal with both the greater than and equals
22 # signals from each partition. The signals are combined using a
23 # cascaded AND/OR to give the following effect:
24 # When a partition is open, the output is set if either the current
25 # partition's greater than flag is set, or the current partition's
26 # equal flag is set AND the previous partition's greater than output
28 class GTCombiner(Elaboratable
):
29 def __init__(self
, width
):
31 self
.mux_input
= Signal(reset_less
=True) # right hand side mux input
32 self
.eqs
= Signal(width
, reset_less
=True) # the flags for EQ
33 self
.gts
= Signal(width
, reset_less
=True) # the flags for GT
34 self
.gates
= Signal(width
-1, reset_less
=True)
35 self
.outputs
= Signal(width
, reset_less
=True)
37 def elaborate(self
, platform
):
41 previnput
= self
.gts
[-1] |
(self
.eqs
[-1] & self
.mux_input
)
42 for i
in range(self
.width
-1, 0, -1): # counts down from width-1 to 1
43 m
.submodules
["mux%d" % i
] = mux
= Combiner()
45 comb
+= mux
.ina
.eq(previnput
)
46 comb
+= mux
.inb
.eq(self
.mux_input
)
47 comb
+= mux
.sel
.eq(self
.gates
[i
-1])
48 comb
+= self
.outputs
[i
].eq(mux
.outb
)
49 previnput
= self
.gts
[i
-1] |
(self
.eqs
[i
-1] & mux
.outa
)
51 comb
+= self
.outputs
[0].eq(previnput
)
56 return [self
.eqs
, self
.gts
, self
.gates
, self
.outputs
]