1 """IEEE754 Floating Point pipelined Divider
3 Relevant bugreport: http://bugs.libre-riscv.org/show_bug.cgi?id=99
7 from nmigen
import Module
8 from nmigen
.cli
import main
, verilog
10 from nmutil
.singlepipe
import (StageChain
, SimpleHandshake
)
12 from ieee754
.fpcommon
.fpbase
import FPState
13 from ieee754
.fpcommon
.denorm
import FPSCData
14 from ieee754
.fpcommon
.postcalc
import FPAddStage1Data
17 from .div0
import FPDivStage0Mod
18 from .div1
import FPDivStage1Mod
19 from .div2
import FPDivStage2Mod
20 from .div0
import FPDivStage0Data
23 class FPDivStages(FPState
, SimpleHandshake
):
25 def __init__(self
, width
, pspec
, n_stages
, begin
, end
):
26 FPState
.__init
__(self
, "align")
29 self
.n_stages
= n_stages
# number of combinatorial stages
30 self
.begin
= begin
# "begin" mode
31 self
.end
= end
# "end" mode
32 SimpleHandshake
.__init
__(self
, self
) # pipeline is its own stage
33 self
.m1o
= self
.ospec()
36 if self
.begin
: # TODO - this is for FPDivStage0Mod
37 # REQUIRED. do NOT change.
38 return FPSCData(self
.width
, self
.pspec
, False) # from denorm
40 if self
.end
: # TODO - this is for FPDivStage2Mod
41 # XXX TODO: replace with "intermediary" (DivPipeCoreInterstageData?)
42 return FPDivStage0Data(self
.width
, self
.pspec
) # DIV ispec (loop)
44 # TODO - this is for FPDivStage1Mod
45 # XXX TODO: replace with "intermediary" (DivPipeCoreInterstageData)
46 return FPDivStage0Data(self
.width
, self
.pspec
) # DIV ispec (loop)
49 if self
.begin
: # TODO - this is for FPDivStage0Mod
50 # XXX TODO: replace with "intermediary" (DivPipeCoreInterstageData)
51 return FPDivStage0Data(self
.width
, self
.pspec
) # DIV ospec (loop)
53 if self
.end
: # TODO - this is for FPDivStage2Mod
54 # REQUIRED. do NOT change.
55 return FPAddStage1Data(self
.width
, self
.pspec
) # to post-norm
57 # TODO - this is for FPDivStage1Mod
58 # XXX TODO: replace with "intermediary" (DivPipeCoreInterstageData)
59 return FPDivStage0Data(self
.width
, self
.pspec
) # DIV ospec (loop)
61 def setup(self
, m
, i
):
62 """ links module to inputs and outputs
65 # start mode accepts data from the FP normalisation stage
66 # and does a bit of munging of the data. it will be chained
67 # into the first DIV combinatorial block,
69 # end mode takes the DIV pipeline/chain data and munges it
70 # into the format that the normalisation can accept.
72 # neither start nor end mode simply takes the exact same
73 # data in as out, this is where the Q/Rem comes in and Q/Rem goes out
77 if self
.begin
: # XXX check this
78 divstages
.append(FPDivStage0Mod(self
.width
, self
.pspec
))
80 for count
in range(self
.n_stages
): # number of combinatorial stages
81 divstages
.append(FPDivStage1Mod(self
.width
, self
.pspec
))
83 if self
.end
: # XXX check this
84 divstages
.append(FPDivStage2Mod(self
.width
, self
.pspec
))
86 chain
= StageChain(divstages
)
89 # output is from the last pipe stage
90 self
.o
= divstages
[-1].o
96 m
.d
.sync
+= self
.m1o
.eq(self
.process(None))
97 m
.next
= "normalise_1"