move fpcommon to separate subdir
[ieee754fpu.git] / src / ieee754 / fpcommon / corrections.py
1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
3 # 2013-12-12
4
5 from nmigen import Module, Elaboratable
6 from nmigen.cli import main, verilog
7 from fpbase import FPState
8 from fpcommon.roundz import FPRoundData
9
10
11 class FPCorrectionsMod(Elaboratable):
12
13 def __init__(self, width, id_wid):
14 self.width = width
15 self.id_wid = id_wid
16 self.i = self.ispec()
17 self.out_z = self.ospec()
18
19 def ispec(self):
20 return FPRoundData(self.width, self.id_wid)
21
22 def ospec(self):
23 return FPRoundData(self.width, self.id_wid)
24
25 def process(self, i):
26 return self.out_z
27
28 def setup(self, m, i):
29 """ links module to inputs and outputs
30 """
31 m.submodules.corrections = self
32 m.d.comb += self.i.eq(i)
33
34 def elaborate(self, platform):
35 m = Module()
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)
42 return m
43
44
45 class FPCorrections(FPState):
46
47 def __init__(self, width, id_wid):
48 FPState.__init__(self, "corrections")
49 self.mod = FPCorrectionsMod(width)
50 self.out_z = self.ospec()
51
52 def ispec(self):
53 return self.mod.ispec()
54
55 def ospec(self):
56 return self.mod.ospec()
57
58 def setup(self, m, in_z):
59 """ links module to inputs and outputs
60 """
61 self.mod.setup(m, in_z)
62
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)
65
66 def action(self, m):
67 m.next = "pack"
68
69