2bc23df0dabf89f8a4e194d5e573a88d5d740d0e
[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, SimpleHandshake,
9 PassThroughStage)
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
19 class FPAddAlignSingleAdd(FPState, SimpleHandshake):
20
21 def __init__(self, pspec):
22 FPState.__init__(self, "align")
23 self.pspec = pspec
24 SimpleHandshake.__init__(self, self) # pipeline is its own stage
25 self.a1o = self.ospec()
26
27 def ispec(self):
28 return FPSCData(self.pspec, True)
29
30 def ospec(self):
31 return FPAddStage1Data(self.pspec) # AddStage1 ospec
32
33 def setup(self, m, i):
34 """ links module to inputs and outputs
35 """
36
37 # chain AddAlignSingle, AddStage0 and AddStage1
38 mod = FPAddAlignSingleMod(self.pspec)
39 a0mod = FPAddStage0Mod(self.pspec)
40 a1mod = FPAddStage1Mod(self.pspec)
41
42 chain = StageChain([mod, a0mod, a1mod])
43 chain.setup(m, i)
44
45 self.o = a1mod.o
46
47 def process(self, i):
48 return self.o
49
50 def action(self, m):
51 m.d.sync += self.a1o.eq(self.process(None))
52 m.next = "normalise_1"
53
54