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
, pspec
):
16 self
.out_z
= self
.ospec()
19 return FPRoundData(self
.pspec
)
22 return FPRoundData(self
.pspec
)
27 def setup(self
, m
, i
):
28 """ links module to inputs and outputs
30 m
.submodules
.corrections
= self
31 m
.d
.comb
+= self
.i
.eq(i
)
33 def elaborate(self
, platform
):
35 m
.submodules
.corr_in_z
= in_z
= FPNumBase(self
.i
.z
)
36 #m.submodules.corr_out_z = self.out_z.z
37 m
.d
.comb
+= self
.out_z
.eq(self
.i
) # copies mid, z, out_do_z
38 with m
.If(~self
.i
.out_do_z
):
39 with m
.If(in_z
.is_denormalised
):
40 m
.d
.comb
+= self
.out_z
.z
.e
.eq(self
.i
.z
.N127
)
44 class FPCorrections(FPState
):
46 def __init__(self
, width
, id_wid
):
47 FPState
.__init
__(self
, "corrections")
48 self
.mod
= FPCorrectionsMod(width
)
49 self
.out_z
= self
.ospec()
52 return self
.mod
.ispec()
55 return self
.mod
.ospec()
57 def setup(self
, m
, in_z
):
58 """ links module to inputs and outputs
60 self
.mod
.setup(m
, in_z
)
62 m
.d
.sync
+= self
.out_z
.eq(self
.mod
.out_z
)
63 m
.d
.sync
+= self
.out_z
.ctx
.eq(self
.mod
.o
.ctx
)