1 """IEEE754 Floating Point Multiplier Pipeline
3 Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
7 from nmigen
import Module
, Signal
, Elaboratable
8 from nmigen
.cli
import main
, verilog
11 from ieee754
.fpcommon
.postcalc
import FPAddStage1Data
12 from ieee754
.fpadd
.add0
import FPAddStage0Data
15 class FPAddStage1Mod(Elaboratable
):
16 """ Second stage of add: preparation for normalisation.
17 detects when tot sum is too big (tot[27] is kinda a carry bit)
20 def __init__(self
, pspec
):
26 return FPAddStage0Data(self
.pspec
)
29 return FPAddStage1Data(self
.pspec
)
34 def setup(self
, m
, i
):
35 """ links module to inputs and outputs
37 m
.submodules
.add1
= self
38 m
.d
.comb
+= self
.i
.eq(i
)
40 def elaborate(self
, platform
):
44 comb
+= self
.o
.z
.eq(self
.i
.z
)
45 # tot[-1] (MSB) gets set when the sum overflows. shift result down
46 with m
.If(~self
.i
.out_do_z
):
47 with m
.If(self
.i
.tot
[-1]):
49 self
.o
.z
.m
.eq(self
.i
.tot
[4:]),
50 self
.o
.of
.m0
.eq(self
.i
.tot
[4]),
51 self
.o
.of
.guard
.eq(self
.i
.tot
[3]),
52 self
.o
.of
.round_bit
.eq(self
.i
.tot
[2]),
53 self
.o
.of
.sticky
.eq(self
.i
.tot
[1] | self
.i
.tot
[0]),
54 self
.o
.z
.e
.eq(self
.i
.z
.e
+ 1)
56 # tot[-1] (MSB) zero case
59 self
.o
.z
.m
.eq(self
.i
.tot
[3:]),
60 self
.o
.of
.m0
.eq(self
.i
.tot
[3]),
61 self
.o
.of
.guard
.eq(self
.i
.tot
[2]),
62 self
.o
.of
.round_bit
.eq(self
.i
.tot
[1]),
63 self
.o
.of
.sticky
.eq(self
.i
.tot
[0])
66 comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
67 comb
+= self
.o
.oz
.eq(self
.i
.oz
)
68 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)