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
, DP
,
7 DivPipeCoreInterstageData
, DivPipeCoreOutputData
)
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)
17 self
.a
, self
.b
= self
.ra
, self
.rb
20 class DIVPipeSpec(CommonPipeSpec
):
21 regspec
= (DIVInputData
.regspec
, ALUOutputData
.regspec
)
22 opsubsetkls
= CompLogicalOpSubset
23 core_config
= DivPipeCoreConfig(
27 supported
=[DP
.UDivRem
]
31 class CoreBaseData(DIVInputData
):
32 def __init__(self
, pspec
, core_data_class
):
33 super().__init
__(pspec
)
34 self
.core
= core_data_class(pspec
.core_config
)
35 self
.divisor_neg
= Signal(reset_less
=True)
36 self
.dividend_neg
= Signal(reset_less
=True)
37 self
.div_by_zero
= Signal(reset_less
=True)
39 # set if an overflow for divide extended instructions is detected
40 # because `abs_dividend >= abs_divisor` for the appropriate bit width;
41 # 0 if the instruction is not a divide extended instruction
42 self
.dive_abs_ov32
= Signal(reset_less
=True)
43 self
.dive_abs_ov64
= Signal(reset_less
=True)
46 yield from super().__iter
__()
47 yield from self
.core
.__iter
__(self
)
48 yield self
.divisor_neg
49 yield self
.dividend_neg
52 return self
.eq_without_core(rhs
) + self
.core
.eq(rhs
.core
)
54 def eq_without_core(self
, rhs
):
55 return super().eq(rhs
) + \
56 [self
.divisor_neg
.eq(rhs
.divisor_neg
),
57 self
.dividend_neg
.eq(rhs
.dividend_neg
)]
60 class CoreInputData(CoreBaseData
):
61 def __init__(self
, pspec
):
62 super().__init
__(pspec
, DivPipeCoreInputData
)
65 class CoreInterstageData(CoreBaseData
):
66 def __init__(self
, pspec
):
67 super().__init
__(pspec
, DivPipeCoreInterstageData
)
70 class CoreOutputData(CoreBaseData
):
71 def __init__(self
, pspec
):
72 super().__init
__(pspec
, DivPipeCoreOutputData
)