b90d02321cfa1988fafe910a54ca0d4f03364656
[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, pspec, e_extra=False):
20 FPState.__init__(self, "normalise_1")
21 #print ("normtopack", pspec)
22 self.pspec = pspec
23 self.e_extra = e_extra
24 SimpleHandshake.__init__(self, self) # pipeline is its own stage
25
26 def ispec(self):
27 return FPAddStage1Data(self.pspec, e_extra=self.e_extra)
28
29 def ospec(self):
30 return FPPackData(self.pspec) # FPPackMod
31
32 def setup(self, m, i):
33 """ links module to inputs and outputs
34 """
35
36 # Normalisation, Rounding Corrections, Pack - in a chain
37 nmod = FPNorm1ModSingle(self.pspec, e_extra=self.e_extra)
38 rmod = FPRoundMod(self.pspec)
39 cmod = FPCorrectionsMod(self.pspec)
40 pmod = FPPackMod(self.pspec)
41 stages = [nmod, rmod, cmod, pmod]
42 chain = StageChain(stages)
43 chain.setup(m, i)
44 self.out_z = pmod.ospec()
45
46 self.o = pmod.o
47
48 def process(self, i):
49 return self.o
50
51 def action(self, m):
52 m.d.sync += self.out_z.eq(self.process(None))
53 m.next = "pack_put_z"