remove parallel-reduction mode from decoder and sv/trans/svp64.py
[openpower-isa.git] / src / openpower / consts.py
1 import enum as _enum
2
3
4 # Can't think of a better place to put these functions.
5 # Return an arbitrary subfield of a larger field.
6 def field_slice(msb0_start, msb0_end, field_width=64):
7 """field_slice
8
9 Answers with a subfield slice of the signal r ("register"),
10 where the start and end bits use IBM "MSB 0" conventions.
11
12 see: https://en.wikipedia.org/wiki/Bit_numbering#MSB_0_bit_numbering
13
14 * assertion: msb0_start < msb0_end.
15 * The range specified is inclusive on both ends.
16 * field_width specifies the total number of bits (note: not bits-1)
17 """
18 if msb0_start >= msb0_end:
19 raise ValueError(
20 "start ({}) must be less than end ({})".format(msb0_start, msb0_end)
21 )
22 # sigh. MSB0 (IBM numbering) is inverted. converting to python
23 # we *swap names* so as not to get confused by having "end, start"
24 lsb0_end = (field_width-1) - msb0_start
25 lsb0_start = (field_width-1) - msb0_end
26
27 return slice(lsb0_start, lsb0_end + 1)
28
29
30 def field(r, msb0_start, msb0_end=None, field_width=64):
31 """Answers with a subfield of the signal r ("register"), where
32 the start and end bits use IBM conventions. start < end, if
33 end is provided. The range specified is inclusive on both ends.
34
35 Answers with a subfield of the signal r ("register"),
36 where the start and end bits use IBM "MSB 0" conventions.
37 If end is not provided, a single bit subfield is returned.
38
39 see: https://en.wikipedia.org/wiki/Bit_numbering#MSB_0_bit_numbering
40
41 * assertion: msb0_start < msb0_end.
42 * The range specified is inclusive on both ends.
43 * field_width specifies the total number of bits (note: not bits-1)
44
45 Example usage:
46
47 comb += field(insn, 0, 6, field_width=32).eq(17)
48 # NOTE: NEVER DIRECTLY ACCESS OPCODE FIELDS IN INSTRUCTIONS.
49 # This example is purely for illustrative purposes only.
50 # Use self.fields.FormXYZ.etcetc instead.
51
52 comb += field(msr, MSRb.TEs, MSRb.TEe).eq(0)
53
54 Proof by substitution:
55
56 field(insn, 0, 6, field_width=32).eq(17)
57 == insn[field_slice(0, 6, field_width=32)].eq(17)
58 == insn[slice((31-6), (31-0)+1)].eq(17)
59 == insn[slice(25, 32)].eq(17)
60 == insn[25:32].eq(17)
61
62 field(msr, MSRb.TEs, MSRb.TEe).eq(0)
63 == field(msr, 53, 54).eq(0)
64 == msr[field_slice(53, 54)].eq(0)
65 == msr[slice((63-54), (63-53)+1)].eq(0) # note cross-over!
66 == msr[slice(9, 11)].eq(0)
67 == msr[9:11].eq(0)
68 """
69 if msb0_end is None:
70 return r[(field_width - 1) - msb0_start]
71 else:
72 return r[field_slice(msb0_start, msb0_end, field_width)]
73
74
75 # just... don't ask. MSB0 is a massive pain in the neck.
76 # this module, aside from creating various field constants,
77 # helps out by creating alternative (identical) classes with
78 # a "b" name to indicate "MSB0 big-endian".
79 class _Const(_enum.IntEnum):
80 pass
81
82
83 class _ConstLEMeta(_enum.EnumMeta):
84 def __call__(metacls, *args, **kwargs):
85 if len(args) > 1:
86 names = args[1]
87 else:
88 names = kwargs.pop("names")
89
90 if isinstance(names, type) and issubclass(names, _enum.Enum):
91 names = dict(names.__members__)
92 if isinstance(names, dict):
93 names = tuple(names.items())
94
95 msb = kwargs.pop("msb")
96 names = {key:(msb - value) for (key, value) in names}
97
98 return super().__call__(*args, names=names, **kwargs)
99
100
101 class _ConstLE(_Const, metaclass=_ConstLEMeta):
102 pass
103
104
105 # Listed in V3.0B Book III Chap 4.2.1
106 # MSR bit numbers, *bigendian* order (PowerISA format)
107 # use this in the simulator
108 class MSRb(_Const):
109 SF = 0 # Sixty-Four bit mode
110 HV = 3 # Hypervisor state
111 UND = 5 # Undefined behavior state (see Bk 2, Sect. 3.2.1)
112 TSs = 29 # Transactional State (subfield)
113 TSe = 30 # Transactional State (subfield)
114 TM = 31 # Transactional Memory Available
115 VEC = 38 # Vector Available
116 VSX = 40 # VSX Available
117 S = 41 # Secure state
118 EE = 48 # External interrupt Enable
119 PR = 49 # PRoblem state
120 FP = 50 # FP available
121 ME = 51 # Machine Check int enable
122 FE0 = 52 # Floating-Point Exception Mode 0
123 TEs = 53 # Trace Enable (subfield)
124 TEe = 54 # Trace Enable (subfield)
125 FE1 = 55 # Floating-Point Exception Mode 1
126 IR = 58 # Instruction Relocation
127 DR = 59 # Data Relocation
128 PMM = 60 # Performance Monitor Mark
129 RI = 62 # Recoverable Interrupt
130 LE = 63 # Little Endian
131
132 # use this inside the HDL (where everything is little-endian)
133 MSR = _ConstLE("MSR", names=MSRb, msb=63)
134
135
136 # Listed in V3.0B Book III 7.5.9 "Program Interrupt"
137
138 # note that these correspond to trap_input_record.traptype bits 0,1,2,3,4
139 # (TODO: add more?)
140 # IMPORTANT: when adding extra bits here it is CRITICALLY IMPORTANT
141 # to expand traptype to cope with the increased range
142
143 # use this in the simulator
144 class PIb(_Const):
145 INVALID = 33 # 1 for an invalid mem err
146 PERMERR = 35 # 1 for an permanent mem err
147 TM_BAD_THING = 42 # 1 for a TM Bad Thing type interrupt
148 FP = 43 # 1 if FP exception
149 ILLEG = 44 # 1 if illegal instruction (not doing hypervisor)
150 PRIV = 45 # 1 if privileged interrupt
151 TRAP = 46 # 1 if exception is "trap" type
152 ADR = 47 # 0 if SRR0 = address of instruction causing exception
153
154 # and use this in the HDL
155 PI = _ConstLE("PI", names=PIb, msb=63)
156
157
158 # see traptype (and trap main_stage.py)
159 # IMPORTANT: when adding extra bits here it is CRITICALLY IMPORTANT
160 # to expand traptype to cope with the increased range
161
162 class TT:
163 FP = 1<<0
164 PRIV = 1<<1
165 TRAP = 1<<2
166 ADDR = 1<<3
167 EINT = 1<<4 # external interrupt
168 DEC = 1<<5 # decrement counter
169 MEMEXC = 1<<6 # LD/ST exception
170 ILLEG = 1<<7 # currently the max
171 # TODO: support for TM_BAD_THING (not included yet in trap main_stage.py)
172 size = 8 # MUST update this to contain the full number of Trap Types
173
174
175 # EXTRA3 3-bit subfield (spec)
176 class SPECb(_Const):
177 VEC = 0 # 1 for vector, 0 for scalar
178 MSB = 1 # augmented register number, MSB
179 LSB = 2 # augmented register number, LSB
180
181
182 SPEC_SIZE = 3
183 SPEC_AUG_SIZE = 2 # augmented subfield size (MSB+LSB above)
184 SPEC = _ConstLE("SPEC", names=SPECb, msb=SPEC_SIZE-1)
185
186
187
188 # EXTRA field, with EXTRA2 subfield encoding
189 class EXTRA2b(_Const):
190 IDX0_VEC = 0
191 IDX0_MSB = 1
192 IDX1_VEC = 2
193 IDX1_MSB = 3
194 IDX2_VEC = 4
195 IDX2_MSB = 5
196 IDX3_VEC = 6
197 IDX3_MSB = 7
198 RESERVED = 8
199
200
201 EXTRA2_SIZE = 9
202 EXTRA2 = _ConstLE("EXTRA2", names=EXTRA2b, msb=EXTRA2_SIZE-1)
203
204 # sigh, make these convenience-modifications afterwards (aliases)
205 # see RM-2P-1S1D-PU in https://libre-soc.org/openpower/sv/svp64
206 EXTRA2b.PACK_en = EXTRA2b.IDX2_VEC
207 EXTRA2b.UNPACK_en = EXTRA2b.IDX2_MSB
208 EXTRA2.PACK_en = EXTRA2.IDX2_VEC
209 EXTRA2.UNPACK_en = EXTRA2.IDX2_MSB
210
211
212 # EXTRA field, with EXTRA3 subfield encoding
213 class EXTRA3:
214 IDX0 = [0, 1, 2]
215 IDX1 = [3, 4, 5]
216 IDX2 = [6, 7, 8]
217 MASK = [6, 7, 8]
218
219
220 EXTRA3_SIZE = 9
221
222
223 # SVP64 ReMapped Field (from v3.1 EXT001 Prefix)
224 class SVP64P:
225 OPC = range(0, 6)
226 SVP64_7_9 = [7, 9]
227 RM = [6, 8] + list(range(10, 32))
228
229 # 24 bits in RM
230 SVP64P_SIZE = 24
231
232
233 # CR SVP64 offsets
234 class SVP64CROffs:
235 CR0 = 0 # TODO: increase when CRs are expanded to 128
236 CR1 = 1 # TODO: increase when CRs are expanded to 128
237 CRPred = 4 # TODO: increase when CRs are expanded to 128
238
239
240 class SVP64MODEb(_Const):
241 # mode bits
242 MOD2_MSB = 0
243 MOD2_LSB = 1
244 MOD3 = 3
245 # pack detection (TODO, CR-ops needs one of these too)
246 LDST_PACK = 2 # set =1 for LD/ST-immediate Pack mode
247 ARITH_PACK = 4 # set =1 for Arithmetic Pack mode
248 # when predicate not set: 0=ignore/skip 1=zero
249 DZ = 3 # for destination
250 SZ = 4 # for source
251 # for branch-conditional
252 BC_SNZ = 3 # for branch-conditional mode
253 BC_VLI = 2 # for VL include/exclude on VLSET mode
254 BC_VLSET = 1 # VLSET mode
255 BC_CTRTEST = 0 # CTR-test mode
256 # reduce mode
257 REDUCE = 2 # 0=normal predication 1=reduce mode
258 SVM = 3 # subvector reduce mode 0=independent 1=horizontal
259 CRM = 4 # CR mode on reduce (Rc=1) 0=some 1=all
260 RG = 4 # Reverse-gear on reduce
261 # saturation mode
262 N = 2 # saturation signed mode 0=signed 1=unsigned
263 # ffirst and predicate result modes
264 INV = 2 # invert CR sense 0=set 1=unset
265 CR_MSB = 3 # CR bit to update (with Rc=1)
266 CR_LSB = 4
267 RC1 = 4 # update CR as if Rc=1 (when Rc=0)
268 # LD immediate els (element-stride) locations, depending on mode
269 ELS_NORMAL = 4
270 ELS_FFIRST_PRED = 3
271 ELS_SAT = 4
272 # BO bits
273 BO_MSB = 2
274 BO_LSB = 4
275
276
277 SVP64MODE_SIZE = 5
278
279
280 SVP64MODE = _ConstLE("SVP64MODE", names=SVP64MODEb, msb=SVP64MODE_SIZE-1)
281
282
283 # add subfields to use with nmutil.sel
284 SVP64MODE.MOD2 = [0, 1]
285 SVP64MODE.CR = [3, 4]
286
287
288 # CR sub-fields
289 class CRb(_Const):
290 LT = 0
291 GT = 1
292 EQ = 2
293 SO = 3
294
295
296 CR_SIZE = 4
297
298
299 CR = _ConstLE("CR", names=CRb, msb=CR_SIZE-1)
300
301
302 # POWER9 Register Files
303 # XXX these are specific to Libre-SOC's decoder. really, they
304 # should be in libre-soc. however... long story: because the
305 # PowerDecoder2 has been moved to openpower-isa, and its decoding
306 # depends on that, then... whoops.
307
308 # "State" Regfile
309 class StateRegsEnum:
310 PC = 0
311 MSR = 1
312 SVSTATE = 2
313 DEC = 3
314 TB = 4
315 N_REGS = 5 # maximum number of regs
316
317 # Fast SPRs Regfile
318 class FastRegsEnum:
319 LR = 0
320 CTR = 1
321 SRR0 = 2
322 SRR1 = 3
323 HSRR0 = 4
324 HSRR1 = 5
325 SPRG0 = 6
326 SPRG1 = 7
327 SPRG2 = 8
328 SPRG3 = 9
329 HSPRG0 = 10
330 HSPRG1 = 11
331 XER = 12 # non-XER bits
332 TAR = 13
333 SVSRR0 = 14
334 # only one spare!
335 N_REGS = 15 # maximum number of regs
336
337 # XER Regfile
338 class XERRegsEnum:
339 SO=0 # this is actually 2-bit but we ignore 1 bit of it
340 CA=1 # CA and CA32
341 OV=2 # OV and OV32
342 N_REGS = 3 # maximum number of regs
343
344
345 if __name__ == '__main__':
346 print ("EXTRA2 pack", EXTRA2.PACK_en, EXTRA2.PACK_en.value)