1 """IEEE754 Floating Point Adder Pipeline
3 Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
7 from nmigen
import Module
, Signal
, Cat
, Elaboratable
8 from nmigen
.cli
import main
, verilog
10 from ieee754
.fpcommon
.fpbase
import FPNumBase
, FPNumBaseRecord
11 from ieee754
.fpcommon
.denorm
import FPSCData
12 from ieee754
.fpcommon
.getop
import FPPipeContext
15 class FPAddStage0Data
:
17 def __init__(self
, pspec
):
19 self
.z
= FPNumBaseRecord(width
, False)
20 self
.out_do_z
= Signal(reset_less
=True)
21 self
.oz
= Signal(width
, reset_less
=True)
22 self
.tot
= Signal(self
.z
.m_width
+ 4, reset_less
=True)
23 self
.ctx
= FPPipeContext(pspec
)
24 self
.muxid
= self
.ctx
.muxid
27 return [self
.z
.eq(i
.z
), self
.out_do_z
.eq(i
.out_do_z
), self
.oz
.eq(i
.oz
),
28 self
.tot
.eq(i
.tot
), self
.ctx
.eq(i
.ctx
)]
31 class FPAddStage0Mod(Elaboratable
):
33 def __init__(self
, pspec
):
39 return FPSCData(self
.pspec
, True)
42 return FPAddStage0Data(self
.pspec
)
47 def setup(self
, m
, i
):
48 """ links module to inputs and outputs
50 m
.submodules
.add0
= self
51 m
.d
.comb
+= self
.i
.eq(i
)
53 def elaborate(self
, platform
):
57 # store intermediate tests (and zero-extended mantissas)
58 seq
= Signal(reset_less
=True)
59 mge
= Signal(reset_less
=True)
60 am0
= Signal(len(self
.i
.a
.m
)+1, reset_less
=True)
61 bm0
= Signal(len(self
.i
.b
.m
)+1, reset_less
=True)
62 comb
+= [seq
.eq(self
.i
.a
.s
== self
.i
.b
.s
),
63 mge
.eq(self
.i
.a
.m
>= self
.i
.b
.m
),
64 am0
.eq(Cat(self
.i
.a
.m
, 0)),
65 bm0
.eq(Cat(self
.i
.b
.m
, 0))
67 # same-sign (both negative or both positive) add mantissas
68 with m
.If(~self
.i
.out_do_z
):
69 comb
+= self
.o
.z
.e
.eq(self
.i
.a
.e
)
72 self
.o
.tot
.eq(am0
+ bm0
),
73 self
.o
.z
.s
.eq(self
.i
.a
.s
)
75 # a mantissa greater than b, use a
78 self
.o
.tot
.eq(am0
- bm0
),
79 self
.o
.z
.s
.eq(self
.i
.a
.s
)
81 # b mantissa greater than a, use b
84 self
.o
.tot
.eq(bm0
- am0
),
85 self
.o
.z
.s
.eq(self
.i
.b
.s
)
88 # pass-through context
89 comb
+= self
.o
.oz
.eq(self
.i
.oz
)
90 comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
91 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)