1 """IEEE754 Floating Point Divider
3 Relevant bugreport: http://bugs.libre-riscv.org/show_bug.cgi?id=99
6 from nmigen
import Module
, Signal
, Cat
, Elaboratable
, Const
7 from nmigen
.cli
import main
, verilog
9 from ieee754
.fpcommon
.fpbase
import (FPNumBaseRecord
, Overflow
)
10 from ieee754
.fpcommon
.fpbase
import FPState
11 from ieee754
.fpcommon
.denorm
import FPSCData
12 from ieee754
.fpcommon
.getop
import FPPipeContext
13 from ieee754
.div_rem_sqrt_rsqrt
.div_pipe
import DivPipeInputData
16 class FPDivStage0Mod(Elaboratable
):
18 def __init__(self
, pspec
):
24 return FPSCData(self
.pspec
, False)
27 return DivPipeInputData(self
.pspec
)
32 def setup(self
, m
, i
):
33 """ links module to inputs and outputs
35 m
.submodules
.div0
= self
36 m
.d
.comb
+= self
.i
.eq(i
)
38 def elaborate(self
, platform
):
41 # XXX TODO, actual DIV code here. this class would be
42 # "step one" which takes the pre-normalised data (see ispec) and
43 # *begins* the processing phase (enters the massive DIV
44 # pipeline chain) - see ospec.
46 # INPUT SPEC: FPSCData
47 # OUTPUT SPEC: DivPipeInputData
49 # NOTE: this stage does *NOT* do *ACTUAL* DIV processing,
50 # it is PURELY the *ENTRY* point into the chain, performing
53 with m
.If(~self
.i
.out_do_z
):
54 # do conversion here, of both self.i.a and self.i.b,
55 # into DivPipeInputData dividend and divisor.
57 # the mantissas, having been de-normalised (and containing
58 # a "1" in the MSB) represent numbers in the range 0.5 to
59 # 0.9999999-recurring. the min and max range of the
60 # result is therefore 0.4999999 (0.5/0.99999) and 1.9999998
63 # zero-extend the mantissas (room for sticky/guard)
64 # plus the extra MSB. See DivPipeBaseStage.get_core_config
65 am0
= Signal(len(self
.i
.a
.m
)+3, reset_less
=True)
66 bm0
= Signal(len(self
.i
.b
.m
)+3, reset_less
=True)
68 am0
.eq(Cat(0,0,0,self
.i
.a
.m
, 0)),
69 bm0
.eq(Cat(0,0,0,self
.i
.b
.m
, 0)),
74 m
.d
.comb
+= [self
.o
.z
.e
.eq(self
.i
.a
.e
- self
.i
.b
.e
+ 1),
75 self
.o
.z
.s
.eq(self
.i
.a
.s ^ self
.i
.b
.s
),
76 self
.o
.dividend
[len(self
.i
.a
.m
)+3:].eq(am0
), # TODO: check
77 self
.o
.divisor_radicand
.eq(bm0
), # TODO: check
78 self
.o
.operation
.eq(Const(0)) # TODO check: DIV
81 # these are required and must not be touched
82 m
.d
.comb
+= self
.o
.oz
.eq(self
.i
.oz
)
83 m
.d
.comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
84 m
.d
.comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)
89 class FPDivStage0(FPState
):
90 """ First stage of div.
93 def __init__(self
, pspec
):
94 FPState
.__init
__(self
, "divider_0")
95 self
.mod
= FPDivStage0Mod(pspec
)
96 self
.o
= self
.mod
.ospec()
98 def setup(self
, m
, i
):
99 """ links module to inputs and outputs
103 # NOTE: these could be done as combinatorial (merge div0+div1)
104 m
.d
.sync
+= self
.o
.eq(self
.mod
.o
)