resolve awful meta-class hacking (with thanks to jsbueno on stackexchange)
[ieee754fpu.git] / src / ieee754 / fpadd / addstages.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
6 from nmigen.cli import main, verilog
7
8 from nmutil.singlepipe import StageChain
9 from ieee754.pipeline import DynamicPipe
10
11 from ieee754.fpcommon.fpbase import FPState
12 from ieee754.fpcommon.denorm import FPSCData
13 from ieee754.fpcommon.postcalc import FPAddStage1Data
14 from ieee754.fpadd.align import FPAddAlignSingleMod
15 from ieee754.fpadd.add0 import FPAddStage0Mod
16 from ieee754.fpadd.add1 import FPAddStage1Mod
17
18 class FPAddAlignSingleAdd(DynamicPipe):
19
20 def __init__(self, pspec):
21 #FPState.__init__(self, "align")
22 self.pspec = pspec
23 super().__init__(pspec)
24 self.a1o = self.ospec()
25
26 def ispec(self):
27 return FPSCData(self.pspec, True)
28
29 def ospec(self):
30 return FPAddStage1Data(self.pspec) # AddStage1 ospec
31
32 def setup(self, m, i):
33 """ links module to inputs and outputs
34 """
35
36 # chain AddAlignSingle, AddStage0 and AddStage1
37 mod = FPAddAlignSingleMod(self.pspec)
38 a0mod = FPAddStage0Mod(self.pspec)
39 a1mod = FPAddStage1Mod(self.pspec)
40
41 chain = StageChain([mod, a0mod, a1mod])
42 chain.setup(m, i)
43
44 self.o = a1mod.o
45
46 def process(self, i):
47 return self.o
48
49 def action(self, m):
50 m.d.sync += self.a1o.eq(self.process(None))
51 m.next = "normalise_1"
52
53