sort out weirdness in FPDIVBasePipe initialisation
[ieee754fpu.git] / src / ieee754 / fpdiv / divstages.py
index b0c539f9805e94080c0713fd83f76fd6739101cc..1b41b9e79dc0cdb84a61822acd3319e66705576e 100644 (file)
@@ -12,67 +12,54 @@ from nmutil.singlepipe import (StageChain, SimpleHandshake)
 from ieee754.fpcommon.fpbase import FPState
 from ieee754.fpcommon.denorm import FPSCData
 from ieee754.fpcommon.postcalc import FPAddStage1Data
+from ieee754.div_rem_sqrt_rsqrt.div_pipe import DivPipeInterstageData
 
 # TODO: write these
 from .div0 import FPDivStage0Mod
-from .div1 import FPDivStage1Mod # can be dropped entirely
-                                 # (replaced with DivPipeCalculateStage)
-                                 # note, yes, DivPipeCalculateStage *NOT*
-                                 # DivPipeCoreCalculateStage
 from .div2 import FPDivStage2Mod
 from .div0 import FPDivStage0Data
 
 
 class FPDivStagesSetup(FPState, SimpleHandshake):
 
-    def __init__(self, width, pspec, n_stages):
+    def __init__(self, pspec, n_stages, stage_offs):
         FPState.__init__(self, "divsetup")
-        self.width = width
         self.pspec = pspec
         self.n_stages = n_stages # number of combinatorial stages
+        self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
         SimpleHandshake.__init__(self, self) # pipeline is its own stage
         self.m1o = self.ospec()
 
     def ispec(self):
         # REQUIRED.  do NOT change.
-        return FPSCData(self.width, self.pspec, False) # from denorm
+        return FPSCData(self.pspec, False) # from denorm
 
     def ospec(self):
-        # XXX TODO: replace with "intermediary" (DivPipeInterstageData)
-        return FPDivStage0Data(self.width, self.pspec) # DIV ospec (loop)
+        return DivPipeInterstageData(self.pspec) # DIV ospec (loop)
 
     def setup(self, m, i):
         """ links module to inputs and outputs.
 
             note: this is a pure *combinatorial* module (StageChain).
             therefore each sub-module must also be combinatorial
-            (and not do too much: in particular, n_stages must be
-            reduced slightly when either self.end=True or self.begin=True)
         """
 
         divstages = []
 
         # Converts from FPSCData into DivPipeInputData
-        divstages.append(FPDivStage0Mod(self.width, self.pspec))
+        divstages.append(FPDivStage0Mod(self.pspec))
 
         # does 1 "convert" (actual processing) from DivPipeInputData
         # into "intermediate" output (DivPipeInterstageData)
-        # vvvvvvv
-        # FIXME divstages.append(DivPipeSetupStage(something))
-        # ^^^^^^^
+        divstages.append(DivPipeSetupStage(self.pspec))
 
         # here is where the intermediary stages are added.
-        # n_stages is adjusted (in pipeline.py), reduced to take
-        # into account the extra processing that self.begin and self.end
-        # will add.
+        # n_stages is adjusted (by pipeline.py), reduced to take
+        # into account extra processing that FPDivStage0Mod and DivPipeSetup
+        # might add.
         for count in range(self.n_stages): # number of combinatorial stages
-            # XXX: this can actually be entirely dropped...
-            divstages.append(FPDivStage1Mod(self.width, self.pspec))
-
-            # ... and replaced with this.
-            # vvvvvvv
-            #divstages.append(DivPipeCalculateStage(core_config, count))
-            # ^^^^^^^
+            idx = count + self.stage_offs
+            divstages.append(DivPipeCalculateStage(self.pspec, idx))
 
         chain = StageChain(divstages)
         chain.setup(m, i)
@@ -88,34 +75,29 @@ class FPDivStagesSetup(FPState, SimpleHandshake):
         m.next = "normalise_1"
 
 
-class FPDivStagesIntermediary(FPState, SimpleHandshake):
+class FPDivStagesIntermediate(FPState, SimpleHandshake):
 
-    def __init__(self, width, pspec, n_stages):
+    def __init__(self, pspec, n_stages, stage_offs):
         FPState.__init__(self, "divintermediate")
-        self.width = width
         self.pspec = pspec
         self.n_stages = n_stages # number of combinatorial stages
-        self.begin = begin # "begin" mode
-        self.end = end # "end" mode
+        self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
         SimpleHandshake.__init__(self, self) # pipeline is its own stage
         self.m1o = self.ospec()
 
     def ispec(self):
         # TODO - this is for FPDivStage1Mod
-        # XXX TODO: replace with "intermediary" (DivPipeInterstageData)
-        return FPDivStage0Data(self.width, self.pspec) # DIV ispec (loop)
+        return DivPipeInterstageData(self.pspec) # DIV ispec (loop)
 
     def ospec(self):
         # TODO - this is for FPDivStage1Mod
-        # XXX TODO: replace with "intermediary" (DivPipeInterstageData)
-        return FPDivStage0Data(self.width, self.pspec) # DIV ospec (loop)
+        return DivPipeInterstageData(self.pspec) # DIV ospec (loop)
 
     def setup(self, m, i):
         """ links module to inputs and outputs.
 
             note: this is a pure *combinatorial* module (StageChain).
             therefore each sub-module must also be combinatorial
-            (and not do too much)
         """
 
         divstages = []
@@ -125,13 +107,8 @@ class FPDivStagesIntermediary(FPState, SimpleHandshake):
         # into account the extra processing that self.begin and self.end
         # will add.
         for count in range(self.n_stages): # number of combinatorial stages
-            # XXX: this can actually be entirely dropped...
-            divstages.append(FPDivStage1Mod(self.width, self.pspec))
-
-            # ... and replaced with this.
-            # vvvvvvv
-            #divstages.append(DivPipeCalculateStage(core_config, count))
-            # ^^^^^^^
+            idx = count + self.stage_offs
+            divstages.append(DivPipeCalculateStage(self.pspec, idx))
 
         chain = StageChain(divstages)
         chain.setup(m, i)
@@ -149,28 +126,26 @@ class FPDivStagesIntermediary(FPState, SimpleHandshake):
 
 class FPDivStagesFinal(FPState, SimpleHandshake):
 
-    def __init__(self, width, pspec, n_stages):
+    def __init__(self, pspec, n_stages, stage_offs):
         FPState.__init__(self, "divfinal")
-        self.width = width
         self.pspec = pspec
         self.n_stages = n_stages # number of combinatorial stages
+        self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
         SimpleHandshake.__init__(self, self) # pipeline is its own stage
         self.m1o = self.ospec()
 
     def ispec(self):
-        # XXX TODO: replace with "intermediary" (DivPipeInterstageData?)
-        return FPDivStage0Data(self.width, self.pspec) # DIV ispec (loop)
+        return DivPipeInterstageData(self.pspec) # DIV ispec (loop)
 
     def ospec(self):
         # REQUIRED.  do NOT change.
-        return FPAddStage1Data(self.width, self.pspec) # to post-norm
+        return FPAddStage1Data(self.pspec) # to post-norm
 
     def setup(self, m, i):
         """ links module to inputs and outputs.
 
             note: this is a pure *combinatorial* module (StageChain).
             therefore each sub-module must also be combinatorial
-            (and not do too much)
         """
 
         # takes the DIV pipeline/chain data and munges it
@@ -183,23 +158,16 @@ class FPDivStagesFinal(FPState, SimpleHandshake):
         # into account the extra processing that self.begin and self.end
         # will add.
         for count in range(self.n_stages): # number of combinatorial stages
-            # XXX: this can actually be entirely dropped...
-            divstages.append(FPDivStage1Mod(self.width, self.pspec))
-
-            # ... and replaced with this.
-            # vvvvvvv
-            #divstages.append(DivPipeCalculateStage(core_config, count))
-            # ^^^^^^^
+            idx = count + self.stage_offs
+            divstages.append(DivPipeCalculateStage(pspec, idx))
 
         # does the final conversion from intermediary to output data
-        # vvvvvvv
-        # FIXME divstages.append(DivPipeFinalStage(something))
-        # ^^^^^^^
+        divstages.append(DivPipeFinalStage(pspec))
 
         # does conversion from DivPipeOutputData into
         # FPAddStage1Data format (bad name, TODO, doesn't matter),
         # so that post-normalisation and corrections can take over
-        divstages.append(FPDivStage2Mod(self.width, self.pspec))
+        divstages.append(FPDivStage2Mod(self.pspec))
 
         chain = StageChain(divstages)
         chain.setup(m, i)