remove debug prints
[ieee754fpu.git] / src / ieee754 / div_rem_sqrt_rsqrt / div_pipe.py
1 # SPDX-License-Identifier: LGPL-2.1-or-later
2 # See Notices.txt for copyright information
3 """ div/rem/sqrt/rsqrt pipeline. """
4
5 from nmigen import Signal
6 from ieee754.div_rem_sqrt_rsqrt.core import (DivPipeCoreConfig,
7 DivPipeCoreInputData,
8 DivPipeCoreInterstageData,
9 DivPipeCoreOutputData,
10 DivPipeCoreSetupStage,
11 DivPipeCoreCalculateStage,
12 DivPipeCoreFinalStage,
13 )
14 from ieee754.fpcommon.getop import FPPipeContext
15 from ieee754.fpcommon.fpbase import FPFormat, FPNumBaseRecord
16
17
18 class DivPipeBaseData:
19 """ input data base type for ``DivPipe``.
20
21 :attribute z: a convenient way to carry the sign and exponent through
22 the pipeline from when they were computed right at the
23 start.
24 :attribute out_do_z: FIXME: document
25 :attribute oz: FIXME: document
26 :attribute ctx: FIXME: document
27 :attribute muxid:
28 FIXME: document
29 Alias of ``ctx.muxid``.
30 :attribute config: the ``DivPipeConfig`` instance.
31 """
32
33 def __init__(self, pspec):
34 """ Create a ``DivPipeBaseData`` instance. """
35 self.pspec = pspec
36 width = pspec.width
37 self.z = FPNumBaseRecord(width, False) # s and e carried: m ignored
38 self.out_do_z = Signal(reset_less=True)
39 self.oz = Signal(width, reset_less=True)
40
41 self.ctx = FPPipeContext(pspec) # context: muxid, operator etc.
42 # FIXME: add proper muxid explanation somewhere and refer to it here
43 self.muxid = self.ctx.muxid # annoying. complicated.
44
45 def __iter__(self):
46 """ Get member signals. """
47 yield from self.z
48 yield self.out_do_z
49 yield self.oz
50 yield from self.ctx
51
52 def eq(self, rhs):
53 """ Assign member signals. """
54 return [self.z.eq(rhs.z), self.out_do_z.eq(rhs.out_do_z),
55 self.oz.eq(rhs.oz), self.ctx.eq(rhs.ctx)]
56
57
58 class DivPipeInputData(DivPipeCoreInputData, DivPipeBaseData):
59 """ input data type for ``DivPipe``. """
60
61 def __init__(self, pspec):
62 """ Create a ``DivPipeInputData`` instance. """
63 DivPipeCoreInputData.__init__(self, pspec.core_config)
64 DivPipeBaseData.__init__(self, pspec)
65
66 def __iter__(self):
67 """ Get member signals. """
68 yield from DivPipeCoreInputData.__iter__(self)
69 yield from DivPipeBaseData.__iter__(self)
70
71 def eq(self, rhs):
72 """ Assign member signals. """
73 return DivPipeCoreInputData.eq(self, rhs) + \
74 DivPipeBaseData.eq(self, rhs)
75
76
77 class DivPipeInterstageData(DivPipeCoreInterstageData, DivPipeBaseData):
78 """ interstage data type for ``DivPipe``. """
79
80 def __init__(self, pspec):
81 """ Create a ``DivPipeInterstageData`` instance. """
82 DivPipeCoreInterstageData.__init__(self, pspec.core_config)
83 DivPipeBaseData.__init__(self, pspec)
84
85 def __iter__(self):
86 """ Get member signals. """
87 yield from DivPipeCoreInterstageData.__iter__(self)
88 yield from DivPipeBaseData.__iter__(self)
89
90 def eq(self, rhs):
91 """ Assign member signals. """
92 #print (self, rhs)
93 return DivPipeCoreInterstageData.eq(self, rhs) + \
94 DivPipeBaseData.eq(self, rhs)
95
96
97 class DivPipeOutputData(DivPipeCoreOutputData, DivPipeBaseData):
98 """ output data type for ``DivPipe``. """
99
100 def __init__(self, pspec):
101 """ Create a ``DivPipeOutputData`` instance. """
102 DivPipeCoreOutputData.__init__(self, pspec.core_config)
103 DivPipeBaseData.__init__(self, pspec)
104
105 def __iter__(self):
106 """ Get member signals. """
107 yield from DivPipeCoreOutputData.__iter__(self)
108 yield from DivPipeBaseData.__iter__(self)
109
110 def eq(self, rhs):
111 """ Assign member signals. """
112 return DivPipeCoreOutputData.eq(self, rhs) + \
113 DivPipeBaseData.eq(self, rhs)
114
115
116 class DivPipeBaseStage:
117 """ Base Mix-in for DivPipe*Stage. """
118
119 def _elaborate(self, m, platform):
120 m.d.comb += self.o.ctx.eq(self.i.ctx)
121 m.d.comb += self.o.z.eq(self.i.z)
122 m.d.comb += self.o.oz.eq(self.i.oz)
123 m.d.comb += self.o.out_do_z.eq(self.i.out_do_z)
124
125
126 class DivPipeSetupStage(DivPipeBaseStage, DivPipeCoreSetupStage):
127
128 def __init__(self, pspec):
129 self.pspec = pspec
130 #print ("DivPipeSetupStage", pspec, pspec.core_config)
131 DivPipeCoreSetupStage.__init__(self, pspec.core_config)
132
133 def ispec(self):
134 """ Get the input spec for this pipeline stage."""
135 return DivPipeInputData(self.pspec)
136
137 def ospec(self):
138 """ Get the output spec for this pipeline stage."""
139 return DivPipeInterstageData(self.pspec)
140
141 def elaborate(self, platform):
142 # XXX TODO: out_do_z logic!
143 m = DivPipeCoreSetupStage.elaborate(self, platform)
144 self._elaborate(m, platform)
145 return m
146
147
148 class DivPipeCalculateStage(DivPipeBaseStage, DivPipeCoreCalculateStage):
149
150 def __init__(self, pspec, stage_index):
151 self.pspec = pspec
152 DivPipeCoreCalculateStage.__init__(self, pspec.core_config, stage_index)
153
154 def ispec(self):
155 """ Get the input spec for this pipeline stage."""
156 return DivPipeInterstageData(self.pspec)
157
158 def ospec(self):
159 """ Get the output spec for this pipeline stage."""
160 return DivPipeInterstageData(self.pspec)
161
162 def elaborate(self, platform):
163 # XXX TODO: out_do_z logic!
164 m = DivPipeCoreCalculateStage.elaborate(self, platform)
165 self._elaborate(m, platform)
166 return m
167
168
169 class DivPipeFinalStage(DivPipeBaseStage, DivPipeCoreFinalStage):
170
171 def __init__(self, pspec):
172 self.pspec = pspec
173 DivPipeCoreFinalStage.__init__(self, pspec.core_config)
174
175 def ispec(self):
176 """ Get the input spec for this pipeline stage."""
177 return DivPipeInterstageData(self.pspec)
178
179 def ospec(self):
180 """ Get the output spec for this pipeline stage."""
181 return DivPipeOutputData(self.pspec)
182
183 def elaborate(self, platform):
184 # XXX TODO: out_do_z logic!
185 m = DivPipeCoreFinalStage.elaborate(self, platform)
186 self._elaborate(m, platform)
187 return m
188