- m.d.comb += decrease_a.eq(insel_a.m_msbzero)
- m.d.comb += decrease_b.eq(insel_b.m_msbzero)
-
- # ok this is near-identical to FPNorm. TODO: modularise
- with m.If(~self.i.out_do_z):
- with m.If(decrease_a):
- # *sigh* not entirely obvious: count leading zeros (clz)
- # with a PriorityEncoder: to find from the MSB
- # we reverse the order of the bits.
- temp_a = Signal(mwid, reset_less=True)
- clz_a = Signal((len(insel_a.e), True), reset_less=True)
- m.d.comb += [
- pe_a.i.eq(insel_a.m[::-1]), # inverted
- clz_a.eq(pe_a.o), # count zeros from MSB down
- temp_a.eq((insel_a.m << clz_a)), # shift mantissa UP
- self.o.a.e.eq(insel_a.e - clz_a), # DECREASE exponent
- self.o.a.m.eq(temp_a),
- ]
-
- with m.If(decrease_b):
- # *sigh* not entirely obvious: count leading zeros (clz)
- # with a PriorityEncoder: to find from the MSB
- # we reverse the order of the bits.
- temp_b = Signal(mwid, reset_less=True)
- clz_b = Signal((len(insel_b.e), True), reset_less=True)
- m.d.comb += [
- pe_b.i.eq(insel_b.m[::-1]), # inverted
- clz_b.eq(pe_b.o), # count zeros from MSB down
- temp_b.eq((insel_b.m << clz_b)), # shift mantissa UP
- self.o.b.e.eq(insel_b.e - clz_b), # DECREASE exponent
- self.o.b.m.eq(temp_b),
- ]
-
- #m.d.comb += self.o.roundz.eq(of.roundz_out)
- #m.d.comb += self.o.ctx.eq(self.i.ctx)
- #m.d.comb += self.o.out_do_z.eq(self.i.out_do_z)
- #m.d.comb += self.o.oz.eq(self.i.oz)
+ comb += decrease_a.eq(insel_a.m_msbzero)
+ comb += decrease_b.eq(insel_b.m_msbzero)
+
+ # ok this is near-identical to FPNorm: use same class (FPMSBHigh)
+ comb += [
+ self.o.a.e.eq(Mux(decrease_a, msb_a.e_out, insel_a.e)),
+ self.o.a.m.eq(Mux(decrease_a, msb_a.m_out, insel_a.m))
+ ]
+ comb += [
+ self.o.b.e.eq(Mux(decrease_b, msb_b.e_out, insel_b.e)),
+ self.o.b.m.eq(Mux(decrease_b, msb_b.m_out, insel_b.m))
+ ]
+
+ comb += self.o.ctx.eq(self.i.ctx)
+ comb += self.o.out_do_z.eq(self.i.out_do_z)
+ comb += self.o.oz.eq(self.i.oz)