big (single-purpose) update: move width arg into pspec
[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 ieee754.fpcommon.fpbase import FPState, FPNumBase
8 from .roundz import FPRoundData
9
10
11 class FPCorrectionsMod(Elaboratable):
12
13 def __init__(self, pspec):
14 self.pspec = pspec
15 self.i = self.ispec()
16 self.out_z = self.ospec()
17
18 def ispec(self):
19 return FPRoundData(self.pspec)
20
21 def ospec(self):
22 return FPRoundData(self.pspec)
23
24 def process(self, i):
25 return self.out_z
26
27 def setup(self, m, i):
28 """ links module to inputs and outputs
29 """
30 m.submodules.corrections = self
31 m.d.comb += self.i.eq(i)
32
33 def elaborate(self, platform):
34 m = Module()
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)
41 return m
42
43
44 class FPCorrections(FPState):
45
46 def __init__(self, width, id_wid):
47 FPState.__init__(self, "corrections")
48 self.mod = FPCorrectionsMod(width)
49 self.out_z = self.ospec()
50
51 def ispec(self):
52 return self.mod.ispec()
53
54 def ospec(self):
55 return self.mod.ospec()
56
57 def setup(self, m, in_z):
58 """ links module to inputs and outputs
59 """
60 self.mod.setup(m, in_z)
61
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)
64
65 def action(self, m):
66 m.next = "pack"
67
68