reduce DIV radix to 1
[soc.git] / src / soc / fu / div / pipe_data.py
1 from nmigen import Signal, Const
2 from soc.fu.pipe_data import IntegerData
3 from soc.fu.alu.pipe_data import ALUOutputData, CommonPipeSpec
4 from soc.fu.logical.logical_input_record import CompLogicalOpSubset
5 from ieee754.div_rem_sqrt_rsqrt.core import (
6 DivPipeCoreConfig, DivPipeCoreInputData,
7 DivPipeCoreInterstageData, DivPipeCoreOutputData)
8
9
10 class DIVInputData(IntegerData):
11 regspec = [('INT', 'ra', '0:63'), # RA
12 ('INT', 'rb', '0:63'), # RB/immediate
13 ('XER', 'xer_so', '32'),] # XER bit 32: SO
14 def __init__(self, pspec):
15 super().__init__(pspec, False)
16 # convenience
17 self.a, self.b = self.ra, self.rb
18
19
20 class DIVPipeSpec(CommonPipeSpec):
21 regspec = (DIVInputData.regspec, ALUOutputData.regspec)
22 opsubsetkls = CompLogicalOpSubset
23 core_config = DivPipeCoreConfig(
24 bit_width=64,
25 fract_width=64,
26 log2_radix=1,
27 )
28
29
30 class CoreBaseData(DIVInputData):
31 def __init__(self, pspec, core_data_class):
32 super().__init__(pspec)
33 self.core = core_data_class(pspec.core_config)
34 self.divisor_neg = Signal(reset_less=True)
35 self.dividend_neg = Signal(reset_less=True)
36 self.div_by_zero = Signal(reset_less=True)
37
38 # set if an overflow for divide extended instructions is detected
39 # because `abs_dividend >= abs_divisor` for the appropriate bit width;
40 # 0 if the instruction is not a divide extended instruction
41 self.dive_abs_ov32 = Signal(reset_less=True)
42 self.dive_abs_ov64 = Signal(reset_less=True)
43
44 def __iter__(self):
45 yield from super().__iter__()
46 yield from self.core.__iter__(self)
47 yield self.divisor_neg
48 yield self.dividend_neg
49
50 def eq(self, rhs):
51 return self.eq_without_core(rhs) + self.core.eq(rhs.core)
52
53 def eq_without_core(self, rhs):
54 return super().eq(rhs) + \
55 [self.divisor_neg.eq(rhs.divisor_neg),
56 self.dividend_neg.eq(rhs.dividend_neg)]
57
58
59 class CoreInputData(CoreBaseData):
60 def __init__(self, pspec):
61 super().__init__(pspec, DivPipeCoreInputData)
62
63
64 class CoreInterstageData(CoreBaseData):
65 def __init__(self, pspec):
66 super().__init__(pspec, DivPipeCoreInterstageData)
67
68
69 class CoreOutputData(CoreBaseData):
70 def __init__(self, pspec):
71 super().__init__(pspec, DivPipeCoreOutputData)