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
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 # TODO: delete (replace by DivPipeCoreInputData)
17 class FPDivStage0Data
:
19 def __init__(self
, pspec
):
20 self
.z
= FPNumBaseRecord(pspec
.width
, False)
21 self
.out_do_z
= Signal(reset_less
=True)
22 self
.oz
= Signal(pspec
.width
, reset_less
=True)
24 self
.ctx
= FPPipeContext(pspec
.width
, pspec
) # context: muxid, operator etc.
25 self
.muxid
= self
.ctx
.muxid
# annoying. complicated.
27 # TODO: here is where Q and R would be put, and passed
28 # down to Stage1 processing.
30 mw
= (self
.z
.m_width
)*2 - 1 + 3 # sticky/round/guard bits + (2*mant) - 1
31 self
.product
= Signal(mw
, reset_less
=True)
34 return [self
.z
.eq(i
.z
), self
.out_do_z
.eq(i
.out_do_z
), self
.oz
.eq(i
.oz
),
35 self
.product
.eq(i
.product
), self
.ctx
.eq(i
.ctx
)]
38 class FPDivStage0Mod(Elaboratable
):
40 def __init__(self
, pspec
):
46 return FPSCData(self
.pspec
, False)
49 return DivPipeInputData(self
.pspec
)
54 def setup(self
, m
, i
):
55 """ links module to inputs and outputs
57 m
.submodules
.div0
= self
58 m
.d
.comb
+= self
.i
.eq(i
)
60 def elaborate(self
, platform
):
63 # XXX TODO, actual DIV code here. this class would be
64 # "step one" which takes the pre-normalised data (see ispec) and
65 # *begins* the processing phase (enters the massive DIV
66 # pipeline chain) - see ospec.
68 # INPUT SPEC: FPSCData
69 # OUTPUT SPEC: DivPipeCoreInputData
71 # NOTE: this stage does *NOT* do *ACTUAL* DIV processing,
72 # it is PURELY the *ENTRY* point into the chain, performing
75 with m
.If(~self
.i
.out_do_z
):
76 # do conversion here, of both self.i.a and self.i.b,
77 # into DivPipeCoreInputData dividend and divisor.
79 # the mantissas, having been de-normalised (and containing
80 # a "1" in the MSB) represent numbers in the range 0.5 to
81 # 0.9999999-recurring. the min and max range of the
82 # result is therefore 0.4999999 (0.5/0.99999) and 1.9999998
85 # zero-extend the mantissas (room for sticky/guard)
86 # plus the extra MSB. See DivPipeBaseStage.get_core_config
87 am0
= Signal(len(self
.i
.a
.m
)+3, reset_less
=True)
88 bm0
= Signal(len(self
.i
.b
.m
)+3, reset_less
=True)
90 am0
.eq(Cat(0, 0, self
.i
.a
.m
, 0)),
91 bm0
.eq(Cat(0, 0, self
.i
.b
.m
, 0))
94 m
.d
.comb
+= [self
.o
.z
.e
.eq(self
.i
.a
.e
- self
.i
.b
.e
+ 1),
95 self
.o
.z
.s
.eq(self
.i
.a
.s ^ self
.i
.b
.s
),
96 self
.o
.dividend
.eq(am0
), # TODO: check
97 self
.o
.divisor_radicand
.eq(bm0
), # TODO: check
98 self
.o
.operation
.eq(Const(0)) # TODO check: DIV
101 # these are required and must not be touched
102 m
.d
.comb
+= self
.o
.oz
.eq(self
.i
.oz
)
103 m
.d
.comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
104 m
.d
.comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)
109 class FPDivStage0(FPState
):
110 """ First stage of div.
113 def __init__(self
, pspec
):
114 FPState
.__init
__(self
, "divider_0")
115 self
.mod
= FPDivStage0Mod(pspec
)
116 self
.o
= self
.mod
.ospec()
118 def setup(self
, m
, i
):
119 """ links module to inputs and outputs
123 # NOTE: these could be done as combinatorial (merge div0+div1)
124 m
.d
.sync
+= self
.o
.eq(self
.mod
.o
)