insel_a.m.name = "i_a_m"
insel_b.m.name = "i_b_m"
+ # FPMSBHigh makes sure that the MSB is HI (duh).
+ # it does so (in a single cycle) by counting the leading zeros
+ # and performing a shift on the mantissa. the same count is then
+ # subtracted from the exponent.
mwid = self.o.z.m_width
msb_a = FPMSBHigh(mwid, len(insel_a.e))
msb_b = FPMSBHigh(mwid, len(insel_b.e))
comb += msb_b.m_in.eq(insel_b.m)
comb += msb_b.e_in.eq(insel_b.e)
- # copy input to output (overridden below)
- comb += self.o.a.eq(insel_a)
- comb += self.o.b.eq(insel_b)
+ # copy input to output sign
+ comb += self.o.a.s.eq(insel_a.s)
+ comb += self.o.b.s.eq(insel_b.s)
# normalisation increase/decrease conditions
decrease_a = Signal(reset_less=True)
comb += decrease_b.eq(insel_b.m_msbzero)
# ok this is near-identical to FPNorm: use same class (FPMSBHigh)
- with m.If(~self.i.out_do_z):
- with m.If(decrease_a):
- comb += [
- self.o.a.e.eq(msb_a.e_out),
- self.o.a.m.eq(msb_a.m_out),
- ]
- with m.If(decrease_b):
- comb += [
- self.o.b.e.eq(msb_b.e_out),
- self.o.b.m.eq(msb_b.m_out),
- ]
+ 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)
# store intermediate tests (and zero-extended mantissas)
am0 = Signal(len(self.i.a.m)+1, reset_less=True)
bm0 = Signal(len(self.i.b.m)+1, reset_less=True)
- comb += [
- am0.eq(Cat(self.i.a.m, 0)),
+ comb += [ am0.eq(Cat(self.i.a.m, 0)),
bm0.eq(Cat(self.i.b.m, 0))
- ]
- # same-sign (both negative or both positive) mul mantissas
- with m.If(~self.i.out_do_z):
- comb += [self.o.z.e.eq(self.i.a.e + self.i.b.e + 1),
- self.o.product.eq(am0 * bm0 * 4),
- self.o.z.s.eq(self.i.a.s ^ self.i.b.s)
]
+ # same-sign (both negative or both positive) mul mantissas
+ comb += [self.o.z.e.eq(self.i.a.e + self.i.b.e + 1),
+ self.o.product.eq(am0 * bm0 * 4),
+ self.o.z.s.eq(self.i.a.s ^ self.i.b.s)
+ ]
comb += self.o.oz.eq(self.i.oz)
comb += self.o.out_do_z.eq(self.i.out_do_z)