1 # SPDX-License-Identifier: LGPL-2.1-or-later
2 # See Notices.txt for copyright information
3 """ div/rem/sqrt/rsqrt pipeline. """
4 from .core
import (DivPipeCoreConfig
, DivPipeCoreInputData
,
5 DivPipeCoreInterstageData
, DivPipeCoreOutputData
)
9 """ input data base type for ``DivPipe``.
12 def __init__(self
, pspec
):
13 """ Create a ``DivPipeBaseData`` instance. """
14 width
= pspec
['width']
15 self
.out_do_z
= Signal(reset_less
=True)
16 self
.oz
= Signal(width
, reset_less
=True)
18 self
.ctx
= FPPipeContext(pspec
) # context: muxid, operator etc.
19 self
.muxid
= self
.ctx
.muxid
# annoying. complicated.
22 """ Get member signals. """
28 """ Assign member signals. """
29 return [self
.out_do_z
.eq(i
.out_do_z
), self
.oz
.eq(i
.oz
),
33 class DivPipeInputData(DivPipeCoreInputData
, DivPipeBaseData
):
34 """ input data type for ``DivPipe``.
37 def __init__(self
, core_config
):
38 """ Create a ``DivPipeInputData`` instance. """
39 DivPipeCoreInputData
.__init
__(self
, core_config
)
40 DivPipeBaseData
.__init
__(self
, pspec
) # XXX TODO args
41 self
.out_do_z
= Signal(reset_less
=True)
42 self
.oz
= Signal(width
, reset_less
=True)
44 self
.ctx
= FPPipeContext(pspec
) # context: muxid, operator etc.
45 self
.muxid
= self
.ctx
.muxid
# annoying. complicated.
48 """ Get member signals. """
49 yield from DivPipeCoreInputData
.__iter
__(self
)
50 yield from DivPipeBaseData
.__iter
__(self
)
53 """ Assign member signals. """
54 return DivPipeBaseData
.eq(self
, rhs
) + \
55 DivPipeCoreInputData
.eq(self
, rhs
)
58 class DivPipeInterstageData(DivPipeCoreInterstageData
, DivPipeBaseData
):
59 """ interstage data type for ``DivPipe``.
61 :attribute core_config: ``DivPipeCoreConfig`` instance describing the
62 configuration to be used.
65 def __init__(self
, core_config
):
66 """ Create a ``DivPipeCoreInterstageData`` instance. """
67 DivPipeCoreInterstageData
.__init
__(self
, core_config
)
68 DivPipeBaseData
.__init
__(self
, pspec
) # XXX TODO args
71 """ Get member signals. """
72 yield from DivPipeInterstageData
.__iter
__(self
)
73 yield from DivPipeBaseData
.__iter
__(self
)
76 """ Assign member signals. """
77 return DivPipeBaseData
.eq(self
, rhs
) + \
78 DivPipeCoreInterstageData
.eq(self
, rhs
)
81 class DivPipeOutputData(DivPipeCoreOutputData
, DivPipeBaseData
):
82 """ interstage data type for ``DivPipe``.
84 :attribute core_config: ``DivPipeCoreConfig`` instance describing the
85 configuration to be used.
88 def __init__(self
, core_config
):
89 """ Create a ``DivPipeCoreOutputData`` instance. """
90 DivPipeCoreOutputData
.__init
__(self
, core_config
)
91 DivPipeBaseData
.__init
__(self
, pspec
) # XXX TODO args
94 """ Get member signals. """
95 yield from DivPipeOutputData
.__iter
__(self
)
96 yield from DivPipeBaseData
.__iter
__(self
)
99 """ Assign member signals. """
100 return DivPipeBaseData
.eq(self
, rhs
) + \
101 DivPipeCoreOutputData
.eq(self
, rhs
)
104 class DivPipeBaseStage
:
105 """ Base Mix-in for DivPipe*Stage """
107 def _elaborate(self
, m
, platform
):
108 m
.d
.comb
+= self
.o
.oz
.eq(self
.i
.oz
)
109 m
.d
.comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
110 m
.d
.comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)