1bf215546Sopenharmony_ci#
2bf215546Sopenharmony_ci# Copyright (c) 2018 Valve Corporation
3bf215546Sopenharmony_ci#
4bf215546Sopenharmony_ci# Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci# copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci# to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci# and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci# Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci#
11bf215546Sopenharmony_ci# The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci# paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci# Software.
14bf215546Sopenharmony_ci#
15bf215546Sopenharmony_ci# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci# IN THE SOFTWARE.
22bf215546Sopenharmony_ci#
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci# Class that represents all the information we have about the opcode
25bf215546Sopenharmony_ci# NOTE: this must be kept in sync with aco_op_info
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ciimport sys
28bf215546Sopenharmony_cifrom enum import Enum
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ciclass InstrClass(Enum):
31bf215546Sopenharmony_ci   Valu32 = 0
32bf215546Sopenharmony_ci   ValuConvert32 = 1
33bf215546Sopenharmony_ci   Valu64 = 2
34bf215546Sopenharmony_ci   ValuQuarterRate32 = 3
35bf215546Sopenharmony_ci   ValuFma = 4
36bf215546Sopenharmony_ci   ValuTranscendental32 = 5
37bf215546Sopenharmony_ci   ValuDouble = 6
38bf215546Sopenharmony_ci   ValuDoubleAdd = 7
39bf215546Sopenharmony_ci   ValuDoubleConvert = 8
40bf215546Sopenharmony_ci   ValuDoubleTranscendental = 9
41bf215546Sopenharmony_ci   Salu = 10
42bf215546Sopenharmony_ci   SMem = 11
43bf215546Sopenharmony_ci   Barrier = 12
44bf215546Sopenharmony_ci   Branch = 13
45bf215546Sopenharmony_ci   Sendmsg = 14
46bf215546Sopenharmony_ci   DS = 15
47bf215546Sopenharmony_ci   Export = 16
48bf215546Sopenharmony_ci   VMem = 17
49bf215546Sopenharmony_ci   Waitcnt = 18
50bf215546Sopenharmony_ci   Other = 19
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ciclass Format(Enum):
53bf215546Sopenharmony_ci   PSEUDO = 0
54bf215546Sopenharmony_ci   SOP1 = 1
55bf215546Sopenharmony_ci   SOP2 = 2
56bf215546Sopenharmony_ci   SOPK = 3
57bf215546Sopenharmony_ci   SOPP = 4
58bf215546Sopenharmony_ci   SOPC = 5
59bf215546Sopenharmony_ci   SMEM = 6
60bf215546Sopenharmony_ci   DS = 8
61bf215546Sopenharmony_ci   MTBUF = 9
62bf215546Sopenharmony_ci   MUBUF = 10
63bf215546Sopenharmony_ci   MIMG = 11
64bf215546Sopenharmony_ci   EXP = 12
65bf215546Sopenharmony_ci   FLAT = 13
66bf215546Sopenharmony_ci   GLOBAL = 14
67bf215546Sopenharmony_ci   SCRATCH = 15
68bf215546Sopenharmony_ci   PSEUDO_BRANCH = 16
69bf215546Sopenharmony_ci   PSEUDO_BARRIER = 17
70bf215546Sopenharmony_ci   PSEUDO_REDUCTION = 18
71bf215546Sopenharmony_ci   VOP3P = 19
72bf215546Sopenharmony_ci   VOP1 = 1 << 8
73bf215546Sopenharmony_ci   VOP2 = 1 << 9
74bf215546Sopenharmony_ci   VOPC = 1 << 10
75bf215546Sopenharmony_ci   VOP3 = 1 << 11
76bf215546Sopenharmony_ci   VINTRP = 1 << 12
77bf215546Sopenharmony_ci   DPP16 = 1 << 13
78bf215546Sopenharmony_ci   SDWA = 1 << 14
79bf215546Sopenharmony_ci   DPP8 = 1 << 15
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   def get_builder_fields(self):
82bf215546Sopenharmony_ci      if self == Format.SOPK:
83bf215546Sopenharmony_ci         return [('uint16_t', 'imm', None)]
84bf215546Sopenharmony_ci      elif self == Format.SOPP:
85bf215546Sopenharmony_ci         return [('uint32_t', 'block', '-1'),
86bf215546Sopenharmony_ci                 ('uint32_t', 'imm', '0')]
87bf215546Sopenharmony_ci      elif self == Format.SMEM:
88bf215546Sopenharmony_ci         return [('memory_sync_info', 'sync', 'memory_sync_info()'),
89bf215546Sopenharmony_ci                 ('bool', 'glc', 'false'),
90bf215546Sopenharmony_ci                 ('bool', 'dlc', 'false'),
91bf215546Sopenharmony_ci                 ('bool', 'nv', 'false')]
92bf215546Sopenharmony_ci      elif self == Format.DS:
93bf215546Sopenharmony_ci         return [('uint16_t', 'offset0', '0'),
94bf215546Sopenharmony_ci                 ('uint8_t', 'offset1', '0'),
95bf215546Sopenharmony_ci                 ('bool', 'gds', 'false')]
96bf215546Sopenharmony_ci      elif self == Format.MTBUF:
97bf215546Sopenharmony_ci         return [('unsigned', 'dfmt', None),
98bf215546Sopenharmony_ci                 ('unsigned', 'nfmt', None),
99bf215546Sopenharmony_ci                 ('unsigned', 'offset', None),
100bf215546Sopenharmony_ci                 ('bool', 'offen', None),
101bf215546Sopenharmony_ci                 ('bool', 'idxen', 'false'),
102bf215546Sopenharmony_ci                 ('bool', 'disable_wqm', 'false'),
103bf215546Sopenharmony_ci                 ('bool', 'glc', 'false'),
104bf215546Sopenharmony_ci                 ('bool', 'dlc', 'false'),
105bf215546Sopenharmony_ci                 ('bool', 'slc', 'false'),
106bf215546Sopenharmony_ci                 ('bool', 'tfe', 'false')]
107bf215546Sopenharmony_ci      elif self == Format.MUBUF:
108bf215546Sopenharmony_ci         return [('unsigned', 'offset', None),
109bf215546Sopenharmony_ci                 ('bool', 'offen', None),
110bf215546Sopenharmony_ci                 ('bool', 'swizzled', 'false'),
111bf215546Sopenharmony_ci                 ('bool', 'idxen', 'false'),
112bf215546Sopenharmony_ci                 ('bool', 'addr64', 'false'),
113bf215546Sopenharmony_ci                 ('bool', 'disable_wqm', 'false'),
114bf215546Sopenharmony_ci                 ('bool', 'glc', 'false'),
115bf215546Sopenharmony_ci                 ('bool', 'dlc', 'false'),
116bf215546Sopenharmony_ci                 ('bool', 'slc', 'false'),
117bf215546Sopenharmony_ci                 ('bool', 'tfe', 'false'),
118bf215546Sopenharmony_ci                 ('bool', 'lds', 'false')]
119bf215546Sopenharmony_ci      elif self == Format.MIMG:
120bf215546Sopenharmony_ci         return [('unsigned', 'dmask', '0xF'),
121bf215546Sopenharmony_ci                 ('bool', 'da', 'false'),
122bf215546Sopenharmony_ci                 ('bool', 'unrm', 'true'),
123bf215546Sopenharmony_ci                 ('bool', 'disable_wqm', 'false'),
124bf215546Sopenharmony_ci                 ('bool', 'glc', 'false'),
125bf215546Sopenharmony_ci                 ('bool', 'dlc', 'false'),
126bf215546Sopenharmony_ci                 ('bool', 'slc', 'false'),
127bf215546Sopenharmony_ci                 ('bool', 'tfe', 'false'),
128bf215546Sopenharmony_ci                 ('bool', 'lwe', 'false'),
129bf215546Sopenharmony_ci                 ('bool', 'r128', 'false'),
130bf215546Sopenharmony_ci                 ('bool', 'a16', 'false'),
131bf215546Sopenharmony_ci                 ('bool', 'd16', 'false')]
132bf215546Sopenharmony_ci         return [('unsigned', 'attribute', None),
133bf215546Sopenharmony_ci                 ('unsigned', 'component', None)]
134bf215546Sopenharmony_ci      elif self == Format.EXP:
135bf215546Sopenharmony_ci         return [('unsigned', 'enabled_mask', None),
136bf215546Sopenharmony_ci                 ('unsigned', 'dest', None),
137bf215546Sopenharmony_ci                 ('bool', 'compr', 'false', 'compressed'),
138bf215546Sopenharmony_ci                 ('bool', 'done', 'false'),
139bf215546Sopenharmony_ci                 ('bool', 'vm', 'false', 'valid_mask')]
140bf215546Sopenharmony_ci      elif self == Format.PSEUDO_BRANCH:
141bf215546Sopenharmony_ci         return [('uint32_t', 'target0', '0', 'target[0]'),
142bf215546Sopenharmony_ci                 ('uint32_t', 'target1', '0', 'target[1]')]
143bf215546Sopenharmony_ci      elif self == Format.PSEUDO_REDUCTION:
144bf215546Sopenharmony_ci         return [('ReduceOp', 'op', None, 'reduce_op'),
145bf215546Sopenharmony_ci                 ('unsigned', 'cluster_size', '0')]
146bf215546Sopenharmony_ci      elif self == Format.PSEUDO_BARRIER:
147bf215546Sopenharmony_ci         return [('memory_sync_info', 'sync', None),
148bf215546Sopenharmony_ci                 ('sync_scope', 'exec_scope', 'scope_invocation')]
149bf215546Sopenharmony_ci      elif self == Format.VINTRP:
150bf215546Sopenharmony_ci         return [('unsigned', 'attribute', None),
151bf215546Sopenharmony_ci                 ('unsigned', 'component', None)]
152bf215546Sopenharmony_ci      elif self == Format.DPP16:
153bf215546Sopenharmony_ci         return [('uint16_t', 'dpp_ctrl', None),
154bf215546Sopenharmony_ci                 ('uint8_t', 'row_mask', '0xF'),
155bf215546Sopenharmony_ci                 ('uint8_t', 'bank_mask', '0xF'),
156bf215546Sopenharmony_ci                 ('bool', 'bound_ctrl', 'true')]
157bf215546Sopenharmony_ci      elif self == Format.VOP3P:
158bf215546Sopenharmony_ci         return [('uint8_t', 'opsel_lo', None),
159bf215546Sopenharmony_ci                 ('uint8_t', 'opsel_hi', None)]
160bf215546Sopenharmony_ci      elif self in [Format.FLAT, Format.GLOBAL, Format.SCRATCH]:
161bf215546Sopenharmony_ci         return [('int16_t', 'offset', 0),
162bf215546Sopenharmony_ci                 ('memory_sync_info', 'sync', 'memory_sync_info()'),
163bf215546Sopenharmony_ci                 ('bool', 'glc', 'false'),
164bf215546Sopenharmony_ci                 ('bool', 'slc', 'false'),
165bf215546Sopenharmony_ci                 ('bool', 'lds', 'false'),
166bf215546Sopenharmony_ci                 ('bool', 'nv', 'false')]
167bf215546Sopenharmony_ci      else:
168bf215546Sopenharmony_ci         return []
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci   def get_builder_field_names(self):
171bf215546Sopenharmony_ci      return [f[1] for f in self.get_builder_fields()]
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   def get_builder_field_dests(self):
174bf215546Sopenharmony_ci      return [(f[3] if len(f) >= 4 else f[1]) for f in self.get_builder_fields()]
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci   def get_builder_field_decls(self):
177bf215546Sopenharmony_ci      return [('%s %s=%s' % (f[0], f[1], f[2]) if f[2] != None else '%s %s' % (f[0], f[1])) for f in self.get_builder_fields()]
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   def get_builder_initialization(self, num_operands):
180bf215546Sopenharmony_ci      res = ''
181bf215546Sopenharmony_ci      if self == Format.SDWA:
182bf215546Sopenharmony_ci         for i in range(min(num_operands, 2)):
183bf215546Sopenharmony_ci            res += 'instr->sel[{0}] = SubdwordSel(op{0}.op.bytes(), 0, false);'.format(i)
184bf215546Sopenharmony_ci         res += 'instr->dst_sel = SubdwordSel(def0.bytes(), 0, false);\n'
185bf215546Sopenharmony_ci      return res
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_ci
188bf215546Sopenharmony_ciclass Opcode(object):
189bf215546Sopenharmony_ci   """Class that represents all the information we have about the opcode
190bf215546Sopenharmony_ci   NOTE: this must be kept in sync with aco_op_info
191bf215546Sopenharmony_ci   """
192bf215546Sopenharmony_ci   def __init__(self, name, opcode_gfx7, opcode_gfx9, opcode_gfx10, format, input_mod, output_mod, is_atomic, cls):
193bf215546Sopenharmony_ci      """Parameters:
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_ci      - name is the name of the opcode (prepend nir_op_ for the enum name)
196bf215546Sopenharmony_ci      - all types are strings that get nir_type_ prepended to them
197bf215546Sopenharmony_ci      - input_types is a list of types
198bf215546Sopenharmony_ci      - algebraic_properties is a space-seperated string, where nir_op_is_ is
199bf215546Sopenharmony_ci        prepended before each entry
200bf215546Sopenharmony_ci      - const_expr is an expression or series of statements that computes the
201bf215546Sopenharmony_ci        constant value of the opcode given the constant values of its inputs.
202bf215546Sopenharmony_ci      """
203bf215546Sopenharmony_ci      assert isinstance(name, str)
204bf215546Sopenharmony_ci      assert isinstance(opcode_gfx7, int)
205bf215546Sopenharmony_ci      assert isinstance(opcode_gfx9, int)
206bf215546Sopenharmony_ci      assert isinstance(opcode_gfx10, int)
207bf215546Sopenharmony_ci      assert isinstance(format, Format)
208bf215546Sopenharmony_ci      assert isinstance(input_mod, bool)
209bf215546Sopenharmony_ci      assert isinstance(output_mod, bool)
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci      self.name = name
212bf215546Sopenharmony_ci      self.opcode_gfx7 = opcode_gfx7
213bf215546Sopenharmony_ci      self.opcode_gfx9 = opcode_gfx9
214bf215546Sopenharmony_ci      self.opcode_gfx10 = opcode_gfx10
215bf215546Sopenharmony_ci      self.input_mod = "1" if input_mod else "0"
216bf215546Sopenharmony_ci      self.output_mod = "1" if output_mod else "0"
217bf215546Sopenharmony_ci      self.is_atomic = "1" if is_atomic else "0"
218bf215546Sopenharmony_ci      self.format = format
219bf215546Sopenharmony_ci      self.cls = cls
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_ci      parts = name.replace('_e64', '').rsplit('_', 2)
222bf215546Sopenharmony_ci      op_dtype = parts[-1]
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_ci      op_dtype_sizes = {'{}{}'.format(prefix, size) : size for prefix in 'biuf' for size in [64, 32, 24, 16]}
225bf215546Sopenharmony_ci      # inline constants are 32-bit for 16-bit integer/typeless instructions: https://reviews.llvm.org/D81841
226bf215546Sopenharmony_ci      op_dtype_sizes['b16'] = 32
227bf215546Sopenharmony_ci      op_dtype_sizes['i16'] = 32
228bf215546Sopenharmony_ci      op_dtype_sizes['u16'] = 32
229bf215546Sopenharmony_ci
230bf215546Sopenharmony_ci      # If we can't tell the operand size, default to 32.
231bf215546Sopenharmony_ci      self.operand_size = op_dtype_sizes.get(op_dtype, 32)
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci      # exceptions for operands:
234bf215546Sopenharmony_ci      if 'qsad_' in name:
235bf215546Sopenharmony_ci        self.operand_size = 0
236bf215546Sopenharmony_ci      elif 'sad_' in name:
237bf215546Sopenharmony_ci        self.operand_size = 32
238bf215546Sopenharmony_ci      elif name in ['v_mad_u64_u32', 'v_mad_i64_i32']:
239bf215546Sopenharmony_ci        self.operand_size = 0
240bf215546Sopenharmony_ci      elif self.operand_size == 24:
241bf215546Sopenharmony_ci        self.operand_size = 32
242bf215546Sopenharmony_ci      elif op_dtype == 'u8' or op_dtype == 'i8':
243bf215546Sopenharmony_ci        self.operand_size = 32
244bf215546Sopenharmony_ci      elif name in ['v_cvt_f32_ubyte0', 'v_cvt_f32_ubyte1',
245bf215546Sopenharmony_ci                    'v_cvt_f32_ubyte2', 'v_cvt_f32_ubyte3']:
246bf215546Sopenharmony_ci        self.operand_size = 32
247bf215546Sopenharmony_ci
248bf215546Sopenharmony_ci# global dictionary of opcodes
249bf215546Sopenharmony_ciopcodes = {}
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_cidef opcode(name, opcode_gfx7 = -1, opcode_gfx9 = -1, opcode_gfx10 = -1, format = Format.PSEUDO, cls = InstrClass.Other, input_mod = False, output_mod = False, is_atomic = False):
252bf215546Sopenharmony_ci   assert name not in opcodes
253bf215546Sopenharmony_ci   opcodes[name] = Opcode(name, opcode_gfx7, opcode_gfx9, opcode_gfx10, format, input_mod, output_mod, is_atomic, cls)
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_cidef default_class(opcodes, cls):
256bf215546Sopenharmony_ci   for op in opcodes:
257bf215546Sopenharmony_ci      if isinstance(op[-1], InstrClass):
258bf215546Sopenharmony_ci         yield op
259bf215546Sopenharmony_ci      else:
260bf215546Sopenharmony_ci         yield op + (cls,)
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ciopcode("exp", 0, 0, 0, format = Format.EXP, cls = InstrClass.Export)
263bf215546Sopenharmony_ciopcode("p_parallelcopy")
264bf215546Sopenharmony_ciopcode("p_startpgm")
265bf215546Sopenharmony_ciopcode("p_phi")
266bf215546Sopenharmony_ciopcode("p_linear_phi")
267bf215546Sopenharmony_ciopcode("p_as_uniform")
268bf215546Sopenharmony_ciopcode("p_unit_test")
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ciopcode("p_create_vector")
271bf215546Sopenharmony_ciopcode("p_extract_vector")
272bf215546Sopenharmony_ciopcode("p_split_vector")
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_ci# start/end the parts where we can use exec based instructions
275bf215546Sopenharmony_ci# implicitly
276bf215546Sopenharmony_ciopcode("p_logical_start")
277bf215546Sopenharmony_ciopcode("p_logical_end")
278bf215546Sopenharmony_ci
279bf215546Sopenharmony_ci# e.g. subgroupMin() in SPIR-V
280bf215546Sopenharmony_ciopcode("p_reduce", format=Format.PSEUDO_REDUCTION)
281bf215546Sopenharmony_ci# e.g. subgroupInclusiveMin()
282bf215546Sopenharmony_ciopcode("p_inclusive_scan", format=Format.PSEUDO_REDUCTION)
283bf215546Sopenharmony_ci# e.g. subgroupExclusiveMin()
284bf215546Sopenharmony_ciopcode("p_exclusive_scan", format=Format.PSEUDO_REDUCTION)
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_ciopcode("p_branch", format=Format.PSEUDO_BRANCH)
287bf215546Sopenharmony_ciopcode("p_cbranch", format=Format.PSEUDO_BRANCH)
288bf215546Sopenharmony_ciopcode("p_cbranch_z", format=Format.PSEUDO_BRANCH)
289bf215546Sopenharmony_ciopcode("p_cbranch_nz", format=Format.PSEUDO_BRANCH)
290bf215546Sopenharmony_ci
291bf215546Sopenharmony_ciopcode("p_barrier", format=Format.PSEUDO_BARRIER)
292bf215546Sopenharmony_ci
293bf215546Sopenharmony_ciopcode("p_spill")
294bf215546Sopenharmony_ciopcode("p_reload")
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci# start/end linear vgprs
297bf215546Sopenharmony_ciopcode("p_start_linear_vgpr")
298bf215546Sopenharmony_ciopcode("p_end_linear_vgpr")
299bf215546Sopenharmony_ci
300bf215546Sopenharmony_ciopcode("p_wqm")
301bf215546Sopenharmony_ciopcode("p_discard_if")
302bf215546Sopenharmony_ciopcode("p_demote_to_helper")
303bf215546Sopenharmony_ciopcode("p_is_helper")
304bf215546Sopenharmony_ciopcode("p_exit_early_if")
305bf215546Sopenharmony_ci
306bf215546Sopenharmony_ci# simulates proper bpermute behavior when it's unsupported, eg. GFX10 wave64
307bf215546Sopenharmony_ciopcode("p_bpermute")
308bf215546Sopenharmony_ci
309bf215546Sopenharmony_ci# creates a lane mask where only the first active lane is selected
310bf215546Sopenharmony_ciopcode("p_elect")
311bf215546Sopenharmony_ci
312bf215546Sopenharmony_ciopcode("p_constaddr")
313bf215546Sopenharmony_ci
314bf215546Sopenharmony_ci# These don't have to be pseudo-ops, but it makes optimization easier to only
315bf215546Sopenharmony_ci# have to consider two instructions.
316bf215546Sopenharmony_ci# (src0 >> (index * bits)) & ((1 << bits) - 1) with optional sign extension
317bf215546Sopenharmony_ciopcode("p_extract") # src1=index, src2=bits, src3=signext
318bf215546Sopenharmony_ci# (src0 & ((1 << bits) - 1)) << (index * bits)
319bf215546Sopenharmony_ciopcode("p_insert") # src1=index, src2=bits
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ciopcode("p_init_scratch")
322bf215546Sopenharmony_ci
323bf215546Sopenharmony_ci# jumps to a shader epilog
324bf215546Sopenharmony_ciopcode("p_jump_to_epilog")
325bf215546Sopenharmony_ci
326bf215546Sopenharmony_ci# SOP2 instructions: 2 scalar inputs, 1 scalar output (+optional scc)
327bf215546Sopenharmony_ciSOP2 = {
328bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name
329bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "s_add_u32"),
330bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "s_sub_u32"),
331bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "s_add_i32"),
332bf215546Sopenharmony_ci   (0x03, 0x03, 0x03, 0x03, 0x03, "s_sub_i32"),
333bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "s_addc_u32"),
334bf215546Sopenharmony_ci   (0x05, 0x05, 0x05, 0x05, 0x05, "s_subb_u32"),
335bf215546Sopenharmony_ci   (0x06, 0x06, 0x06, 0x06, 0x06, "s_min_i32"),
336bf215546Sopenharmony_ci   (0x07, 0x07, 0x07, 0x07, 0x07, "s_min_u32"),
337bf215546Sopenharmony_ci   (0x08, 0x08, 0x08, 0x08, 0x08, "s_max_i32"),
338bf215546Sopenharmony_ci   (0x09, 0x09, 0x09, 0x09, 0x09, "s_max_u32"),
339bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x0a, 0x0a, 0x0a, "s_cselect_b32"),
340bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x0b, 0x0b, 0x0b, "s_cselect_b64"),
341bf215546Sopenharmony_ci   (0x0e, 0x0e, 0x0c, 0x0c, 0x0e, "s_and_b32"),
342bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0d, 0x0d, 0x0f, "s_and_b64"),
343bf215546Sopenharmony_ci   (0x10, 0x10, 0x0e, 0x0e, 0x10, "s_or_b32"),
344bf215546Sopenharmony_ci   (0x11, 0x11, 0x0f, 0x0f, 0x11, "s_or_b64"),
345bf215546Sopenharmony_ci   (0x12, 0x12, 0x10, 0x10, 0x12, "s_xor_b32"),
346bf215546Sopenharmony_ci   (0x13, 0x13, 0x11, 0x11, 0x13, "s_xor_b64"),
347bf215546Sopenharmony_ci   (0x14, 0x14, 0x12, 0x12, 0x14, "s_andn2_b32"),
348bf215546Sopenharmony_ci   (0x15, 0x15, 0x13, 0x13, 0x15, "s_andn2_b64"),
349bf215546Sopenharmony_ci   (0x16, 0x16, 0x14, 0x14, 0x16, "s_orn2_b32"),
350bf215546Sopenharmony_ci   (0x17, 0x17, 0x15, 0x15, 0x17, "s_orn2_b64"),
351bf215546Sopenharmony_ci   (0x18, 0x18, 0x16, 0x16, 0x18, "s_nand_b32"),
352bf215546Sopenharmony_ci   (0x19, 0x19, 0x17, 0x17, 0x19, "s_nand_b64"),
353bf215546Sopenharmony_ci   (0x1a, 0x1a, 0x18, 0x18, 0x1a, "s_nor_b32"),
354bf215546Sopenharmony_ci   (0x1b, 0x1b, 0x19, 0x19, 0x1b, "s_nor_b64"),
355bf215546Sopenharmony_ci   (0x1c, 0x1c, 0x1a, 0x1a, 0x1c, "s_xnor_b32"),
356bf215546Sopenharmony_ci   (0x1d, 0x1d, 0x1b, 0x1b, 0x1d, "s_xnor_b64"),
357bf215546Sopenharmony_ci   (0x1e, 0x1e, 0x1c, 0x1c, 0x1e, "s_lshl_b32"),
358bf215546Sopenharmony_ci   (0x1f, 0x1f, 0x1d, 0x1d, 0x1f, "s_lshl_b64"),
359bf215546Sopenharmony_ci   (0x20, 0x20, 0x1e, 0x1e, 0x20, "s_lshr_b32"),
360bf215546Sopenharmony_ci   (0x21, 0x21, 0x1f, 0x1f, 0x21, "s_lshr_b64"),
361bf215546Sopenharmony_ci   (0x22, 0x22, 0x20, 0x20, 0x22, "s_ashr_i32"),
362bf215546Sopenharmony_ci   (0x23, 0x23, 0x21, 0x21, 0x23, "s_ashr_i64"),
363bf215546Sopenharmony_ci   (0x24, 0x24, 0x22, 0x22, 0x24, "s_bfm_b32"),
364bf215546Sopenharmony_ci   (0x25, 0x25, 0x23, 0x23, 0x25, "s_bfm_b64"),
365bf215546Sopenharmony_ci   (0x26, 0x26, 0x24, 0x24, 0x26, "s_mul_i32"),
366bf215546Sopenharmony_ci   (0x27, 0x27, 0x25, 0x25, 0x27, "s_bfe_u32"),
367bf215546Sopenharmony_ci   (0x28, 0x28, 0x26, 0x26, 0x28, "s_bfe_i32"),
368bf215546Sopenharmony_ci   (0x29, 0x29, 0x27, 0x27, 0x29, "s_bfe_u64"),
369bf215546Sopenharmony_ci   (0x2a, 0x2a, 0x28, 0x28, 0x2a, "s_bfe_i64"),
370bf215546Sopenharmony_ci   (0x2b, 0x2b, 0x29, 0x29,   -1, "s_cbranch_g_fork", InstrClass.Branch),
371bf215546Sopenharmony_ci   (0x2c, 0x2c, 0x2a, 0x2a, 0x2c, "s_absdiff_i32"),
372bf215546Sopenharmony_ci   (  -1,   -1, 0x2b, 0x2b,   -1, "s_rfe_restore_b64", InstrClass.Branch),
373bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x2e, 0x2e, "s_lshl1_add_u32"),
374bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x2f, 0x2f, "s_lshl2_add_u32"),
375bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x30, 0x30, "s_lshl3_add_u32"),
376bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x31, 0x31, "s_lshl4_add_u32"),
377bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x32, 0x32, "s_pack_ll_b32_b16"),
378bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x33, 0x33, "s_pack_lh_b32_b16"),
379bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x34, 0x34, "s_pack_hh_b32_b16"),
380bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x2c, 0x35, "s_mul_hi_u32"),
381bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x2d, 0x36, "s_mul_hi_i32"),
382bf215546Sopenharmony_ci   # actually a pseudo-instruction. it's lowered to SALU during assembly though, so it's useful to identify it as a SOP2.
383bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1,   -1, "p_constaddr_addlo"),
384bf215546Sopenharmony_ci}
385bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, cls) in default_class(SOP2, InstrClass.Salu):
386bf215546Sopenharmony_ci    opcode(name, gfx7, gfx9, gfx10, Format.SOP2, cls)
387bf215546Sopenharmony_ci
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ci# SOPK instructions: 0 input (+ imm), 1 output + optional scc
390bf215546Sopenharmony_ciSOPK = {
391bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name
392bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "s_movk_i32"),
393bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x01, "s_version"),
394bf215546Sopenharmony_ci   (0x02, 0x02, 0x01, 0x01, 0x02, "s_cmovk_i32"),
395bf215546Sopenharmony_ci   (0x03, 0x03, 0x02, 0x02, 0x03, "s_cmpk_eq_i32"),
396bf215546Sopenharmony_ci   (0x04, 0x04, 0x03, 0x03, 0x04, "s_cmpk_lg_i32"),
397bf215546Sopenharmony_ci   (0x05, 0x05, 0x04, 0x04, 0x05, "s_cmpk_gt_i32"),
398bf215546Sopenharmony_ci   (0x06, 0x06, 0x05, 0x05, 0x06, "s_cmpk_ge_i32"),
399bf215546Sopenharmony_ci   (0x07, 0x07, 0x06, 0x06, 0x07, "s_cmpk_lt_i32"),
400bf215546Sopenharmony_ci   (0x08, 0x08, 0x07, 0x07, 0x08, "s_cmpk_le_i32"),
401bf215546Sopenharmony_ci   (0x09, 0x09, 0x08, 0x08, 0x09, "s_cmpk_eq_u32"),
402bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x09, 0x09, 0x0a, "s_cmpk_lg_u32"),
403bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x0a, 0x0a, 0x0b, "s_cmpk_gt_u32"),
404bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x0b, 0x0b, 0x0c, "s_cmpk_ge_u32"),
405bf215546Sopenharmony_ci   (0x0d, 0x0d, 0x0c, 0x0c, 0x0d, "s_cmpk_lt_u32"),
406bf215546Sopenharmony_ci   (0x0e, 0x0e, 0x0d, 0x0d, 0x0e, "s_cmpk_le_u32"),
407bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0e, 0x0e, 0x0f, "s_addk_i32"),
408bf215546Sopenharmony_ci   (0x10, 0x10, 0x0f, 0x0f, 0x10, "s_mulk_i32"),
409bf215546Sopenharmony_ci   (0x11, 0x11, 0x10, 0x10,   -1, "s_cbranch_i_fork", InstrClass.Branch),
410bf215546Sopenharmony_ci   (0x12, 0x12, 0x11, 0x11, 0x12, "s_getreg_b32"),
411bf215546Sopenharmony_ci   (0x13, 0x13, 0x12, 0x12, 0x13, "s_setreg_b32"),
412bf215546Sopenharmony_ci   (0x15, 0x15, 0x14, 0x14, 0x15, "s_setreg_imm32_b32"), # requires 32bit literal
413bf215546Sopenharmony_ci   (  -1,   -1, 0x15, 0x15, 0x16, "s_call_b64", InstrClass.Branch),
414bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x17, "s_waitcnt_vscnt", InstrClass.Waitcnt),
415bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x18, "s_waitcnt_vmcnt", InstrClass.Waitcnt),
416bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x19, "s_waitcnt_expcnt", InstrClass.Waitcnt),
417bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x1a, "s_waitcnt_lgkmcnt", InstrClass.Waitcnt),
418bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x1b, "s_subvector_loop_begin", InstrClass.Branch),
419bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x1c, "s_subvector_loop_end", InstrClass.Branch),
420bf215546Sopenharmony_ci}
421bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, cls) in default_class(SOPK, InstrClass.Salu):
422bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.SOPK, cls)
423bf215546Sopenharmony_ci
424bf215546Sopenharmony_ci
425bf215546Sopenharmony_ci# SOP1 instructions: 1 input, 1 output (+optional SCC)
426bf215546Sopenharmony_ciSOP1 = {
427bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name
428bf215546Sopenharmony_ci   (0x03, 0x03, 0x00, 0x00, 0x03, "s_mov_b32"),
429bf215546Sopenharmony_ci   (0x04, 0x04, 0x01, 0x01, 0x04, "s_mov_b64"),
430bf215546Sopenharmony_ci   (0x05, 0x05, 0x02, 0x02, 0x05, "s_cmov_b32"),
431bf215546Sopenharmony_ci   (0x06, 0x06, 0x03, 0x03, 0x06, "s_cmov_b64"),
432bf215546Sopenharmony_ci   (0x07, 0x07, 0x04, 0x04, 0x07, "s_not_b32"),
433bf215546Sopenharmony_ci   (0x08, 0x08, 0x05, 0x05, 0x08, "s_not_b64"),
434bf215546Sopenharmony_ci   (0x09, 0x09, 0x06, 0x06, 0x09, "s_wqm_b32"),
435bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x07, 0x07, 0x0a, "s_wqm_b64"),
436bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x08, 0x08, 0x0b, "s_brev_b32"),
437bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x09, 0x09, 0x0c, "s_brev_b64"),
438bf215546Sopenharmony_ci   (0x0d, 0x0d, 0x0a, 0x0a, 0x0d, "s_bcnt0_i32_b32"),
439bf215546Sopenharmony_ci   (0x0e, 0x0e, 0x0b, 0x0b, 0x0e, "s_bcnt0_i32_b64"),
440bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0c, 0x0c, 0x0f, "s_bcnt1_i32_b32"),
441bf215546Sopenharmony_ci   (0x10, 0x10, 0x0d, 0x0d, 0x10, "s_bcnt1_i32_b64"),
442bf215546Sopenharmony_ci   (0x11, 0x11, 0x0e, 0x0e, 0x11, "s_ff0_i32_b32"),
443bf215546Sopenharmony_ci   (0x12, 0x12, 0x0f, 0x0f, 0x12, "s_ff0_i32_b64"),
444bf215546Sopenharmony_ci   (0x13, 0x13, 0x10, 0x10, 0x13, "s_ff1_i32_b32"),
445bf215546Sopenharmony_ci   (0x14, 0x14, 0x11, 0x11, 0x14, "s_ff1_i32_b64"),
446bf215546Sopenharmony_ci   (0x15, 0x15, 0x12, 0x12, 0x15, "s_flbit_i32_b32"),
447bf215546Sopenharmony_ci   (0x16, 0x16, 0x13, 0x13, 0x16, "s_flbit_i32_b64"),
448bf215546Sopenharmony_ci   (0x17, 0x17, 0x14, 0x14, 0x17, "s_flbit_i32"),
449bf215546Sopenharmony_ci   (0x18, 0x18, 0x15, 0x15, 0x18, "s_flbit_i32_i64"),
450bf215546Sopenharmony_ci   (0x19, 0x19, 0x16, 0x16, 0x19, "s_sext_i32_i8"),
451bf215546Sopenharmony_ci   (0x1a, 0x1a, 0x17, 0x17, 0x1a, "s_sext_i32_i16"),
452bf215546Sopenharmony_ci   (0x1b, 0x1b, 0x18, 0x18, 0x1b, "s_bitset0_b32"),
453bf215546Sopenharmony_ci   (0x1c, 0x1c, 0x19, 0x19, 0x1c, "s_bitset0_b64"),
454bf215546Sopenharmony_ci   (0x1d, 0x1d, 0x1a, 0x1a, 0x1d, "s_bitset1_b32"),
455bf215546Sopenharmony_ci   (0x1e, 0x1e, 0x1b, 0x1b, 0x1e, "s_bitset1_b64"),
456bf215546Sopenharmony_ci   (0x1f, 0x1f, 0x1c, 0x1c, 0x1f, "s_getpc_b64"),
457bf215546Sopenharmony_ci   (0x20, 0x20, 0x1d, 0x1d, 0x20, "s_setpc_b64", InstrClass.Branch),
458bf215546Sopenharmony_ci   (0x21, 0x21, 0x1e, 0x1e, 0x21, "s_swappc_b64", InstrClass.Branch),
459bf215546Sopenharmony_ci   (0x22, 0x22, 0x1f, 0x1f, 0x22, "s_rfe_b64", InstrClass.Branch),
460bf215546Sopenharmony_ci   (0x24, 0x24, 0x20, 0x20, 0x24, "s_and_saveexec_b64"),
461bf215546Sopenharmony_ci   (0x25, 0x25, 0x21, 0x21, 0x25, "s_or_saveexec_b64"),
462bf215546Sopenharmony_ci   (0x26, 0x26, 0x22, 0x22, 0x26, "s_xor_saveexec_b64"),
463bf215546Sopenharmony_ci   (0x27, 0x27, 0x23, 0x23, 0x27, "s_andn2_saveexec_b64"),
464bf215546Sopenharmony_ci   (0x28, 0x28, 0x24, 0x24, 0x28, "s_orn2_saveexec_b64"),
465bf215546Sopenharmony_ci   (0x29, 0x29, 0x25, 0x25, 0x29, "s_nand_saveexec_b64"),
466bf215546Sopenharmony_ci   (0x2a, 0x2a, 0x26, 0x26, 0x2a, "s_nor_saveexec_b64"),
467bf215546Sopenharmony_ci   (0x2b, 0x2b, 0x27, 0x27, 0x2b, "s_xnor_saveexec_b64"),
468bf215546Sopenharmony_ci   (0x2c, 0x2c, 0x28, 0x28, 0x2c, "s_quadmask_b32"),
469bf215546Sopenharmony_ci   (0x2d, 0x2d, 0x29, 0x29, 0x2d, "s_quadmask_b64"),
470bf215546Sopenharmony_ci   (0x2e, 0x2e, 0x2a, 0x2a, 0x2e, "s_movrels_b32"),
471bf215546Sopenharmony_ci   (0x2f, 0x2f, 0x2b, 0x2b, 0x2f, "s_movrels_b64"),
472bf215546Sopenharmony_ci   (0x30, 0x30, 0x2c, 0x2c, 0x30, "s_movreld_b32"),
473bf215546Sopenharmony_ci   (0x31, 0x31, 0x2d, 0x2d, 0x31, "s_movreld_b64"),
474bf215546Sopenharmony_ci   (0x32, 0x32, 0x2e, 0x2e,   -1, "s_cbranch_join", InstrClass.Branch),
475bf215546Sopenharmony_ci   (0x34, 0x34, 0x30, 0x30, 0x34, "s_abs_i32"),
476bf215546Sopenharmony_ci   (0x35, 0x35,   -1,   -1, 0x35, "s_mov_fed_b32"),
477bf215546Sopenharmony_ci   (  -1,   -1, 0x32, 0x32,   -1, "s_set_gpr_idx_idx"),
478bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x33, 0x37, "s_andn1_saveexec_b64"),
479bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x34, 0x38, "s_orn1_saveexec_b64"),
480bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x35, 0x39, "s_andn1_wrexec_b64"),
481bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x36, 0x3a, "s_andn2_wrexec_b64"),
482bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x37, 0x3b, "s_bitreplicate_b64_b32"),
483bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x3c, "s_and_saveexec_b32"),
484bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x3d, "s_or_saveexec_b32"),
485bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x3e, "s_xor_saveexec_b32"),
486bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x3f, "s_andn2_saveexec_b32"),
487bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x40, "s_orn2_saveexec_b32"),
488bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x41, "s_nand_saveexec_b32"),
489bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x42, "s_nor_saveexec_b32"),
490bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x43, "s_xnor_saveexec_b32"),
491bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x44, "s_andn1_saveexec_b32"),
492bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x45, "s_orn1_saveexec_b32"),
493bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x46, "s_andn1_wrexec_b32"),
494bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x47, "s_andn2_wrexec_b32"),
495bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x49, "s_movrelsd_2_b32"),
496bf215546Sopenharmony_ci   # actually a pseudo-instruction. it's lowered to SALU during assembly though, so it's useful to identify it as a SOP1.
497bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1,   -1, "p_constaddr_getpc"),
498bf215546Sopenharmony_ci}
499bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, cls) in default_class(SOP1, InstrClass.Salu):
500bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.SOP1, cls)
501bf215546Sopenharmony_ci
502bf215546Sopenharmony_ci
503bf215546Sopenharmony_ci# SOPC instructions: 2 inputs and 0 outputs (+SCC)
504bf215546Sopenharmony_ciSOPC = {
505bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name
506bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "s_cmp_eq_i32"),
507bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "s_cmp_lg_i32"),
508bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "s_cmp_gt_i32"),
509bf215546Sopenharmony_ci   (0x03, 0x03, 0x03, 0x03, 0x03, "s_cmp_ge_i32"),
510bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "s_cmp_lt_i32"),
511bf215546Sopenharmony_ci   (0x05, 0x05, 0x05, 0x05, 0x05, "s_cmp_le_i32"),
512bf215546Sopenharmony_ci   (0x06, 0x06, 0x06, 0x06, 0x06, "s_cmp_eq_u32"),
513bf215546Sopenharmony_ci   (0x07, 0x07, 0x07, 0x07, 0x07, "s_cmp_lg_u32"),
514bf215546Sopenharmony_ci   (0x08, 0x08, 0x08, 0x08, 0x08, "s_cmp_gt_u32"),
515bf215546Sopenharmony_ci   (0x09, 0x09, 0x09, 0x09, 0x09, "s_cmp_ge_u32"),
516bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x0a, 0x0a, 0x0a, "s_cmp_lt_u32"),
517bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x0b, 0x0b, 0x0b, "s_cmp_le_u32"),
518bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x0c, 0x0c, 0x0c, "s_bitcmp0_b32"),
519bf215546Sopenharmony_ci   (0x0d, 0x0d, 0x0d, 0x0d, 0x0d, "s_bitcmp1_b32"),
520bf215546Sopenharmony_ci   (0x0e, 0x0e, 0x0e, 0x0e, 0x0e, "s_bitcmp0_b64"),
521bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0f, 0x0f, 0x0f, "s_bitcmp1_b64"),
522bf215546Sopenharmony_ci   (0x10, 0x10, 0x10, 0x10,   -1, "s_setvskip"),
523bf215546Sopenharmony_ci   (  -1,   -1, 0x11, 0x11,   -1, "s_set_gpr_idx_on"),
524bf215546Sopenharmony_ci   (  -1,   -1, 0x12, 0x12, 0x12, "s_cmp_eq_u64"),
525bf215546Sopenharmony_ci   (  -1,   -1, 0x13, 0x13, 0x13, "s_cmp_lg_u64"),
526bf215546Sopenharmony_ci}
527bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name) in SOPC:
528bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.SOPC, InstrClass.Salu)
529bf215546Sopenharmony_ci
530bf215546Sopenharmony_ci
531bf215546Sopenharmony_ci# SOPP instructions: 0 inputs (+optional scc/vcc), 0 outputs
532bf215546Sopenharmony_ciSOPP = {
533bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name
534bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "s_nop"),
535bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "s_endpgm"),
536bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "s_branch", InstrClass.Branch),
537bf215546Sopenharmony_ci   (  -1,   -1, 0x03, 0x03, 0x03, "s_wakeup"),
538bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "s_cbranch_scc0", InstrClass.Branch),
539bf215546Sopenharmony_ci   (0x05, 0x05, 0x05, 0x05, 0x05, "s_cbranch_scc1", InstrClass.Branch),
540bf215546Sopenharmony_ci   (0x06, 0x06, 0x06, 0x06, 0x06, "s_cbranch_vccz", InstrClass.Branch),
541bf215546Sopenharmony_ci   (0x07, 0x07, 0x07, 0x07, 0x07, "s_cbranch_vccnz", InstrClass.Branch),
542bf215546Sopenharmony_ci   (0x08, 0x08, 0x08, 0x08, 0x08, "s_cbranch_execz", InstrClass.Branch),
543bf215546Sopenharmony_ci   (0x09, 0x09, 0x09, 0x09, 0x09, "s_cbranch_execnz", InstrClass.Branch),
544bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x0a, 0x0a, 0x0a, "s_barrier", InstrClass.Barrier),
545bf215546Sopenharmony_ci   (  -1, 0x0b, 0x0b, 0x0b, 0x0b, "s_setkill"),
546bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x0c, 0x0c, 0x0c, "s_waitcnt", InstrClass.Waitcnt),
547bf215546Sopenharmony_ci   (0x0d, 0x0d, 0x0d, 0x0d, 0x0d, "s_sethalt"),
548bf215546Sopenharmony_ci   (0x0e, 0x0e, 0x0e, 0x0e, 0x0e, "s_sleep"),
549bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0f, 0x0f, 0x0f, "s_setprio"),
550bf215546Sopenharmony_ci   (0x10, 0x10, 0x10, 0x10, 0x10, "s_sendmsg", InstrClass.Sendmsg),
551bf215546Sopenharmony_ci   (0x11, 0x11, 0x11, 0x11, 0x11, "s_sendmsghalt", InstrClass.Sendmsg),
552bf215546Sopenharmony_ci   (0x12, 0x12, 0x12, 0x12, 0x12, "s_trap", InstrClass.Branch),
553bf215546Sopenharmony_ci   (0x13, 0x13, 0x13, 0x13, 0x13, "s_icache_inv"),
554bf215546Sopenharmony_ci   (0x14, 0x14, 0x14, 0x14, 0x14, "s_incperflevel"),
555bf215546Sopenharmony_ci   (0x15, 0x15, 0x15, 0x15, 0x15, "s_decperflevel"),
556bf215546Sopenharmony_ci   (0x16, 0x16, 0x16, 0x16, 0x16, "s_ttracedata"),
557bf215546Sopenharmony_ci   (  -1, 0x17, 0x17, 0x17, 0x17, "s_cbranch_cdbgsys", InstrClass.Branch),
558bf215546Sopenharmony_ci   (  -1, 0x18, 0x18, 0x18, 0x18, "s_cbranch_cdbguser", InstrClass.Branch),
559bf215546Sopenharmony_ci   (  -1, 0x19, 0x19, 0x19, 0x19, "s_cbranch_cdbgsys_or_user", InstrClass.Branch),
560bf215546Sopenharmony_ci   (  -1, 0x1a, 0x1a, 0x1a, 0x1a, "s_cbranch_cdbgsys_and_user", InstrClass.Branch),
561bf215546Sopenharmony_ci   (  -1,   -1, 0x1b, 0x1b, 0x1b, "s_endpgm_saved"),
562bf215546Sopenharmony_ci   (  -1,   -1, 0x1c, 0x1c,   -1, "s_set_gpr_idx_off"),
563bf215546Sopenharmony_ci   (  -1,   -1, 0x1d, 0x1d,   -1, "s_set_gpr_idx_mode"),
564bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x1e, 0x1e, "s_endpgm_ordered_ps_done"),
565bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x1f, "s_code_end"),
566bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x20, "s_inst_prefetch"),
567bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x21, "s_clause"),
568bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x22, "s_wait_idle"),
569bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x23, "s_waitcnt_depctr"),
570bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x24, "s_round_mode"),
571bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x25, "s_denorm_mode"),
572bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x26, "s_ttracedata_imm"),
573bf215546Sopenharmony_ci}
574bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, cls) in default_class(SOPP, InstrClass.Salu):
575bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.SOPP, cls)
576bf215546Sopenharmony_ci
577bf215546Sopenharmony_ci
578bf215546Sopenharmony_ci# SMEM instructions: sbase input (2 sgpr), potentially 2 offset inputs, 1 sdata input/output
579bf215546Sopenharmony_ci# Unlike GFX10, GFX10.3 does not have SMEM store, atomic or scratch instructions
580bf215546Sopenharmony_ciSMEM = {
581bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name
582bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "s_load_dword"),
583bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "s_load_dwordx2"),
584bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "s_load_dwordx4"),
585bf215546Sopenharmony_ci   (0x03, 0x03, 0x03, 0x03, 0x03, "s_load_dwordx8"),
586bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "s_load_dwordx16"),
587bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x05, 0x05, "s_scratch_load_dword"),
588bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x06, 0x06, "s_scratch_load_dwordx2"),
589bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x07, 0x07, "s_scratch_load_dwordx4"),
590bf215546Sopenharmony_ci   (0x08, 0x08, 0x08, 0x08, 0x08, "s_buffer_load_dword"),
591bf215546Sopenharmony_ci   (0x09, 0x09, 0x09, 0x09, 0x09, "s_buffer_load_dwordx2"),
592bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x0a, 0x0a, 0x0a, "s_buffer_load_dwordx4"),
593bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x0b, 0x0b, 0x0b, "s_buffer_load_dwordx8"),
594bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x0c, 0x0c, 0x0c, "s_buffer_load_dwordx16"),
595bf215546Sopenharmony_ci   (  -1,   -1, 0x10, 0x10, 0x10, "s_store_dword"),
596bf215546Sopenharmony_ci   (  -1,   -1, 0x11, 0x11, 0x11, "s_store_dwordx2"),
597bf215546Sopenharmony_ci   (  -1,   -1, 0x12, 0x12, 0x12, "s_store_dwordx4"),
598bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x15, 0x15, "s_scratch_store_dword"),
599bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x16, 0x16, "s_scratch_store_dwordx2"),
600bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x17, 0x17, "s_scratch_store_dwordx4"),
601bf215546Sopenharmony_ci   (  -1,   -1, 0x18, 0x18, 0x18, "s_buffer_store_dword"),
602bf215546Sopenharmony_ci   (  -1,   -1, 0x19, 0x19, 0x19, "s_buffer_store_dwordx2"),
603bf215546Sopenharmony_ci   (  -1,   -1, 0x1a, 0x1a, 0x1a, "s_buffer_store_dwordx4"),
604bf215546Sopenharmony_ci   (  -1,   -1, 0x1f, 0x1f, 0x1f, "s_gl1_inv"),
605bf215546Sopenharmony_ci   (0x1f, 0x1f, 0x20, 0x20, 0x20, "s_dcache_inv"),
606bf215546Sopenharmony_ci   (  -1,   -1, 0x21, 0x21, 0x21, "s_dcache_wb"),
607bf215546Sopenharmony_ci   (  -1, 0x1d, 0x22, 0x22,   -1, "s_dcache_inv_vol"),
608bf215546Sopenharmony_ci   (  -1,   -1, 0x23, 0x23,   -1, "s_dcache_wb_vol"),
609bf215546Sopenharmony_ci   (0x1e, 0x1e, 0x24, 0x24, 0x24, "s_memtime"), #GFX6-GFX10
610bf215546Sopenharmony_ci   (  -1,   -1, 0x25, 0x25, 0x25, "s_memrealtime"),
611bf215546Sopenharmony_ci   (  -1,   -1, 0x26, 0x26, 0x26, "s_atc_probe"),
612bf215546Sopenharmony_ci   (  -1,   -1, 0x27, 0x27, 0x27, "s_atc_probe_buffer"),
613bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x28, 0x28, "s_dcache_discard"),
614bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x29, 0x29, "s_dcache_discard_x2"),
615bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x2a, "s_get_waveid_in_workgroup"),
616bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x40, 0x40, "s_buffer_atomic_swap"),
617bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x41, 0x41, "s_buffer_atomic_cmpswap"),
618bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x42, 0x42, "s_buffer_atomic_add"),
619bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x43, 0x43, "s_buffer_atomic_sub"),
620bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x44, 0x44, "s_buffer_atomic_smin"),
621bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x45, 0x45, "s_buffer_atomic_umin"),
622bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x46, 0x46, "s_buffer_atomic_smax"),
623bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x47, 0x47, "s_buffer_atomic_umax"),
624bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x48, 0x48, "s_buffer_atomic_and"),
625bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x49, 0x49, "s_buffer_atomic_or"),
626bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x4a, 0x4a, "s_buffer_atomic_xor"),
627bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x4b, 0x4b, "s_buffer_atomic_inc"),
628bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x4c, 0x4c, "s_buffer_atomic_dec"),
629bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x60, 0x60, "s_buffer_atomic_swap_x2"),
630bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x61, 0x61, "s_buffer_atomic_cmpswap_x2"),
631bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x62, 0x62, "s_buffer_atomic_add_x2"),
632bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x63, 0x63, "s_buffer_atomic_sub_x2"),
633bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x64, 0x64, "s_buffer_atomic_smin_x2"),
634bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x65, 0x65, "s_buffer_atomic_umin_x2"),
635bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x66, 0x66, "s_buffer_atomic_smax_x2"),
636bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x67, 0x67, "s_buffer_atomic_umax_x2"),
637bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x68, 0x68, "s_buffer_atomic_and_x2"),
638bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x69, 0x69, "s_buffer_atomic_or_x2"),
639bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x6a, 0x6a, "s_buffer_atomic_xor_x2"),
640bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x6b, 0x6b, "s_buffer_atomic_inc_x2"),
641bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x6c, 0x6c, "s_buffer_atomic_dec_x2"),
642bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x80, 0x80, "s_atomic_swap"),
643bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x81, 0x81, "s_atomic_cmpswap"),
644bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x82, 0x82, "s_atomic_add"),
645bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x83, 0x83, "s_atomic_sub"),
646bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x84, 0x84, "s_atomic_smin"),
647bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x85, 0x85, "s_atomic_umin"),
648bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x86, 0x86, "s_atomic_smax"),
649bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x87, 0x87, "s_atomic_umax"),
650bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x88, 0x88, "s_atomic_and"),
651bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x89, 0x89, "s_atomic_or"),
652bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x8a, 0x8a, "s_atomic_xor"),
653bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x8b, 0x8b, "s_atomic_inc"),
654bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x8c, 0x8c, "s_atomic_dec"),
655bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa0, 0xa0, "s_atomic_swap_x2"),
656bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa1, 0xa1, "s_atomic_cmpswap_x2"),
657bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa2, 0xa2, "s_atomic_add_x2"),
658bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa3, 0xa3, "s_atomic_sub_x2"),
659bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa4, 0xa4, "s_atomic_smin_x2"),
660bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa5, 0xa5, "s_atomic_umin_x2"),
661bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa6, 0xa6, "s_atomic_smax_x2"),
662bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa7, 0xa7, "s_atomic_umax_x2"),
663bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa8, 0xa8, "s_atomic_and_x2"),
664bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xa9, 0xa9, "s_atomic_or_x2"),
665bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xaa, 0xaa, "s_atomic_xor_x2"),
666bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xab, 0xab, "s_atomic_inc_x2"),
667bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0xac, 0xac, "s_atomic_dec_x2"),
668bf215546Sopenharmony_ci}
669bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name) in SMEM:
670bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.SMEM, InstrClass.SMem, is_atomic = "atomic" in name)
671bf215546Sopenharmony_ci
672bf215546Sopenharmony_ci
673bf215546Sopenharmony_ci# VOP2 instructions: 2 inputs, 1 output (+ optional vcc)
674bf215546Sopenharmony_ci# TODO: misses some GFX6_7 opcodes which were shifted to VOP3 in GFX8
675bf215546Sopenharmony_ciVOP2 = {
676bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name, input/output modifiers
677bf215546Sopenharmony_ci   (0x01, 0x01,   -1,   -1,   -1, "v_readlane_b32", False),
678bf215546Sopenharmony_ci   (0x02, 0x02,   -1,   -1,   -1, "v_writelane_b32", False),
679bf215546Sopenharmony_ci   (0x03, 0x03, 0x01, 0x01, 0x03, "v_add_f32", True),
680bf215546Sopenharmony_ci   (0x04, 0x04, 0x02, 0x02, 0x04, "v_sub_f32", True),
681bf215546Sopenharmony_ci   (0x05, 0x05, 0x03, 0x03, 0x05, "v_subrev_f32", True),
682bf215546Sopenharmony_ci   (0x06, 0x06,   -1,   -1, 0x06, "v_mac_legacy_f32", True), #GFX6,7,10
683bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x06, "v_fmac_legacy_f32", True), #GFX10.3+
684bf215546Sopenharmony_ci   (0x07, 0x07, 0x04, 0x04, 0x07, "v_mul_legacy_f32", True),
685bf215546Sopenharmony_ci   (0x08, 0x08, 0x05, 0x05, 0x08, "v_mul_f32", True),
686bf215546Sopenharmony_ci   (0x09, 0x09, 0x06, 0x06, 0x09, "v_mul_i32_i24", False),
687bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x07, 0x07, 0x0a, "v_mul_hi_i32_i24", False),
688bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x08, 0x08, 0x0b, "v_mul_u32_u24", False),
689bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x09, 0x09, 0x0c, "v_mul_hi_u32_u24", False),
690bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x39, 0x0d, "v_dot4c_i32_i8", False),
691bf215546Sopenharmony_ci   (0x0d, 0x0d,   -1,   -1,   -1, "v_min_legacy_f32", True),
692bf215546Sopenharmony_ci   (0x0e, 0x0e,   -1,   -1,   -1, "v_max_legacy_f32", True),
693bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0a, 0x0a, 0x0f, "v_min_f32", True),
694bf215546Sopenharmony_ci   (0x10, 0x10, 0x0b, 0x0b, 0x10, "v_max_f32", True),
695bf215546Sopenharmony_ci   (0x11, 0x11, 0x0c, 0x0c, 0x11, "v_min_i32", False),
696bf215546Sopenharmony_ci   (0x12, 0x12, 0x0d, 0x0d, 0x12, "v_max_i32", False),
697bf215546Sopenharmony_ci   (0x13, 0x13, 0x0e, 0x0e, 0x13, "v_min_u32", False),
698bf215546Sopenharmony_ci   (0x14, 0x14, 0x0f, 0x0f, 0x14, "v_max_u32", False),
699bf215546Sopenharmony_ci   (0x15, 0x15,   -1,   -1,   -1, "v_lshr_b32", False),
700bf215546Sopenharmony_ci   (0x16, 0x16, 0x10, 0x10, 0x16, "v_lshrrev_b32", False),
701bf215546Sopenharmony_ci   (0x17, 0x17,   -1,   -1,   -1, "v_ashr_i32", False),
702bf215546Sopenharmony_ci   (0x18, 0x18, 0x11, 0x11, 0x18, "v_ashrrev_i32", False),
703bf215546Sopenharmony_ci   (0x19, 0x19,   -1,   -1,   -1, "v_lshl_b32", False),
704bf215546Sopenharmony_ci   (0x1a, 0x1a, 0x12, 0x12, 0x1a, "v_lshlrev_b32", False),
705bf215546Sopenharmony_ci   (0x1b, 0x1b, 0x13, 0x13, 0x1b, "v_and_b32", False),
706bf215546Sopenharmony_ci   (0x1c, 0x1c, 0x14, 0x14, 0x1c, "v_or_b32", False),
707bf215546Sopenharmony_ci   (0x1d, 0x1d, 0x15, 0x15, 0x1d, "v_xor_b32", False),
708bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x1e, "v_xnor_b32", False),
709bf215546Sopenharmony_ci   (0x1f, 0x1f, 0x16, 0x16, 0x1f, "v_mac_f32", True),
710bf215546Sopenharmony_ci   (0x20, 0x20, 0x17, 0x17, 0x20, "v_madmk_f32", False),
711bf215546Sopenharmony_ci   (0x21, 0x21, 0x18, 0x18, 0x21, "v_madak_f32", False),
712bf215546Sopenharmony_ci   (0x24, 0x24,   -1,   -1,   -1, "v_mbcnt_hi_u32_b32", False),
713bf215546Sopenharmony_ci   (0x25, 0x25, 0x19, 0x19,   -1, "v_add_co_u32", False), # VOP3B only in RDNA
714bf215546Sopenharmony_ci   (0x26, 0x26, 0x1a, 0x1a,   -1, "v_sub_co_u32", False), # VOP3B only in RDNA
715bf215546Sopenharmony_ci   (0x27, 0x27, 0x1b, 0x1b,   -1, "v_subrev_co_u32", False), # VOP3B only in RDNA
716bf215546Sopenharmony_ci   (0x28, 0x28, 0x1c, 0x1c, 0x28, "v_addc_co_u32", False), # v_add_co_ci_u32 in RDNA
717bf215546Sopenharmony_ci   (0x29, 0x29, 0x1d, 0x1d, 0x29, "v_subb_co_u32", False), # v_sub_co_ci_u32 in RDNA
718bf215546Sopenharmony_ci   (0x2a, 0x2a, 0x1e, 0x1e, 0x2a, "v_subbrev_co_u32", False), # v_subrev_co_ci_u32 in RDNA
719bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x2b, "v_fmac_f32", True),
720bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x2c, "v_fmamk_f32", True),
721bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x2d, "v_fmaak_f32", True),
722bf215546Sopenharmony_ci   (0x2f, 0x2f,   -1,   -1, 0x2f, "v_cvt_pkrtz_f16_f32", True),
723bf215546Sopenharmony_ci   (  -1,   -1, 0x1f, 0x1f, 0x32, "v_add_f16", True),
724bf215546Sopenharmony_ci   (  -1,   -1, 0x20, 0x20, 0x33, "v_sub_f16", True),
725bf215546Sopenharmony_ci   (  -1,   -1, 0x21, 0x21, 0x34, "v_subrev_f16", True),
726bf215546Sopenharmony_ci   (  -1,   -1, 0x22, 0x22, 0x35, "v_mul_f16", True),
727bf215546Sopenharmony_ci   (  -1,   -1, 0x23, 0x23,   -1, "v_mac_f16", True),
728bf215546Sopenharmony_ci   (  -1,   -1, 0x24, 0x24,   -1, "v_madmk_f16", False),
729bf215546Sopenharmony_ci   (  -1,   -1, 0x25, 0x25,   -1, "v_madak_f16", False),
730bf215546Sopenharmony_ci   (  -1,   -1, 0x26, 0x26,   -1, "v_add_u16", False),
731bf215546Sopenharmony_ci   (  -1,   -1, 0x27, 0x27,   -1, "v_sub_u16", False),
732bf215546Sopenharmony_ci   (  -1,   -1, 0x28, 0x28,   -1, "v_subrev_u16", False),
733bf215546Sopenharmony_ci   (  -1,   -1, 0x29, 0x29,   -1, "v_mul_lo_u16", False),
734bf215546Sopenharmony_ci   (  -1,   -1, 0x2a, 0x2a,   -1, "v_lshlrev_b16", False),
735bf215546Sopenharmony_ci   (  -1,   -1, 0x2b, 0x2b,   -1, "v_lshrrev_b16", False),
736bf215546Sopenharmony_ci   (  -1,   -1, 0x2c, 0x2c,   -1, "v_ashrrev_i16", False),
737bf215546Sopenharmony_ci   (  -1,   -1, 0x2d, 0x2d, 0x39, "v_max_f16", True),
738bf215546Sopenharmony_ci   (  -1,   -1, 0x2e, 0x2e, 0x3a, "v_min_f16", True),
739bf215546Sopenharmony_ci   (  -1,   -1, 0x2f, 0x2f,   -1, "v_max_u16", False),
740bf215546Sopenharmony_ci   (  -1,   -1, 0x30, 0x30,   -1, "v_max_i16", False),
741bf215546Sopenharmony_ci   (  -1,   -1, 0x31, 0x31,   -1, "v_min_u16", False),
742bf215546Sopenharmony_ci   (  -1,   -1, 0x32, 0x32,   -1, "v_min_i16", False),
743bf215546Sopenharmony_ci   (  -1,   -1, 0x33, 0x33, 0x3b, "v_ldexp_f16", False),
744bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x34, 0x25, "v_add_u32", False), # use v_add_co_u32 on GFX8, called v_add_nc_u32 in RDNA
745bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x35, 0x26, "v_sub_u32", False), # use v_sub_co_u32 on GFX8, called v_sub_nc_u32 in RDNA
746bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x36, 0x27, "v_subrev_u32", False), # use v_subrev_co_u32 on GFX8, called v_subrev_nc_u32 in RDNA
747bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x36, "v_fmac_f16", False),
748bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x37, "v_fmamk_f16", False),
749bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x38, "v_fmaak_f16", False),
750bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x3c, "v_pk_fmac_f16", False),
751bf215546Sopenharmony_ci}
752bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, modifiers) in VOP2:
753bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOP2, InstrClass.Valu32, modifiers, modifiers)
754bf215546Sopenharmony_ci
755bf215546Sopenharmony_ciif True:
756bf215546Sopenharmony_ci    # v_cndmask_b32 can use input modifiers but not output modifiers
757bf215546Sopenharmony_ci    (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x00, 0x00, 0x00, 0x00, 0x01, "v_cndmask_b32")
758bf215546Sopenharmony_ci    opcode(name, gfx7, gfx9, gfx10, Format.VOP2, InstrClass.Valu32, True, False)
759bf215546Sopenharmony_ci
760bf215546Sopenharmony_ci
761bf215546Sopenharmony_ci# VOP1 instructions: instructions with 1 input and 1 output
762bf215546Sopenharmony_ciVOP1 = {
763bf215546Sopenharmony_ci  # GFX6, GFX7, GFX8, GFX9, GFX10, name, input_modifiers, output_modifiers
764bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "v_nop", False, False),
765bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "v_mov_b32", False, False),
766bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "v_readfirstlane_b32", False, False),
767bf215546Sopenharmony_ci   (0x03, 0x03, 0x03, 0x03, 0x03, "v_cvt_i32_f64", True, False, InstrClass.ValuDoubleConvert),
768bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "v_cvt_f64_i32", False, True, InstrClass.ValuDoubleConvert),
769bf215546Sopenharmony_ci   (0x05, 0x05, 0x05, 0x05, 0x05, "v_cvt_f32_i32", False, True),
770bf215546Sopenharmony_ci   (0x06, 0x06, 0x06, 0x06, 0x06, "v_cvt_f32_u32", False, True),
771bf215546Sopenharmony_ci   (0x07, 0x07, 0x07, 0x07, 0x07, "v_cvt_u32_f32", True, False),
772bf215546Sopenharmony_ci   (0x08, 0x08, 0x08, 0x08, 0x08, "v_cvt_i32_f32", True, False),
773bf215546Sopenharmony_ci   (0x09, 0x09,   -1,   -1, 0x09, "v_mov_fed_b32", True, False), # LLVM mentions it for GFX8_9
774bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x0a, 0x0a, 0x0a, "v_cvt_f16_f32", True, True),
775bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1,   -1, "p_cvt_f16_f32_rtne", True, True),
776bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x0b, 0x0b, 0x0b, "v_cvt_f32_f16", True, True),
777bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x0c, 0x0c, 0x0c, "v_cvt_rpi_i32_f32", True, False),
778bf215546Sopenharmony_ci   (0x0d, 0x0d, 0x0d, 0x0d, 0x0d, "v_cvt_flr_i32_f32", True, False),
779bf215546Sopenharmony_ci   (0x0e, 0x0e, 0x0e, 0x0e, 0x0e, "v_cvt_off_f32_i4", False, True),
780bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0f, 0x0f, 0x0f, "v_cvt_f32_f64", True, True, InstrClass.ValuDoubleConvert),
781bf215546Sopenharmony_ci   (0x10, 0x10, 0x10, 0x10, 0x10, "v_cvt_f64_f32", True, True, InstrClass.ValuDoubleConvert),
782bf215546Sopenharmony_ci   (0x11, 0x11, 0x11, 0x11, 0x11, "v_cvt_f32_ubyte0", False, True),
783bf215546Sopenharmony_ci   (0x12, 0x12, 0x12, 0x12, 0x12, "v_cvt_f32_ubyte1", False, True),
784bf215546Sopenharmony_ci   (0x13, 0x13, 0x13, 0x13, 0x13, "v_cvt_f32_ubyte2", False, True),
785bf215546Sopenharmony_ci   (0x14, 0x14, 0x14, 0x14, 0x14, "v_cvt_f32_ubyte3", False, True),
786bf215546Sopenharmony_ci   (0x15, 0x15, 0x15, 0x15, 0x15, "v_cvt_u32_f64", True, False, InstrClass.ValuDoubleConvert),
787bf215546Sopenharmony_ci   (0x16, 0x16, 0x16, 0x16, 0x16, "v_cvt_f64_u32", False, True, InstrClass.ValuDoubleConvert),
788bf215546Sopenharmony_ci   (  -1, 0x17, 0x17, 0x17, 0x17, "v_trunc_f64", True, True, InstrClass.ValuDouble),
789bf215546Sopenharmony_ci   (  -1, 0x18, 0x18, 0x18, 0x18, "v_ceil_f64", True, True, InstrClass.ValuDouble),
790bf215546Sopenharmony_ci   (  -1, 0x19, 0x19, 0x19, 0x19, "v_rndne_f64", True, True, InstrClass.ValuDouble),
791bf215546Sopenharmony_ci   (  -1, 0x1a, 0x1a, 0x1a, 0x1a, "v_floor_f64", True, True, InstrClass.ValuDouble),
792bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x1b, "v_pipeflush", False, False),
793bf215546Sopenharmony_ci   (0x20, 0x20, 0x1b, 0x1b, 0x20, "v_fract_f32", True, True),
794bf215546Sopenharmony_ci   (0x21, 0x21, 0x1c, 0x1c, 0x21, "v_trunc_f32", True, True),
795bf215546Sopenharmony_ci   (0x22, 0x22, 0x1d, 0x1d, 0x22, "v_ceil_f32", True, True),
796bf215546Sopenharmony_ci   (0x23, 0x23, 0x1e, 0x1e, 0x23, "v_rndne_f32", True, True),
797bf215546Sopenharmony_ci   (0x24, 0x24, 0x1f, 0x1f, 0x24, "v_floor_f32", True, True),
798bf215546Sopenharmony_ci   (0x25, 0x25, 0x20, 0x20, 0x25, "v_exp_f32", True, True, InstrClass.ValuTranscendental32),
799bf215546Sopenharmony_ci   (0x26, 0x26,   -1,   -1,   -1, "v_log_clamp_f32", True, True, InstrClass.ValuTranscendental32),
800bf215546Sopenharmony_ci   (0x27, 0x27, 0x21, 0x21, 0x27, "v_log_f32", True, True, InstrClass.ValuTranscendental32),
801bf215546Sopenharmony_ci   (0x28, 0x28,   -1,   -1,   -1, "v_rcp_clamp_f32", True, True, InstrClass.ValuTranscendental32),
802bf215546Sopenharmony_ci   (0x29, 0x29,   -1,   -1,   -1, "v_rcp_legacy_f32", True, True, InstrClass.ValuTranscendental32),
803bf215546Sopenharmony_ci   (0x2a, 0x2a, 0x22, 0x22, 0x2a, "v_rcp_f32", True, True, InstrClass.ValuTranscendental32),
804bf215546Sopenharmony_ci   (0x2b, 0x2b, 0x23, 0x23, 0x2b, "v_rcp_iflag_f32", True, True, InstrClass.ValuTranscendental32),
805bf215546Sopenharmony_ci   (0x2c, 0x2c,   -1,   -1,   -1, "v_rsq_clamp_f32", True, True, InstrClass.ValuTranscendental32),
806bf215546Sopenharmony_ci   (0x2d, 0x2d,   -1,   -1,   -1, "v_rsq_legacy_f32", True, True, InstrClass.ValuTranscendental32),
807bf215546Sopenharmony_ci   (0x2e, 0x2e, 0x24, 0x24, 0x2e, "v_rsq_f32", True, True, InstrClass.ValuTranscendental32),
808bf215546Sopenharmony_ci   (0x2f, 0x2f, 0x25, 0x25, 0x2f, "v_rcp_f64", True, True, InstrClass.ValuDoubleTranscendental),
809bf215546Sopenharmony_ci   (0x30, 0x30,   -1,   -1,   -1, "v_rcp_clamp_f64", True, True, InstrClass.ValuDoubleTranscendental),
810bf215546Sopenharmony_ci   (0x31, 0x31, 0x26, 0x26, 0x31, "v_rsq_f64", True, True, InstrClass.ValuDoubleTranscendental),
811bf215546Sopenharmony_ci   (0x32, 0x32,   -1,   -1,   -1, "v_rsq_clamp_f64", True, True, InstrClass.ValuDoubleTranscendental),
812bf215546Sopenharmony_ci   (0x33, 0x33, 0x27, 0x27, 0x33, "v_sqrt_f32", True, True, InstrClass.ValuTranscendental32),
813bf215546Sopenharmony_ci   (0x34, 0x34, 0x28, 0x28, 0x34, "v_sqrt_f64", True, True, InstrClass.ValuDoubleTranscendental),
814bf215546Sopenharmony_ci   (0x35, 0x35, 0x29, 0x29, 0x35, "v_sin_f32", True, True, InstrClass.ValuTranscendental32),
815bf215546Sopenharmony_ci   (0x36, 0x36, 0x2a, 0x2a, 0x36, "v_cos_f32", True, True, InstrClass.ValuTranscendental32),
816bf215546Sopenharmony_ci   (0x37, 0x37, 0x2b, 0x2b, 0x37, "v_not_b32", False, False),
817bf215546Sopenharmony_ci   (0x38, 0x38, 0x2c, 0x2c, 0x38, "v_bfrev_b32", False, False),
818bf215546Sopenharmony_ci   (0x39, 0x39, 0x2d, 0x2d, 0x39, "v_ffbh_u32", False, False),
819bf215546Sopenharmony_ci   (0x3a, 0x3a, 0x2e, 0x2e, 0x3a, "v_ffbl_b32", False, False),
820bf215546Sopenharmony_ci   (0x3b, 0x3b, 0x2f, 0x2f, 0x3b, "v_ffbh_i32", False, False),
821bf215546Sopenharmony_ci   (0x3c, 0x3c, 0x30, 0x30, 0x3c, "v_frexp_exp_i32_f64", True, False, InstrClass.ValuDouble),
822bf215546Sopenharmony_ci   (0x3d, 0x3d, 0x31, 0x31, 0x3d, "v_frexp_mant_f64", True, False, InstrClass.ValuDouble),
823bf215546Sopenharmony_ci   (0x3e, 0x3e, 0x32, 0x32, 0x3e, "v_fract_f64", True, True, InstrClass.ValuDouble),
824bf215546Sopenharmony_ci   (0x3f, 0x3f, 0x33, 0x33, 0x3f, "v_frexp_exp_i32_f32", True, False),
825bf215546Sopenharmony_ci   (0x40, 0x40, 0x34, 0x34, 0x40, "v_frexp_mant_f32", True, False),
826bf215546Sopenharmony_ci   (0x41, 0x41, 0x35, 0x35, 0x41, "v_clrexcp", False, False),
827bf215546Sopenharmony_ci   (0x42, 0x42, 0x36,   -1, 0x42, "v_movreld_b32", False, False),
828bf215546Sopenharmony_ci   (0x43, 0x43, 0x37,   -1, 0x43, "v_movrels_b32", False, False),
829bf215546Sopenharmony_ci   (0x44, 0x44, 0x38,   -1, 0x44, "v_movrelsd_b32", False, False),
830bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x48, "v_movrelsd_2_b32", False, False),
831bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x37,   -1, "v_screen_partition_4se_b32", False, False),
832bf215546Sopenharmony_ci   (  -1,   -1, 0x39, 0x39, 0x50, "v_cvt_f16_u16", False, True),
833bf215546Sopenharmony_ci   (  -1,   -1, 0x3a, 0x3a, 0x51, "v_cvt_f16_i16", False, True),
834bf215546Sopenharmony_ci   (  -1,   -1, 0x3b, 0x3b, 0x52, "v_cvt_u16_f16", True, False),
835bf215546Sopenharmony_ci   (  -1,   -1, 0x3c, 0x3c, 0x53, "v_cvt_i16_f16", True, False),
836bf215546Sopenharmony_ci   (  -1,   -1, 0x3d, 0x3d, 0x54, "v_rcp_f16", True, True, InstrClass.ValuTranscendental32),
837bf215546Sopenharmony_ci   (  -1,   -1, 0x3e, 0x3e, 0x55, "v_sqrt_f16", True, True, InstrClass.ValuTranscendental32),
838bf215546Sopenharmony_ci   (  -1,   -1, 0x3f, 0x3f, 0x56, "v_rsq_f16", True, True, InstrClass.ValuTranscendental32),
839bf215546Sopenharmony_ci   (  -1,   -1, 0x40, 0x40, 0x57, "v_log_f16", True, True, InstrClass.ValuTranscendental32),
840bf215546Sopenharmony_ci   (  -1,   -1, 0x41, 0x41, 0x58, "v_exp_f16", True, True, InstrClass.ValuTranscendental32),
841bf215546Sopenharmony_ci   (  -1,   -1, 0x42, 0x42, 0x59, "v_frexp_mant_f16", True, False),
842bf215546Sopenharmony_ci   (  -1,   -1, 0x43, 0x43, 0x5a, "v_frexp_exp_i16_f16", True, False),
843bf215546Sopenharmony_ci   (  -1,   -1, 0x44, 0x44, 0x5b, "v_floor_f16", True, True),
844bf215546Sopenharmony_ci   (  -1,   -1, 0x45, 0x45, 0x5c, "v_ceil_f16", True, True),
845bf215546Sopenharmony_ci   (  -1,   -1, 0x46, 0x46, 0x5d, "v_trunc_f16", True, True),
846bf215546Sopenharmony_ci   (  -1,   -1, 0x47, 0x47, 0x5e, "v_rndne_f16", True, True),
847bf215546Sopenharmony_ci   (  -1,   -1, 0x48, 0x48, 0x5f, "v_fract_f16", True, True),
848bf215546Sopenharmony_ci   (  -1,   -1, 0x49, 0x49, 0x60, "v_sin_f16", True, True, InstrClass.ValuTranscendental32),
849bf215546Sopenharmony_ci   (  -1,   -1, 0x4a, 0x4a, 0x61, "v_cos_f16", True, True, InstrClass.ValuTranscendental32),
850bf215546Sopenharmony_ci   (  -1, 0x46, 0x4b, 0x4b,   -1, "v_exp_legacy_f32", True, True, InstrClass.ValuTranscendental32),
851bf215546Sopenharmony_ci   (  -1, 0x45, 0x4c, 0x4c,   -1, "v_log_legacy_f32", True, True, InstrClass.ValuTranscendental32),
852bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x4f, 0x62, "v_sat_pk_u8_i16", False, False),
853bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x4d, 0x63, "v_cvt_norm_i16_f16", True, False),
854bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x4e, 0x64, "v_cvt_norm_u16_f16", True, False),
855bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x51, 0x65, "v_swap_b32", False, False),
856bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x68, "v_swaprel_b32", False, False),
857bf215546Sopenharmony_ci}
858bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, in_mod, out_mod, cls) in default_class(VOP1, InstrClass.Valu32):
859bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOP1, cls, in_mod, out_mod)
860bf215546Sopenharmony_ci
861bf215546Sopenharmony_ci
862bf215546Sopenharmony_ci# VOPC instructions:
863bf215546Sopenharmony_ci
864bf215546Sopenharmony_ciVOPC_CLASS = {
865bf215546Sopenharmony_ci   (0x88, 0x88, 0x10, 0x10, 0x88, "v_cmp_class_f32"),
866bf215546Sopenharmony_ci   (  -1,   -1, 0x14, 0x14, 0x8f, "v_cmp_class_f16"),
867bf215546Sopenharmony_ci   (0x98, 0x98, 0x11, 0x11, 0x98, "v_cmpx_class_f32"),
868bf215546Sopenharmony_ci   (  -1,   -1, 0x15, 0x15, 0x9f, "v_cmpx_class_f16"),
869bf215546Sopenharmony_ci   (0xa8, 0xa8, 0x12, 0x12, 0xa8, "v_cmp_class_f64", InstrClass.ValuDouble),
870bf215546Sopenharmony_ci   (0xb8, 0xb8, 0x13, 0x13, 0xb8, "v_cmpx_class_f64", InstrClass.ValuDouble),
871bf215546Sopenharmony_ci}
872bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, cls) in default_class(VOPC_CLASS, InstrClass.Valu32):
873bf215546Sopenharmony_ci    opcode(name, gfx7, gfx9, gfx10, Format.VOPC, cls, True, False)
874bf215546Sopenharmony_ci
875bf215546Sopenharmony_ciCOMPF = ["f", "lt", "eq", "le", "gt", "lg", "ge", "o", "u", "nge", "nlg", "ngt", "nle", "neq", "nlt", "tru"]
876bf215546Sopenharmony_ci
877bf215546Sopenharmony_cifor i in range(8):
878bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0x20+i, 0x20+i, 0xc8+i, "v_cmp_"+COMPF[i]+"_f16")
879bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32, True, False)
880bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0x30+i, 0x30+i, 0xd8+i, "v_cmpx_"+COMPF[i]+"_f16")
881bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32, True, False)
882bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0x28+i, 0x28+i, 0xe8+i, "v_cmp_"+COMPF[i+8]+"_f16")
883bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32, True, False)
884bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0x38+i, 0x38+i, 0xf8+i, "v_cmpx_"+COMPF[i+8]+"_f16")
885bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32, True, False)
886bf215546Sopenharmony_ci
887bf215546Sopenharmony_cifor i in range(16):
888bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x00+i, 0x00+i, 0x40+i, 0x40+i, 0x00+i, "v_cmp_"+COMPF[i]+"_f32")
889bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32, True, False)
890bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x10+i, 0x10+i, 0x50+i, 0x50+i, 0x10+i, "v_cmpx_"+COMPF[i]+"_f32")
891bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32, True, False)
892bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x20+i, 0x20+i, 0x60+i, 0x60+i, 0x20+i, "v_cmp_"+COMPF[i]+"_f64")
893bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.ValuDouble, True, False)
894bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x30+i, 0x30+i, 0x70+i, 0x70+i, 0x30+i, "v_cmpx_"+COMPF[i]+"_f64")
895bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.ValuDouble, True, False)
896bf215546Sopenharmony_ci   # GFX_6_7
897bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x40+i, 0x40+i, -1, -1, -1, "v_cmps_"+COMPF[i]+"_f32")
898bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x50+i, 0x50+i, -1, -1, -1, "v_cmpsx_"+COMPF[i]+"_f32")
899bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x60+i, 0x60+i, -1, -1, -1, "v_cmps_"+COMPF[i]+"_f64")
900bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x70+i, 0x70+i, -1, -1, -1, "v_cmpsx_"+COMPF[i]+"_f64")
901bf215546Sopenharmony_ci
902bf215546Sopenharmony_ciCOMPI = ["f", "lt", "eq", "le", "gt", "lg", "ge", "tru"]
903bf215546Sopenharmony_ci
904bf215546Sopenharmony_ci# GFX_8_9
905bf215546Sopenharmony_cifor i in [0,7]: # only 0 and 7
906bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xa0+i, 0xa0+i, -1, "v_cmp_"+COMPI[i]+"_i16")
907bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
908bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xb0+i, 0xb0+i, -1, "v_cmpx_"+COMPI[i]+"_i16")
909bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
910bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xa8+i, 0xa8+i, -1, "v_cmp_"+COMPI[i]+"_u16")
911bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
912bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xb8+i, 0xb8+i, -1, "v_cmpx_"+COMPI[i]+"_u16")
913bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
914bf215546Sopenharmony_ci
915bf215546Sopenharmony_cifor i in range(1, 7): # [1..6]
916bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xa0+i, 0xa0+i, 0x88+i, "v_cmp_"+COMPI[i]+"_i16")
917bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
918bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xb0+i, 0xb0+i, 0x98+i, "v_cmpx_"+COMPI[i]+"_i16")
919bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
920bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xa8+i, 0xa8+i, 0xa8+i, "v_cmp_"+COMPI[i]+"_u16")
921bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
922bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, 0xb8+i, 0xb8+i, 0xb8+i, "v_cmpx_"+COMPI[i]+"_u16")
923bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_cifor i in range(8):
926bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x80+i, 0x80+i, 0xc0+i, 0xc0+i, 0x80+i, "v_cmp_"+COMPI[i]+"_i32")
927bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
928bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0x90+i, 0x90+i, 0xd0+i, 0xd0+i, 0x90+i, "v_cmpx_"+COMPI[i]+"_i32")
929bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
930bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0xa0+i, 0xa0+i, 0xe0+i, 0xe0+i, 0xa0+i, "v_cmp_"+COMPI[i]+"_i64")
931bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu64)
932bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0xb0+i, 0xb0+i, 0xf0+i, 0xf0+i, 0xb0+i, "v_cmpx_"+COMPI[i]+"_i64")
933bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu64)
934bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0xc0+i, 0xc0+i, 0xc8+i, 0xc8+i, 0xc0+i, "v_cmp_"+COMPI[i]+"_u32")
935bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
936bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0xd0+i, 0xd0+i, 0xd8+i, 0xd8+i, 0xd0+i, "v_cmpx_"+COMPI[i]+"_u32")
937bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu32)
938bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0xe0+i, 0xe0+i, 0xe8+i, 0xe8+i, 0xe0+i, "v_cmp_"+COMPI[i]+"_u64")
939bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu64)
940bf215546Sopenharmony_ci   (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (0xf0+i, 0xf0+i, 0xf8+i, 0xf8+i, 0xf0+i, "v_cmpx_"+COMPI[i]+"_u64")
941bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOPC, InstrClass.Valu64)
942bf215546Sopenharmony_ci
943bf215546Sopenharmony_ci
944bf215546Sopenharmony_ci# VOPP instructions: packed 16bit instructions - 1 or 2 inputs and 1 output
945bf215546Sopenharmony_ciVOPP = {
946bf215546Sopenharmony_ci   # opcode, name, input/output modifiers
947bf215546Sopenharmony_ci   (0x00, "v_pk_mad_i16", False),
948bf215546Sopenharmony_ci   (0x01, "v_pk_mul_lo_u16", False),
949bf215546Sopenharmony_ci   (0x02, "v_pk_add_i16", False),
950bf215546Sopenharmony_ci   (0x03, "v_pk_sub_i16", False),
951bf215546Sopenharmony_ci   (0x04, "v_pk_lshlrev_b16", False),
952bf215546Sopenharmony_ci   (0x05, "v_pk_lshrrev_b16", False),
953bf215546Sopenharmony_ci   (0x06, "v_pk_ashrrev_i16", False),
954bf215546Sopenharmony_ci   (0x07, "v_pk_max_i16", False),
955bf215546Sopenharmony_ci   (0x08, "v_pk_min_i16", False),
956bf215546Sopenharmony_ci   (0x09, "v_pk_mad_u16", False),
957bf215546Sopenharmony_ci   (0x0a, "v_pk_add_u16", False),
958bf215546Sopenharmony_ci   (0x0b, "v_pk_sub_u16", False),
959bf215546Sopenharmony_ci   (0x0c, "v_pk_max_u16", False),
960bf215546Sopenharmony_ci   (0x0d, "v_pk_min_u16", False),
961bf215546Sopenharmony_ci   (0x0e, "v_pk_fma_f16", True),
962bf215546Sopenharmony_ci   (0x0f, "v_pk_add_f16", True),
963bf215546Sopenharmony_ci   (0x10, "v_pk_mul_f16", True),
964bf215546Sopenharmony_ci   (0x11, "v_pk_min_f16", True),
965bf215546Sopenharmony_ci   (0x12, "v_pk_max_f16", True),
966bf215546Sopenharmony_ci   (0x20, "v_fma_mix_f32", True), # v_mad_mix_f32 in VEGA ISA, v_fma_mix_f32 in RDNA ISA
967bf215546Sopenharmony_ci   (0x21, "v_fma_mixlo_f16", True), # v_mad_mixlo_f16 in VEGA ISA, v_fma_mixlo_f16 in RDNA ISA
968bf215546Sopenharmony_ci   (0x22, "v_fma_mixhi_f16", True), # v_mad_mixhi_f16 in VEGA ISA, v_fma_mixhi_f16 in RDNA ISA
969bf215546Sopenharmony_ci}
970bf215546Sopenharmony_ci# note that these are only supported on gfx9+ so we'll need to distinguish between gfx8 and gfx9 here
971bf215546Sopenharmony_ci# (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, -1, code, code, name)
972bf215546Sopenharmony_cifor (code, name, modifiers) in VOPP:
973bf215546Sopenharmony_ci   opcode(name, -1, code, code, Format.VOP3P, InstrClass.Valu32, modifiers, modifiers)
974bf215546Sopenharmony_ciopcode("v_dot2_i32_i16", -1, 0x26, 0x14, Format.VOP3P, InstrClass.Valu32)
975bf215546Sopenharmony_ciopcode("v_dot2_u32_u16", -1, 0x27, 0x15, Format.VOP3P, InstrClass.Valu32)
976bf215546Sopenharmony_ciopcode("v_dot4_i32_i8", -1, 0x28, 0x16, Format.VOP3P, InstrClass.Valu32)
977bf215546Sopenharmony_ciopcode("v_dot4_u32_u8", -1, 0x29, 0x17, Format.VOP3P, InstrClass.Valu32)
978bf215546Sopenharmony_ci
979bf215546Sopenharmony_ci
980bf215546Sopenharmony_ci# VINTERP instructions:
981bf215546Sopenharmony_ciVINTRP = {
982bf215546Sopenharmony_ci   (0x00, "v_interp_p1_f32"),
983bf215546Sopenharmony_ci   (0x01, "v_interp_p2_f32"),
984bf215546Sopenharmony_ci   (0x02, "v_interp_mov_f32"),
985bf215546Sopenharmony_ci}
986bf215546Sopenharmony_ci# (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (code, code, code, code, code, name)
987bf215546Sopenharmony_cifor (code, name) in VINTRP:
988bf215546Sopenharmony_ci   opcode(name, code, code, code, Format.VINTRP, InstrClass.Valu32)
989bf215546Sopenharmony_ci
990bf215546Sopenharmony_ci# VOP3 instructions: 3 inputs, 1 output
991bf215546Sopenharmony_ci# VOP3b instructions: have a unique scalar output, e.g. VOP2 with vcc out
992bf215546Sopenharmony_ciVOP3 = {
993bf215546Sopenharmony_ci   (0x140, 0x140, 0x1c0, 0x1c0, 0x140, "v_mad_legacy_f32", True, True), # GFX6-GFX10
994bf215546Sopenharmony_ci   (0x141, 0x141, 0x1c1, 0x1c1, 0x141, "v_mad_f32", True, True),
995bf215546Sopenharmony_ci   (0x142, 0x142, 0x1c2, 0x1c2, 0x142, "v_mad_i32_i24", False, False),
996bf215546Sopenharmony_ci   (0x143, 0x143, 0x1c3, 0x1c3, 0x143, "v_mad_u32_u24", False, False),
997bf215546Sopenharmony_ci   (0x144, 0x144, 0x1c4, 0x1c4, 0x144, "v_cubeid_f32", True, True),
998bf215546Sopenharmony_ci   (0x145, 0x145, 0x1c5, 0x1c5, 0x145, "v_cubesc_f32", True, True),
999bf215546Sopenharmony_ci   (0x146, 0x146, 0x1c6, 0x1c6, 0x146, "v_cubetc_f32", True, True),
1000bf215546Sopenharmony_ci   (0x147, 0x147, 0x1c7, 0x1c7, 0x147, "v_cubema_f32", True, True),
1001bf215546Sopenharmony_ci   (0x148, 0x148, 0x1c8, 0x1c8, 0x148, "v_bfe_u32", False, False),
1002bf215546Sopenharmony_ci   (0x149, 0x149, 0x1c9, 0x1c9, 0x149, "v_bfe_i32", False, False),
1003bf215546Sopenharmony_ci   (0x14a, 0x14a, 0x1ca, 0x1ca, 0x14a, "v_bfi_b32", False, False),
1004bf215546Sopenharmony_ci   (0x14b, 0x14b, 0x1cb, 0x1cb, 0x14b, "v_fma_f32", True, True, InstrClass.ValuFma),
1005bf215546Sopenharmony_ci   (0x14c, 0x14c, 0x1cc, 0x1cc, 0x14c, "v_fma_f64", True, True, InstrClass.ValuDouble),
1006bf215546Sopenharmony_ci   (0x14d, 0x14d, 0x1cd, 0x1cd, 0x14d, "v_lerp_u8", False, False),
1007bf215546Sopenharmony_ci   (0x14e, 0x14e, 0x1ce, 0x1ce, 0x14e, "v_alignbit_b32", False, False),
1008bf215546Sopenharmony_ci   (0x14f, 0x14f, 0x1cf, 0x1cf, 0x14f, "v_alignbyte_b32", False, False),
1009bf215546Sopenharmony_ci   (0x150, 0x150,    -1,    -1, 0x150, "v_mullit_f32", True, True),
1010bf215546Sopenharmony_ci   (0x151, 0x151, 0x1d0, 0x1d0, 0x151, "v_min3_f32", True, True),
1011bf215546Sopenharmony_ci   (0x152, 0x152, 0x1d1, 0x1d1, 0x152, "v_min3_i32", False, False),
1012bf215546Sopenharmony_ci   (0x153, 0x153, 0x1d2, 0x1d2, 0x153, "v_min3_u32", False, False),
1013bf215546Sopenharmony_ci   (0x154, 0x154, 0x1d3, 0x1d3, 0x154, "v_max3_f32", True, True),
1014bf215546Sopenharmony_ci   (0x155, 0x155, 0x1d4, 0x1d4, 0x155, "v_max3_i32", False, False),
1015bf215546Sopenharmony_ci   (0x156, 0x156, 0x1d5, 0x1d5, 0x156, "v_max3_u32", False, False),
1016bf215546Sopenharmony_ci   (0x157, 0x157, 0x1d6, 0x1d6, 0x157, "v_med3_f32", True, True),
1017bf215546Sopenharmony_ci   (0x158, 0x158, 0x1d7, 0x1d7, 0x158, "v_med3_i32", False, False),
1018bf215546Sopenharmony_ci   (0x159, 0x159, 0x1d8, 0x1d8, 0x159, "v_med3_u32", False, False),
1019bf215546Sopenharmony_ci   (0x15a, 0x15a, 0x1d9, 0x1d9, 0x15a, "v_sad_u8", False, False),
1020bf215546Sopenharmony_ci   (0x15b, 0x15b, 0x1da, 0x1da, 0x15b, "v_sad_hi_u8", False, False),
1021bf215546Sopenharmony_ci   (0x15c, 0x15c, 0x1db, 0x1db, 0x15c, "v_sad_u16", False, False),
1022bf215546Sopenharmony_ci   (0x15d, 0x15d, 0x1dc, 0x1dc, 0x15d, "v_sad_u32", False, False),
1023bf215546Sopenharmony_ci   (0x15e, 0x15e, 0x1dd, 0x1dd, 0x15e, "v_cvt_pk_u8_f32", True, False),
1024bf215546Sopenharmony_ci   (0x15f, 0x15f, 0x1de, 0x1de, 0x15f, "v_div_fixup_f32", True, True),
1025bf215546Sopenharmony_ci   (0x160, 0x160, 0x1df, 0x1df, 0x160, "v_div_fixup_f64", True, True),
1026bf215546Sopenharmony_ci   (0x161, 0x161,    -1,    -1,    -1, "v_lshl_b64", False, False, InstrClass.Valu64),
1027bf215546Sopenharmony_ci   (0x162, 0x162,    -1,    -1,    -1, "v_lshr_b64", False, False, InstrClass.Valu64),
1028bf215546Sopenharmony_ci   (0x163, 0x163,    -1,    -1,    -1, "v_ashr_i64", False, False, InstrClass.Valu64),
1029bf215546Sopenharmony_ci   (0x164, 0x164, 0x280, 0x280, 0x164, "v_add_f64", True, True, InstrClass.ValuDoubleAdd),
1030bf215546Sopenharmony_ci   (0x165, 0x165, 0x281, 0x281, 0x165, "v_mul_f64", True, True, InstrClass.ValuDouble),
1031bf215546Sopenharmony_ci   (0x166, 0x166, 0x282, 0x282, 0x166, "v_min_f64", True, True, InstrClass.ValuDouble),
1032bf215546Sopenharmony_ci   (0x167, 0x167, 0x283, 0x283, 0x167, "v_max_f64", True, True, InstrClass.ValuDouble),
1033bf215546Sopenharmony_ci   (0x168, 0x168, 0x284, 0x284, 0x168, "v_ldexp_f64", False, True, InstrClass.ValuDouble), # src1 can take input modifiers
1034bf215546Sopenharmony_ci   (0x169, 0x169, 0x285, 0x285, 0x169, "v_mul_lo_u32", False, False, InstrClass.ValuQuarterRate32),
1035bf215546Sopenharmony_ci   (0x16a, 0x16a, 0x286, 0x286, 0x16a, "v_mul_hi_u32", False, False, InstrClass.ValuQuarterRate32),
1036bf215546Sopenharmony_ci   (0x16b, 0x16b, 0x285, 0x285, 0x16b, "v_mul_lo_i32", False, False, InstrClass.ValuQuarterRate32), # identical to v_mul_lo_u32
1037bf215546Sopenharmony_ci   (0x16c, 0x16c, 0x287, 0x287, 0x16c, "v_mul_hi_i32", False, False, InstrClass.ValuQuarterRate32),
1038bf215546Sopenharmony_ci   (0x16d, 0x16d, 0x1e0, 0x1e0, 0x16d, "v_div_scale_f32", True, True), # writes to VCC
1039bf215546Sopenharmony_ci   (0x16e, 0x16e, 0x1e1, 0x1e1, 0x16e, "v_div_scale_f64", True, True, InstrClass.ValuDouble), # writes to VCC
1040bf215546Sopenharmony_ci   (0x16f, 0x16f, 0x1e2, 0x1e2, 0x16f, "v_div_fmas_f32", True, True), # takes VCC input
1041bf215546Sopenharmony_ci   (0x170, 0x170, 0x1e3, 0x1e3, 0x170, "v_div_fmas_f64", True, True, InstrClass.ValuDouble), # takes VCC input
1042bf215546Sopenharmony_ci   (0x171, 0x171, 0x1e4, 0x1e4, 0x171, "v_msad_u8", False, False),
1043bf215546Sopenharmony_ci   (0x172, 0x172, 0x1e5, 0x1e5, 0x172, "v_qsad_pk_u16_u8", False, False),
1044bf215546Sopenharmony_ci   (0x172,    -1,    -1,    -1,    -1, "v_qsad_u8", False, False), # what's the difference?
1045bf215546Sopenharmony_ci   (0x173, 0x173, 0x1e6, 0x1e6, 0x173, "v_mqsad_pk_u16_u8", False, False),
1046bf215546Sopenharmony_ci   (0x173,    -1,    -1,    -1,    -1, "v_mqsad_u8", False, False), # what's the difference?
1047bf215546Sopenharmony_ci   (0x174, 0x174, 0x292, 0x292, 0x174, "v_trig_preop_f64", False, False, InstrClass.ValuDouble),
1048bf215546Sopenharmony_ci   (   -1, 0x175, 0x1e7, 0x1e7, 0x175, "v_mqsad_u32_u8", False, False),
1049bf215546Sopenharmony_ci   (   -1, 0x176, 0x1e8, 0x1e8, 0x176, "v_mad_u64_u32", False, False, InstrClass.Valu64),
1050bf215546Sopenharmony_ci   (   -1, 0x177, 0x1e9, 0x1e9, 0x177, "v_mad_i64_i32", False, False, InstrClass.Valu64),
1051bf215546Sopenharmony_ci   (   -1,    -1, 0x1ea, 0x1ea,    -1, "v_mad_legacy_f16", True, True),
1052bf215546Sopenharmony_ci   (   -1,    -1, 0x1eb, 0x1eb,    -1, "v_mad_legacy_u16", False, False),
1053bf215546Sopenharmony_ci   (   -1,    -1, 0x1ec, 0x1ec,    -1, "v_mad_legacy_i16", False, False),
1054bf215546Sopenharmony_ci   (   -1,    -1, 0x1ed, 0x1ed, 0x344, "v_perm_b32", False, False),
1055bf215546Sopenharmony_ci   (   -1,    -1, 0x1ee, 0x1ee,    -1, "v_fma_legacy_f16", True, True, InstrClass.ValuFma),
1056bf215546Sopenharmony_ci   (   -1,    -1, 0x1ef, 0x1ef,    -1, "v_div_fixup_legacy_f16", True, True),
1057bf215546Sopenharmony_ci   (0x12c, 0x12c, 0x1f0, 0x1f0,    -1, "v_cvt_pkaccum_u8_f32", True, False),
1058bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f1, 0x373, "v_mad_u32_u16", False, False),
1059bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f2, 0x375, "v_mad_i32_i16", False, False),
1060bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f3, 0x345, "v_xad_u32", False, False),
1061bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f4, 0x351, "v_min3_f16", True, True),
1062bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f5, 0x352, "v_min3_i16", False, False),
1063bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f6, 0x353, "v_min3_u16", False, False),
1064bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f7, 0x354, "v_max3_f16", True, True),
1065bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f8, 0x355, "v_max3_i16", False, False),
1066bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1f9, 0x356, "v_max3_u16", False, False),
1067bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1fa, 0x357, "v_med3_f16", True, True),
1068bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1fb, 0x358, "v_med3_i16", False, False),
1069bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1fc, 0x359, "v_med3_u16", False, False),
1070bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1fd, 0x346, "v_lshl_add_u32", False, False),
1071bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1fe, 0x347, "v_add_lshl_u32", False, False),
1072bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x1ff, 0x36d, "v_add3_u32", False, False),
1073bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x200, 0x36f, "v_lshl_or_b32", False, False),
1074bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x201, 0x371, "v_and_or_b32", False, False),
1075bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x202, 0x372, "v_or3_b32", False, False),
1076bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x203,    -1, "v_mad_f16", True, True),
1077bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x204, 0x340, "v_mad_u16", False, False),
1078bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x205, 0x35e, "v_mad_i16", False, False),
1079bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x206, 0x34b, "v_fma_f16", True, True),
1080bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x207, 0x35f, "v_div_fixup_f16", True, True),
1081bf215546Sopenharmony_ci   (   -1,    -1, 0x274, 0x274, 0x342, "v_interp_p1ll_f16", True, True),
1082bf215546Sopenharmony_ci   (   -1,    -1, 0x275, 0x275, 0x343, "v_interp_p1lv_f16", True, True),
1083bf215546Sopenharmony_ci   (   -1,    -1, 0x276, 0x276,    -1, "v_interp_p2_legacy_f16", True, True),
1084bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x277, 0x35a, "v_interp_p2_f16", True, True),
1085bf215546Sopenharmony_ci   (0x12b, 0x12b, 0x288, 0x288, 0x362, "v_ldexp_f32", False, True),
1086bf215546Sopenharmony_ci   (   -1,    -1, 0x289, 0x289, 0x360, "v_readlane_b32_e64", False, False),
1087bf215546Sopenharmony_ci   (   -1,    -1, 0x28a, 0x28a, 0x361, "v_writelane_b32_e64", False, False),
1088bf215546Sopenharmony_ci   (0x122, 0x122, 0x28b, 0x28b, 0x364, "v_bcnt_u32_b32", False, False),
1089bf215546Sopenharmony_ci   (0x123, 0x123, 0x28c, 0x28c, 0x365, "v_mbcnt_lo_u32_b32", False, False),
1090bf215546Sopenharmony_ci   (   -1,    -1, 0x28d, 0x28d, 0x366, "v_mbcnt_hi_u32_b32_e64", False, False),
1091bf215546Sopenharmony_ci   (   -1,    -1, 0x28f, 0x28f, 0x2ff, "v_lshlrev_b64", False, False, InstrClass.Valu64),
1092bf215546Sopenharmony_ci   (   -1,    -1, 0x290, 0x290, 0x300, "v_lshrrev_b64", False, False, InstrClass.Valu64),
1093bf215546Sopenharmony_ci   (   -1,    -1, 0x291, 0x291, 0x301, "v_ashrrev_i64", False, False, InstrClass.Valu64),
1094bf215546Sopenharmony_ci   (0x11e, 0x11e, 0x293, 0x293, 0x363, "v_bfm_b32", False, False),
1095bf215546Sopenharmony_ci   (0x12d, 0x12d, 0x294, 0x294, 0x368, "v_cvt_pknorm_i16_f32", True, False),
1096bf215546Sopenharmony_ci   (0x12e, 0x12e, 0x295, 0x295, 0x369, "v_cvt_pknorm_u16_f32", True, False),
1097bf215546Sopenharmony_ci   (0x12f, 0x12f, 0x296, 0x296, 0x12f, "v_cvt_pkrtz_f16_f32_e64", True, False), # GFX6_7_10 is VOP2 with opcode 0x02f
1098bf215546Sopenharmony_ci   (0x130, 0x130, 0x297, 0x297, 0x36a, "v_cvt_pk_u16_u32", False, False),
1099bf215546Sopenharmony_ci   (0x131, 0x131, 0x298, 0x298, 0x36b, "v_cvt_pk_i16_i32", False, False),
1100bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x299, 0x312, "v_cvt_pknorm_i16_f16", True, False),
1101bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x29a, 0x313, "v_cvt_pknorm_u16_f16", True, False),
1102bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x29c, 0x37f, "v_add_i32", False, False),
1103bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x29d, 0x376, "v_sub_i32", False, False),
1104bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x29e, 0x30d, "v_add_i16", False, False),
1105bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x29f, 0x30e, "v_sub_i16", False, False),
1106bf215546Sopenharmony_ci   (   -1,    -1,    -1, 0x2a0, 0x311, "v_pack_b32_f16", True, False),
1107bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x178, "v_xor3_b32", False, False),
1108bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x377, "v_permlane16_b32", False, False),
1109bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x378, "v_permlanex16_b32", False, False),
1110bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x30f, "v_add_co_u32_e64", False, False),
1111bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x310, "v_sub_co_u32_e64", False, False),
1112bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x319, "v_subrev_co_u32_e64", False, False),
1113bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x303, "v_add_u16_e64", False, False),
1114bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x304, "v_sub_u16_e64", False, False),
1115bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x305, "v_mul_lo_u16_e64", False, False),
1116bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x309, "v_max_u16_e64", False, False),
1117bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x30a, "v_max_i16_e64", False, False),
1118bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x30b, "v_min_u16_e64", False, False),
1119bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x30c, "v_min_i16_e64", False, False),
1120bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x307, "v_lshrrev_b16_e64", False, False),
1121bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x308, "v_ashrrev_i16_e64", False, False),
1122bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x314, "v_lshlrev_b16_e64", False, False),
1123bf215546Sopenharmony_ci   (   -1,    -1,    -1,    -1, 0x140, "v_fma_legacy_f32", True, True, InstrClass.ValuFma), #GFX10.3+
1124bf215546Sopenharmony_ci}
1125bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name, in_mod, out_mod, cls) in default_class(VOP3, InstrClass.Valu32):
1126bf215546Sopenharmony_ci   opcode(name, gfx7, gfx9, gfx10, Format.VOP3, cls, in_mod, out_mod)
1127bf215546Sopenharmony_ci
1128bf215546Sopenharmony_ci
1129bf215546Sopenharmony_ci# DS instructions: 3 inputs (1 addr, 2 data), 1 output
1130bf215546Sopenharmony_ciDS = {
1131bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "ds_add_u32"),
1132bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "ds_sub_u32"),
1133bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "ds_rsub_u32"),
1134bf215546Sopenharmony_ci   (0x03, 0x03, 0x03, 0x03, 0x03, "ds_inc_u32"),
1135bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "ds_dec_u32"),
1136bf215546Sopenharmony_ci   (0x05, 0x05, 0x05, 0x05, 0x05, "ds_min_i32"),
1137bf215546Sopenharmony_ci   (0x06, 0x06, 0x06, 0x06, 0x06, "ds_max_i32"),
1138bf215546Sopenharmony_ci   (0x07, 0x07, 0x07, 0x07, 0x07, "ds_min_u32"),
1139bf215546Sopenharmony_ci   (0x08, 0x08, 0x08, 0x08, 0x08, "ds_max_u32"),
1140bf215546Sopenharmony_ci   (0x09, 0x09, 0x09, 0x09, 0x09, "ds_and_b32"),
1141bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x0a, 0x0a, 0x0a, "ds_or_b32"),
1142bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x0b, 0x0b, 0x0b, "ds_xor_b32"),
1143bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x0c, 0x0c, 0x0c, "ds_mskor_b32"),
1144bf215546Sopenharmony_ci   (0x0d, 0x0d, 0x0d, 0x0d, 0x0d, "ds_write_b32"),
1145bf215546Sopenharmony_ci   (0x0e, 0x0e, 0x0e, 0x0e, 0x0e, "ds_write2_b32"),
1146bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x0f, 0x0f, 0x0f, "ds_write2st64_b32"),
1147bf215546Sopenharmony_ci   (0x10, 0x10, 0x10, 0x10, 0x10, "ds_cmpst_b32"),
1148bf215546Sopenharmony_ci   (0x11, 0x11, 0x11, 0x11, 0x11, "ds_cmpst_f32"),
1149bf215546Sopenharmony_ci   (0x12, 0x12, 0x12, 0x12, 0x12, "ds_min_f32"),
1150bf215546Sopenharmony_ci   (0x13, 0x13, 0x13, 0x13, 0x13, "ds_max_f32"),
1151bf215546Sopenharmony_ci   (  -1, 0x14, 0x14, 0x14, 0x14, "ds_nop"),
1152bf215546Sopenharmony_ci   (  -1,   -1, 0x15, 0x15, 0x15, "ds_add_f32"),
1153bf215546Sopenharmony_ci   (  -1,   -1, 0x1d, 0x1d, 0xb0, "ds_write_addtid_b32"),
1154bf215546Sopenharmony_ci   (0x1e, 0x1e, 0x1e, 0x1e, 0x1e, "ds_write_b8"),
1155bf215546Sopenharmony_ci   (0x1f, 0x1f, 0x1f, 0x1f, 0x1f, "ds_write_b16"),
1156bf215546Sopenharmony_ci   (0x20, 0x20, 0x20, 0x20, 0x20, "ds_add_rtn_u32"),
1157bf215546Sopenharmony_ci   (0x21, 0x21, 0x21, 0x21, 0x21, "ds_sub_rtn_u32"),
1158bf215546Sopenharmony_ci   (0x22, 0x22, 0x22, 0x22, 0x22, "ds_rsub_rtn_u32"),
1159bf215546Sopenharmony_ci   (0x23, 0x23, 0x23, 0x23, 0x23, "ds_inc_rtn_u32"),
1160bf215546Sopenharmony_ci   (0x24, 0x24, 0x24, 0x24, 0x24, "ds_dec_rtn_u32"),
1161bf215546Sopenharmony_ci   (0x25, 0x25, 0x25, 0x25, 0x25, "ds_min_rtn_i32"),
1162bf215546Sopenharmony_ci   (0x26, 0x26, 0x26, 0x26, 0x26, "ds_max_rtn_i32"),
1163bf215546Sopenharmony_ci   (0x27, 0x27, 0x27, 0x27, 0x27, "ds_min_rtn_u32"),
1164bf215546Sopenharmony_ci   (0x28, 0x28, 0x28, 0x28, 0x28, "ds_max_rtn_u32"),
1165bf215546Sopenharmony_ci   (0x29, 0x29, 0x29, 0x29, 0x29, "ds_and_rtn_b32"),
1166bf215546Sopenharmony_ci   (0x2a, 0x2a, 0x2a, 0x2a, 0x2a, "ds_or_rtn_b32"),
1167bf215546Sopenharmony_ci   (0x2b, 0x2b, 0x2b, 0x2b, 0x2b, "ds_xor_rtn_b32"),
1168bf215546Sopenharmony_ci   (0x2c, 0x2c, 0x2c, 0x2c, 0x2c, "ds_mskor_rtn_b32"),
1169bf215546Sopenharmony_ci   (0x2d, 0x2d, 0x2d, 0x2d, 0x2d, "ds_wrxchg_rtn_b32"),
1170bf215546Sopenharmony_ci   (0x2e, 0x2e, 0x2e, 0x2e, 0x2e, "ds_wrxchg2_rtn_b32"),
1171bf215546Sopenharmony_ci   (0x2f, 0x2f, 0x2f, 0x2f, 0x2f, "ds_wrxchg2st64_rtn_b32"),
1172bf215546Sopenharmony_ci   (0x30, 0x30, 0x30, 0x30, 0x30, "ds_cmpst_rtn_b32"),
1173bf215546Sopenharmony_ci   (0x31, 0x31, 0x31, 0x31, 0x31, "ds_cmpst_rtn_f32"),
1174bf215546Sopenharmony_ci   (0x32, 0x32, 0x32, 0x32, 0x32, "ds_min_rtn_f32"),
1175bf215546Sopenharmony_ci   (0x33, 0x33, 0x33, 0x33, 0x33, "ds_max_rtn_f32"),
1176bf215546Sopenharmony_ci   (  -1, 0x34, 0x34, 0x34, 0x34, "ds_wrap_rtn_b32"),
1177bf215546Sopenharmony_ci   (  -1,   -1, 0x35, 0x35, 0x55, "ds_add_rtn_f32"),
1178bf215546Sopenharmony_ci   (0x36, 0x36, 0x36, 0x36, 0x36, "ds_read_b32"),
1179bf215546Sopenharmony_ci   (0x37, 0x37, 0x37, 0x37, 0x37, "ds_read2_b32"),
1180bf215546Sopenharmony_ci   (0x38, 0x38, 0x38, 0x38, 0x38, "ds_read2st64_b32"),
1181bf215546Sopenharmony_ci   (0x39, 0x39, 0x39, 0x39, 0x39, "ds_read_i8"),
1182bf215546Sopenharmony_ci   (0x3a, 0x3a, 0x3a, 0x3a, 0x3a, "ds_read_u8"),
1183bf215546Sopenharmony_ci   (0x3b, 0x3b, 0x3b, 0x3b, 0x3b, "ds_read_i16"),
1184bf215546Sopenharmony_ci   (0x3c, 0x3c, 0x3c, 0x3c, 0x3c, "ds_read_u16"),
1185bf215546Sopenharmony_ci   (0x35, 0x35, 0x3d, 0x3d, 0x35, "ds_swizzle_b32"), #data1 & offset, no addr/data2
1186bf215546Sopenharmony_ci   (  -1,   -1, 0x3e, 0x3e, 0xb2, "ds_permute_b32"),
1187bf215546Sopenharmony_ci   (  -1,   -1, 0x3f, 0x3f, 0xb3, "ds_bpermute_b32"),
1188bf215546Sopenharmony_ci   (0x40, 0x40, 0x40, 0x40, 0x40, "ds_add_u64"),
1189bf215546Sopenharmony_ci   (0x41, 0x41, 0x41, 0x41, 0x41, "ds_sub_u64"),
1190bf215546Sopenharmony_ci   (0x42, 0x42, 0x42, 0x42, 0x42, "ds_rsub_u64"),
1191bf215546Sopenharmony_ci   (0x43, 0x43, 0x43, 0x43, 0x43, "ds_inc_u64"),
1192bf215546Sopenharmony_ci   (0x44, 0x44, 0x44, 0x44, 0x44, "ds_dec_u64"),
1193bf215546Sopenharmony_ci   (0x45, 0x45, 0x45, 0x45, 0x45, "ds_min_i64"),
1194bf215546Sopenharmony_ci   (0x46, 0x46, 0x46, 0x46, 0x46, "ds_max_i64"),
1195bf215546Sopenharmony_ci   (0x47, 0x47, 0x47, 0x47, 0x47, "ds_min_u64"),
1196bf215546Sopenharmony_ci   (0x48, 0x48, 0x48, 0x48, 0x48, "ds_max_u64"),
1197bf215546Sopenharmony_ci   (0x49, 0x49, 0x49, 0x49, 0x49, "ds_and_b64"),
1198bf215546Sopenharmony_ci   (0x4a, 0x4a, 0x4a, 0x4a, 0x4a, "ds_or_b64"),
1199bf215546Sopenharmony_ci   (0x4b, 0x4b, 0x4b, 0x4b, 0x4b, "ds_xor_b64"),
1200bf215546Sopenharmony_ci   (0x4c, 0x4c, 0x4c, 0x4c, 0x4c, "ds_mskor_b64"),
1201bf215546Sopenharmony_ci   (0x4d, 0x4d, 0x4d, 0x4d, 0x4d, "ds_write_b64"),
1202bf215546Sopenharmony_ci   (0x4e, 0x4e, 0x4e, 0x4e, 0x4e, "ds_write2_b64"),
1203bf215546Sopenharmony_ci   (0x4f, 0x4f, 0x4f, 0x4f, 0x4f, "ds_write2st64_b64"),
1204bf215546Sopenharmony_ci   (0x50, 0x50, 0x50, 0x50, 0x50, "ds_cmpst_b64"),
1205bf215546Sopenharmony_ci   (0x51, 0x51, 0x51, 0x51, 0x51, "ds_cmpst_f64"),
1206bf215546Sopenharmony_ci   (0x52, 0x52, 0x52, 0x52, 0x52, "ds_min_f64"),
1207bf215546Sopenharmony_ci   (0x53, 0x53, 0x53, 0x53, 0x53, "ds_max_f64"),
1208bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x54, 0xa0, "ds_write_b8_d16_hi"),
1209bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x55, 0xa1, "ds_write_b16_d16_hi"),
1210bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x56, 0xa2, "ds_read_u8_d16"),
1211bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x57, 0xa3, "ds_read_u8_d16_hi"),
1212bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x58, 0xa4, "ds_read_i8_d16"),
1213bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x59, 0xa5, "ds_read_i8_d16_hi"),
1214bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x5a, 0xa6, "ds_read_u16_d16"),
1215bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x5b, 0xa7, "ds_read_u16_d16_hi"),
1216bf215546Sopenharmony_ci   (0x60, 0x60, 0x60, 0x60, 0x60, "ds_add_rtn_u64"),
1217bf215546Sopenharmony_ci   (0x61, 0x61, 0x61, 0x61, 0x61, "ds_sub_rtn_u64"),
1218bf215546Sopenharmony_ci   (0x62, 0x62, 0x62, 0x62, 0x62, "ds_rsub_rtn_u64"),
1219bf215546Sopenharmony_ci   (0x63, 0x63, 0x63, 0x63, 0x63, "ds_inc_rtn_u64"),
1220bf215546Sopenharmony_ci   (0x64, 0x64, 0x64, 0x64, 0x64, "ds_dec_rtn_u64"),
1221bf215546Sopenharmony_ci   (0x65, 0x65, 0x65, 0x65, 0x65, "ds_min_rtn_i64"),
1222bf215546Sopenharmony_ci   (0x66, 0x66, 0x66, 0x66, 0x66, "ds_max_rtn_i64"),
1223bf215546Sopenharmony_ci   (0x67, 0x67, 0x67, 0x67, 0x67, "ds_min_rtn_u64"),
1224bf215546Sopenharmony_ci   (0x68, 0x68, 0x68, 0x68, 0x68, "ds_max_rtn_u64"),
1225bf215546Sopenharmony_ci   (0x69, 0x69, 0x69, 0x69, 0x69, "ds_and_rtn_b64"),
1226bf215546Sopenharmony_ci   (0x6a, 0x6a, 0x6a, 0x6a, 0x6a, "ds_or_rtn_b64"),
1227bf215546Sopenharmony_ci   (0x6b, 0x6b, 0x6b, 0x6b, 0x6b, "ds_xor_rtn_b64"),
1228bf215546Sopenharmony_ci   (0x6c, 0x6c, 0x6c, 0x6c, 0x6c, "ds_mskor_rtn_b64"),
1229bf215546Sopenharmony_ci   (0x6d, 0x6d, 0x6d, 0x6d, 0x6d, "ds_wrxchg_rtn_b64"),
1230bf215546Sopenharmony_ci   (0x6e, 0x6e, 0x6e, 0x6e, 0x6e, "ds_wrxchg2_rtn_b64"),
1231bf215546Sopenharmony_ci   (0x6f, 0x6f, 0x6f, 0x6f, 0x6f, "ds_wrxchg2st64_rtn_b64"),
1232bf215546Sopenharmony_ci   (0x70, 0x70, 0x70, 0x70, 0x70, "ds_cmpst_rtn_b64"),
1233bf215546Sopenharmony_ci   (0x71, 0x71, 0x71, 0x71, 0x71, "ds_cmpst_rtn_f64"),
1234bf215546Sopenharmony_ci   (0x72, 0x72, 0x72, 0x72, 0x72, "ds_min_rtn_f64"),
1235bf215546Sopenharmony_ci   (0x73, 0x73, 0x73, 0x73, 0x73, "ds_max_rtn_f64"),
1236bf215546Sopenharmony_ci   (0x76, 0x76, 0x76, 0x76, 0x76, "ds_read_b64"),
1237bf215546Sopenharmony_ci   (0x77, 0x77, 0x77, 0x77, 0x77, "ds_read2_b64"),
1238bf215546Sopenharmony_ci   (0x78, 0x78, 0x78, 0x78, 0x78, "ds_read2st64_b64"),
1239bf215546Sopenharmony_ci   (  -1, 0x7e, 0x7e, 0x7e, 0x7e, "ds_condxchg32_rtn_b64"),
1240bf215546Sopenharmony_ci   (0x80, 0x80, 0x80, 0x80, 0x80, "ds_add_src2_u32"),
1241bf215546Sopenharmony_ci   (0x81, 0x81, 0x81, 0x81, 0x81, "ds_sub_src2_u32"),
1242bf215546Sopenharmony_ci   (0x82, 0x82, 0x82, 0x82, 0x82, "ds_rsub_src2_u32"),
1243bf215546Sopenharmony_ci   (0x83, 0x83, 0x83, 0x83, 0x83, "ds_inc_src2_u32"),
1244bf215546Sopenharmony_ci   (0x84, 0x84, 0x84, 0x84, 0x84, "ds_dec_src2_u32"),
1245bf215546Sopenharmony_ci   (0x85, 0x85, 0x85, 0x85, 0x85, "ds_min_src2_i32"),
1246bf215546Sopenharmony_ci   (0x86, 0x86, 0x86, 0x86, 0x86, "ds_max_src2_i32"),
1247bf215546Sopenharmony_ci   (0x87, 0x87, 0x87, 0x87, 0x87, "ds_min_src2_u32"),
1248bf215546Sopenharmony_ci   (0x88, 0x88, 0x88, 0x88, 0x88, "ds_max_src2_u32"),
1249bf215546Sopenharmony_ci   (0x89, 0x89, 0x89, 0x89, 0x89, "ds_and_src2_b32"),
1250bf215546Sopenharmony_ci   (0x8a, 0x8a, 0x8a, 0x8a, 0x8a, "ds_or_src2_b32"),
1251bf215546Sopenharmony_ci   (0x8b, 0x8b, 0x8b, 0x8b, 0x8b, "ds_xor_src2_b32"),
1252bf215546Sopenharmony_ci   (0x8d, 0x8d, 0x8d, 0x8d, 0x8d, "ds_write_src2_b32"),
1253bf215546Sopenharmony_ci   (0x92, 0x92, 0x92, 0x92, 0x92, "ds_min_src2_f32"),
1254bf215546Sopenharmony_ci   (0x93, 0x93, 0x93, 0x93, 0x93, "ds_max_src2_f32"),
1255bf215546Sopenharmony_ci   (  -1,   -1, 0x95, 0x95, 0x95, "ds_add_src2_f32"),
1256bf215546Sopenharmony_ci   (  -1, 0x18, 0x98, 0x98, 0x18, "ds_gws_sema_release_all"),
1257bf215546Sopenharmony_ci   (0x19, 0x19, 0x99, 0x99, 0x19, "ds_gws_init"),
1258bf215546Sopenharmony_ci   (0x1a, 0x1a, 0x9a, 0x9a, 0x1a, "ds_gws_sema_v"),
1259bf215546Sopenharmony_ci   (0x1b, 0x1b, 0x9b, 0x9b, 0x1b, "ds_gws_sema_br"),
1260bf215546Sopenharmony_ci   (0x1c, 0x1c, 0x9c, 0x9c, 0x1c, "ds_gws_sema_p"),
1261bf215546Sopenharmony_ci   (0x1d, 0x1d, 0x9d, 0x9d, 0x1d, "ds_gws_barrier"),
1262bf215546Sopenharmony_ci   (  -1,   -1, 0xb6, 0xb6, 0xb1, "ds_read_addtid_b32"),
1263bf215546Sopenharmony_ci   (0x3d, 0x3d, 0xbd, 0xbd, 0x3d, "ds_consume"),
1264bf215546Sopenharmony_ci   (0x3e, 0x3e, 0xbe, 0xbe, 0x3e, "ds_append"),
1265bf215546Sopenharmony_ci   (0x3f, 0x3f, 0xbf, 0xbf, 0x3f, "ds_ordered_count"),
1266bf215546Sopenharmony_ci   (0xc0, 0xc0, 0xc0, 0xc0, 0xc0, "ds_add_src2_u64"),
1267bf215546Sopenharmony_ci   (0xc1, 0xc1, 0xc1, 0xc1, 0xc1, "ds_sub_src2_u64"),
1268bf215546Sopenharmony_ci   (0xc2, 0xc2, 0xc2, 0xc2, 0xc2, "ds_rsub_src2_u64"),
1269bf215546Sopenharmony_ci   (0xc3, 0xc3, 0xc3, 0xc3, 0xc3, "ds_inc_src2_u64"),
1270bf215546Sopenharmony_ci   (0xc4, 0xc4, 0xc4, 0xc4, 0xc4, "ds_dec_src2_u64"),
1271bf215546Sopenharmony_ci   (0xc5, 0xc5, 0xc5, 0xc5, 0xc5, "ds_min_src2_i64"),
1272bf215546Sopenharmony_ci   (0xc6, 0xc6, 0xc6, 0xc6, 0xc6, "ds_max_src2_i64"),
1273bf215546Sopenharmony_ci   (0xc7, 0xc7, 0xc7, 0xc7, 0xc7, "ds_min_src2_u64"),
1274bf215546Sopenharmony_ci   (0xc8, 0xc8, 0xc8, 0xc8, 0xc8, "ds_max_src2_u64"),
1275bf215546Sopenharmony_ci   (0xc9, 0xc9, 0xc9, 0xc9, 0xc9, "ds_and_src2_b64"),
1276bf215546Sopenharmony_ci   (0xca, 0xca, 0xca, 0xca, 0xca, "ds_or_src2_b64"),
1277bf215546Sopenharmony_ci   (0xcb, 0xcb, 0xcb, 0xcb, 0xcb, "ds_xor_src2_b64"),
1278bf215546Sopenharmony_ci   (0xcd, 0xcd, 0xcd, 0xcd, 0xcd, "ds_write_src2_b64"),
1279bf215546Sopenharmony_ci   (0xd2, 0xd2, 0xd2, 0xd2, 0xd2, "ds_min_src2_f64"),
1280bf215546Sopenharmony_ci   (0xd3, 0xd3, 0xd3, 0xd3, 0xd3, "ds_max_src2_f64"),
1281bf215546Sopenharmony_ci   (  -1, 0xde, 0xde, 0xde, 0xde, "ds_write_b96"),
1282bf215546Sopenharmony_ci   (  -1, 0xdf, 0xdf, 0xdf, 0xdf, "ds_write_b128"),
1283bf215546Sopenharmony_ci   (  -1, 0xfd, 0xfd,   -1,   -1, "ds_condxchg32_rtn_b128"),
1284bf215546Sopenharmony_ci   (  -1, 0xfe, 0xfe, 0xfe, 0xfe, "ds_read_b96"),
1285bf215546Sopenharmony_ci   (  -1, 0xff, 0xff, 0xff, 0xff, "ds_read_b128"),
1286bf215546Sopenharmony_ci}
1287bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name) in DS:
1288bf215546Sopenharmony_ci    opcode(name, gfx7, gfx9, gfx10, Format.DS, InstrClass.DS)
1289bf215546Sopenharmony_ci
1290bf215546Sopenharmony_ci# MUBUF instructions:
1291bf215546Sopenharmony_ciMUBUF = {
1292bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "buffer_load_format_x"),
1293bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "buffer_load_format_xy"),
1294bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "buffer_load_format_xyz"),
1295bf215546Sopenharmony_ci   (0x03, 0x03, 0x03, 0x03, 0x03, "buffer_load_format_xyzw"),
1296bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "buffer_store_format_x"),
1297bf215546Sopenharmony_ci   (0x05, 0x05, 0x05, 0x05, 0x05, "buffer_store_format_xy"),
1298bf215546Sopenharmony_ci   (0x06, 0x06, 0x06, 0x06, 0x06, "buffer_store_format_xyz"),
1299bf215546Sopenharmony_ci   (0x07, 0x07, 0x07, 0x07, 0x07, "buffer_store_format_xyzw"),
1300bf215546Sopenharmony_ci   (  -1,   -1, 0x08, 0x08, 0x80, "buffer_load_format_d16_x"),
1301bf215546Sopenharmony_ci   (  -1,   -1, 0x09, 0x09, 0x81, "buffer_load_format_d16_xy"),
1302bf215546Sopenharmony_ci   (  -1,   -1, 0x0a, 0x0a, 0x82, "buffer_load_format_d16_xyz"),
1303bf215546Sopenharmony_ci   (  -1,   -1, 0x0b, 0x0b, 0x83, "buffer_load_format_d16_xyzw"),
1304bf215546Sopenharmony_ci   (  -1,   -1, 0x0c, 0x0c, 0x84, "buffer_store_format_d16_x"),
1305bf215546Sopenharmony_ci   (  -1,   -1, 0x0d, 0x0d, 0x85, "buffer_store_format_d16_xy"),
1306bf215546Sopenharmony_ci   (  -1,   -1, 0x0e, 0x0e, 0x86, "buffer_store_format_d16_xyz"),
1307bf215546Sopenharmony_ci   (  -1,   -1, 0x0f, 0x0f, 0x87, "buffer_store_format_d16_xyzw"),
1308bf215546Sopenharmony_ci   (0x08, 0x08, 0x10, 0x10, 0x08, "buffer_load_ubyte"),
1309bf215546Sopenharmony_ci   (0x09, 0x09, 0x11, 0x11, 0x09, "buffer_load_sbyte"),
1310bf215546Sopenharmony_ci   (0x0a, 0x0a, 0x12, 0x12, 0x0a, "buffer_load_ushort"),
1311bf215546Sopenharmony_ci   (0x0b, 0x0b, 0x13, 0x13, 0x0b, "buffer_load_sshort"),
1312bf215546Sopenharmony_ci   (0x0c, 0x0c, 0x14, 0x14, 0x0c, "buffer_load_dword"),
1313bf215546Sopenharmony_ci   (0x0d, 0x0d, 0x15, 0x15, 0x0d, "buffer_load_dwordx2"),
1314bf215546Sopenharmony_ci   (  -1, 0x0f, 0x16, 0x16, 0x0f, "buffer_load_dwordx3"),
1315bf215546Sopenharmony_ci   (0x0f, 0x0e, 0x17, 0x17, 0x0e, "buffer_load_dwordx4"),
1316bf215546Sopenharmony_ci   (0x18, 0x18, 0x18, 0x18, 0x18, "buffer_store_byte"),
1317bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x19, 0x19, "buffer_store_byte_d16_hi"),
1318bf215546Sopenharmony_ci   (0x1a, 0x1a, 0x1a, 0x1a, 0x1a, "buffer_store_short"),
1319bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x1b, 0x1b, "buffer_store_short_d16_hi"),
1320bf215546Sopenharmony_ci   (0x1c, 0x1c, 0x1c, 0x1c, 0x1c, "buffer_store_dword"),
1321bf215546Sopenharmony_ci   (0x1d, 0x1d, 0x1d, 0x1d, 0x1d, "buffer_store_dwordx2"),
1322bf215546Sopenharmony_ci   (  -1, 0x1f, 0x1e, 0x1e, 0x1f, "buffer_store_dwordx3"),
1323bf215546Sopenharmony_ci   (0x1e, 0x1e, 0x1f, 0x1f, 0x1e, "buffer_store_dwordx4"),
1324bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x20, 0x20, "buffer_load_ubyte_d16"),
1325bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x21, 0x21, "buffer_load_ubyte_d16_hi"),
1326bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x22, 0x22, "buffer_load_sbyte_d16"),
1327bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x23, 0x23, "buffer_load_sbyte_d16_hi"),
1328bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x24, 0x24, "buffer_load_short_d16"),
1329bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x25, 0x25, "buffer_load_short_d16_hi"),
1330bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x26, 0x26, "buffer_load_format_d16_hi_x"),
1331bf215546Sopenharmony_ci   (  -1,   -1,   -1, 0x27, 0x27, "buffer_store_format_d16_hi_x"),
1332bf215546Sopenharmony_ci   (  -1,   -1, 0x3d, 0x3d,   -1, "buffer_store_lds_dword"),
1333bf215546Sopenharmony_ci   (0x71, 0x71, 0x3e, 0x3e,   -1, "buffer_wbinvl1"),
1334bf215546Sopenharmony_ci   (0x70, 0x70, 0x3f, 0x3f,   -1, "buffer_wbinvl1_vol"),
1335bf215546Sopenharmony_ci   (0x30, 0x30, 0x40, 0x40, 0x30, "buffer_atomic_swap"),
1336bf215546Sopenharmony_ci   (0x31, 0x31, 0x41, 0x41, 0x31, "buffer_atomic_cmpswap"),
1337bf215546Sopenharmony_ci   (0x32, 0x32, 0x42, 0x42, 0x32, "buffer_atomic_add"),
1338bf215546Sopenharmony_ci   (0x33, 0x33, 0x43, 0x43, 0x33, "buffer_atomic_sub"),
1339bf215546Sopenharmony_ci   (0x34,   -1,   -1,   -1,   -1, "buffer_atomic_rsub"),
1340bf215546Sopenharmony_ci   (0x35, 0x35, 0x44, 0x44, 0x35, "buffer_atomic_smin"),
1341bf215546Sopenharmony_ci   (0x36, 0x36, 0x45, 0x45, 0x36, "buffer_atomic_umin"),
1342bf215546Sopenharmony_ci   (0x37, 0x37, 0x46, 0x46, 0x37, "buffer_atomic_smax"),
1343bf215546Sopenharmony_ci   (0x38, 0x38, 0x47, 0x47, 0x38, "buffer_atomic_umax"),
1344bf215546Sopenharmony_ci   (0x39, 0x39, 0x48, 0x48, 0x39, "buffer_atomic_and"),
1345bf215546Sopenharmony_ci   (0x3a, 0x3a, 0x49, 0x49, 0x3a, "buffer_atomic_or"),
1346bf215546Sopenharmony_ci   (0x3b, 0x3b, 0x4a, 0x4a, 0x3b, "buffer_atomic_xor"),
1347bf215546Sopenharmony_ci   (0x3c, 0x3c, 0x4b, 0x4b, 0x3c, "buffer_atomic_inc"),
1348bf215546Sopenharmony_ci   (0x3d, 0x3d, 0x4c, 0x4c, 0x3d, "buffer_atomic_dec"),
1349bf215546Sopenharmony_ci   (0x3e, 0x3e,   -1,   -1, 0x3e, "buffer_atomic_fcmpswap"),
1350bf215546Sopenharmony_ci   (0x3f, 0x3f,   -1,   -1, 0x3f, "buffer_atomic_fmin"),
1351bf215546Sopenharmony_ci   (0x40, 0x40,   -1,   -1, 0x40, "buffer_atomic_fmax"),
1352bf215546Sopenharmony_ci   (0x50, 0x50, 0x60, 0x60, 0x50, "buffer_atomic_swap_x2"),
1353bf215546Sopenharmony_ci   (0x51, 0x51, 0x61, 0x61, 0x51, "buffer_atomic_cmpswap_x2"),
1354bf215546Sopenharmony_ci   (0x52, 0x52, 0x62, 0x62, 0x52, "buffer_atomic_add_x2"),
1355bf215546Sopenharmony_ci   (0x53, 0x53, 0x63, 0x63, 0x53, "buffer_atomic_sub_x2"),
1356bf215546Sopenharmony_ci   (0x54,   -1,   -1,   -1,   -1, "buffer_atomic_rsub_x2"),
1357bf215546Sopenharmony_ci   (0x55, 0x55, 0x64, 0x64, 0x55, "buffer_atomic_smin_x2"),
1358bf215546Sopenharmony_ci   (0x56, 0x56, 0x65, 0x65, 0x56, "buffer_atomic_umin_x2"),
1359bf215546Sopenharmony_ci   (0x57, 0x57, 0x66, 0x66, 0x57, "buffer_atomic_smax_x2"),
1360bf215546Sopenharmony_ci   (0x58, 0x58, 0x67, 0x67, 0x58, "buffer_atomic_umax_x2"),
1361bf215546Sopenharmony_ci   (0x59, 0x59, 0x68, 0x68, 0x59, "buffer_atomic_and_x2"),
1362bf215546Sopenharmony_ci   (0x5a, 0x5a, 0x69, 0x69, 0x5a, "buffer_atomic_or_x2"),
1363bf215546Sopenharmony_ci   (0x5b, 0x5b, 0x6a, 0x6a, 0x5b, "buffer_atomic_xor_x2"),
1364bf215546Sopenharmony_ci   (0x5c, 0x5c, 0x6b, 0x6b, 0x5c, "buffer_atomic_inc_x2"),
1365bf215546Sopenharmony_ci   (0x5d, 0x5d, 0x6c, 0x6c, 0x5d, "buffer_atomic_dec_x2"),
1366bf215546Sopenharmony_ci   (0x5e, 0x5e,   -1,   -1, 0x5e, "buffer_atomic_fcmpswap_x2"),
1367bf215546Sopenharmony_ci   (0x5f, 0x5f,   -1,   -1, 0x5f, "buffer_atomic_fmin_x2"),
1368bf215546Sopenharmony_ci   (0x60, 0x60,   -1,   -1, 0x60, "buffer_atomic_fmax_x2"),
1369bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x71, "buffer_gl0_inv"),
1370bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x72, "buffer_gl1_inv"),
1371bf215546Sopenharmony_ci   (  -1,   -1,   -1,   -1, 0x34, "buffer_atomic_csub"), #GFX10.3+. seems glc must be set
1372bf215546Sopenharmony_ci}
1373bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name) in MUBUF:
1374bf215546Sopenharmony_ci    opcode(name, gfx7, gfx9, gfx10, Format.MUBUF, InstrClass.VMem, is_atomic = "atomic" in name)
1375bf215546Sopenharmony_ci
1376bf215546Sopenharmony_ciMTBUF = {
1377bf215546Sopenharmony_ci   (0x00, 0x00, 0x00, 0x00, 0x00, "tbuffer_load_format_x"),
1378bf215546Sopenharmony_ci   (0x01, 0x01, 0x01, 0x01, 0x01, "tbuffer_load_format_xy"),
1379bf215546Sopenharmony_ci   (0x02, 0x02, 0x02, 0x02, 0x02, "tbuffer_load_format_xyz"),
1380bf215546Sopenharmony_ci   (0x03, 0x03, 0x03, 0x03, 0x03, "tbuffer_load_format_xyzw"),
1381bf215546Sopenharmony_ci   (0x04, 0x04, 0x04, 0x04, 0x04, "tbuffer_store_format_x"),
1382bf215546Sopenharmony_ci   (0x05, 0x05, 0x05, 0x05, 0x05, "tbuffer_store_format_xy"),
1383bf215546Sopenharmony_ci   (0x06, 0x06, 0x06, 0x06, 0x06, "tbuffer_store_format_xyz"),
1384bf215546Sopenharmony_ci   (0x07, 0x07, 0x07, 0x07, 0x07, "tbuffer_store_format_xyzw"),
1385bf215546Sopenharmony_ci   (  -1,   -1, 0x08, 0x08, 0x08, "tbuffer_load_format_d16_x"),
1386bf215546Sopenharmony_ci   (  -1,   -1, 0x09, 0x09, 0x09, "tbuffer_load_format_d16_xy"),
1387bf215546Sopenharmony_ci   (  -1,   -1, 0x0a, 0x0a, 0x0a, "tbuffer_load_format_d16_xyz"),
1388bf215546Sopenharmony_ci   (  -1,   -1, 0x0b, 0x0b, 0x0b, "tbuffer_load_format_d16_xyzw"),
1389bf215546Sopenharmony_ci   (  -1,   -1, 0x0c, 0x0c, 0x0c, "tbuffer_store_format_d16_x"),
1390bf215546Sopenharmony_ci   (  -1,   -1, 0x0d, 0x0d, 0x0d, "tbuffer_store_format_d16_xy"),
1391bf215546Sopenharmony_ci   (  -1,   -1, 0x0e, 0x0e, 0x0e, "tbuffer_store_format_d16_xyz"),
1392bf215546Sopenharmony_ci   (  -1,   -1, 0x0f, 0x0f, 0x0f, "tbuffer_store_format_d16_xyzw"),
1393bf215546Sopenharmony_ci}
1394bf215546Sopenharmony_cifor (gfx6, gfx7, gfx8, gfx9, gfx10, name) in MTBUF:
1395bf215546Sopenharmony_ci    opcode(name, gfx7, gfx9, gfx10, Format.MTBUF, InstrClass.VMem)
1396bf215546Sopenharmony_ci
1397bf215546Sopenharmony_ci
1398bf215546Sopenharmony_ciIMAGE = {
1399bf215546Sopenharmony_ci   (0x00, "image_load"),
1400bf215546Sopenharmony_ci   (0x01, "image_load_mip"),
1401bf215546Sopenharmony_ci   (0x02, "image_load_pck"),
1402bf215546Sopenharmony_ci   (0x03, "image_load_pck_sgn"),
1403bf215546Sopenharmony_ci   (0x04, "image_load_mip_pck"),
1404bf215546Sopenharmony_ci   (0x05, "image_load_mip_pck_sgn"),
1405bf215546Sopenharmony_ci   (0x08, "image_store"),
1406bf215546Sopenharmony_ci   (0x09, "image_store_mip"),
1407bf215546Sopenharmony_ci   (0x0a, "image_store_pck"),
1408bf215546Sopenharmony_ci   (0x0b, "image_store_mip_pck"),
1409bf215546Sopenharmony_ci   (0x0e, "image_get_resinfo"),
1410bf215546Sopenharmony_ci   (0x60, "image_get_lod"),
1411bf215546Sopenharmony_ci}
1412bf215546Sopenharmony_ci# (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (code, code, code, code, code, name)
1413bf215546Sopenharmony_cifor (code, name) in IMAGE:
1414bf215546Sopenharmony_ci   opcode(name, code, code, code, Format.MIMG, InstrClass.VMem)
1415bf215546Sopenharmony_ci
1416bf215546Sopenharmony_ciopcode("image_msaa_load", -1, -1, 0x80, Format.MIMG, InstrClass.VMem) #GFX10.3+
1417bf215546Sopenharmony_ci
1418bf215546Sopenharmony_ciIMAGE_ATOMIC = {
1419bf215546Sopenharmony_ci   (0x0f, 0x0f, 0x10, "image_atomic_swap"),
1420bf215546Sopenharmony_ci   (0x10, 0x10, 0x11, "image_atomic_cmpswap"),
1421bf215546Sopenharmony_ci   (0x11, 0x11, 0x12, "image_atomic_add"),
1422bf215546Sopenharmony_ci   (0x12, 0x12, 0x13, "image_atomic_sub"),
1423bf215546Sopenharmony_ci   (0x13,   -1,   -1, "image_atomic_rsub"),
1424bf215546Sopenharmony_ci   (0x14, 0x14, 0x14, "image_atomic_smin"),
1425bf215546Sopenharmony_ci   (0x15, 0x15, 0x15, "image_atomic_umin"),
1426bf215546Sopenharmony_ci   (0x16, 0x16, 0x16, "image_atomic_smax"),
1427bf215546Sopenharmony_ci   (0x17, 0x17, 0x17, "image_atomic_umax"),
1428bf215546Sopenharmony_ci   (0x18, 0x18, 0x18, "image_atomic_and"),
1429bf215546Sopenharmony_ci   (0x19, 0x19, 0x19, "image_atomic_or"),
1430bf215546Sopenharmony_ci   (0x1a, 0x1a, 0x1a, "image_atomic_xor"),
1431bf215546Sopenharmony_ci   (0x1b, 0x1b, 0x1b, "image_atomic_inc"),
1432bf215546Sopenharmony_ci   (0x1c, 0x1c, 0x1c, "image_atomic_dec"),
1433bf215546Sopenharmony_ci   (0x1d, 0x1d,   -1, "image_atomic_fcmpswap"),
1434bf215546Sopenharmony_ci   (0x1e, 0x1e,   -1, "image_atomic_fmin"),
1435bf215546Sopenharmony_ci   (0x1f, 0x1f,   -1, "image_atomic_fmax"),
1436bf215546Sopenharmony_ci}
1437bf215546Sopenharmony_ci# (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (gfx6, gfx7, gfx89, gfx89, ???, name)
1438bf215546Sopenharmony_ci# gfx7 and gfx10 opcodes are the same here
1439bf215546Sopenharmony_cifor (gfx6, gfx7, gfx89, name) in IMAGE_ATOMIC:
1440bf215546Sopenharmony_ci   opcode(name, gfx7, gfx89, gfx7, Format.MIMG, InstrClass.VMem, is_atomic = True)
1441bf215546Sopenharmony_ci
1442bf215546Sopenharmony_ciIMAGE_SAMPLE = {
1443bf215546Sopenharmony_ci   (0x20, "image_sample"),
1444bf215546Sopenharmony_ci   (0x21, "image_sample_cl"),
1445bf215546Sopenharmony_ci   (0x22, "image_sample_d"),
1446bf215546Sopenharmony_ci   (0x23, "image_sample_d_cl"),
1447bf215546Sopenharmony_ci   (0x24, "image_sample_l"),
1448bf215546Sopenharmony_ci   (0x25, "image_sample_b"),
1449bf215546Sopenharmony_ci   (0x26, "image_sample_b_cl"),
1450bf215546Sopenharmony_ci   (0x27, "image_sample_lz"),
1451bf215546Sopenharmony_ci   (0x28, "image_sample_c"),
1452bf215546Sopenharmony_ci   (0x29, "image_sample_c_cl"),
1453bf215546Sopenharmony_ci   (0x2a, "image_sample_c_d"),
1454bf215546Sopenharmony_ci   (0x2b, "image_sample_c_d_cl"),
1455bf215546Sopenharmony_ci   (0x2c, "image_sample_c_l"),
1456bf215546Sopenharmony_ci   (0x2d, "image_sample_c_b"),
1457bf215546Sopenharmony_ci   (0x2e, "image_sample_c_b_cl"),
1458bf215546Sopenharmony_ci   (0x2f, "image_sample_c_lz"),
1459bf215546Sopenharmony_ci   (0x30, "image_sample_o"),
1460bf215546Sopenharmony_ci   (0x31, "image_sample_cl_o"),
1461bf215546Sopenharmony_ci   (0x32, "image_sample_d_o"),
1462bf215546Sopenharmony_ci   (0x33, "image_sample_d_cl_o"),
1463bf215546Sopenharmony_ci   (0x34, "image_sample_l_o"),
1464bf215546Sopenharmony_ci   (0x35, "image_sample_b_o"),
1465bf215546Sopenharmony_ci   (0x36, "image_sample_b_cl_o"),
1466bf215546Sopenharmony_ci   (0x37, "image_sample_lz_o"),
1467bf215546Sopenharmony_ci   (0x38, "image_sample_c_o"),
1468bf215546Sopenharmony_ci   (0x39, "image_sample_c_cl_o"),
1469bf215546Sopenharmony_ci   (0x3a, "image_sample_c_d_o"),
1470bf215546Sopenharmony_ci   (0x3b, "image_sample_c_d_cl_o"),
1471bf215546Sopenharmony_ci   (0x3c, "image_sample_c_l_o"),
1472bf215546Sopenharmony_ci   (0x3d, "image_sample_c_b_o"),
1473bf215546Sopenharmony_ci   (0x3e, "image_sample_c_b_cl_o"),
1474bf215546Sopenharmony_ci   (0x3f, "image_sample_c_lz_o"),
1475bf215546Sopenharmony_ci   (0x68, "image_sample_cd"),
1476bf215546Sopenharmony_ci   (0x69, "image_sample_cd_cl"),
1477bf215546Sopenharmony_ci   (0x6a, "image_sample_c_cd"),
1478bf215546Sopenharmony_ci   (0x6b, "image_sample_c_cd_cl"),
1479bf215546Sopenharmony_ci   (0x6c, "image_sample_cd_o"),
1480bf215546Sopenharmony_ci   (0x6d, "image_sample_cd_cl_o"),
1481bf215546Sopenharmony_ci   (0x6e, "image_sample_c_cd_o"),
1482bf215546Sopenharmony_ci   (0x6f, "image_sample_c_cd_cl_o"),
1483bf215546Sopenharmony_ci}
1484bf215546Sopenharmony_ci# (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (code, code, code, code, code, name)
1485bf215546Sopenharmony_cifor (code, name) in IMAGE_SAMPLE:
1486bf215546Sopenharmony_ci   opcode(name, code, code, code, Format.MIMG, InstrClass.VMem)
1487bf215546Sopenharmony_ci
1488bf215546Sopenharmony_ciIMAGE_SAMPLE_G16 = {
1489bf215546Sopenharmony_ci   (0xa2, "image_sample_d_g16"),
1490bf215546Sopenharmony_ci   (0xa3, "image_sample_d_cl_g16"),
1491bf215546Sopenharmony_ci   (0xaa, "image_sample_c_d_g16"),
1492bf215546Sopenharmony_ci   (0xab, "image_sample_c_d_cl_g16"),
1493bf215546Sopenharmony_ci   (0xb2, "image_sample_d_o_g16"),
1494bf215546Sopenharmony_ci   (0xb3, "image_sample_d_cl_o_g16"),
1495bf215546Sopenharmony_ci   (0xba, "image_sample_c_d_o_g16"),
1496bf215546Sopenharmony_ci   (0xbb, "image_sample_c_d_cl_o_g16"),
1497bf215546Sopenharmony_ci}
1498bf215546Sopenharmony_ci
1499bf215546Sopenharmony_ci# (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (-1, -1, -1, -1, code, name)
1500bf215546Sopenharmony_cifor (code, name) in IMAGE_SAMPLE_G16:
1501bf215546Sopenharmony_ci   opcode(name, -1, -1, code, Format.MIMG, InstrClass.VMem)
1502bf215546Sopenharmony_ci
1503bf215546Sopenharmony_ciIMAGE_GATHER4 = {
1504bf215546Sopenharmony_ci   (0x40, "image_gather4"),
1505bf215546Sopenharmony_ci   (0x41, "image_gather4_cl"),
1506bf215546Sopenharmony_ci   #(0x42, "image_gather4h"), VEGA only?
1507bf215546Sopenharmony_ci   (0x44, "image_gather4_l"), # following instructions have different opcodes according to ISA sheet.
1508bf215546Sopenharmony_ci   (0x45, "image_gather4_b"),
1509bf215546Sopenharmony_ci   (0x46, "image_gather4_b_cl"),
1510bf215546Sopenharmony_ci   (0x47, "image_gather4_lz"),
1511bf215546Sopenharmony_ci   (0x48, "image_gather4_c"),
1512bf215546Sopenharmony_ci   (0x49, "image_gather4_c_cl"), # previous instructions have different opcodes according to ISA sheet.
1513bf215546Sopenharmony_ci   #(0x4a, "image_gather4h_pck"), VEGA only?
1514bf215546Sopenharmony_ci   #(0x4b, "image_gather8h_pck"), VGEA only?
1515bf215546Sopenharmony_ci   (0x4c, "image_gather4_c_l"),
1516bf215546Sopenharmony_ci   (0x4d, "image_gather4_c_b"),
1517bf215546Sopenharmony_ci   (0x4e, "image_gather4_c_b_cl"),
1518bf215546Sopenharmony_ci   (0x4f, "image_gather4_c_lz"),
1519bf215546Sopenharmony_ci   (0x50, "image_gather4_o"),
1520bf215546Sopenharmony_ci   (0x51, "image_gather4_cl_o"),
1521bf215546Sopenharmony_ci   (0x54, "image_gather4_l_o"),
1522bf215546Sopenharmony_ci   (0x55, "image_gather4_b_o"),
1523bf215546Sopenharmony_ci   (0x56, "image_gather4_b_cl_o"),
1524bf215546Sopenharmony_ci   (0x57, "image_gather4_lz_o"),
1525bf215546Sopenharmony_ci   (0x58, "image_gather4_c_o"),
1526bf215546Sopenharmony_ci   (0x59, "image_gather4_c_cl_o"),
1527bf215546Sopenharmony_ci   (0x5c, "image_gather4_c_l_o"),
1528bf215546Sopenharmony_ci   (0x5d, "image_gather4_c_b_o"),
1529bf215546Sopenharmony_ci   (0x5e, "image_gather4_c_b_cl_o"),
1530bf215546Sopenharmony_ci   (0x5f, "image_gather4_c_lz_o"),
1531bf215546Sopenharmony_ci}
1532bf215546Sopenharmony_ci# (gfx6, gfx7, gfx8, gfx9, gfx10, name) = (code, code, code, code, code, name)
1533bf215546Sopenharmony_cifor (code, name) in IMAGE_GATHER4:
1534bf215546Sopenharmony_ci   opcode(name, code, code, code, Format.MIMG, InstrClass.VMem)
1535bf215546Sopenharmony_ci
1536bf215546Sopenharmony_ciopcode("image_bvh64_intersect_ray", -1, -1, 231, Format.MIMG, InstrClass.VMem)
1537bf215546Sopenharmony_ci
1538bf215546Sopenharmony_ciFLAT = {
1539bf215546Sopenharmony_ci   #GFX7, GFX8_9, GFX10
1540bf215546Sopenharmony_ci   (0x08, 0x10, 0x08, "flat_load_ubyte"),
1541bf215546Sopenharmony_ci   (0x09, 0x11, 0x09, "flat_load_sbyte"),
1542bf215546Sopenharmony_ci   (0x0a, 0x12, 0x0a, "flat_load_ushort"),
1543bf215546Sopenharmony_ci   (0x0b, 0x13, 0x0b, "flat_load_sshort"),
1544bf215546Sopenharmony_ci   (0x0c, 0x14, 0x0c, "flat_load_dword"),
1545bf215546Sopenharmony_ci   (0x0d, 0x15, 0x0d, "flat_load_dwordx2"),
1546bf215546Sopenharmony_ci   (0x0f, 0x16, 0x0f, "flat_load_dwordx3"),
1547bf215546Sopenharmony_ci   (0x0e, 0x17, 0x0e, "flat_load_dwordx4"),
1548bf215546Sopenharmony_ci   (0x18, 0x18, 0x18, "flat_store_byte"),
1549bf215546Sopenharmony_ci   (  -1, 0x19, 0x19, "flat_store_byte_d16_hi"),
1550bf215546Sopenharmony_ci   (0x1a, 0x1a, 0x1a, "flat_store_short"),
1551bf215546Sopenharmony_ci   (  -1, 0x1b, 0x1b, "flat_store_short_d16_hi"),
1552bf215546Sopenharmony_ci   (0x1c, 0x1c, 0x1c, "flat_store_dword"),
1553bf215546Sopenharmony_ci   (0x1d, 0x1d, 0x1d, "flat_store_dwordx2"),
1554bf215546Sopenharmony_ci   (0x1f, 0x1e, 0x1f, "flat_store_dwordx3"),
1555bf215546Sopenharmony_ci   (0x1e, 0x1f, 0x1e, "flat_store_dwordx4"),
1556bf215546Sopenharmony_ci   (  -1, 0x20, 0x20, "flat_load_ubyte_d16"),
1557bf215546Sopenharmony_ci   (  -1, 0x21, 0x21, "flat_load_ubyte_d16_hi"),
1558bf215546Sopenharmony_ci   (  -1, 0x22, 0x22, "flat_load_sbyte_d16"),
1559bf215546Sopenharmony_ci   (  -1, 0x23, 0x23, "flat_load_sbyte_d16_hi"),
1560bf215546Sopenharmony_ci   (  -1, 0x24, 0x24, "flat_load_short_d16"),
1561bf215546Sopenharmony_ci   (  -1, 0x25, 0x25, "flat_load_short_d16_hi"),
1562bf215546Sopenharmony_ci   (0x30, 0x40, 0x30, "flat_atomic_swap"),
1563bf215546Sopenharmony_ci   (0x31, 0x41, 0x31, "flat_atomic_cmpswap"),
1564bf215546Sopenharmony_ci   (0x32, 0x42, 0x32, "flat_atomic_add"),
1565bf215546Sopenharmony_ci   (0x33, 0x43, 0x33, "flat_atomic_sub"),
1566bf215546Sopenharmony_ci   (0x35, 0x44, 0x35, "flat_atomic_smin"),
1567bf215546Sopenharmony_ci   (0x36, 0x45, 0x36, "flat_atomic_umin"),
1568bf215546Sopenharmony_ci   (0x37, 0x46, 0x37, "flat_atomic_smax"),
1569bf215546Sopenharmony_ci   (0x38, 0x47, 0x38, "flat_atomic_umax"),
1570bf215546Sopenharmony_ci   (0x39, 0x48, 0x39, "flat_atomic_and"),
1571bf215546Sopenharmony_ci   (0x3a, 0x49, 0x3a, "flat_atomic_or"),
1572bf215546Sopenharmony_ci   (0x3b, 0x4a, 0x3b, "flat_atomic_xor"),
1573bf215546Sopenharmony_ci   (0x3c, 0x4b, 0x3c, "flat_atomic_inc"),
1574bf215546Sopenharmony_ci   (0x3d, 0x4c, 0x3d, "flat_atomic_dec"),
1575bf215546Sopenharmony_ci   (0x3e,   -1, 0x3e, "flat_atomic_fcmpswap"),
1576bf215546Sopenharmony_ci   (0x3f,   -1, 0x3f, "flat_atomic_fmin"),
1577bf215546Sopenharmony_ci   (0x40,   -1, 0x40, "flat_atomic_fmax"),
1578bf215546Sopenharmony_ci   (0x50, 0x60, 0x50, "flat_atomic_swap_x2"),
1579bf215546Sopenharmony_ci   (0x51, 0x61, 0x51, "flat_atomic_cmpswap_x2"),
1580bf215546Sopenharmony_ci   (0x52, 0x62, 0x52, "flat_atomic_add_x2"),
1581bf215546Sopenharmony_ci   (0x53, 0x63, 0x53, "flat_atomic_sub_x2"),
1582bf215546Sopenharmony_ci   (0x55, 0x64, 0x55, "flat_atomic_smin_x2"),
1583bf215546Sopenharmony_ci   (0x56, 0x65, 0x56, "flat_atomic_umin_x2"),
1584bf215546Sopenharmony_ci   (0x57, 0x66, 0x57, "flat_atomic_smax_x2"),
1585bf215546Sopenharmony_ci   (0x58, 0x67, 0x58, "flat_atomic_umax_x2"),
1586bf215546Sopenharmony_ci   (0x59, 0x68, 0x59, "flat_atomic_and_x2"),
1587bf215546Sopenharmony_ci   (0x5a, 0x69, 0x5a, "flat_atomic_or_x2"),
1588bf215546Sopenharmony_ci   (0x5b, 0x6a, 0x5b, "flat_atomic_xor_x2"),
1589bf215546Sopenharmony_ci   (0x5c, 0x6b, 0x5c, "flat_atomic_inc_x2"),
1590bf215546Sopenharmony_ci   (0x5d, 0x6c, 0x5d, "flat_atomic_dec_x2"),
1591bf215546Sopenharmony_ci   (0x5e,   -1, 0x5e, "flat_atomic_fcmpswap_x2"),
1592bf215546Sopenharmony_ci   (0x5f,   -1, 0x5f, "flat_atomic_fmin_x2"),
1593bf215546Sopenharmony_ci   (0x60,   -1, 0x60, "flat_atomic_fmax_x2"),
1594bf215546Sopenharmony_ci}
1595bf215546Sopenharmony_cifor (gfx7, gfx8, gfx10, name) in FLAT:
1596bf215546Sopenharmony_ci    opcode(name, gfx7, gfx8, gfx10, Format.FLAT, InstrClass.VMem, is_atomic = "atomic" in name) #TODO: also LDS?
1597bf215546Sopenharmony_ci
1598bf215546Sopenharmony_ciGLOBAL = {
1599bf215546Sopenharmony_ci   #GFX8_9, GFX10
1600bf215546Sopenharmony_ci   (0x10, 0x08, "global_load_ubyte"),
1601bf215546Sopenharmony_ci   (0x11, 0x09, "global_load_sbyte"),
1602bf215546Sopenharmony_ci   (0x12, 0x0a, "global_load_ushort"),
1603bf215546Sopenharmony_ci   (0x13, 0x0b, "global_load_sshort"),
1604bf215546Sopenharmony_ci   (0x14, 0x0c, "global_load_dword"),
1605bf215546Sopenharmony_ci   (0x15, 0x0d, "global_load_dwordx2"),
1606bf215546Sopenharmony_ci   (0x16, 0x0f, "global_load_dwordx3"),
1607bf215546Sopenharmony_ci   (0x17, 0x0e, "global_load_dwordx4"),
1608bf215546Sopenharmony_ci   (0x18, 0x18, "global_store_byte"),
1609bf215546Sopenharmony_ci   (0x19, 0x19, "global_store_byte_d16_hi"),
1610bf215546Sopenharmony_ci   (0x1a, 0x1a, "global_store_short"),
1611bf215546Sopenharmony_ci   (0x1b, 0x1b, "global_store_short_d16_hi"),
1612bf215546Sopenharmony_ci   (0x1c, 0x1c, "global_store_dword"),
1613bf215546Sopenharmony_ci   (0x1d, 0x1d, "global_store_dwordx2"),
1614bf215546Sopenharmony_ci   (0x1e, 0x1f, "global_store_dwordx3"),
1615bf215546Sopenharmony_ci   (0x1f, 0x1e, "global_store_dwordx4"),
1616bf215546Sopenharmony_ci   (0x20, 0x20, "global_load_ubyte_d16"),
1617bf215546Sopenharmony_ci   (0x21, 0x21, "global_load_ubyte_d16_hi"),
1618bf215546Sopenharmony_ci   (0x22, 0x22, "global_load_sbyte_d16"),
1619bf215546Sopenharmony_ci   (0x23, 0x23, "global_load_sbyte_d16_hi"),
1620bf215546Sopenharmony_ci   (0x24, 0x24, "global_load_short_d16"),
1621bf215546Sopenharmony_ci   (0x25, 0x25, "global_load_short_d16_hi"),
1622bf215546Sopenharmony_ci   (0x40, 0x30, "global_atomic_swap"),
1623bf215546Sopenharmony_ci   (0x41, 0x31, "global_atomic_cmpswap"),
1624bf215546Sopenharmony_ci   (0x42, 0x32, "global_atomic_add"),
1625bf215546Sopenharmony_ci   (0x43, 0x33, "global_atomic_sub"),
1626bf215546Sopenharmony_ci   (0x44, 0x35, "global_atomic_smin"),
1627bf215546Sopenharmony_ci   (0x45, 0x36, "global_atomic_umin"),
1628bf215546Sopenharmony_ci   (0x46, 0x37, "global_atomic_smax"),
1629bf215546Sopenharmony_ci   (0x47, 0x38, "global_atomic_umax"),
1630bf215546Sopenharmony_ci   (0x48, 0x39, "global_atomic_and"),
1631bf215546Sopenharmony_ci   (0x49, 0x3a, "global_atomic_or"),
1632bf215546Sopenharmony_ci   (0x4a, 0x3b, "global_atomic_xor"),
1633bf215546Sopenharmony_ci   (0x4b, 0x3c, "global_atomic_inc"),
1634bf215546Sopenharmony_ci   (0x4c, 0x3d, "global_atomic_dec"),
1635bf215546Sopenharmony_ci   (  -1, 0x3e, "global_atomic_fcmpswap"),
1636bf215546Sopenharmony_ci   (  -1, 0x3f, "global_atomic_fmin"),
1637bf215546Sopenharmony_ci   (  -1, 0x40, "global_atomic_fmax"),
1638bf215546Sopenharmony_ci   (0x60, 0x50, "global_atomic_swap_x2"),
1639bf215546Sopenharmony_ci   (0x61, 0x51, "global_atomic_cmpswap_x2"),
1640bf215546Sopenharmony_ci   (0x62, 0x52, "global_atomic_add_x2"),
1641bf215546Sopenharmony_ci   (0x63, 0x53, "global_atomic_sub_x2"),
1642bf215546Sopenharmony_ci   (0x64, 0x55, "global_atomic_smin_x2"),
1643bf215546Sopenharmony_ci   (0x65, 0x56, "global_atomic_umin_x2"),
1644bf215546Sopenharmony_ci   (0x66, 0x57, "global_atomic_smax_x2"),
1645bf215546Sopenharmony_ci   (0x67, 0x58, "global_atomic_umax_x2"),
1646bf215546Sopenharmony_ci   (0x68, 0x59, "global_atomic_and_x2"),
1647bf215546Sopenharmony_ci   (0x69, 0x5a, "global_atomic_or_x2"),
1648bf215546Sopenharmony_ci   (0x6a, 0x5b, "global_atomic_xor_x2"),
1649bf215546Sopenharmony_ci   (0x6b, 0x5c, "global_atomic_inc_x2"),
1650bf215546Sopenharmony_ci   (0x6c, 0x5d, "global_atomic_dec_x2"),
1651bf215546Sopenharmony_ci   (  -1, 0x5e, "global_atomic_fcmpswap_x2"),
1652bf215546Sopenharmony_ci   (  -1, 0x5f, "global_atomic_fmin_x2"),
1653bf215546Sopenharmony_ci   (  -1, 0x60, "global_atomic_fmax_x2"),
1654bf215546Sopenharmony_ci   (  -1, 0x16, "global_load_dword_addtid"), #GFX10.3+
1655bf215546Sopenharmony_ci   (  -1, 0x17, "global_store_dword_addtid"), #GFX10.3+
1656bf215546Sopenharmony_ci   (  -1, 0x34, "global_atomic_csub"), #GFX10.3+. seems glc must be set
1657bf215546Sopenharmony_ci}
1658bf215546Sopenharmony_cifor (gfx8, gfx10, name) in GLOBAL:
1659bf215546Sopenharmony_ci    opcode(name, -1, gfx8, gfx10, Format.GLOBAL, InstrClass.VMem, is_atomic = "atomic" in name)
1660bf215546Sopenharmony_ci
1661bf215546Sopenharmony_ciSCRATCH = {
1662bf215546Sopenharmony_ci   #GFX8_9, GFX10
1663bf215546Sopenharmony_ci   (0x10, 0x08, "scratch_load_ubyte"),
1664bf215546Sopenharmony_ci   (0x11, 0x09, "scratch_load_sbyte"),
1665bf215546Sopenharmony_ci   (0x12, 0x0a, "scratch_load_ushort"),
1666bf215546Sopenharmony_ci   (0x13, 0x0b, "scratch_load_sshort"),
1667bf215546Sopenharmony_ci   (0x14, 0x0c, "scratch_load_dword"),
1668bf215546Sopenharmony_ci   (0x15, 0x0d, "scratch_load_dwordx2"),
1669bf215546Sopenharmony_ci   (0x16, 0x0f, "scratch_load_dwordx3"),
1670bf215546Sopenharmony_ci   (0x17, 0x0e, "scratch_load_dwordx4"),
1671bf215546Sopenharmony_ci   (0x18, 0x18, "scratch_store_byte"),
1672bf215546Sopenharmony_ci   (0x19, 0x19, "scratch_store_byte_d16_hi"),
1673bf215546Sopenharmony_ci   (0x1a, 0x1a, "scratch_store_short"),
1674bf215546Sopenharmony_ci   (0x1b, 0x1b, "scratch_store_short_d16_hi"),
1675bf215546Sopenharmony_ci   (0x1c, 0x1c, "scratch_store_dword"),
1676bf215546Sopenharmony_ci   (0x1d, 0x1d, "scratch_store_dwordx2"),
1677bf215546Sopenharmony_ci   (0x1e, 0x1f, "scratch_store_dwordx3"),
1678bf215546Sopenharmony_ci   (0x1f, 0x1e, "scratch_store_dwordx4"),
1679bf215546Sopenharmony_ci   (0x20, 0x20, "scratch_load_ubyte_d16"),
1680bf215546Sopenharmony_ci   (0x21, 0x21, "scratch_load_ubyte_d16_hi"),
1681bf215546Sopenharmony_ci   (0x22, 0x22, "scratch_load_sbyte_d16"),
1682bf215546Sopenharmony_ci   (0x23, 0x23, "scratch_load_sbyte_d16_hi"),
1683bf215546Sopenharmony_ci   (0x24, 0x24, "scratch_load_short_d16"),
1684bf215546Sopenharmony_ci   (0x25, 0x25, "scratch_load_short_d16_hi"),
1685bf215546Sopenharmony_ci}
1686bf215546Sopenharmony_cifor (gfx8, gfx10, name) in SCRATCH:
1687bf215546Sopenharmony_ci    opcode(name, -1, gfx8, gfx10, Format.SCRATCH, InstrClass.VMem)
1688bf215546Sopenharmony_ci
1689bf215546Sopenharmony_ci# check for duplicate opcode numbers
1690bf215546Sopenharmony_cifor ver in ['gfx9', 'gfx10']:
1691bf215546Sopenharmony_ci    op_to_name = {}
1692bf215546Sopenharmony_ci    for op in opcodes.values():
1693bf215546Sopenharmony_ci        if op.format in [Format.PSEUDO, Format.PSEUDO_BRANCH, Format.PSEUDO_BARRIER, Format.PSEUDO_REDUCTION]:
1694bf215546Sopenharmony_ci            continue
1695bf215546Sopenharmony_ci
1696bf215546Sopenharmony_ci        num = getattr(op, 'opcode_' + ver)
1697bf215546Sopenharmony_ci        if num == -1:
1698bf215546Sopenharmony_ci            continue
1699bf215546Sopenharmony_ci
1700bf215546Sopenharmony_ci        key = (op.format, num)
1701bf215546Sopenharmony_ci
1702bf215546Sopenharmony_ci        if key in op_to_name:
1703bf215546Sopenharmony_ci            # exceptions
1704bf215546Sopenharmony_ci            names = set([op_to_name[key], op.name])
1705bf215546Sopenharmony_ci            if ver in ['gfx8', 'gfx9'] and names == set(['v_mul_lo_i32', 'v_mul_lo_u32']):
1706bf215546Sopenharmony_ci                continue
1707bf215546Sopenharmony_ci            # v_mad_legacy_f32 is replaced with v_fma_legacy_f32 on GFX10.3
1708bf215546Sopenharmony_ci            if ver == 'gfx10' and names == set(['v_mad_legacy_f32', 'v_fma_legacy_f32']):
1709bf215546Sopenharmony_ci                continue
1710bf215546Sopenharmony_ci            # v_mac_legacy_f32 is replaced with v_fmac_legacy_f32 on GFX10.3
1711bf215546Sopenharmony_ci            if ver == 'gfx10' and names == set(['v_mac_legacy_f32', 'v_fmac_legacy_f32']):
1712bf215546Sopenharmony_ci                continue
1713bf215546Sopenharmony_ci
1714bf215546Sopenharmony_ci            print('%s and %s share the same opcode number (%s)' % (op_to_name[key], op.name, ver))
1715bf215546Sopenharmony_ci            sys.exit(1)
1716bf215546Sopenharmony_ci        else:
1717bf215546Sopenharmony_ci            op_to_name[key] = op.name
1718bf215546Sopenharmony_ci
1719