c26a74a005c985779471b772ad3631065910acfa
[ieee754fpu.git] / src / ieee754 / fpdiv / divstages.py
1 """IEEE754 Floating Point pipelined Divider
2
3 Relevant bugreport: http://bugs.libre-riscv.org/show_bug.cgi?id=99
4
5 """
6
7 from ieee754.fpcommon.modbase import FPModBaseChain
8 from ieee754.div_rem_sqrt_rsqrt.div_pipe import (DivPipeInterstageData,
9 DivPipeSetupStage,
10 DivPipeCalculateStage,
11 DivPipeFinalStage,
12 )
13 from ieee754.fpdiv.div0 import FPDivStage0Mod
14 from ieee754.fpdiv.div2 import FPDivStage2Mod
15
16
17 class FPDivStagesSetup(FPModBaseChain):
18
19 def __init__(self, pspec, n_stages, stage_offs):
20 self.n_stages = n_stages # number of combinatorial stages
21 self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
22 super().__init__(pspec)
23
24 def get_chain(self):
25 """ gets module chain
26
27 note: this is a pure *combinatorial* module (StageChain).
28 therefore each sub-module must also be combinatorial
29 """
30
31 divstages = []
32
33 # Converts from FPSCData into DivPipeInputData
34 divstages.append(FPDivStage0Mod(self.pspec))
35
36 # does 1 "convert" (actual processing) from DivPipeInputData
37 # into "intermediate" output (DivPipeInterstageData)
38 divstages.append(DivPipeSetupStage(self.pspec))
39
40 # here is where the intermediary stages are added.
41 # n_stages is adjusted (by pipeline.py), reduced to take
42 # into account extra processing that FPDivStage0Mod and DivPipeSetup
43 # might add.
44 for count in range(self.n_stages): # number of combinatorial stages
45 idx = count + self.stage_offs
46 divstages.append(DivPipeCalculateStage(self.pspec, idx))
47
48 return divstages
49
50
51 class FPDivStagesIntermediate(FPModBaseChain):
52
53 def __init__(self, pspec, n_stages, stage_offs):
54 self.n_stages = n_stages # number of combinatorial stages
55 self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
56 super().__init__(pspec)
57
58 def get_chain(self):
59 """ gets module chain
60
61 note: this is a pure *combinatorial* module (StageChain).
62 therefore each sub-module must also be combinatorial
63 """
64
65 divstages = []
66
67 # here is where the intermediary stages are added.
68 # n_stages is adjusted (in pipeline.py), reduced to take
69 # into account the extra processing that self.begin and self.end
70 # will add.
71 for count in range(self.n_stages): # number of combinatorial stages
72 idx = count + self.stage_offs
73 divstages.append(DivPipeCalculateStage(self.pspec, idx))
74
75 return divstages
76
77
78 class FPDivStagesFinal(FPModBaseChain):
79
80 def __init__(self, pspec, n_stages, stage_offs):
81 self.n_stages = n_stages # number of combinatorial stages
82 self.stage_offs = stage_offs # each CalcStage needs *absolute* idx
83 super().__init__(pspec)
84
85 def get_chain(self):
86 """ gets module chain
87
88 note: this is a pure *combinatorial* module (StageChain).
89 therefore each sub-module must also be combinatorial
90 """
91
92 # takes the DIV pipeline/chain data and munges it
93 # into the format that the normalisation can accept.
94
95 divstages = []
96
97 # here is where the intermediary stages are added.
98 # n_stages is adjusted (in pipeline.py), reduced to take
99 # into account the extra processing that self.begin and self.end
100 # will add.
101 for count in range(self.n_stages): # number of combinatorial stages
102 idx = count + self.stage_offs
103 divstages.append(DivPipeCalculateStage(self.pspec, idx))
104
105 # does the final conversion from intermediary to output data
106 divstages.append(DivPipeFinalStage(self.pspec))
107
108 # does conversion from DivPipeOutputData into
109 # FPAddStage1Data format (bad name, TODO, doesn't matter),
110 # so that post-normalisation and corrections can take over
111 divstages.append(FPDivStage2Mod(self.pspec))
112
113 return divstages