from nmigen import Signal, Const
+from nmutil.dynamicpipe import DynamicPipe, SimpleHandshakeRedir
import math
class CordicInitialData:
yield from self.z
def eq(self, i):
- return [self.z.eq(i.z)]
+ return [self.z0.eq(i.z0)]
class CordicData:
self.ZMAX = int(round(self.M * math.pi/2))
zm = Const(-self.ZMAX)
self.iterations = zm.width - 1
+
+ self.pipekls = SimpleHandshakeRedir
+ self.stage = None
super().__init__(pspec, "cordicinit")
def ispec(self):
- return CordicInitialData(self.pspec, False)
+ return CordicInitialData(self.pspec)
def ospec(self):
- return CordicData(self.pspec, False)
+ return CordicData(self.pspec)
def elaborate(self, platform):
m = Module()
self.stagenum = stagenum
def ispec(self):
- return CordicData(self.pspec, False)
+ return CordicData(self.pspec)
def ospec(self):
- return CordicData(self.pspec, False)
+ return CordicData(self.pspec)
def elaborate(self, platform):
m = Module()
from nmutil.singlepipe import ControlBase
from nmutil.concurrentunit import ReservationStations, num_bits
+from nmutil.pipemodbase import PipeModBaseChain
-from ieee754.cordic.sin_cos_pipe_stages import (
+from ieee754.cordic.sin_cos_pipe_stage import (
CordicStage, CordicInitialStage)
from ieee754.cordic.pipe_data import (CordicPipeSpec, CordicData,
- CordicInitalData)
+ CordicInitialData)
+
+class CordicPipeChain(PipeModBaseChain):
+ def get_chain(self):
+ initstage = CordicInitialStage(self.pspec)
+ cordicstages = []
+ for i in range(self.pspec.iterations):
+ stage = CordicStage(self.pspec, i)
+ cordicstages.append(stage)
+ return [initstage] + cordicstages
+
class CordicBasePipe(ControlBase):
def __init__(self, pspec):
ControlBase.__init__(self)
- self.init = CordicInitialStage(pspec)
- self.cordicstages = []
- for i in range(pspec.iterations):
- stage = CordicStage(pspec, i)
- self.cordicstages.append(stage)
- self._eqs = self.connect([self.init] + self.cordicstages)
+ self.chain = CordicPipeChain(pspec)
+ self._eqs = self.connect([self.chain])
def elaborate(self, platform):
m = ControlBase.elaborate(self, platform)
- m.submodules.init = self.init
- for i, stage in enumerate(self.cordicstages):
- setattr(m.submodules, "stage%d" % i, stage)
+ m.submodules.chain = self.chain
m.d.comb += self._eqs
return m
--- /dev/null
+from nmigen import Module, Signal
+from nmigen.back.pysim import Simulator, Delay
+from nmigen.test.utils import FHDLTestCase
+
+from ieee754.cordic.sin_cos_pipeline import CordicBasePipe
+from ieee754.cordic.pipe_data import CordicPipeSpec
+from python_sin_cos import run_cordic
+import unittest
+
+
+class SinCosTestCase(FHDLTestCase):
+ def run_test(self, zin=0, fracbits=8, expected_sin=0, expected_cos=0):
+ m = Module()
+ pspec = CordicPipeSpec(fracbits=fracbits)
+ m.submodules.dut = dut = CordicBasePipe(pspec)
+
+ z = Signal(dut.p.data_i.z0.shape())
+ x = Signal(dut.n.data_o.x.shape())
+ y = Signal(dut.n.data_o.y.shape())
+
+ sim = Simulator(m)
+ sim.add_clock(1e-6)
+
+ def process():
+ yield z.eq(zin)
+ for i in range(10):
+ yield
+ sim.add_sync_process(process)
+ with sim.write_vcd("pipeline.vcd", "pipeline.gtkw", traces=[
+ z, x, y]):
+ sim.run()
+
+ def run_test_assert(self, z, fracbits=8):
+ (sin, cos) = run_cordic(z, fracbits=fracbits, log=False)
+ self.run_test(zin=z, fracbits=fracbits,
+ expected_sin=sin, expected_cos=cos)
+
+ def test_0(self):
+ self.run_test_assert(0)
+
+
+if __name__ == "__main__":
+ unittest.main()