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
15 # TODO: delete (replace by DivPipeCoreInputData)
16 class FPDivStage0Data
:
18 def __init__(self
, width
, pspec
):
19 self
.z
= FPNumBaseRecord(width
, False)
20 self
.out_do_z
= Signal(reset_less
=True)
21 self
.oz
= Signal(width
, reset_less
=True)
24 self
.ctx
= FPPipeContext(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
),
36 self
.product
.eq(i
.product
), self
.ctx
.eq(i
.ctx
)]
39 class FPDivStage0Mod(Elaboratable
):
41 def __init__(self
, width
, id_wid
):
48 return FPSCData(self
.width
, self
.id_wid
, False)
51 return FPDivStage0Data(self
.width
, self
.id_wid
)
56 def setup(self
, m
, i
):
57 """ links module to inputs and outputs
59 m
.submodules
.div0
= self
60 m
.d
.comb
+= self
.i
.eq(i
)
62 def elaborate(self
, platform
):
65 # XXX TODO, actual DIV code here. this class would be
66 # "step one" which takes the pre-normalised data (see ispec) and
67 # *begins* the processing phase (enters the massive DIV
68 # pipeline chain) - see ospec.
70 # NOTE: this stage does *NOT* do *ACTUAL* DIV processing,
71 # it is PURELY the *ENTRY* point into the chain, performing
74 # store intermediate tests (and zero-extended mantissas)
75 am0
= Signal(len(self
.i
.a
.m
)+1, reset_less
=True)
76 bm0
= Signal(len(self
.i
.b
.m
)+1, reset_less
=True)
78 am0
.eq(Cat(self
.i
.a
.m
, 0)),
79 bm0
.eq(Cat(self
.i
.b
.m
, 0))
81 # same-sign (both negative or both positive) div mantissas
82 with m
.If(~self
.i
.out_do_z
):
83 m
.d
.comb
+= [self
.o
.z
.e
.eq(self
.i
.a
.e
+ self
.i
.b
.e
+ 1),
84 # TODO: no, not product, first stage Q and R etc. etc.
86 self
.o
.product
.eq(am0
* bm0
* 4),
87 self
.o
.z
.s
.eq(self
.i
.a
.s ^ self
.i
.b
.s
)
90 m
.d
.comb
+= self
.o
.oz
.eq(self
.i
.oz
)
91 m
.d
.comb
+= self
.o
.out_do_z
.eq(self
.i
.out_do_z
)
92 m
.d
.comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)
96 class FPDivStage0(FPState
):
97 """ First stage of div.
100 def __init__(self
, width
, id_wid
):
101 FPState
.__init
__(self
, "divider_0")
102 self
.mod
= FPDivStage0Mod(width
)
103 self
.o
= self
.mod
.ospec()
105 def setup(self
, m
, i
):
106 """ links module to inputs and outputs
110 # NOTE: these could be done as combinatorial (merge div0+div1)
111 m
.d
.sync
+= self
.o
.eq(self
.mod
.o
)