switch pspec from dict to PipelineSpec
authorJacob Lifshay <programmerjake@gmail.com>
Sun, 14 Jul 2019 07:13:39 +0000 (00:13 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Sun, 14 Jul 2019 07:13:39 +0000 (00:13 -0700)
20 files changed:
src/ieee754/div_rem_sqrt_rsqrt/div_pipe.py
src/ieee754/fcvt/pipeline.py
src/ieee754/fpadd/add0.py
src/ieee754/fpadd/align.py
src/ieee754/fpadd/pipeline.py
src/ieee754/fpadd/specialcases.py
src/ieee754/fpcommon/denorm.py
src/ieee754/fpcommon/getop.py
src/ieee754/fpcommon/pack.py
src/ieee754/fpcommon/postcalc.py
src/ieee754/fpcommon/postnormalise.py
src/ieee754/fpcommon/roundz.py
src/ieee754/fpdiv/div0.py
src/ieee754/fpdiv/pipeline.py
src/ieee754/fpdiv/specialcases.py
src/ieee754/fpmul/mul0.py
src/ieee754/fpmul/mul1.py
src/ieee754/fpmul/pipeline.py
src/ieee754/fpmul/specialcases.py
src/ieee754/pipeline.py [new file with mode: 0644]

index aa0b9f90b0ec2d3929c2b9812d6f915687d7c7af..7daac8a9824edb0592599d0fe7bd8ed59b07e68d 100644 (file)
@@ -39,7 +39,7 @@ class DivPipeBaseData:
     def __init__(self, config):
         """ Create a ``DivPipeBaseData`` instance. """
         self.config = config
-        width = config.pspec['width']
+        width = config.pspec.width
         self.out_do_z = Signal(reset_less=True)
         self.oz = Signal(width, reset_less=True)
 
index 378855a034f05d428cf14bc8412b2e2afbb7e3e4..4178629ead67e5ca63c6020e0fff86e8c7021ae1 100644 (file)
@@ -29,6 +29,7 @@ from nmutil.singlepipe import SimpleHandshake, StageChain
 
 from ieee754.fpcommon.fpbase import FPState, FPID
 from ieee754.fpcommon.getop import FPADDBaseData
+from ieee754.pipeline import PipelineSpec
 
 
 class FPCVTSpecialCasesMod(Elaboratable):
@@ -64,18 +65,18 @@ class FPCVTSpecialCasesMod(Elaboratable):
         #m.submodules.sc_out_z = self.o.z
 
         # decode: XXX really should move to separate stage
-        print ("in_width out", self.in_pspec['width'],
-                               self.out_pspec['width'])
-        a1 = FPNumBaseRecord(self.in_pspec['width'], False)
-        print ("a1", a1.width, a1.rmw, a1.e_width, a1.e_start, a1.e_end)
+        print("in_width out", self.in_pspec.width,
+              self.out_pspec.width)
+        a1 = FPNumBaseRecord(self.in_pspec.width, False)
+        print("a1", a1.width, a1.rmw, a1.e_width, a1.e_start, a1.e_end)
         m.submodules.sc_decode_a = a1 = FPNumDecode(None, a1)
         m.d.comb += a1.v.eq(self.i.a)
         z1 = self.o.z
-        print ("z1", z1.width, z1.rmw, z1.e_width, z1.e_start, z1.e_end)
+        print("z1", z1.width, z1.rmw, z1.e_width, z1.e_start, z1.e_end)
 
         me = a1.rmw
         ms = a1.rmw - self.o.z.rmw
-        print ("ms-me", ms, me)
+        print("ms-me", ms, me)
 
         # intermediaries
         exp_sub_n126 = Signal((a1.e_width, True), reset_less=True)
@@ -96,7 +97,7 @@ class FPCVTSpecialCasesMod(Elaboratable):
             m.d.comb += self.o.of.guard.eq(a1.m[ms-1])
             m.d.comb += self.o.of.round_bit.eq(a1.m[ms-2])
             m.d.comb += self.o.of.sticky.eq(a1.m[:ms-2].bool())
-            m.d.comb += self.o.of.m0.eq(a1.m[ms]) # bit of a1
+            m.d.comb += self.o.of.m0.eq(a1.m[ms])  # bit of a1
 
             m.d.comb += self.o.z.s.eq(a1.s)
             m.d.comb += self.o.z.e.eq(a1.e)
@@ -115,7 +116,7 @@ class FPCVTSpecialCasesMod(Elaboratable):
 
         # if a mantissa greater than 127, return inf
         with m.Elif(exp_gt127):
-            print ("inf", self.o.z.inf(a1.s))
+            print("inf", self.o.z.inf(a1.s))
             m.d.comb += self.o.z.inf(a1.s)
             m.d.comb += self.o.out_do_z.eq(1)
 
@@ -124,15 +125,15 @@ class FPCVTSpecialCasesMod(Elaboratable):
             m.d.comb += self.o.of.guard.eq(a1.m[ms-1])
             m.d.comb += self.o.of.round_bit.eq(a1.m[ms-2])
             m.d.comb += self.o.of.sticky.eq(a1.m[:ms-2].bool())
-            m.d.comb += self.o.of.m0.eq(a1.m[ms]) # bit of a1
+            m.d.comb += self.o.of.m0.eq(a1.m[ms])  # bit of a1
 
             # XXX TODO: this is basically duplicating FPRoundMod. hmmm...
-            print ("alen", a1.e_start, z1.fp.N126, N126)
-            print ("m1", self.o.z.rmw, a1.m[-self.o.z.rmw-1:])
+            print("alen", a1.e_start, z1.fp.N126, N126)
+            print("m1", self.o.z.rmw, a1.m[-self.o.z.rmw-1:])
             mo = Signal(self.o.z.m_width-1)
             m.d.comb += mo.eq(a1.m[ms:me])
             with m.If(self.o.of.roundz):
-                with m.If((~mo == 0)): # all 1s
+                with m.If((~mo == 0)):  # all 1s
                     m.d.comb += self.o.z.create(a1.s, a1.e+1, mo+1)
                 with m.Else():
                     m.d.comb += self.o.z.create(a1.s, a1.e, mo+1)
@@ -161,7 +162,7 @@ class FPCVTSpecialCases(FPState):
         """ links module to inputs and outputs
         """
         self.mod.setup(m, i, self.out_do_z)
-        m.d.sync += self.out_z.v.eq(self.mod.out_z.v) # only take the output
+        m.d.sync += self.out_z.v.eq(self.mod.out_z.v)  # only take the output
         m.d.sync += self.out_z.ctx.eq(self.mod.o.ctx)  # (and context)
 
     def action(self, m):
@@ -208,20 +209,14 @@ class FPCVTMuxInOut(ReservationStations):
 
         Fan-in and Fan-out are combinatorial.
     """
+
     def __init__(self, in_width, out_width, num_rows, op_wid=0):
         self.op_wid = op_wid
         self.id_wid = num_bits(in_width)
         self.out_id_wid = num_bits(out_width)
 
-        self.in_pspec = {}
-        self.in_pspec['id_wid'] = self.id_wid
-        self.in_pspec['op_wid'] = self.op_wid
-        self.in_pspec['width'] = in_width
-
-        self.out_pspec = {}
-        self.out_pspec['id_wid'] = self.out_id_wid
-        self.out_pspec['op_wid'] = op_wid
-        self.out_pspec['width'] = out_width
+        self.in_pspec = PipelineSpec(in_width, self.id_wid, self.op_wid)
+        self.out_pspec = PipelineSpec(out_width, self.out_id_wid, op_wid)
 
         self.alu = FPCVTBasePipe(self.in_pspec, self.out_pspec)
         ReservationStations.__init__(self, num_rows)
index e5a683daef6cde8bf56a3a13b0d059fd7ee50b79..c56b035d1a1c1136a2b929abd95282b67b01504a 100644 (file)
@@ -14,7 +14,7 @@ from ieee754.fpcommon.getop import FPPipeContext
 class FPAddStage0Data:
 
     def __init__(self, pspec):
-        width = pspec['width']
+        width = pspec.width
         self.z = FPNumBaseRecord(width, False)
         self.out_do_z = Signal(reset_less=True)
         self.oz = Signal(width, reset_less=True)
index 1db5affaccd27c76e79ad5dde81b2330484b278c..5ffe1a6215045dafaff8b850760c7e9ad5292d27 100644 (file)
@@ -16,7 +16,7 @@ from ieee754.fpcommon.getop import FPPipeContext
 class FPNumIn2Ops:
 
     def __init__(self, pspec):
-        width = pspec['width']
+        width = pspec.width
         self.a = FPNumBaseRecord(width)
         self.b = FPNumBaseRecord(width)
         self.z = FPNumBaseRecord(width, False)
@@ -136,7 +136,7 @@ class FPAddAlignSingleMod(Elaboratable):
         #m.submodules.align_out_b = self.o.b
 
         # temporary (muxed) input and output to be shifted
-        width = self.pspec['width']
+        width = self.pspec.width
         t_inp = FPNumBaseRecord(width)
         t_out = FPNumBaseRecord(width)
         espec = (len(self.i.a.e), True)
@@ -196,7 +196,7 @@ class FPAddAlignSingle(FPState):
 
     def __init__(self, pspec):
         FPState.__init__(self, "align")
-        width = pspec['width']
+        width = pspec.width
         self.mod = FPAddAlignSingleMod(pspec)
         self.out_a = FPNumIn(None, width)
         self.out_b = FPNumIn(None, width)
index bee4cf3f736b8c3547bb6ee818db05da3fc0839f..9a7820f70e3ed5e2d14ac3638e082cecd780dada 100644 (file)
@@ -16,7 +16,7 @@ from ieee754.fpcommon.pack import FPPackData
 from ieee754.fpcommon.normtopack import FPNormToPack
 from .specialcases import FPAddSpecialCasesDeNorm
 from .addstages import FPAddAlignSingleAdd
-
+from ieee754.pipeline import PipelineSpec
 
 
 class FPADDBasePipe(ControlBase):
@@ -46,10 +46,11 @@ class FPADDMuxInOut(ReservationStations):
 
         Fan-in and Fan-out are combinatorial.
     """
+
     def __init__(self, width, num_rows, op_wid=None):
         self.id_wid = num_bits(width)
         self.op_wid = op_wid
-        self.pspec = {'width': width, 'id_wid': self.id_wid, 'op_wid': op_wid}
+        self.pspec = PipelineSpec(width, self.id_wid, op_wid)
         self.alu = FPADDBasePipe(self.pspec)
         ReservationStations.__init__(self, num_rows)
 
index b6eb1a475becb8098847405e6d51252fe9185a82..1ae338d099a9f67aeaebc0cd6291d06520a79f41 100644 (file)
@@ -46,7 +46,7 @@ class FPAddSpecialCasesMod(Elaboratable):
         #m.submodules.sc_out_z = self.o.z
 
         # decode: XXX really should move to separate stage
-        width = self.pspec['width']
+        width = self.pspec.width
         a1 = FPNumBaseRecord(width)
         b1 = FPNumBaseRecord(width)
         m.submodules.sc_decode_a = a1 = FPNumDecode(None, a1)
index 586213691abaa88dd593fe73d043f892ec71503a..ef1acb6dd072d1399164a9aa6dd0cf66ca4b9a01 100644 (file)
@@ -14,7 +14,7 @@ from ieee754.fpcommon.getop import FPPipeContext
 class FPSCData:
 
     def __init__(self, pspec, m_extra):
-        width = pspec['width']
+        width = pspec.width
         # NOTE: difference between z and oz is that oz is created by
         # special-cases module(s) and will propagate, along with its
         # "bypass" signal out_do_z, through the pipeline, *disabling*
index 8f580c1fd7b5f959310bb64511fab82f73ba4c59..27f677c7a2056f72bc67c914454f3df0e10b0c9b 100644 (file)
@@ -91,7 +91,7 @@ class FPPipeContext:
                                    "operator". instance must have an "eq"
                                    function.
         """
-        self.id_wid = pspec['id_wid']
+        self.id_wid = pspec.id_width
         self.op_wid = pspec.get('op_wid', 0)
         self.muxid = Signal(self.id_wid, reset_less=True)   # RS multiplex ID
         opkls = pspec.get('opkls', None)
@@ -116,7 +116,7 @@ class FPPipeContext:
 class FPADDBaseData:
 
     def __init__(self, pspec, n_ops=2):
-        width = pspec['width']
+        width = pspec.width
         self.ctx = FPPipeContext(pspec)
         ops = []
         for i in range(n_ops):
index 529dd51b49d7a61de48c6d9a224b3ae79e09c23a..1240ca62e42be0aa7c414f7373dc92e19adfdda8 100644 (file)
@@ -15,7 +15,7 @@ from ieee754.fpcommon.getop import FPPipeContext
 class FPPackData:
 
     def __init__(self, pspec):
-        width = pspec['width']
+        width = pspec.width
         self.z = Signal(width, reset_less=True)    # result
         self.ctx = FPPipeContext(pspec)
 
@@ -63,7 +63,7 @@ class FPPackMod(Elaboratable):
 
     def elaborate(self, platform):
         m = Module()
-        z = FPNumBaseRecord(self.pspec['width'], False)
+        z = FPNumBaseRecord(self.pspec.width, False)
         m.submodules.pack_in_z = in_z = FPNumBase(self.i.z)
         #m.submodules.pack_out_z = out_z = FPNumOut(z)
         m.d.comb += self.o.ctx.eq(self.i.ctx)
index 47c7d8d5a6337e4a452a6dc166560459b37ccd68..ce7b273683437f3c266ff782cf356145130edd99 100644 (file)
@@ -9,7 +9,7 @@ from ieee754.fpcommon.getop import FPPipeContext
 class FPAddStage1Data:
 
     def __init__(self, pspec, e_extra=False):
-        width = pspec['width']
+        width = pspec.width
         self.z = FPNumBaseRecord(width, False, e_extra)
         self.out_do_z = Signal(reset_less=True)
         self.oz = Signal(width, reset_less=True)
index 2bf5727880dd23dfba7701c8a201ee44ecd0065b..b4c4a54d9e59b29136204eb6acb21af5d2ac782b 100644 (file)
@@ -17,7 +17,7 @@ from .postcalc import FPAddStage1Data
 class FPNorm1Data:
 
     def __init__(self, pspec):
-        width = pspec['width']
+        width = pspec.width
         self.roundz = Signal(reset_less=True, name="norm1_roundz")
         self.z = FPNumBaseRecord(width, False)
         self.out_do_z = Signal(reset_less=True)
index 7704151f34dc79f69e8f99a3bf573c8febf4dd6b..9c9af127e57bd92b658f1d52ae81399f5c1e34f1 100644 (file)
@@ -14,7 +14,7 @@ from .postnormalise import FPNorm1Data
 class FPRoundData:
 
     def __init__(self, pspec):
-        width = pspec['width']
+        width = pspec.width
         self.z = FPNumBaseRecord(width, False)
         self.ctx = FPPipeContext(pspec)
         self.muxid = self.ctx.muxid
index 81166c74afe54f1f85c2c88cbd85a8bd2a2573fd..8529e38274a1fe74ca9ec8b3bbadb96b5effb235 100644 (file)
@@ -16,11 +16,11 @@ from ieee754.fpcommon.getop import FPPipeContext
 class FPDivStage0Data:
 
     def __init__(self, pspec):
-        self.z = FPNumBaseRecord(pspec['width'], False)
+        self.z = FPNumBaseRecord(pspec.width, False)
         self.out_do_z = Signal(reset_less=True)
-        self.oz = Signal(pspec['width'], reset_less=True)
+        self.oz = Signal(pspec.width, reset_less=True)
 
-        self.ctx = FPPipeContext(pspec['width'], pspec) # context: muxid, operator etc.
+        self.ctx = FPPipeContext(pspec.width, pspec) # context: muxid, operator etc.
         self.muxid = self.ctx.muxid             # annoying. complicated.
 
         # TODO: here is where Q and R would be put, and passed
index e632a6d99269759486341b90d28a092da4691d01..60b1689c8d7c820e8c74275028bb0a69a2cf23d3 100644 (file)
@@ -70,6 +70,7 @@ from .specialcases import FPDIVSpecialCasesDeNorm
 from .divstages import (FPDivStagesSetup,
                         FPDivStagesIntermediate,
                         FPDivStagesFinal)
+from ieee754.pipeline import PipelineSpec
 
 
 class FPDIVBasePipe(ControlBase):
@@ -82,22 +83,22 @@ class FPDIVBasePipe(ControlBase):
 
         pipechain = []
         n_stages = 6      # TODO (depends on width)
-        n_comb_stages = 3 # TODO (depends on how many RS's we want)
-                          # to which the answer: "as few as possible"
-                          # is required.  too many ReservationStations
-                          # means "big problems".
+        n_comb_stages = 3  # TODO (depends on how many RS's we want)
+        # to which the answer: "as few as possible"
+        # is required.  too many ReservationStations
+        # means "big problems".
 
         for i in range(n_stages):
 
             # needs to convert input from pipestart ospec
             if i == 0:
                 kls = FPDivStagesSetup
-                n_comb_stages -= 1 # reduce due to work done at start
+                n_comb_stages -= 1  # reduce due to work done at start
 
             # needs to convert output to pipeend ispec
             elif i == n_stages - 1:
                 kls = FPDivStagesFinal
-                n_comb_stages -= 1 # FIXME - reduce due to work done at end?
+                n_comb_stages -= 1  # FIXME - reduce due to work done at end?
 
             # intermediary stage
             else:
@@ -133,15 +134,13 @@ class FPDIVMuxInOut(ReservationStations):
         :op_wid: - set this to the width of an operator which can
                    then be used to change the behaviour of the pipeline.
     """
+
     def __init__(self, width, num_rows, op_wid=0):
         self.id_wid = num_bits(width)
-        self.pspec = {}
-        self.pspec['width'] = width
-        self.pspec['id_wid'] = self.id_wid
-        self.pspec['op_wid'] = op_wid
+        self.pspec = PipelineSpec(width, self.id_wid, op_wid)
         # XXX TODO - a class (or function?) that takes the pspec (right here)
         # and creates... "something".  that "something" MUST have an eq function
-        # self.pspec['opkls'] = DivPipeCoreOperation
+        # self.pspec.opkls = DivPipeCoreOperation
         self.alu = FPDIVBasePipe(self.pspec)
         ReservationStations.__init__(self, num_rows)
 
index f17044241d771e3bf7bd4bff45a3249f60782511..d039eaaf303382134eed733cbab3632dcc8dd9c0 100644 (file)
@@ -44,8 +44,8 @@ class FPDIVSpecialCasesMod(Elaboratable):
         #m.submodules.sc_out_z = self.o.z
 
         # decode: XXX really should move to separate stage
-        a1 = FPNumBaseRecord(self.pspec['width'], False)
-        b1 = FPNumBaseRecord(self.pspec['width'], False)
+        a1 = FPNumBaseRecord(self.pspec.width, False)
+        b1 = FPNumBaseRecord(self.pspec.width, False)
         m.submodules.sc_decode_a = a1 = FPNumDecode(None, a1)
         m.submodules.sc_decode_b = b1 = FPNumDecode(None, b1)
         m.d.comb += [a1.v.eq(self.i.a),
index f56f69b532d524cef9a92a68699c63fcee693563..656e9bc0624e94ef15ab9154fb9e74d44b944588 100644 (file)
@@ -14,7 +14,7 @@ from ieee754.fpcommon.getop import FPPipeContext
 class FPMulStage0Data:
 
     def __init__(self, pspec):
-        width = pspec['width']
+        width = pspec.width
         self.z = FPNumBaseRecord(width, False)
         self.out_do_z = Signal(reset_less=True)
         self.oz = Signal(width, reset_less=True)
index 763b8722d21166fc979dfa2be94edd00a33294d2..841efcdfed3df98d4fd0aebadb7feb3c3a47791e 100644 (file)
@@ -65,7 +65,7 @@ class FPMulStage1(FPState):
 
     def __init__(self, pspec):
         FPState.__init__(self, "multiply_1")
-        width = pspec['width']
+        width = pspec.width
         self.mod = FPMulStage1Mod(pspec)
         self.out_z = FPNumBaseRecord(width, False)
         self.norm_stb = Signal()
index f146b1a70bd67c6bf5b34d93a2e883d3c3b5b559..08c151d0020105864724dc8d1505e45c4954480c 100644 (file)
@@ -14,7 +14,7 @@ from ieee754.fpcommon.pack import FPPackData
 from ieee754.fpcommon.normtopack import FPNormToPack
 from .specialcases import FPMulSpecialCasesDeNorm
 from .mulstages import FPMulStages
-
+from ieee754.pipeline import PipelineSpec
 
 
 class FPMULBasePipe(ControlBase):
@@ -44,13 +44,11 @@ class FPMULMuxInOut(ReservationStations):
 
         Fan-in and Fan-out are combinatorial.
     """
+
     def __init__(self, width, num_rows, op_wid=0):
-        self.pspec = {}
         self.id_wid = num_bits(width)
         self.op_wid = op_wid
-        self.pspec['id_wid'] = self.id_wid
-        self.pspec['width'] = width
-        self.pspec['op_wid'] = self.op_wid
+        self.pspec = PipelineSpec(width, self.id_wid, self.op_wid)
         self.alu = FPMULBasePipe(self.pspec)
         ReservationStations.__init__(self, num_rows)
 
index 43fc1810dfc17a28082634cd1a8327a422bd3ee8..68e75d150e91844a4359f9c300ca4c9f267d8f0e 100644 (file)
@@ -45,7 +45,7 @@ class FPMulSpecialCasesMod(Elaboratable):
         #m.submodules.sc_out_z = self.o.z
 
         # decode: XXX really should move to separate stage
-        width = self.pspec['width']
+        width = self.pspec.width
         a1 = FPNumBaseRecord(width, False)
         b1 = FPNumBaseRecord(width, False)
         m.submodules.sc_decode_a = a1 = FPNumDecode(None, a1)
diff --git a/src/ieee754/pipeline.py b/src/ieee754/pipeline.py
new file mode 100644 (file)
index 0000000..f2ec693
--- /dev/null
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# See Notices.txt for copyright information
+
+
+class PipelineSpec:
+    """ Pipeline Specification base class.
+
+    :attribute width: FIXME: document
+    :attribute id_width: FIXME: document
+    :attribute opcode_width: FIXME: document
+    """
+
+    def __init__(self, width, id_width, opcode_width):
+        """ Create a PipelineSpec. """
+        self.width = width
+        self.id_width = id_width
+        self.opcode_width = opcode_width