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 fpbase
import FPState
8 from fpcommon
.roundz
import FPRoundData
11 class FPCorrectionsMod(Elaboratable
):
13 def __init__(self
, width
, id_wid
):
17 self
.out_z
= self
.ospec()
20 return FPRoundData(self
.width
, self
.id_wid
)
23 return FPRoundData(self
.width
, self
.id_wid
)
28 def setup(self
, m
, i
):
29 """ links module to inputs and outputs
31 m
.submodules
.corrections
= self
32 m
.d
.comb
+= self
.i
.eq(i
)
34 def elaborate(self
, platform
):
36 m
.submodules
.corr_in_z
= self
.i
.z
37 m
.submodules
.corr_out_z
= self
.out_z
.z
38 m
.d
.comb
+= self
.out_z
.eq(self
.i
) # copies mid, z, out_do_z
39 with m
.If(~self
.i
.out_do_z
):
40 with m
.If(self
.i
.z
.is_denormalised
):
41 m
.d
.comb
+= self
.out_z
.z
.e
.eq(self
.i
.z
.N127
)
45 class FPCorrections(FPState
):
47 def __init__(self
, width
, id_wid
):
48 FPState
.__init
__(self
, "corrections")
49 self
.mod
= FPCorrectionsMod(width
)
50 self
.out_z
= self
.ospec()
53 return self
.mod
.ispec()
56 return self
.mod
.ospec()
58 def setup(self
, m
, in_z
):
59 """ links module to inputs and outputs
61 self
.mod
.setup(m
, in_z
)
63 m
.d
.sync
+= self
.out_z
.eq(self
.mod
.out_z
)
64 m
.d
.sync
+= self
.out_z
.mid
.eq(self
.mod
.o
.mid
)