switch to exact version of cython
[ieee754fpu.git] / src / ieee754 / fpcommon / pack.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, Signal
6
7 from nmutil.pipemodbase import PipeModBase
8 from ieee754.fpcommon.fpbase import FPFormat, FPNumBaseRecord, FPNumBase, \
9 FPRoundingMode
10 from ieee754.fpcommon.roundz import FPRoundData
11 from ieee754.fpcommon.packdata import FPPackData
12
13
14 class FPPackMod(PipeModBase):
15
16 def __init__(self, pspec):
17 super().__init__(pspec, "pack")
18
19 def ispec(self):
20 return FPRoundData(self.pspec)
21
22 def ospec(self):
23 return FPPackData(self.pspec)
24
25 def elaborate(self, platform):
26 m = Module()
27 comb = m.d.comb
28
29 z = FPNumBaseRecord(m_extra=False, name="z",
30 fpformat=FPFormat.from_pspec(self.pspec))
31 m.submodules.pack_in_z = in_z = FPNumBase(self.i.z)
32 overflow_array = FPRoundingMode.make_array(
33 lambda rm: rm.overflow_rounds_to_inf(self.i.z.s))
34 overflow_rounds_to_inf = Signal()
35 m.d.comb += overflow_rounds_to_inf.eq(overflow_array[self.i.rm])
36
37 with m.If(~self.i.out_do_z):
38 with m.If(in_z.is_overflowed):
39 with m.If(overflow_rounds_to_inf):
40 comb += z.inf(self.i.z.s)
41 with m.Else():
42 comb += z.max_normal(self.i.z.s)
43 with m.Else():
44 comb += z.create(self.i.z.s, self.i.z.e, self.i.z.m)
45 with m.Else():
46 comb += z.v.eq(self.i.oz)
47
48 comb += self.o.ctx.eq(self.i.ctx)
49 comb += self.o.z.eq(z.v)
50
51 return m