cleanup on msb1 and align: use Mux, remove out_do_z
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 25 Aug 2019 08:50:47 +0000 (09:50 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 25 Aug 2019 08:50:47 +0000 (09:50 +0100)
src/ieee754/fpmul/align.py
src/ieee754/fpmul/mul0.py

index f2559c2b2787a4e25470516dd6df71fb8fd4c004..53ffeb3f73833929e3892add3e9bad014286d0b6 100644 (file)
@@ -36,6 +36,10 @@ class FPAlignModSingle(PipeModBase):
         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))
@@ -48,9 +52,9 @@ class FPAlignModSingle(PipeModBase):
         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)
@@ -59,17 +63,14 @@ class FPAlignModSingle(PipeModBase):
         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)
index 97821a65a182aa80cc972cf29fd1768c3f51d9a4..6b00762a33664eb508c8081b09aff7f5325cac2a 100644 (file)
@@ -32,16 +32,14 @@ class FPMulStage0Mod(PipeModBase):
         # 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)