switch to exact version of cython
[ieee754fpu.git] / src / ieee754 / fpmul / align.py
index 507e21a45ec0100af8e28e5dcc1276e5505c3245..53ffeb3f73833929e3892add3e9bad014286d0b6 100644 (file)
@@ -4,15 +4,15 @@ from nmigen import Module, Signal, Cat, Mux
 from nmigen.cli import main, verilog
 from math import log
 
-from nmutil.pipemodbase import FPModBase
+from nmutil.pipemodbase import PipeModBase
 from ieee754.fpcommon.fpbase import FPNumBase
 from ieee754.fpcommon.getop import FPPipeContext
 from ieee754.fpcommon.msbhigh import FPMSBHigh
 from ieee754.fpcommon.denorm import FPSCData
-from ieee754.fpcommon.postcalc import FPAddStage1Data
+from ieee754.fpcommon.postcalc import FPPostCalcData
 
 
-class FPAlignModSingle(FPModBase):
+class FPAlignModSingle(PipeModBase):
 
     def __init__(self, pspec, e_extra=False):
         self.e_extra = e_extra
@@ -36,6 +36,10 @@ class FPAlignModSingle(FPModBase):
         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(FPModBase):
         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(FPModBase):
         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)