1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
5 from nmigen
import Module
, Signal
7 from nmutil
.pipemodbase
import PipeModBase
8 from ieee754
.fpcommon
.fpbase
import FPFormat
, FPNumBaseRecord
, FPNumBase
, \
10 from ieee754
.fpcommon
.roundz
import FPRoundData
11 from ieee754
.fpcommon
.packdata
import FPPackData
14 class FPPackMod(PipeModBase
):
16 def __init__(self
, pspec
):
17 super().__init
__(pspec
, "pack")
20 return FPRoundData(self
.pspec
)
23 return FPPackData(self
.pspec
)
25 def elaborate(self
, platform
):
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
])
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
)
42 comb
+= z
.max_normal(self
.i
.z
.s
)
44 comb
+= z
.create(self
.i
.z
.s
, self
.i
.z
.e
, self
.i
.z
.m
)
46 comb
+= z
.v
.eq(self
.i
.oz
)
48 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)
49 comb
+= self
.o
.z
.eq(z
.v
)