Add cordic stages to fp cordic pipeline
[ieee754fpu.git] / src / ieee754 / cordic / fp_pipeline.py
1 from nmutil.singlepipe import ControlBase
2 from nmutil.pipemodbase import PipeModBaseChain
3
4 from ieee754.fpcommon.denorm import FPAddDeNormMod
5 from ieee754.cordic.fp_pipe_init_stages import (FPCordicInitStage,
6 FPCordicConvertFixed)
7 from ieee754.cordic.sin_cos_pipe_stage import (CordicStage,
8 CordicInitialStage)
9
10
11 class CordicPipeChain(PipeModBaseChain):
12 def __init__(self, pspec, stages):
13 self.stages = stages
14 super().__init__(pspec)
15
16 def get_chain(self):
17 return self.stages
18
19
20 class FPCordicBasePipe(ControlBase):
21 def __init__(self, pspec):
22 ControlBase.__init__(self)
23 self.pspec = pspec
24
25 self.denorm = CordicPipeChain(pspec,
26 [FPCordicInitStage(self.pspec),
27 FPAddDeNormMod(self.pspec, False),
28 FPCordicConvertFixed(self.pspec)])
29
30 self.cordicstages = []
31
32 initstage = CordicInitialStage(pspec)
33 stages = []
34 for i in range(pspec.iterations):
35 stages.append(CordicStage(pspec, i))
36 chunks = self.chunkify(initstage, stages)
37 for chunk in chunks:
38 chain = CordicPipeChain(pspec, chunk)
39 self.cordicstages.append(chain)
40
41 self._eqs = self.connect([self.denorm] + self.cordicstages)
42
43 def chunkify(self, initstage, stages):
44 chunks = []
45
46 for i in range(0, len(stages), self.pspec.rounds_per_stage):
47 chunks.append(stages[i:i + self.pspec.rounds_per_stage])
48 chunks[0].insert(0, initstage)
49
50 return chunks
51
52 def elaborate(self, platform):
53 m = ControlBase.elaborate(self, platform)
54 m.submodules.denorm = self.denorm
55 for i, stage in enumerate(self.cordicstages):
56 setattr(m.submodules, "cordic%d" % i,
57 stage)
58 m.d.comb += self._eqs
59 return m