tidyup, use FPModBaseChain and FPModBase
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 31 Jul 2019 12:13:11 +0000 (13:13 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Wed, 31 Jul 2019 12:13:11 +0000 (13:13 +0100)
src/ieee754/fpcommon/modbase.py
src/ieee754/fpdiv/divstages.py

index 1b338747350de6ab52c6c947024a9f690c75594c..b8bd1a91006dd82827f12c4a8fc65c1692474ca5 100644 (file)
@@ -24,6 +24,10 @@ class FPModBase(Elaboratable):
 
 class FPModBaseChain(DynamicPipe):
     """FPModBaseChain: common code between stage-chained pipes
+
+    Links a set of combinatorial modules (get_chain) together
+    and uses pspec.pipekls to dynamically select the pipeline type
+    Also conforms to the Pipeline Stage API
     """
     def __init__(self, pspec):
         self.pspec = pspec
index 81f9f3118f70963d54e8179300279a40995ef296..c26a74a005c985779471b772ad3631065910acfa 100644 (file)
@@ -4,42 +4,25 @@ Relevant bugreport: http://bugs.libre-riscv.org/show_bug.cgi?id=99
 
 """
 
-from nmigen import Module
-from nmigen.cli import main, verilog
-
-from nmutil.singlepipe import StageChain
-
-from ieee754.pipeline import DynamicPipe
-from ieee754.fpcommon.denorm import FPSCData
-from ieee754.fpcommon.postcalc import FPAddStage1Data
+from ieee754.fpcommon.modbase import FPModBaseChain
 from ieee754.div_rem_sqrt_rsqrt.div_pipe import (DivPipeInterstageData,
                                                  DivPipeSetupStage,
                                                  DivPipeCalculateStage,
                                                  DivPipeFinalStage,
                                                 )
+from ieee754.fpdiv.div0 import FPDivStage0Mod
+from ieee754.fpdiv.div2 import FPDivStage2Mod
 
-# TODO: write these
-from .div0 import FPDivStage0Mod
-from .div2 import FPDivStage2Mod
 
-
-class FPDivStagesSetup(DynamicPipe):
+class FPDivStagesSetup(FPModBaseChain):
 
     def __init__(self, pspec, n_stages, stage_offs):
-        self.pspec = pspec
         self.n_stages = n_stages # number of combinatorial stages
         self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
         super().__init__(pspec)
 
-    def ispec(self):
-        # REQUIRED.  do NOT change.
-        return FPSCData(self.pspec, False) # from denorm
-
-    def ospec(self):
-        return DivPipeInterstageData(self.pspec) # DIV ospec (loop)
-
-    def setup(self, m, i):
-        """ links module to inputs and outputs.
+    def get_chain(self):
+        """ gets module chain
 
             note: this is a pure *combinatorial* module (StageChain).
             therefore each sub-module must also be combinatorial
@@ -62,34 +45,18 @@ class FPDivStagesSetup(DynamicPipe):
             idx = count + self.stage_offs
             divstages.append(DivPipeCalculateStage(self.pspec, idx))
 
-        chain = StageChain(divstages)
-        chain.setup(m, i)
-
-        # output is from the last pipe stage
-        self.o = divstages[-1].o
+        return divstages
 
-    def process(self, i):
-        return self.o
 
-
-class FPDivStagesIntermediate(DynamicPipe):
+class FPDivStagesIntermediate(FPModBaseChain):
 
     def __init__(self, pspec, n_stages, stage_offs):
-        self.pspec = pspec
         self.n_stages = n_stages # number of combinatorial stages
         self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
         super().__init__(pspec)
 
-    def ispec(self):
-        # TODO - this is for FPDivStage1Mod
-        return DivPipeInterstageData(self.pspec) # DIV ispec (loop)
-
-    def ospec(self):
-        # TODO - this is for FPDivStage1Mod
-        return DivPipeInterstageData(self.pspec) # DIV ospec (loop)
-
-    def setup(self, m, i):
-        """ links module to inputs and outputs.
+    def get_chain(self):
+        """ gets module chain
 
             note: this is a pure *combinatorial* module (StageChain).
             therefore each sub-module must also be combinatorial
@@ -105,33 +72,18 @@ class FPDivStagesIntermediate(DynamicPipe):
             idx = count + self.stage_offs
             divstages.append(DivPipeCalculateStage(self.pspec, idx))
 
-        chain = StageChain(divstages)
-        chain.setup(m, i)
-
-        # output is from the last pipe stage
-        self.o = divstages[-1].o
+        return divstages
 
-    def process(self, i):
-        return self.o
 
-
-class FPDivStagesFinal(DynamicPipe):
+class FPDivStagesFinal(FPModBaseChain):
 
     def __init__(self, pspec, n_stages, stage_offs):
-        self.pspec = pspec
         self.n_stages = n_stages # number of combinatorial stages
         self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
         super().__init__(pspec)
 
-    def ispec(self):
-        return DivPipeInterstageData(self.pspec) # DIV ispec (loop)
-
-    def ospec(self):
-        # REQUIRED.  do NOT change.
-        return FPAddStage1Data(self.pspec) # to post-norm
-
-    def setup(self, m, i):
-        """ links module to inputs and outputs.
+    def get_chain(self):
+        """ gets module chain
 
             note: this is a pure *combinatorial* module (StageChain).
             therefore each sub-module must also be combinatorial
@@ -158,11 +110,4 @@ class FPDivStagesFinal(DynamicPipe):
         # so that post-normalisation and corrections can take over
         divstages.append(FPDivStage2Mod(self.pspec))
 
-        chain = StageChain(divstages)
-        chain.setup(m, i)
-
-        # output is from the last pipe stage
-        self.o = divstages[-1].o
-
-    def process(self, i):
-        return self.o
+        return divstages