1 # SPDX-License-Identifier: LGPL-2.1-or-later
2 # See Notices.txt for copyright information
3 """ div/rem/sqrt/rsqrt pipeline. """
5 from .core
import (DivPipeCoreConfig
, DivPipeCoreInputData
,
6 DivPipeCoreInterstageData
, DivPipeCoreOutputData
)
7 from ieee754
.fpcommon
.getop
import FPPipeContext
11 """ Configuration for the div/rem/sqrt/rsqrt pipeline.
13 :attribute pspec: FIXME: document
14 :attribute core_config: the ``DivPipeCoreConfig`` instance.
17 def __init__(self
, pspec
):
18 """ Create a ``DivPipeConfig`` instance. """
20 # FIXME: get bit_width, fract_width, and log2_radix from pspec or pass
22 self
.core_config
= DivPipeCoreConfig(bit_width
,
27 class DivPipeBaseData
:
28 """ input data base type for ``DivPipe``.
30 :attribute out_do_z: FIXME: document
31 :attribute oz: FIXME: document
32 :attribute ctx: FIXME: document
35 Alias of ``ctx.muxid``.
36 :attribute config: the ``DivPipeConfig`` instance.
39 def __init__(self
, config
):
40 """ Create a ``DivPipeBaseData`` instance. """
42 width
= config
.pspec
['width']
43 self
.out_do_z
= Signal(reset_less
=True)
44 self
.oz
= Signal(width
, reset_less
=True)
46 self
.ctx
= FPPipeContext(config
.pspec
) # context: muxid, operator etc.
47 # FIXME: add proper muxid explanation somewhere and refer to it here
48 self
.muxid
= self
.ctx
.muxid
# annoying. complicated.
51 """ Get member signals. """
57 """ Assign member signals. """
58 return [self
.out_do_z
.eq(i
.out_do_z
), self
.oz
.eq(i
.oz
),
62 class DivPipeInputData(DivPipeCoreInputData
, DivPipeBaseData
):
63 """ input data type for ``DivPipe``. """
65 def __init__(self
, config
):
66 """ Create a ``DivPipeInputData`` instance. """
67 DivPipeCoreInputData
.__init
__(self
, config
.core_config
)
68 DivPipeBaseData
.__init
__(self
, config
)
71 """ Get member signals. """
72 yield from DivPipeCoreInputData
.__iter
__(self
)
73 yield from DivPipeBaseData
.__iter
__(self
)
76 """ Assign member signals. """
77 return DivPipeCoreInputData
.eq(self
, rhs
) + \
78 DivPipeBaseData
.eq(self
, rhs
)
81 class DivPipeInterstageData(DivPipeCoreInterstageData
, DivPipeBaseData
):
82 """ interstage data type for ``DivPipe``. """
84 def __init__(self
, config
):
85 """ Create a ``DivPipeInterstageData`` instance. """
86 DivPipeCoreInterstageData
.__init
__(self
, config
.core_config
)
87 DivPipeBaseData
.__init
__(self
, config
)
90 """ Get member signals. """
91 yield from DivPipeCoreInterstageData
.__iter
__(self
)
92 yield from DivPipeBaseData
.__iter
__(self
)
95 """ Assign member signals. """
96 return DivPipeCoreInterstageData
.eq(self
, rhs
) + \
97 DivPipeBaseData
.eq(self
, rhs
)
100 class DivPipeOutputData(DivPipeCoreOutputData
, DivPipeBaseData
):
101 """ output data type for ``DivPipe``. """
103 def __init__(self
, config
):
104 """ Create a ``DivPipeOutputData`` instance. """
105 DivPipeCoreOutputData
.__init
__(self
, config
.core_config
)
106 DivPipeBaseData
.__init
__(self
, config
)
109 """ Get member signals. """
110 yield from DivPipeCoreOutputData
.__iter
__(self
)
111 yield from DivPipeBaseData
.__iter
__(self
)
114 """ Assign member signals. """
115 return DivPipeCoreOutputData
.eq(self
, rhs
) + \
116 DivPipeBaseData
.eq(self
, rhs
)
119 class DivPipeBaseStage
:
120 """ Base Mix-in for DivPipe*Stage. """
122 def _elaborate(self
, m
, platform
):
123 m
.d
.comb
+= self
.o
.oz
.eq(self
.i
.oz
)
124 m
.d
.comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
125 m
.d
.comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)
127 # FIXME: in DivPipeSetupStage.elaborate
128 # DivPipeBaseStage._elaborate(self, m, platform)
130 # FIXME: in DivPipeCalculateStage.elaborate
131 # DivPipeBaseStage._elaborate(self, m, platform)
133 # FIXME: in DivPipeFinalStage.elaborate
134 # DivPipeBaseStage._elaborate(self, m, platform)