1 """IEEE754 Floating Point Multiplier Pipeline
3 Copyright (C) 2019 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
7 from nmigen
import Module
, Signal
8 from nmigen
.cli
import main
, verilog
11 from nmutil
.pipemodbase
import PipeModBase
12 from ieee754
.fpcommon
.postcalc
import FPPostCalcData
13 from ieee754
.fpadd
.add0
import FPAddStage0Data
16 class FPAddStage1Mod(PipeModBase
):
17 """ Second stage of add: preparation for normalisation.
18 detects when tot sum is too big (tot[27] is kinda a carry bit)
21 def __init__(self
, pspec
):
22 super().__init
__(pspec
, "add1")
25 return FPAddStage0Data(self
.pspec
)
28 return FPPostCalcData(self
.pspec
)
30 def elaborate(self
, platform
):
34 comb
+= self
.o
.z
.eq(self
.i
.z
)
35 # tot[-1] (MSB) gets set when the sum overflows. shift result down
36 with m
.If(~self
.i
.out_do_z
):
37 with m
.If(self
.i
.tot
[-1]):
39 self
.o
.z
.m
.eq(self
.i
.tot
[4:]),
40 self
.o
.of
.m0
.eq(self
.i
.tot
[4]),
41 self
.o
.of
.guard
.eq(self
.i
.tot
[3]),
42 self
.o
.of
.round_bit
.eq(self
.i
.tot
[2]),
43 self
.o
.of
.sticky
.eq(self
.i
.tot
[1] | self
.i
.tot
[0]),
44 self
.o
.z
.e
.eq(self
.i
.z
.e
+ 1)
46 # tot[-1] (MSB) zero case
49 self
.o
.z
.m
.eq(self
.i
.tot
[3:]),
50 self
.o
.of
.m0
.eq(self
.i
.tot
[3]),
51 self
.o
.of
.guard
.eq(self
.i
.tot
[2]),
52 self
.o
.of
.round_bit
.eq(self
.i
.tot
[1]),
53 self
.o
.of
.sticky
.eq(self
.i
.tot
[0])
56 comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
57 comb
+= self
.o
.oz
.eq(self
.i
.oz
)
58 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)