1 # IEEE Floating Point Multiplier
3 from nmigen
import Module
, Signal
, Elaboratable
4 from nmigen
.cli
import main
, verilog
6 from ieee754
.fpcommon
.fpbase
import FPState
7 from ieee754
.fpcommon
.postcalc
import FPAddStage1Data
8 from .mul0
import FPMulStage0Data
11 class FPMulStage1Mod(FPState
, Elaboratable
):
12 """ Second stage of mul: preparation for normalisation.
15 def __init__(self
, width
, id_wid
, op_wid
=None):
23 return FPMulStage0Data(self
.width
, self
.id_wid
, self
.op_wid
)
26 return FPAddStage1Data(self
.width
, self
.id_wid
, self
.op_wid
)
31 def setup(self
, m
, i
):
32 """ links module to inputs and outputs
34 m
.submodules
.mul1
= self
35 #m.submodules.mul1_out_overflow = self.o.of
37 m
.d
.comb
+= self
.i
.eq(i
)
39 def elaborate(self
, platform
):
41 m
.d
.comb
+= self
.o
.z
.eq(self
.i
.z
)
42 with m
.If(~self
.i
.out_do_z
):
45 self
.o
.z
.m
.eq(self
.i
.product
[mw
+2:]),
46 self
.o
.of
.m0
.eq(self
.i
.product
[mw
+2]),
47 self
.o
.of
.guard
.eq(self
.i
.product
[mw
+1]),
48 self
.o
.of
.round_bit
.eq(self
.i
.product
[mw
]),
49 self
.o
.of
.sticky
.eq(self
.i
.product
[0:mw
].bool())
52 m
.d
.comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
53 m
.d
.comb
+= self
.o
.oz
.eq(self
.i
.oz
)
54 m
.d
.comb
+= self
.o
.mid
.eq(self
.i
.mid
)
56 m
.d
.comb
+= self
.o
.op
.eq(self
.i
.op
)
61 class FPMulStage1(FPState
):
63 def __init__(self
, width
, id_wid
):
64 FPState
.__init
__(self
, "multiply_1")
65 self
.mod
= FPMulStage1Mod(width
)
66 self
.out_z
= FPNumBaseRecord(width
, False)
67 self
.out_of
= Overflow()
68 self
.norm_stb
= Signal()
70 def setup(self
, m
, i
):
71 """ links module to inputs and outputs
75 m
.d
.sync
+= self
.norm_stb
.eq(0) # sets to zero when not in mul1 state
77 m
.d
.sync
+= self
.out_of
.eq(self
.mod
.out_of
)
78 m
.d
.sync
+= self
.out_z
.eq(self
.mod
.out_z
)
79 m
.d
.sync
+= self
.norm_stb
.eq(1)
82 m
.next
= "normalise_1"