1 # IEEE Floating Point Adder (Single Precision)
2 # Copyright (C) Jonathan P Dawson 2013
5 from nmigen
import Module
, Signal
6 from nmigen
.cli
import main
, verilog
8 from ieee754
.fpcommon
.modbase
import FPModBase
9 from ieee754
.fpcommon
.fpbase
import FPNumBaseRecord
, FPNumBase
10 from ieee754
.fpcommon
.roundz
import FPRoundData
11 from ieee754
.fpcommon
.getop
import FPPipeContext
16 def __init__(self
, pspec
):
18 self
.z
= Signal(width
, reset_less
=True) # result
19 self
.ctx
= FPPipeContext(pspec
)
21 # this is complicated: it's a workaround, due to the
22 # array-indexing not working properly in nmigen.
23 # self.ports() is used to access the ArrayProxy objects by name,
24 # however it doesn't work recursively. the workaround:
25 # drop the sub-objects into *this* scope and they can be
26 # accessed / set. it's horrible.
27 self
.muxid
= self
.ctx
.muxid
31 return [self
.z
.eq(i
.z
), self
.ctx
.eq(i
.ctx
)]
41 class FPPackMod(FPModBase
):
43 def __init__(self
, pspec
):
44 super().__init
__(pspec
, "pack")
47 return FPRoundData(self
.pspec
)
50 return FPPackData(self
.pspec
)
52 def elaborate(self
, platform
):
56 z
= FPNumBaseRecord(self
.pspec
.width
, False, name
="z")
57 m
.submodules
.pack_in_z
= in_z
= FPNumBase(self
.i
.z
)
59 with m
.If(~self
.i
.out_do_z
):
60 with m
.If(in_z
.is_overflowed
):
61 comb
+= z
.inf(self
.i
.z
.s
)
63 comb
+= z
.create(self
.i
.z
.s
, self
.i
.z
.e
, self
.i
.z
.m
)
65 comb
+= z
.v
.eq(self
.i
.oz
)
67 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)
68 comb
+= self
.o
.z
.eq(z
.v
)