Add stage to convert input float to fixed point number
[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
8
9 class CordicPipeChain(PipeModBaseChain):
10 def __init__(self, pspec, stages):
11 self.stages = stages
12 super().__init__(pspec)
13
14 def get_chain(self):
15 return self.stages
16
17
18 class FPCordicBasePipe(ControlBase):
19 def __init__(self, pspec):
20 ControlBase.__init__(self)
21 self.pspec = pspec
22
23 self.denorm = CordicPipeChain(pspec,
24 [FPCordicInitStage(self.pspec),
25 FPAddDeNormMod(self.pspec, False),
26 FPCordicConvertFixed(self.pspec)])
27
28 self._eqs = self.connect([self.denorm])
29
30 def chunkify(self, initstage, stages):
31 chunks = []
32
33 for i in range(0, len(stages), self.pspec.rounds_per_stage):
34 chunks.append(stages[i:i + self.pspec.rounds_per_stage])
35 chunks[0].insert(0, initstage)
36
37 return chunks
38
39 def elaborate(self, platform):
40 m = ControlBase.elaborate(self, platform)
41 m.submodules.denorm = self.denorm
42 m.d.comb += self._eqs
43 return m