1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
5 from nmigen
import Module
, Elaboratable
6 from nmigen
.cli
import main
, verilog
7 from ieee754
.fpcommon
.fpbase
import FPState
, FPNumBase
8 from .roundz
import FPRoundData
11 class FPCorrectionsMod(Elaboratable
):
13 def __init__(self
, width
, id_wid
, op_wid
=None):
16 self
.op_wid
= op_wid
# operand width
18 self
.out_z
= self
.ospec()
21 return FPRoundData(self
.width
, self
.id_wid
, self
.op_wid
)
24 return FPRoundData(self
.width
, self
.id_wid
, self
.op_wid
)
29 def setup(self
, m
, i
):
30 """ links module to inputs and outputs
32 m
.submodules
.corrections
= self
33 m
.d
.comb
+= self
.i
.eq(i
)
35 def elaborate(self
, platform
):
37 m
.submodules
.corr_in_z
= in_z
= FPNumBase(self
.i
.z
)
38 #m.submodules.corr_out_z = self.out_z.z
39 m
.d
.comb
+= self
.out_z
.eq(self
.i
) # copies mid, z, out_do_z
40 with m
.If(~self
.i
.out_do_z
):
41 with m
.If(in_z
.is_denormalised
):
42 m
.d
.comb
+= self
.out_z
.z
.e
.eq(self
.i
.z
.N127
)
46 class FPCorrections(FPState
):
48 def __init__(self
, width
, id_wid
):
49 FPState
.__init
__(self
, "corrections")
50 self
.mod
= FPCorrectionsMod(width
)
51 self
.out_z
= self
.ospec()
54 return self
.mod
.ispec()
57 return self
.mod
.ospec()
59 def setup(self
, m
, in_z
):
60 """ links module to inputs and outputs
62 self
.mod
.setup(m
, in_z
)
64 m
.d
.sync
+= self
.out_z
.eq(self
.mod
.out_z
)
65 m
.d
.sync
+= self
.out_z
.mid
.eq(self
.mod
.o
.mid
)