1 # This stage is intended to do most of the work of executing DIV
2 # This module however should not gate the carry or overflow, that's up
5 from nmigen
import (Module
, Signal
, Cat
, Repl
, Mux
, Const
, Array
)
6 from nmutil
.pipemodbase
import PipeModBase
7 from soc
.fu
.logical
.pipe_data
import LogicalInputData
8 from soc
.fu
.alu
.pipe_data
import ALUOutputData
9 from ieee754
.part
.partsig
import PartitionedSignal
10 from soc
.decoder
.power_enums
import InternalOp
12 from soc
.decoder
.power_fields
import DecodeFields
13 from soc
.decoder
.power_fieldsn
import SignalBitRange
16 class DivMainStage(PipeModBase
):
17 def __init__(self
, pspec
):
18 super().__init
__(pspec
, "main")
19 self
.fields
= DecodeFields(SignalBitRange
, [self
.i
.ctx
.op
.insn
])
20 self
.fields
.create_specs()
23 return LogicalInputData(self
.pspec
)
26 return ALUOutputData(self
.pspec
)
28 def elaborate(self
, platform
):
31 op
, a
, b
, o
= self
.i
.ctx
.op
, self
.i
.a
, self
.i
.b
, self
.o
.o
33 ##########################
36 with m
.Switch(op
.insn_type
):
38 ###### AND, OR, XOR #######
39 with m
.Case(InternalOp
.OP_AND
):
41 with m
.Case(InternalOp
.OP_OR
):
43 with m
.Case(InternalOp
.OP_XOR
):
47 with m
.Case(InternalOp
.OP_BPERM
):
48 m
.submodules
.bpermd
= bpermd
= Bpermd(64)
49 comb
+= bpermd
.rs
.eq(a
)
50 comb
+= bpermd
.rb
.eq(b
)
51 comb
+= o
.eq(bpermd
.ra
)
53 ###### sticky overflow and context, both pass-through #####
55 comb
+= self
.o
.xer_so
.data
.eq(self
.i
.xer_so
)
56 comb
+= self
.o
.ctx
.eq(self
.i
.ctx
)