add operand down pipeline chain
[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, width, id_wid, op_wid=None):
14 self.width = width
15 self.id_wid = id_wid
16 self.op_wid = op_wid # operand width
17 self.i = self.ispec()
18 self.out_z = self.ospec()
19
20 def ispec(self):
21 return FPRoundData(self.width, self.id_wid, self.op_wid)
22
23 def ospec(self):
24 return FPRoundData(self.width, self.id_wid, self.op_wid)
25
26 def process(self, i):
27 return self.out_z
28
29 def setup(self, m, i):
30 """ links module to inputs and outputs
31 """
32 m.submodules.corrections = self
33 m.d.comb += self.i.eq(i)
34
35 def elaborate(self, platform):
36 m = Module()
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)
43 return m
44
45
46 class FPCorrections(FPState):
47
48 def __init__(self, width, id_wid):
49 FPState.__init__(self, "corrections")
50 self.mod = FPCorrectionsMod(width)
51 self.out_z = self.ospec()
52
53 def ispec(self):
54 return self.mod.ispec()
55
56 def ospec(self):
57 return self.mod.ospec()
58
59 def setup(self, m, in_z):
60 """ links module to inputs and outputs
61 """
62 self.mod.setup(m, in_z)
63
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)
66
67 def action(self, m):
68 m.next = "pack"
69
70