1 """IEEE754 Floating Point Library
3 Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
5 """
7 from nmigen import Module, Mux
8 from nmigen.cli import main, verilog
9 from math import log
11 from nmutil.pipemodbase import PipeModBase
12 from ieee754.fpcommon.fpbase import FPNumBase
13 from ieee754.fpcommon.pscdata import FPSCData
18 def __init__(self, pspec, m_extra):
19 self.m_extra = m_extra
20 super().__init__(pspec, "denormalise")
22 def ispec(self):
23 return FPSCData(self.pspec, self.m_extra)
25 def ospec(self):
26 return FPSCData(self.pspec, self.m_extra)
28 def elaborate(self, platform):
29 m = Module()
30 comb = m.d.comb
32 m.submodules.denorm_in_a = in_a = FPNumBase(self.i.a)
33 m.submodules.denorm_in_b = in_b = FPNumBase(self.i.b)
35 # XXX hmmm, don't like repeating identical code
36 comb += self.o.a.eq(self.i.a)
37 ae = self.i.a.e
38 am = self.i.a.m
39 # either limit exponent, or set top mantissa bit
40 comb += self.o.a.e.eq(Mux(in_a.exp_n127, self.i.a.N126, ae))
41 comb += self.o.a.m[-1].eq(Mux(in_a.exp_n127, am[-1], 1))
43 # XXX code now repeated for b
44 comb += self.o.b.eq(self.i.b)
45 be = self.i.b.e
46 bm = self.i.b.m
47 # either limit exponent, or set top mantissa bit
48 comb += self.o.b.e.eq(Mux(in_b.exp_n127, self.i.b.N126, be))
49 comb += self.o.b.m[-1].eq(Mux(in_b.exp_n127, bm[-1], 1))
51 comb += self.o.ctx.eq(self.i.ctx)
52 comb += self.o.z.eq(self.i.z)
53 comb += self.o.out_do_z.eq(self.i.out_do_z)
54 comb += self.o.oz.eq(self.i.oz)
56 return m