add __init__.py to add dir
[ieee754fpu.git] / src / ieee754 / add / 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 singlepipe import StageChain, SimpleHandshake
8
9 from fpbase import FPState, FPID
10 from fpcommon.postcalc import FPAddStage1Data
11 from fpcommon.postnormalise import FPNorm1ModSingle
12 from fpcommon.roundz import FPRoundMod
13 from fpcommon.corrections import FPCorrectionsMod
14 from fpcommon.pack import FPPackData, FPPackMod
15
16
17 class FPNormToPack(FPState, SimpleHandshake):
18
19 def __init__(self, width, id_wid):
20 FPState.__init__(self, "normalise_1")
21 self.id_wid = id_wid
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.id_wid) # Norm1ModSingle ispec
27
28 def ospec(self):
29 return FPPackData(self.width, self.id_wid) # FPPackMod ospec
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.id_wid)
37 rmod = FPRoundMod(self.width, self.id_wid)
38 cmod = FPCorrectionsMod(self.width, self.id_wid)
39 pmod = FPPackMod(self.width, self.id_wid)
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"