use new FPBaseData as a "spec" (context), initialised with a dict (pspec)
[ieee754fpu.git] / src / ieee754 / fpcommon / normtopack.py
1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
3 # 2013-12-12
4
5 #from nmigen.cli import main, verilog
6
7 from nmutil.singlepipe import StageChain, SimpleHandshake
8
9 from ieee754.fpcommon.fpbase import FPState, FPID
10 from .postcalc import FPAddStage1Data
11 from .postnormalise import FPNorm1ModSingle
12 from .roundz import FPRoundMod
13 from .corrections import FPCorrectionsMod
14 from .pack import FPPackData, FPPackMod
15
16
17 class FPNormToPack(FPState, SimpleHandshake):
18
19 def __init__(self, width, pspec):
20 FPState.__init__(self, "normalise_1")
21 self.pspec = pspec
22 self.width = width
23 SimpleHandshake.__init__(self, self) # pipeline is its own stage
24
25 def ispec(self):
26 return FPAddStage1Data(self.width, self.pspec)
27
28 def ospec(self):
29 return FPPackData(self.width, self.pspec) # FPPackMod
30
31 def setup(self, m, i):
32 """ links module to inputs and outputs
33 """
34
35 # Normalisation, Rounding Corrections, Pack - in a chain
36 nmod = FPNorm1ModSingle(self.width, self.pspec)
37 rmod = FPRoundMod(self.width, self.pspec)
38 cmod = FPCorrectionsMod(self.width, self.pspec)
39 pmod = FPPackMod(self.width, self.pspec)
40 stages = [nmod, rmod, cmod, pmod]
41 chain = StageChain(stages)
42 chain.setup(m, i)
43 self.out_z = pmod.ospec()
44
45 self.o = pmod.o
46
47 def process(self, i):
48 return self.o
49
50 def action(self, m):
51 m.d.sync += self.out_z.eq(self.process(None))
52 m.next = "pack_put_z"