Add proof for using the greater than combiner to do equals as well
[ieee754fpu.git] / src / ieee754 / part_cmp / experiments / gt_combiner.py
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
4
5
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
13 # is true
14 class GTCombiner(Elaboratable):
15 def __init__(self, width):
16 self.width = 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)
22
23 def elaborate(self, platform):
24 m = Module()
25 comb = m.d.comb
26
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()
30
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)
36
37 comb += self.outputs[0].eq(previnput)
38
39 return m
40
41 def ports(self):
42 return [self.eqs, self.gts, self.gates, self.outputs]