8db281aee5b0b40758d8a81237720b511f840137
1 """IEEE Floating Point Divider
3 Relevant bugreport: http://bugs.libre-riscv.org/show_bug.cgi?id=99
6 from nmigen
import Module
, Signal
, Elaboratable
7 from nmigen
.cli
import main
, verilog
9 from ieee754
.fpcommon
.fpbase
import FPState
10 from ieee754
.fpcommon
.postcalc
import FPAddStage1Data
11 from .div0
import FPDivStage0Data
# XXX TODO: replace
14 class FPDivStage2Mod(FPState
, Elaboratable
):
15 """ Second stage of div: preparation for normalisation.
18 def __init__(self
, pspec
):
24 # TODO: DivPipeCoreInterstageData
25 return FPDivStage0Data(self
.pspec
) # Q/Rem in...
28 # XXX REQUIRED. MUST NOT BE CHANGED. this is the format
29 # required for ongoing processing (normalisation, correction etc.)
30 return FPAddStage1Data(self
.pspec
) # out to post-process
35 def setup(self
, m
, i
):
36 """ links module to inputs and outputs
38 m
.submodules
.div1
= self
39 #m.submodules.div1_out_overflow = self.o.of
41 m
.d
.comb
+= self
.i
.eq(i
)
43 def elaborate(self
, platform
):
46 # copies sign and exponent and mantissa (mantissa to be overridden
48 m
.d
.comb
+= self
.o
.z
.eq(self
.i
.z
)
50 # TODO: this is "phase 3" of divide (the very end of the pipeline)
51 # takes the Q and R data (whatever) and performs
52 # last-stage guard/round/sticky and copies mantissa into z.
53 # post-processing stages take care of things from that point.
55 # NOTE: this phase does NOT do ACTUAL DIV processing, it ONLY
56 # does "conversion" *out* of the Q/REM last stage
58 with m
.If(~self
.i
.out_do_z
):
61 self
.o
.z
.m
.eq(self
.i
.product
[mw
+2:]),
62 self
.o
.of
.m0
.eq(self
.i
.product
[mw
+2]),
63 self
.o
.of
.guard
.eq(self
.i
.product
[mw
+1]),
64 self
.o
.of
.round_bit
.eq(self
.i
.product
[mw
]),
65 self
.o
.of
.sticky
.eq(self
.i
.product
[0:mw
].bool())
68 m
.d
.comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
69 m
.d
.comb
+= self
.o
.oz
.eq(self
.i
.oz
)
70 m
.d
.comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)
75 class FPDivStage2(FPState
):
77 def __init__(self
, pspec
):
78 FPState
.__init
__(self
, "divider_1")
79 self
.mod
= FPDivStage2Mod(pspec
)
80 self
.out_z
= FPNumBaseRecord(pspec
, False)
81 self
.out_of
= Overflow()
82 self
.norm_stb
= Signal()
84 def setup(self
, m
, i
):
85 """ links module to inputs and outputs
89 m
.d
.sync
+= self
.norm_stb
.eq(0) # sets to zero when not in div1 state
91 m
.d
.sync
+= self
.out_of
.eq(self
.mod
.out_of
)
92 m
.d
.sync
+= self
.out_z
.eq(self
.mod
.out_z
)
93 m
.d
.sync
+= self
.norm_stb
.eq(1)
96 m
.next
= "normalise_1"