split out corrections to separate module
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 29 Mar 2019 11:49:37 +0000 (11:49 +0000)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Fri, 29 Mar 2019 11:49:37 +0000 (11:49 +0000)
src/add/fpcommon/corrections.py [new file with mode: 0644]
src/add/nmigen_add_experiment.py

diff --git a/src/add/fpcommon/corrections.py b/src/add/fpcommon/corrections.py
new file mode 100644 (file)
index 0000000..a79ddcc
--- /dev/null
@@ -0,0 +1,79 @@
+# IEEE Floating Point Adder (Single Precision)
+# Copyright (C) Jonathan P Dawson 2013
+# 2013-12-12
+
+from nmigen import Module, Signal, Cat, Mux, Array, Const
+from nmigen.lib.coding import PriorityEncoder
+from nmigen.cli import main, verilog
+from math import log
+
+from fpbase import FPNumIn, FPNumOut, FPOp, Overflow, FPBase, FPNumBase
+from fpbase import MultiShiftRMerge, Trigger
+from singlepipe import (ControlBase, StageChain, UnbufferedPipeline,
+                        PassThroughStage)
+from multipipe import CombMuxOutPipe
+from multipipe import PriorityCombMuxInPipe
+
+from fpbase import FPState, FPID
+from fpcommon.roundz import FPRoundData
+
+
+class FPCorrectionsMod:
+
+    def __init__(self, width, id_wid):
+        self.width = width
+        self.id_wid = id_wid
+        self.i = self.ispec()
+        self.out_z = self.ospec()
+
+    def ispec(self):
+        return FPRoundData(self.width, self.id_wid)
+
+    def ospec(self):
+        return FPRoundData(self.width, self.id_wid)
+
+    def process(self, i):
+        return self.out_z
+
+    def setup(self, m, i):
+        """ links module to inputs and outputs
+        """
+        m.submodules.corrections = self
+        m.d.comb += self.i.eq(i)
+
+    def elaborate(self, platform):
+        m = Module()
+        m.submodules.corr_in_z = self.i.z
+        m.submodules.corr_out_z = self.out_z.z
+        m.d.comb += self.out_z.eq(self.i) # copies mid, z, out_do_z
+        with m.If(~self.i.out_do_z):
+            with m.If(self.i.z.is_denormalised):
+                m.d.comb += self.out_z.z.e.eq(self.i.z.N127)
+        return m
+
+
+class FPCorrections(FPState):
+
+    def __init__(self, width, id_wid):
+        FPState.__init__(self, "corrections")
+        self.mod = FPCorrectionsMod(width)
+        self.out_z = self.ospec()
+
+    def ispec(self):
+        return self.mod.ispec()
+
+    def ospec(self):
+        return self.mod.ospec()
+
+    def setup(self, m, in_z):
+        """ links module to inputs and outputs
+        """
+        self.mod.setup(m, in_z)
+
+        m.d.sync += self.out_z.eq(self.mod.out_z)
+        m.d.sync += self.out_z.mid.eq(self.mod.o.mid)
+
+    def action(self, m):
+        m.next = "pack"
+
+
index bb3c9702382f76e422fbce3c4b6946aa1b8f0ddb..9eb5a4bd985bbfb016e36081fa16af5bf3538cb4 100644 (file)
@@ -21,6 +21,7 @@ from fpcommon.postcalc import FPAddStage1Data
 from fpcommon.postnormalise import (FPNorm1Data, FPNorm1ModSingle,
                             FPNorm1ModMulti, FPNorm1Single, FPNorm1Multi)
 from fpcommon.roundz import (FPRoundData, FPRoundMod, FPRound)
 from fpcommon.postnormalise import (FPNorm1Data, FPNorm1ModSingle,
                             FPNorm1ModMulti, FPNorm1Single, FPNorm1Multi)
 from fpcommon.roundz import (FPRoundData, FPRoundMod, FPRound)
+from fpcommon.corrections import (FPCorrectionsMod, FPCorrections)
 
 
 class FPAddSpecialCasesMod:
 
 
 class FPAddSpecialCasesMod:
@@ -672,65 +673,6 @@ class FPNormToPack(FPState, UnbufferedPipeline):
         m.next = "pack_put_z"
 
 
         m.next = "pack_put_z"
 
 
-class FPCorrectionsMod:
-
-    def __init__(self, width, id_wid):
-        self.width = width
-        self.id_wid = id_wid
-        self.i = self.ispec()
-        self.out_z = self.ospec()
-
-    def ispec(self):
-        return FPRoundData(self.width, self.id_wid)
-
-    def ospec(self):
-        return FPRoundData(self.width, self.id_wid)
-
-    def process(self, i):
-        return self.out_z
-
-    def setup(self, m, i):
-        """ links module to inputs and outputs
-        """
-        m.submodules.corrections = self
-        m.d.comb += self.i.eq(i)
-
-    def elaborate(self, platform):
-        m = Module()
-        m.submodules.corr_in_z = self.i.z
-        m.submodules.corr_out_z = self.out_z.z
-        m.d.comb += self.out_z.eq(self.i) # copies mid, z, out_do_z
-        with m.If(~self.i.out_do_z):
-            with m.If(self.i.z.is_denormalised):
-                m.d.comb += self.out_z.z.e.eq(self.i.z.N127)
-        return m
-
-
-class FPCorrections(FPState):
-
-    def __init__(self, width, id_wid):
-        FPState.__init__(self, "corrections")
-        self.mod = FPCorrectionsMod(width)
-        self.out_z = self.ospec()
-
-    def ispec(self):
-        return self.mod.ispec()
-
-    def ospec(self):
-        return self.mod.ospec()
-
-    def setup(self, m, in_z):
-        """ links module to inputs and outputs
-        """
-        self.mod.setup(m, in_z)
-
-        m.d.sync += self.out_z.eq(self.mod.out_z)
-        m.d.sync += self.out_z.mid.eq(self.mod.o.mid)
-
-    def action(self, m):
-        m.next = "pack"
-
-
 class FPPackData:
 
     def __init__(self, width, id_wid):
 class FPPackData:
 
     def __init__(self, width, id_wid):