| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2017-2021 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
#ifndef IGA_IR_TYPES_HPP |
| 10 |
#define IGA_IR_TYPES_HPP |
| 11 |
|
| 12 |
// WARNING: the IR is subject to change without any notice. External tools |
| 13 |
// should use the official interfaces in the external API. Those interfaces |
| 14 |
// are tested between releases and maintained even with changes to the IR. |
| 15 |
|
| 16 |
#include <cstdint> |
| 17 |
#include <tuple> |
| 18 |
|
| 19 |
#include "../EnumBitset.hpp" |
| 20 |
#include "../api/iga.h" |
| 21 |
#include "../api/iga_bxml_enums.hpp" |
| 22 |
#include "../api/iga_types_ext.hpp" |
| 23 |
|
| 24 |
namespace iga { |
| 25 |
|
| 26 |
// The GEN platform version |
| 27 |
enum class Platform { |
| 28 |
// GEN version encoding. The version encoding must be the same as GEN_VER in |
| 29 |
// iga.h |
| 30 |
#define IGA_GEN_VER_ORDINAL(MAJ, MIN) ((MAJ) << 16) | (MIN) |
| 31 |
|
| 32 |
// XE version encoding. The version encoding must be the same as XE_VER in iga.h |
| 33 |
#define IGA_XE_VER_ORDINAL(XE, SUBVER) (((XE) << 24) | SUBVER) |
| 34 |
|
| 35 |
INVALID = 0, |
| 36 |
|
| 37 |
GEN6 = IGA_GEN_VER_ORDINAL(6, 0), |
| 38 |
GEN7 = IGA_GEN_VER_ORDINAL(7, 0), |
| 39 |
GEN7P5 = IGA_GEN_VER_ORDINAL(7, 5), |
| 40 |
GEN8 = IGA_GEN_VER_ORDINAL(8, 0), |
| 41 |
GEN8LP = IGA_GEN_VER_ORDINAL(8, 1), |
| 42 |
GEN9 = IGA_GEN_VER_ORDINAL(9, 0), |
| 43 |
GEN9LP = IGA_GEN_VER_ORDINAL(9, 1), |
| 44 |
GEN9P5 = IGA_GEN_VER_ORDINAL(9, 5), |
| 45 |
GEN10 = IGA_GEN_VER_ORDINAL(10, 0), |
| 46 |
GEN11 = IGA_GEN_VER_ORDINAL(11, 0), |
| 47 |
// XE version |
| 48 |
XE = IGA_XE_VER_ORDINAL(1, 0), // TGL |
| 49 |
XE_HP = IGA_XE_VER_ORDINAL(1, 1), |
| 50 |
XE_HPG = IGA_XE_VER_ORDINAL(1, 2), |
| 51 |
XE_HPC = IGA_XE_VER_ORDINAL(1, 4), // XeHPC-XT, preserved (1, 3) for XeHPC-XL |
| 52 |
XE2 = IGA_XE_VER_ORDINAL(2, 0), |
| 53 |
XE3 = IGA_XE_VER_ORDINAL(3, 0), |
| 54 |
XE3P_XPC = IGA_XE_VER_ORDINAL(3, 3), |
| 55 |
FUTURE = 0x7FFFFFFF |
| 56 |
#undef IGA_GEN_VER_ORDINAL |
| 57 |
}; |
| 58 |
|
| 59 |
struct Predication { |
| 60 |
PredCtrl function; |
| 61 |
bool inverse; // TODO: enum |
| 62 |
|
| 63 |
Predication() : function(PredCtrl::NONE), inverse(false) {} |
| 64 |
Predication(PredCtrl ctrl, bool inv) : function(ctrl), inverse(inv) {} |
| 65 |
}; |
| 66 |
|
| 67 |
typedef BranchCtrl BranchCntrl; // for backwards compatibility |
| 68 |
|
| 69 |
static inline int ExecSizeToInt(ExecSize es) { return static_cast<int>(es); } |
| 70 |
static inline ExecSize ExecSizeFromInt(int es) { |
| 71 |
return static_cast<ExecSize>(es); |
| 72 |
} |
| 73 |
|
| 74 |
// for math macro register access (madm, math.invm, and math.rsqrtm) |
| 75 |
// e.g. madm (8) r13.mme2:f r14:mme7:f r16:nomme ... |
| 76 |
// ^^^^ ^^^^ ^^^^^ |
| 77 |
enum class MathMacroExt { |
| 78 |
INVALID, |
| 79 |
MME0, // encodes as 0000b |
| 80 |
MME1, // encodes as 0001b |
| 81 |
MME2, // encodes as 0010b |
| 82 |
MME3, // encodes as 0011b |
| 83 |
MME4, // encodes as 0100b |
| 84 |
MME5, // encodes as 0101b |
| 85 |
MME6, // encodes as 0110b |
| 86 |
MME7, // encodes as 0111b |
| 87 |
NOMME, // encodes as 1000b |
| 88 |
}; |
| 89 |
|
| 90 |
// how much to shift <right,left> to get to from byte offset |
| 91 |
// to subregister offset |
| 92 |
// I.e. subReg = (byteOff << left) >> right; |
| 93 |
// this allows us to scale a subregister byte offset up OR down |
| 94 |
static inline std::tuple<uint32_t, uint32_t> |
| 95 |
TypeSizeShiftsOffsetToSubreg(Type type) { |
| 96 |
uint32_t shl = 0, shr = 0; // by default no scaling |
| 97 |
|
| 98 |
switch (type) { |
| 99 |
// subbyte types |
| 100 |
case Type::U1: |
| 101 |
shl = 3; |
| 102 |
break; |
| 103 |
case Type::U2: |
| 104 |
case Type::S2: |
| 105 |
shl = 2; |
| 106 |
break; |
| 107 |
case Type::U4: |
| 108 |
case Type::S4: |
| 109 |
// FP4 data type |
| 110 |
case Type::E2M1: |
| 111 |
shl = 1; |
| 112 |
break; |
| 113 |
|
| 114 |
case Type::QF: |
| 115 |
case Type::BF8: |
| 116 |
case Type::HF8: |
| 117 |
break; |
| 118 |
case Type::TF32: |
| 119 |
shr = 2; |
| 120 |
break; |
| 121 |
|
| 122 |
// 1-byte types |
| 123 |
case Type::UB: |
| 124 |
case Type::B: |
| 125 |
break; |
| 126 |
// 2-byte types |
| 127 |
case Type::UW: |
| 128 |
case Type::W: |
| 129 |
case Type::HF: |
| 130 |
case Type::BF: |
| 131 |
shr = 1; |
| 132 |
break; |
| 133 |
// 4-byte types |
| 134 |
case Type::UD: |
| 135 |
case Type::D: |
| 136 |
case Type::F: |
| 137 |
case Type::NF: // NF regions the same as F |
| 138 |
shr = 2; |
| 139 |
break; |
| 140 |
case Type::UQ: |
| 141 |
case Type::Q: |
| 142 |
case Type::DF: |
| 143 |
shr = 3; |
| 144 |
break; |
| 145 |
default: // invalid types |
| 146 |
break; |
| 147 |
} |
| 148 |
return std::make_tuple(shl, shr); |
| 149 |
} |
| 150 |
|
| 151 |
// e.g. Type::UD == 32 |
| 152 |
static inline uint32_t TypeSizeInBits(Type t) { |
| 153 |
auto ti = TypeSizeShiftsOffsetToSubreg(t); |
| 154 |
return (8 << std::get<1>(ti)) >> std::get<0>(ti); |
| 155 |
} |
| 156 |
static inline uint32_t TypeSizeInBitsWithDefault(Type type, int dft = 0) { |
| 157 |
return type == Type::INVALID ? dft : TypeSizeInBits(type); |
| 158 |
} |
| 159 |
static inline bool TypeIs64b(Type t) { |
| 160 |
return TypeSizeInBitsWithDefault(t, 0) == 64; |
| 161 |
} |
| 162 |
static inline bool TypeIsFloating(Type t) { |
| 163 |
switch (t) { |
| 164 |
case Type::F: |
| 165 |
case Type::BF: |
| 166 |
case Type::QF: |
| 167 |
case Type::BF8: |
| 168 |
case Type::HF8: |
| 169 |
case Type::TF32: |
| 170 |
case Type::HF: |
| 171 |
case Type::DF: |
| 172 |
case Type::VF: |
| 173 |
case Type::NF: |
| 174 |
return true; |
| 175 |
default: |
| 176 |
return false; |
| 177 |
} |
| 178 |
} |
| 179 |
// static inline bool TypeIsSubByte(Type t) { |
| 180 |
// return std::get<1>(TypeSizeShiftsOffsetToSubreg(t)) > 0; |
| 181 |
// } |
| 182 |
|
| 183 |
struct Region { |
| 184 |
enum class Vert { |
| 185 |
VT_0 = 0, |
| 186 |
VT_1 = 1, |
| 187 |
VT_2 = 2, |
| 188 |
VT_4 = 4, |
| 189 |
VT_8 = 8, |
| 190 |
VT_16 = 16, |
| 191 |
VT_32 = 32, |
| 192 |
|
| 193 |
VT_VxH = 31, // special VxH mode for indirect region |
| 194 |
VT_INVALID = 63, |
| 195 |
}; |
| 196 |
enum class Width { |
| 197 |
WI_1 = 1, |
| 198 |
WI_2 = 2, |
| 199 |
WI_4 = 4, |
| 200 |
WI_8 = 8, |
| 201 |
WI_16 = 16, |
| 202 |
WI_INVALID = 31 |
| 203 |
}; |
| 204 |
enum class Horz { |
| 205 |
HZ_0 = 0, // not permitted on DstOps (unless MBZ) |
| 206 |
HZ_1 = 1, |
| 207 |
HZ_2 = 2, |
| 208 |
HZ_4 = 4, |
| 209 |
HZ_INVALID = 15 |
| 210 |
}; |
| 211 |
union { |
| 212 |
struct { |
| 213 |
unsigned int v : 6; |
| 214 |
unsigned int w : 5; |
| 215 |
unsigned int h : 4; |
| 216 |
}; |
| 217 |
uint32_t bits; |
| 218 |
}; |
| 219 |
|
| 220 |
constexpr void set(Vert _v, Width _w, Horz _h) { |
| 221 |
this->bits = 0; // clear padding |
| 222 |
v = static_cast<unsigned int>(_v); |
| 223 |
w = static_cast<unsigned int>(_w); |
| 224 |
h = static_cast<unsigned int>(_h); |
| 225 |
} |
| 226 |
|
| 227 |
constexpr void set(Vert vt) { v = static_cast<unsigned int>(vt); } |
| 228 |
constexpr void set(Width wi) { w = static_cast<unsigned int>(wi); } |
| 229 |
constexpr void set(Horz hz) { h = static_cast<unsigned int>(hz); } |
| 230 |
constexpr void setDstHz(Horz hz) { |
| 231 |
set(Vert::VT_INVALID, Width::WI_INVALID, hz); |
| 232 |
} |
| 233 |
|
| 234 |
Horz getHz() const { return static_cast<Horz>(h); } |
| 235 |
Vert getVt() const { return static_cast<Vert>(v); } |
| 236 |
Width getWi() const { return static_cast<Width>(w); } |
| 237 |
|
| 238 |
// checks if a region is invalid (assembler will program it to correct bits) |
| 239 |
bool isInvalid() const { return *this == INVALID; } |
| 240 |
// checks if a region is of the for <V;W,H> |
| 241 |
bool isVWH() const { |
| 242 |
return getVt() != Vert::VT_INVALID && getWi() != Width::WI_INVALID && |
| 243 |
getHz() != Horz::HZ_INVALID; |
| 244 |
} |
| 245 |
|
| 246 |
bool isScalar() const { |
| 247 |
if ((v == 0 && h == 0) || (v == 0 && w == 1) || |
| 248 |
bits == SRCXX0.bits) |
| 249 |
return true; |
| 250 |
return false; |
| 251 |
} |
| 252 |
|
| 253 |
// define [in]equality based on bits |
| 254 |
bool operator==(const Region &b) const { |
| 255 |
// careful: fails if padding differs (we prevent that now) |
| 256 |
return b.bits == bits; |
| 257 |
} |
| 258 |
bool operator!=(const Region &b) const { return !(*this == b); } |
| 259 |
|
| 260 |
// some useful region constants |
| 261 |
static const Region INVALID; // all RESERVED elements |
| 262 |
// |
| 263 |
// dst |
| 264 |
static const Region DST1; // <1> |
| 265 |
static const Region DST2; // <2> |
| 266 |
static const Region DST4; // <4> |
| 267 |
// |
| 268 |
// generalized src regions |
| 269 |
static const Region SRC010; // <0;1,0> (broadcast scalar) |
| 270 |
static const Region SRC110; // <1;1,0> (packed access) |
| 271 |
static const Region SRC210; // <2;1,0> (even strided access) |
| 272 |
static const Region SRC410; // <4;1,0> (quarter stided access) |
| 273 |
static const Region SRC810; // <8;1,0> |
| 274 |
static const Region SRC1610; // <16;1,0> |
| 275 |
// |
| 276 |
// older src regions |
| 277 |
static const Region SRC221; // <2;2,1> |
| 278 |
static const Region SRC441; // <4;4,1> |
| 279 |
static const Region SRC881; // <8;8,1> |
| 280 |
static const Region SRCFF1; // <16;16,1> |
| 281 |
// |
| 282 |
// special cases |
| 283 |
// ternary src0/src1 |
| 284 |
static const Region SRC0X0; // <0;0> (ternary align1 src0 and src1) |
| 285 |
static const Region SRC2X1; // <2;1> (ternary align1 src0 and src1) |
| 286 |
static const Region SRC1X0; // <1;0> XE_LP changes 2 to 1 in encoding |
| 287 |
static const Region SRC4X1; // <4;1> (ternary align1 src0 and src1) |
| 288 |
static const Region SRC4X2; // <4;2> single-stride 2 |
| 289 |
static const Region SRC8X4; // <8;4> single-stride 4 |
| 290 |
// ternary src2 |
| 291 |
static const Region SRC8X1; // <8;1> (ternary align1 src0 and src1) |
| 292 |
static const Region SRCXX0; // <0> (ternary align1 src2) |
| 293 |
static const Region SRCXX1; // <1> (ternary align1 src2) |
| 294 |
static const Region SRCXX2; // <2> (ternary align1 src2) |
| 295 |
}; |
| 296 |
|
| 297 |
// A set of instruction options |
| 298 |
typedef EnumBitset<InstOpt> InstOptSet; |
| 299 |
|
| 300 |
struct RegRef { |
| 301 |
uint16_t regNum = 0; |
| 302 |
uint16_t subRegNum = 0; |
| 303 |
|
| 304 |
constexpr RegRef() {} |
| 305 |
constexpr RegRef(uint16_t rNum, uint16_t srNum) |
| 306 |
: regNum(rNum), subRegNum(srNum) {} |
| 307 |
constexpr RegRef(int rNum, int srNum) |
| 308 |
: regNum((uint16_t)rNum), subRegNum((uint16_t)srNum) {} |
| 309 |
constexpr RegRef(uint32_t rNum, uint32_t srNum) |
| 310 |
: regNum((uint16_t)rNum), subRegNum((uint16_t)srNum) {} |
| 311 |
|
| 312 |
bool operator==(const RegRef &rr) const { |
| 313 |
return regNum == rr.regNum && subRegNum == rr.subRegNum; |
| 314 |
} |
| 315 |
bool operator!=(const RegRef &rr) const { return !(*this == rr); } |
| 316 |
}; |
| 317 |
|
| 318 |
static constexpr RegRef REGREF_INVALID{0xFFFF, 0xFFFF}; |
| 319 |
static constexpr RegRef REGREF_ZERO_ZERO{0, 0}; |
| 320 |
|
| 321 |
struct SendDesc { |
| 322 |
enum class Kind { IMM, REG32A }; |
| 323 |
Kind type; |
| 324 |
|
| 325 |
union { |
| 326 |
RegRef reg; |
| 327 |
uint32_t imm; |
| 328 |
}; |
| 329 |
|
| 330 |
constexpr SendDesc() : SendDesc(0) {} |
| 331 |
constexpr SendDesc(uint32_t desc) : type(Kind::IMM), imm(desc) {} |
| 332 |
constexpr SendDesc(RegRef a0r) : type(Kind::REG32A), reg(a0r) {} |
| 333 |
|
| 334 |
bool isReg() const { return type == Kind::REG32A; } |
| 335 |
bool isImm() const { return type == Kind::IMM; } |
| 336 |
}; |
| 337 |
|
| 338 |
// Conversion from iga_gen_t to an internal platform Platform |
| 339 |
// we could just re-interpret the bits but this checks for garbage |
| 340 |
// (validates the enum) |
| 341 |
// This is not static so that it can be used by other compilation units. |
| 342 |
Platform ToPlatform(iga_gen_t gen); |
| 343 |
|
| 344 |
} // namespace iga |
| 345 |
#endif |