Combine a selectable number of rounds into one pipeline stage
authorMichael Nolan <mtnolan2640@gmail.com>
Thu, 2 Apr 2020 17:01:46 +0000 (13:01 -0400)
committerMichael Nolan <mtnolan2640@gmail.com>
Thu, 2 Apr 2020 17:01:46 +0000 (13:01 -0400)
src/ieee754/cordic/pipe_data.py
src/ieee754/cordic/sin_cos_pipeline.py
src/ieee754/cordic/test/test_pipe.py

index a477d20014d0494420f784b9600a62ca1bc46797..bcdeae9d9a131b984fe4fd523098001f11831929 100644 (file)
@@ -37,8 +37,10 @@ class CordicData:
 
 
 class CordicPipeSpec:
-    def __init__(self, fracbits):
+    def __init__(self, fracbits, rounds_per_stage):
         self.fracbits = fracbits
+        # Number of cordic operations per pipeline stage
+        self.rounds_per_stage = rounds_per_stage
         self.M = (1 << fracbits)
         self.ZMAX = int(round(self.M * math.pi/2))
         zm = Const(-self.ZMAX)
index 42dd6fc5df114c9d080d6491c795322b9663181b..5bc60e4868cd6ea8d947d286f3e76db296e188dd 100644 (file)
@@ -17,17 +17,29 @@ class CordicPipeChain(PipeModBaseChain):
 class CordicBasePipe(ControlBase):
     def __init__(self, pspec):
         ControlBase.__init__(self)
+        self.pspec = pspec
         self.cordicstages = []
+        initstage = CordicInitialStage(pspec)
+        stages = []
         for i in range(pspec.iterations):
-            if i == 0:
-                stages = [CordicInitialStage(pspec), CordicStage(pspec, i)]
-            else:
-                stages = [CordicStage(pspec, i)]
-            stage = CordicPipeChain(pspec, stages)
-            self.cordicstages.append(stage)
+            stages.append(CordicStage(pspec, i))
+        chunks = self.chunkify(initstage, stages)
+        print(len(chunks))
+        for chunk in chunks:
+            chain = CordicPipeChain(pspec, chunk)
+            self.cordicstages.append(chain)
 
         self._eqs = self.connect(self.cordicstages)
 
+    def chunkify(self, initstage, stages):
+        chunks = []
+
+        for i in range(0, len(stages), self.pspec.rounds_per_stage):
+            chunks.append(stages[i:i + self.pspec.rounds_per_stage])
+        chunks[0].insert(0, initstage)
+
+        return chunks
+
     def elaborate(self, platform):
         m = ControlBase.elaborate(self, platform)
         for i, stage in enumerate(self.cordicstages):
index 809ca7f7f5ae0f249c4e4679a681d9e4cb1d9a12..880351ade028b4d89190685beb40298e261fc9f1 100644 (file)
@@ -13,7 +13,7 @@ import random
 class SinCosTestCase(FHDLTestCase):
     def run_test(self, inputs, outputs, fracbits=8):
         m = Module()
-        pspec = CordicPipeSpec(fracbits=fracbits)
+        pspec = CordicPipeSpec(fracbits=fracbits, rounds_per_stage=4)
         m.submodules.dut = dut = CordicBasePipe(pspec)
 
         z = Signal(dut.p.data_i.z0.shape())