| 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_MODELS_HPP |
| 10 |
#define IGA_MODELS_HPP |
| 11 |
|
| 12 |
#include "../IR/Types.hpp" |
| 13 |
#include "../asserts.hpp" |
| 14 |
#include "OpSpec.hpp" |
| 15 |
|
| 16 |
#include <cstddef> |
| 17 |
#include <cstdint> |
| 18 |
|
| 19 |
namespace iga { |
| 20 |
|
| 21 |
struct RegInfo { |
| 22 |
// the register name corresponding to this platform |
| 23 |
RegName regName; |
| 24 |
// the lexical identifier for this register |
| 25 |
const char *syntax; |
| 26 |
// a description of this register |
| 27 |
// e.g. "State Register" |
| 28 |
const char *desc; |
| 29 |
|
| 30 |
// For GRF this is nothing. |
| 31 |
// For ARF this is RegNum[7:4]. |
| 32 |
// The value is unshifted. I.e. only 4 bits. |
| 33 |
// |
| 34 |
// RegNum[3:0] usually holds the register number itself for |
| 35 |
// the particular ARF. E.g. acc1 has 0001b there. |
| 36 |
// The exception is mme, which maps to acc2-9 on some platforms and |
| 37 |
// other accumulators elsewhere. |
| 38 |
uint32_t regNum7_4; |
| 39 |
// The amount to add to the register number given to set |
| 40 |
// RegNum[3:0]. For most this will be 0, but a MMR will be offset |
| 41 |
// within the ACC space (since they are shared) |
| 42 |
int regNumBase; |
| 43 |
|
| 44 |
// platform where this was first introduced |
| 45 |
Platform platIntrd; |
| 46 |
// platform where this was last used |
| 47 |
Platform platLast; |
| 48 |
// access granularity (in bytes) |
| 49 |
int accGran; |
| 50 |
|
| 51 |
// number of registers |
| 52 |
// Zero 0 means no reg. number and the register has only 1 |
| 53 |
// e.g. "ce" instead of "ce0" |
| 54 |
int numRegs; |
| 55 |
// The number of bytes in each subregister |
| 56 |
// Certain registers are kind of wonky and have uneven sized registers |
| 57 |
int numBytesPerReg[16]; |
| 58 |
|
| 59 |
bool isRegNumberValid(int reg) const { |
| 60 |
// wonky because null and sp have "0" registers (meaning 1 implied) |
| 61 |
// so reg==0 is alway valid for everyone |
| 62 |
return reg == 0 || |
| 63 |
(reg >= 0 && reg < numRegs); // otherwise: one of several registers |
| 64 |
} |
| 65 |
bool isSubRegByteOffsetValid(int regNum, int subregByte, int grfSize) const { |
| 66 |
int regBytes = 0; |
| 67 |
// special handling null register that we may use sub-register number for |
| 68 |
// other purposes. At those cases the sub register number of null should not |
| 69 |
// excceed GRF bound. |
| 70 |
if (regName == RegName::ARF_NULL) { |
| 71 |
regBytes = grfSize; |
| 72 |
} else { |
| 73 |
regBytes = regName == RegName::GRF_R ? grfSize : numBytesPerReg[regNum]; |
| 74 |
} |
| 75 |
return subregByte < regBytes; |
| 76 |
} |
| 77 |
|
| 78 |
bool supportsRegioning() const { |
| 79 |
// needs to be more liberal than before |
| 80 |
// context save and restore seems to region some of the |
| 81 |
// non-regionable registers |
| 82 |
return regName == RegName::ARF_NULL || hasSubregs(); |
| 83 |
} |
| 84 |
bool supportedOn(Platform p) const { return platIntrd <= p && p <= platLast; } |
| 85 |
bool hasRegNum() const { |
| 86 |
return numRegs > 0; // e.g. "cr0" or "r13" VS "ce" or "null" |
| 87 |
} |
| 88 |
bool hasSubregs() const { |
| 89 |
switch (regName) { |
| 90 |
case RegName::ARF_IP: |
| 91 |
case RegName::ARF_CE: |
| 92 |
case RegName::ARF_NULL: |
| 93 |
return false; |
| 94 |
default: |
| 95 |
return true; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
int getNumReg() const { return numRegs; } |
| 100 |
bool encode(int reg, uint16_t ®NumBits) const; |
| 101 |
uint8_t encodeARFRegNum(int reg) const; |
| 102 |
bool decode(uint8_t regNumBits, int ®) const; |
| 103 |
}; // RegInfo |
| 104 |
|
| 105 |
// returns the table for all platforms. |
| 106 |
// Most users should try and use one of the Model::lookupXXX methods |
| 107 |
const RegInfo *GetRegisterSpecificationTable(int &len); |
| 108 |
|
| 109 |
// See IRChecker.cpp / checkDst (these ARFs need {Switch}) |
| 110 |
static inline bool arfNeedsSwitch(RegName rn) { |
| 111 |
// ARFs without a scoreboard need {Switch} before the write |
| 112 |
// Registers with scoreboard and no switch required - |
| 113 |
// Accumulator/address register/flag register/notify register |
| 114 |
// Registers without scoreboard and switch required - |
| 115 |
// Control Register/State Register/Stack Pointer/Timestamp/Pause/IP |
| 116 |
// register |
| 117 |
// CE is read only. |
| 118 |
// FC does not require switch. It is read/write only in CSR SIP Routine. |
| 119 |
// TDR does not require switch. It is read/write only in CSR SIP Routine. |
| 120 |
|
| 121 |
switch (rn) { |
| 122 |
case RegName::ARF_CR: |
| 123 |
case RegName::ARF_DBG: |
| 124 |
case RegName::ARF_IP: |
| 125 |
case RegName::ARF_SP: |
| 126 |
case RegName::ARF_SR: |
| 127 |
case RegName::ARF_TM: |
| 128 |
return true; |
| 129 |
default: |
| 130 |
return false; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
static inline bool IsRegisterScaled(RegName regName, const Platform platform) { |
| 135 |
switch (regName) { |
| 136 |
case RegName::GRF_R: |
| 137 |
case RegName::ARF_NULL: |
| 138 |
case RegName::ARF_A: |
| 139 |
case RegName::ARF_ACC: |
| 140 |
case RegName::ARF_MME: |
| 141 |
case RegName::ARF_TM: |
| 142 |
case RegName::ARF_CR: |
| 143 |
case RegName::ARF_SP: |
| 144 |
case RegName::ARF_S: |
| 145 |
case RegName::ARF_F: |
| 146 |
case RegName::ARF_N: |
| 147 |
case RegName::ARF_DBG: |
| 148 |
case RegName::ARF_SR: |
| 149 |
case RegName::ARF_TDR: |
| 150 |
return true; |
| 151 |
|
| 152 |
case RegName::ARF_FC: |
| 153 |
case RegName::ARF_MSG: |
| 154 |
// FC and MSG are non-scaled on pre-XE2 |
| 155 |
// pre-PVC: sub-register number is in B size no mater what operand type |
| 156 |
// PVC: sub-register number is in W size no mater what operand type |
| 157 |
// XE2+: sub-register is scaled as GRF |
| 158 |
if (platform >= Platform::XE2) |
| 159 |
return true; |
| 160 |
return false; |
| 161 |
|
| 162 |
default: |
| 163 |
return false; |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
// helper function to translate offset in binary to subReg Num |
| 168 |
static inline uint8_t BinaryOffsetToSubReg(uint32_t offset, RegName regName, |
| 169 |
Type type, const Platform platform) { |
| 170 |
if (!IsRegisterScaled(regName, platform) || type == Type::INVALID) { |
| 171 |
// special handle non-scaled ARF on XeHPC+: |
| 172 |
// the sub reg number should be taken from Src0.SubReg[5:1] |
| 173 |
if (platform >= Platform::XE_HPC) |
| 174 |
offset = offset >> 1; |
| 175 |
return (uint8_t)offset; |
| 176 |
} |
| 177 |
auto tsh = TypeSizeShiftsOffsetToSubreg(type); |
| 178 |
return (uint8_t)((offset << std::get<0>(tsh)) >> std::get<1>(tsh)); |
| 179 |
} |
| 180 |
|
| 181 |
// helper functions to translate subReg number to Offset in binary |
| 182 |
// for regular cases (grf, flag, ...), the offset in binary is the byte offst of |
| 183 |
// the sub-reg for the special cases (fc), the offset depends. |
| 184 |
static inline uint32_t SubRegToBinaryOffset(int subRegNum, RegName regName, |
| 185 |
Type type, |
| 186 |
const Platform platform) { |
| 187 |
if (!IsRegisterScaled(regName, platform) || type == Type::INVALID) { |
| 188 |
// special handle non-scaled ARF on XeHPC+: Src0.SubReg[0] must be 0 |
| 189 |
// the given sub reg number should be set to Src0.SubReg[5:1] |
| 190 |
if (platform >= Platform::XE_HPC) |
| 191 |
subRegNum = subRegNum << 1; |
| 192 |
return subRegNum; |
| 193 |
} |
| 194 |
auto tsh = TypeSizeShiftsOffsetToSubreg(type); |
| 195 |
// NOTE: flipped tuple access (1 <-> 0) since we are unscaling |
| 196 |
return (subRegNum << std::get<1>(tsh)) >> std::get<0>(tsh); |
| 197 |
} |
| 198 |
|
| 199 |
// enables abstract iteration of all OpSpecs in the Model |
| 200 |
// see Model::ops() |
| 201 |
class OpSpecTableIterator { |
| 202 |
Op curr; |
| 203 |
const OpSpec *const opsArray; |
| 204 |
void advanceToNextValid() { |
| 205 |
advance(); // advance at least one |
| 206 |
while (curr <= Op::LAST_OP && !currValid()) { |
| 207 |
advance(); |
| 208 |
} |
| 209 |
} |
| 210 |
bool currValid() const { return opsArray[(int)curr].isValid(); } |
| 211 |
void advance() { |
| 212 |
if (curr <= Op::LAST_OP) { |
| 213 |
curr = (Op)((int)curr + 1); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
public: |
| 218 |
OpSpecTableIterator(const OpSpec *const ops, Op from) |
| 219 |
: curr(from), opsArray(ops) { |
| 220 |
if (!currValid()) { // if FIRST_OP is bogus, go to next |
| 221 |
advanceToNextValid(); |
| 222 |
} |
| 223 |
} |
| 224 |
bool operator==(const OpSpecTableIterator &rhs) const { |
| 225 |
return curr == rhs.curr; |
| 226 |
} |
| 227 |
bool operator!=(const OpSpecTableIterator &rhs) const { |
| 228 |
return !(*this == rhs); |
| 229 |
} |
| 230 |
// OpSpecTableIterator operator++(int); // post-increment |
| 231 |
OpSpecTableIterator &operator++() { // pre-increment |
| 232 |
advanceToNextValid(); |
| 233 |
return *this; |
| 234 |
} |
| 235 |
const OpSpec *operator*() const { return opsArray + (int)curr; } |
| 236 |
}; |
| 237 |
class OpSpecTableWalker { |
| 238 |
private: |
| 239 |
const OpSpec *const opsArray; |
| 240 |
OpSpecTableIterator end_itr; |
| 241 |
|
| 242 |
public: |
| 243 |
OpSpecTableWalker(const OpSpec *const ops) |
| 244 |
: opsArray(ops), end_itr(ops, (Op)((int)Op::LAST_OP + 1)) {} |
| 245 |
OpSpecTableIterator begin() const { |
| 246 |
return OpSpecTableIterator(opsArray, Op::FIRST_OP); |
| 247 |
} |
| 248 |
const OpSpecTableIterator &end() const { return end_itr; } |
| 249 |
}; |
| 250 |
|
| 251 |
// error info if we fail to resolve the OpSpec |
| 252 |
// only valid if `decoodeOpSpec` returns nullptr |
| 253 |
struct OpSpecMissInfo { |
| 254 |
uint64_t opcode; // the opcode bits we tried to lookup |
| 255 |
// for subfunctions (e.g. math.*), this'll be |
| 256 |
// the subfunction bits we were looking for |
| 257 |
}; |
| 258 |
|
| 259 |
// Corresponds to a platform model (e.g. GEN9) |
| 260 |
// Has methods to lookup the various operations (OpSpec's) by name |
| 261 |
// opcode value (7 bit encoding), and enumeration value (Op). |
| 262 |
struct Model { |
| 263 |
Platform platform; |
| 264 |
|
| 265 |
// the table of supported ops for this model indexed by iga::Op |
| 266 |
const OpSpec *const opsArray; |
| 267 |
// |
| 268 |
// file ext (e.g. "12p1" for TGL) |
| 269 |
ModelString extension; |
| 270 |
// |
| 271 |
// various platform names we match for this model (e.g. "TGL") |
| 272 |
static const size_t MAX_NAMES = 6; |
| 273 |
ModelString names[MAX_NAMES]; |
| 274 |
|
| 275 |
constexpr Model(Platform p, const OpSpec *const opsArr, ModelString ext, |
| 276 |
ModelString name0, ModelString name1 = ModelString(), |
| 277 |
ModelString name2 = ModelString(), |
| 278 |
ModelString name3 = ModelString(), |
| 279 |
ModelString name4 = ModelString(), |
| 280 |
ModelString name5 = ModelString()) |
| 281 |
: platform(p), opsArray(opsArr), |
| 282 |
extension(ext), names{name0, name1, name2, name3, name4, name5} {} |
| 283 |
|
| 284 |
/* |
| 285 |
* Enables iteration of all valid ops in the table in a for all loop |
| 286 |
* E.g. one would write: |
| 287 |
* iga::Model model = ... |
| 288 |
* for (const OpSpec *os : model.ops()) { |
| 289 |
* IGA_ASSERT(os->isValid(), "all ops walked will be valid"); |
| 290 |
* } |
| 291 |
*/ |
| 292 |
OpSpecTableWalker ops() const { return OpSpecTableWalker(opsArray); } |
| 293 |
|
| 294 |
const OpSpec &lookupOpSpec(Op op) const; |
| 295 |
const OpSpec &lookupOpSpecByCode(unsigned opcode) const; |
| 296 |
const OpSpec &lookupOpSpecFromBits(const void *bits, |
| 297 |
OpSpecMissInfo &missInfo) const; |
| 298 |
const RegInfo *lookupArfRegInfoByRegNum(uint8_t regNum7_0) const; |
| 299 |
const RegInfo *lookupRegInfoByRegName(RegName name) const; |
| 300 |
|
| 301 |
static const Model *LookupModel(Platform platform); |
| 302 |
// |
| 303 |
// same as above, but asserts if nullptr |
| 304 |
// useful in cases where we know the platform is valid |
| 305 |
static const Model &LookupModelRef(Platform platform); |
| 306 |
|
| 307 |
bool supportsHwDeps() const { return platform <= Platform::GEN11; } |
| 308 |
// send is unary (sends is binary) |
| 309 |
bool supportsUnarySend() const { return supportsHwDeps(); } |
| 310 |
// sends merged with send (send is binary) |
| 311 |
bool supportsXeSend() const { return !supportsHwDeps(); } |
| 312 |
// registers in control flow is stored in src1 for |
| 313 |
// certain instructions |
| 314 |
bool supportsSrc1CtrlFlow() const { return supportsUnarySend(); } |
| 315 |
|
| 316 |
// the wait instruction exists |
| 317 |
bool supportsWait() const { return supportsHwDeps(); } |
| 318 |
|
| 319 |
// ImplAcc must be Align16 |
| 320 |
bool supportsAlign16ImplicitAcc() const { |
| 321 |
return platform <= Platform::GEN10; |
| 322 |
} |
| 323 |
// If the GED_ACCESS_MODE is supported |
| 324 |
bool supportsAccessMode() const { return supportsAlign16ImplicitAcc(); } |
| 325 |
|
| 326 |
// {NoSrcDepSet} allowed |
| 327 |
bool supportNoSrcDepSet() const { |
| 328 |
return platform >= Platform::GEN9 && !supportsXeSend(); |
| 329 |
} |
| 330 |
// {NoPreempt} allowed |
| 331 |
bool supportsNoPreempt() const { |
| 332 |
return platform >= Platform::GEN10 && !supportsXeSend(); |
| 333 |
} |
| 334 |
// implies that: |
| 335 |
// - branches don't have types |
| 336 |
// - the pc is always relative to pre-inc (even jmpi) |
| 337 |
bool supportsSimplifiedBranches() const { return platform >= Platform::XE; } |
| 338 |
|
| 339 |
bool supportsAlign16() const { return platform <= Platform::GEN10; } |
| 340 |
bool supportsAlign16MacroOnly() const { return platform == Platform::GEN10; } |
| 341 |
bool supportsAlign16Ternary() const { return platform < Platform::GEN10; } |
| 342 |
bool supportsAlign16MacroInst() const { return platform <= Platform::GEN10; } |
| 343 |
|
| 344 |
|
| 345 |
uint32_t getNumGRF() const; |
| 346 |
uint32_t getNumFlagReg() const; |
| 347 |
uint32_t getGRFByteSize() const; |
| 348 |
|
| 349 |
uint32_t getRegCount(RegName rn) const; |
| 350 |
uint32_t getBytesPerReg(RegName rn) const; |
| 351 |
|
| 352 |
/// getSWSBEncodeMode - get the default swsb encoding mode derived from |
| 353 |
/// platform |
| 354 |
SWSB_ENCODE_MODE getSWSBEncodeMode() const { |
| 355 |
if (platform == Platform::XE) |
| 356 |
return SWSB_ENCODE_MODE::SingleDistPipe; |
| 357 |
else if (platform == Platform::XE_HP) |
| 358 |
return SWSB_ENCODE_MODE::ThreeDistPipe; |
| 359 |
else if (platform == Platform::XE_HPG) |
| 360 |
return SWSB_ENCODE_MODE::ThreeDistPipe; |
| 361 |
else if (platform == Platform::XE_HPC) |
| 362 |
return SWSB_ENCODE_MODE::FourDistPipeReduction; // XE_HPC is XeHPC-Bstep |
| 363 |
// (PVC-XT) |
| 364 |
else if (platform == Platform::XE2) |
| 365 |
return SWSB_ENCODE_MODE::FourDistPipeReduction; |
| 366 |
else if (platform == Platform::XE3) |
| 367 |
return SWSB_ENCODE_MODE::FiveDistPipe; |
| 368 |
else if (platform >= Platform::XE3P_XPC) |
| 369 |
return SWSB_ENCODE_MODE::FiveDistPipeCvtToIntNoFwd; |
| 370 |
return SWSB_ENCODE_MODE::SWSBInvalidMode; |
| 371 |
} |
| 372 |
|
| 373 |
// Get the max number of swsb id |
| 374 |
uint32_t getMaxSWSBTokenNum() const { |
| 375 |
switch (getSWSBEncodeMode()) { |
| 376 |
case SWSB_ENCODE_MODE::SingleDistPipe: |
| 377 |
case SWSB_ENCODE_MODE::ThreeDistPipe: |
| 378 |
case SWSB_ENCODE_MODE::ThreeDistPipeDPMath: |
| 379 |
return 16; |
| 380 |
case SWSB_ENCODE_MODE::FourDistPipe: |
| 381 |
case SWSB_ENCODE_MODE::FourDistPipeReduction: |
| 382 |
case SWSB_ENCODE_MODE::FiveDistPipe: |
| 383 |
case SWSB_ENCODE_MODE::FiveDistPipeReduction: |
| 384 |
case SWSB_ENCODE_MODE::FiveDistPipeCvtToInt: |
| 385 |
case SWSB_ENCODE_MODE::FiveDistPipeSWSBCntr: |
| 386 |
case SWSB_ENCODE_MODE::FiveDistPipeCvtToIntNoFwd: |
| 387 |
return 32; |
| 388 |
default: |
| 389 |
break; |
| 390 |
} |
| 391 |
|
| 392 |
return 16; |
| 393 |
} |
| 394 |
|
| 395 |
uint32_t getSWSBMaxValidDistance() const { return 7; } |
| 396 |
|
| 397 |
// hasReadModifiedWriteOnByteDst - on the platform having 64-byte |
| 398 |
// size GRF, we're not able to perform byte write to a GRF. |
| 399 |
// The platform will read the other half and perform word write. |
| 400 |
// This will affect swsb setting behavior. |
| 401 |
bool hasReadModifiedWriteOnByteDst() const { return getGRFByteSize() == 64; } |
| 402 |
|
| 403 |
bool srcHasReducedRegion(uint32_t srcIdx) const; |
| 404 |
}; // class Model |
| 405 |
|
| 406 |
/////////////////////////////////////////////////////////////////////////// |
| 407 |
// In rare cases where one must iterate all models |
| 408 |
extern const Model *const ALL_MODELS[]; |
| 409 |
extern const size_t ALL_MODELS_LEN; |
| 410 |
} // namespace iga |
| 411 |
|
| 412 |
#endif // IGA_MODELS_HPP |