aco: deduplicate Format definition

Reviewed-by: Daniel Schürmann <daniel@schuermann.dev
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25943>
This commit is contained in:
Georg Lehmann 2023-10-28 12:53:00 +02:00 committed by Marge Bot
parent 6e0bf33a89
commit 6cd78281f6
4 changed files with 56 additions and 86 deletions

View file

@ -59,59 +59,6 @@ enum {
DEBUG_NO_VALIDATE_IR = 0x400, DEBUG_NO_VALIDATE_IR = 0x400,
}; };
/**
* Representation of the instruction's microcode encoding format
* Note: Some Vector ALU Formats can be combined, such that:
* - VOP2* | VOP3 represents a VOP2 instruction in VOP3 encoding
* - VOP2* | DPP represents a VOP2 instruction with data parallel primitive.
* - VOP2* | SDWA represents a VOP2 instruction with sub-dword addressing.
*
* (*) The same is applicable for VOP1 and VOPC instructions.
*/
enum class Format : uint16_t {
/* Pseudo Instruction Format */
PSEUDO = 0,
/* Scalar ALU & Control Formats */
SOP1 = 1,
SOP2 = 2,
SOPK = 3,
SOPP = 4,
SOPC = 5,
/* Scalar Memory Format */
SMEM = 6,
/* LDS/GDS Format */
DS = 8,
LDSDIR = 9,
/* Vector Memory Buffer Formats */
MTBUF = 10,
MUBUF = 11,
/* Vector Memory Image Format */
MIMG = 12,
/* Export Format */
EXP = 13,
/* Flat Formats */
FLAT = 14,
GLOBAL = 15,
SCRATCH = 16,
PSEUDO_BRANCH = 17,
PSEUDO_BARRIER = 18,
PSEUDO_REDUCTION = 19,
/* Vector ALU Formats */
VINTERP_INREG = 21,
VOP3P = 1 << 7,
VOP1 = 1 << 8,
VOP2 = 1 << 9,
VOPC = 1 << 10,
VOP3 = 1 << 11,
/* Vector Parameter Interpolation Format */
VINTRP = 1 << 12,
DPP16 = 1 << 13,
SDWA = 1 << 14,
DPP8 = 1 << 15,
};
enum storage_class : uint8_t { enum storage_class : uint8_t {
storage_none = 0x0, /* no synchronization and can be reordered around aliasing stores */ storage_none = 0x0, /* no synchronization and can be reordered around aliasing stores */
storage_buffer = 0x1, /* SSBOs and global memory */ storage_buffer = 0x1, /* SSBOs and global memory */
@ -1278,7 +1225,7 @@ struct Instruction {
assert(isVINTRP()); assert(isVINTRP());
return *(VINTRP_instruction*)this; return *(VINTRP_instruction*)this;
} }
constexpr bool isVINTRP() const noexcept { return (uint16_t)format & (uint16_t)Format::VINTRP; } constexpr bool isVINTRP() const noexcept { return format == Format::VINTRP; }
DPP16_instruction& dpp16() noexcept DPP16_instruction& dpp16() noexcept
{ {
assert(isDPP16()); assert(isDPP16());

View file

@ -25,7 +25,7 @@
# NOTE: this must be kept in sync with aco_op_info # NOTE: this must be kept in sync with aco_op_info
import sys import sys
from enum import Enum from enum import Enum, IntEnum, auto
class InstrClass(Enum): class InstrClass(Enum):
Valu32 = "valu32" Valu32 = "valu32"
@ -50,36 +50,53 @@ class InstrClass(Enum):
Waitcnt = "waitcnt" Waitcnt = "waitcnt"
Other = "other" Other = "other"
class Format(Enum): # Representation of the instruction's microcode encoding format
# Note: Some Vector ALU Formats can be combined, such that:
# - VOP2* | VOP3 represents a VOP2 instruction in VOP3 encoding
# - VOP2* | DPP represents a VOP2 instruction with data parallel primitive.
# - VOP2* | SDWA represents a VOP2 instruction with sub-dword addressing.
#
# (*) The same is applicable for VOP1 and VOPC instructions.
class Format(IntEnum):
# Pseudo Instruction Formats
PSEUDO = 0 PSEUDO = 0
SOP1 = 1 PSEUDO_BRANCH = auto()
SOP2 = 2 PSEUDO_BARRIER = auto()
SOPK = 3 PSEUDO_REDUCTION = auto()
SOPP = 4 # Scalar ALU & Control Formats
SOPC = 5 SOP1 = auto()
SMEM = 6 SOP2 = auto()
DS = 8 SOPK = auto()
LDSDIR = 9 SOPP = auto()
MTBUF = 10 SOPC = auto()
MUBUF = 11 # Scalar Memory Format
MIMG = 12 SMEM = auto()
EXP = 13 # LDS/GDS Format
FLAT = 14 DS = auto()
GLOBAL = 15 LDSDIR = auto()
SCRATCH = 16 # Vector Memory Buffer Formats
PSEUDO_BRANCH = 17 MTBUF = auto()
PSEUDO_BARRIER = 18 MUBUF = auto()
PSEUDO_REDUCTION = 19 # Vector Memory Image Format
VINTERP_INREG = 21 MIMG = auto()
VOP3P = 1 << 7 # Export Format
VOP1 = 1 << 8 EXP = auto()
VOP2 = 1 << 9 # Flat Formats
VOPC = 1 << 10 FLAT = auto()
VOP3 = 1 << 11 GLOBAL = auto()
VINTRP = 1 << 12 SCRATCH = auto()
# Vector Parameter Interpolation Formats
VINTRP = auto()
# Vector ALU Formats
VINTERP_INREG = auto()
VOP1 = 1 << 7
VOP2 = 1 << 8
VOPC = 1 << 9
VOP3 = 1 << 10
VOP3P = 1 << 11
SDWA = 1 << 12
DPP16 = 1 << 13 DPP16 = 1 << 13
SDWA = 1 << 14 DPP8 = 1 << 14
DPP8 = 1 << 15
def get_builder_fields(self): def get_builder_fields(self):
if self == Format.SOPK: if self == Format.SOPK:

View file

@ -32,6 +32,12 @@ template = """\
namespace aco { namespace aco {
enum class Format : uint16_t {
% for e in Format:
${e.name} = ${hex(e.value)},
% endfor
};
enum class instr_class : uint8_t { enum class instr_class : uint8_t {
% for name in InstrClass: % for name in InstrClass:
${name.value}, ${name.value},
@ -52,7 +58,7 @@ enum class aco_opcode : uint16_t {
} }
#endif /* _ACO_OPCODES_ */""" #endif /* _ACO_OPCODES_ */"""
from aco_opcodes import opcodes, InstrClass from aco_opcodes import opcodes, InstrClass, Format
from mako.template import Template from mako.template import Template
print(Template(template).render(opcodes=opcodes, InstrClass=InstrClass)) print(Template(template).render(opcodes=opcodes, InstrClass=InstrClass, Format=Format))

View file

@ -116,7 +116,7 @@ validate_ir(Program* program)
base_format = Format::VOP2; base_format = Format::VOP2;
else if ((uint32_t)base_format & (uint32_t)Format::VOPC) else if ((uint32_t)base_format & (uint32_t)Format::VOPC)
base_format = Format::VOPC; base_format = Format::VOPC;
else if ((uint32_t)base_format & (uint32_t)Format::VINTRP) { else if (base_format == Format::VINTRP) {
if (instr->opcode == aco_opcode::v_interp_p1ll_f16 || if (instr->opcode == aco_opcode::v_interp_p1ll_f16 ||
instr->opcode == aco_opcode::v_interp_p1lv_f16 || instr->opcode == aco_opcode::v_interp_p1lv_f16 ||
instr->opcode == aco_opcode::v_interp_p2_legacy_f16 || instr->opcode == aco_opcode::v_interp_p2_legacy_f16 ||