1 # SPDX-License-Identifier: LGPL-2.1-or-later
2 # See Notices.txt for copyright information
3 """Integer Multiplication."""
5 from nmigen
import Signal
, Module
, Value
, Elaboratable
, Cat
, C
, Mux
, Repl
6 from nmigen
.cli
import main
8 from ieee754
.part_mul_add
.multiply
import (InputData
, OutputData
,
9 AllTerms
, AddReduceInternal
,
10 Intermediates
, FinalOut
)
12 from nmutil
.pipemodbase
import PipeModBaseChain
13 from nmutil
.singlepipe
import ControlBase
14 from ieee754
.pipeline
import PipelineSpec
17 class MulStages(PipeModBaseChain
):
19 def __init__(self
, pspec
, part_pts
):
20 self
.part_pts
= part_pts
21 super().__init
__(pspec
)
24 # chain AddReduce, Intermediates and FinalOut
25 part_pts
= self
.part_pts
27 at
= AddReduceInternal(self
.pspec
, n_inputs
, part_pts
, partition_step
=2)
30 interm
= Intermediates(self
.pspec
, part_pts
)
31 finalout
= FinalOut(self
.pspec
, part_pts
)
32 self
.output
= finalout
.o
.output
34 return levels
+ [interm
, finalout
]
37 class AllTermsPipe(PipeModBaseChain
):
39 def __init__(self
, pspec
, n_inputs
):
40 self
.n_inputs
= n_inputs
41 super().__init
__(pspec
)
46 nmod
= AllTerms(self
.pspec
, self
.n_inputs
)
51 class MulPipe_8_16_32_64(ControlBase
):
52 """Signed/Unsigned 8/16/32/64-bit partitioned integer multiplier pipeline
56 """ register_levels: specifies the points in the cascade at which
57 flip-flops are to be inserted.
60 self
.id_wid
= 0 # num_bits(num_rows)
62 self
.pspec
= PipelineSpec(64, self
.id_wid
, self
.op_wid
, n_ops
=3)
63 self
.pspec
.n_parts
= 8
65 ControlBase
.__init
__(self
)
68 self
.allterms
= AllTermsPipe(self
.pspec
, n_inputs
)
69 stage
= self
.allterms
.chain
[0]
70 part_pts
= stage
.i
.part_pts
71 self
.mulstages
= MulStages(self
.pspec
, part_pts
)
73 self
._eqs
= self
.connect([self
.allterms
, self
.mulstages
])
77 self
.output
= self
.mulstages
.output
85 def elaborate(self
, platform
):
86 m
= ControlBase
.elaborate(self
, platform
)
88 m
.submodules
.allterms
= self
.allterms
89 m
.submodules
.mulstages
= self
.mulstages
95 if __name__
== "__main__":
96 m
= MulPipe_8_16_32_64()