| 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_OPSPEC_HPP |
| 10 |
#define IGA_OPSPEC_HPP |
| 11 |
|
| 12 |
#include "../IR/Types.hpp" |
| 13 |
#include "../strings.hpp" |
| 14 |
|
| 15 |
#include <cstddef> |
| 16 |
#include <cstdint> |
| 17 |
|
| 18 |
namespace iga { |
| 19 |
// An operation specification (OpSpec). |
| 20 |
// |
| 21 |
// Each model contains an array of these built-in |
| 22 |
struct OpSpec { |
| 23 |
// The various syntaxes and formats that each instruction can support |
| 24 |
// The naming convention groups the instructions logically as |
| 25 |
// |
| 26 |
// NULLARY => takes no operands |
| 27 |
// BASIC_{UNARY,BINARY}_* => takes one or two operands encodes |
| 28 |
// in basic format |
| 29 |
// MATH_{UNARY,BINARY} => much like BASIC, but supports MathFC |
| 30 |
// SYNC_{UNARY} => wait, sync.* |
| 31 |
// |
| 32 |
// The special value of GROUP is used for operations that break into |
| 33 |
// multiple suboperations such as the math function. |
| 34 |
// |
| 35 |
// The suffixes also have important meaning. |
| 36 |
// REG means it takes only a register as a source operand |
| 37 |
// IMM means only a source immediate value |
| 38 |
// REGIMM means either REG or IMM |
| 39 |
// |
| 40 |
// TODO: use a bit feature for REG, REGIMM, IMM etc... |
| 41 |
// REG - a unary register operand |
| 42 |
// IMM - a unary immediate operand |
| 43 |
// REGIMM - a unary register operand or immediate |
| 44 |
// REG_REG - a binary register, register |
| 45 |
// REG_IMM - a binary register and immediate |
| 46 |
// REG_REGIMM - binary reg and then a reg or immediate |
| 47 |
// REGIMM_REG_REGIMM - ternary |
| 48 |
// ... other ideas |
| 49 |
// IMPL_NULL_DST - implicit null DST |
| 50 |
enum Format { |
| 51 |
// feature bits for constructing ordinals |
| 52 |
// these can be masked out of the ordinals to determine various |
| 53 |
// features of the format |
| 54 |
BASIC = 0x10000, |
| 55 |
MATH = BASIC << 1, // MATH_* (includes MATH_MACRO) |
| 56 |
SEND = MATH << 1, // SEND_* |
| 57 |
JUMP = SEND << 1, // JUMP_* |
| 58 |
SPECIAL = JUMP << 1, // NULLARY, WAIT, WDEP |
| 59 |
|
| 60 |
HAS_DST = SPECIAL << 1, // has a destination |
| 61 |
UNARY = HAS_DST << 1, // takes one operand |
| 62 |
BINARY = UNARY << 1, // takes two operands |
| 63 |
TERNARY = BINARY << 1, // takes three operands |
| 64 |
QUINARY = TERNARY << 1, // takes five operands |
| 65 |
|
| 66 |
///////////////////////////////////////////////// |
| 67 |
// THE ACTUAL VALID ENTRIES |
| 68 |
// These are all unique combinations of the above ordinals. |
| 69 |
// |
| 70 |
// for unpopulated entries |
| 71 |
INVALID = 0, |
| 72 |
|
| 73 |
// op (..) reg reg |
| 74 |
// e.g. movi (PreCNL) |
| 75 |
BASIC_UNARY_REG = (BASIC | HAS_DST | UNARY) + 1, |
| 76 |
// op (..) reg (reg|imm32|imm64) |
| 77 |
// e.g. mov, not, ... |
| 78 |
BASIC_UNARY_REGIMM = BASIC_UNARY_REG + 1, |
| 79 |
|
| 80 |
// op (..) reg imm32 |
| 81 |
BASIC_BINARY_REG_IMM = (BASIC | HAS_DST | BINARY) + 1, |
| 82 |
// op (..) reg reg |
| 83 |
BASIC_BINARY_REG_REG = BASIC_BINARY_REG_IMM + 1, |
| 84 |
// op (..) reg (reg|imm32) |
| 85 |
BASIC_BINARY_REG_REGIMM = BASIC_BINARY_REG_REG + 1, |
| 86 |
|
| 87 |
// Math operations. |
| 88 |
// We determine the number of sources by subfunction. |
| 89 |
// |
| 90 |
// math[.unr_fc] (exec_size) reg (reg|imm32) |
| 91 |
// math[.bin_fc] (exec_size) reg reg (reg|imm32) |
| 92 |
// math[.unrm_fc] (exec_size) reg.acc reg.acc |
| 93 |
// math[.binm_fc] (exec_size) reg.acc reg.acc reg.acc |
| 94 |
MATH_BINARY_REG_REGIMM = (MATH | HAS_DST | BINARY) + 1, // pow, exp, fdiv |
| 95 |
|
| 96 |
// op (..) reg reg reg reg |
| 97 |
// op (..) reg reg reg imm16 |
| 98 |
// op (..) reg imm16 reg reg |
| 99 |
// op (..) reg.acc reg.acc reg.acc reg.acc |
| 100 |
TERNARY_REGIMM_REG_REGIMM = (TERNARY | HAS_DST) + 1, |
| 101 |
|
| 102 |
// BRANCHING OPS |
| 103 |
// brop (..) label16 [PreBDW] |
| 104 |
// brop (..) label32 [BDW+] |
| 105 |
// e.g. endif, else (PreBDW) |
| 106 |
JUMP_UNARY_IMM = (JUMP | UNARY) + 1, |
| 107 |
// br (..) reg [implicit null in dst] |
| 108 |
// e.g. ret |
| 109 |
JUMP_UNARY_REG = JUMP_UNARY_IMM + 1, |
| 110 |
// brop (..) [reg|label32] [PreBDW] |
| 111 |
// brop (..) [reg|label16] [BDW+] |
| 112 |
// e.g. jmpi, brd |
| 113 |
// No destination |
| 114 |
JUMP_UNARY_REGIMM = JUMP_UNARY_REG + 1, |
| 115 |
// op (...) reg (lbl|reg) |
| 116 |
// e.g. call, calla |
| 117 |
// Has destination |
| 118 |
JUMP_UNARY_CALL_REGIMM = (JUMP | HAS_DST | UNARY) + 1, |
| 119 |
// brc (..) lbl16 lbl16 [PreBDW] |
| 120 |
// brc (..) lbl32 lbl32 [BDW+] |
| 121 |
// brc (..) reg32 null [PreHSW] |
| 122 |
// brc (..) reg64 null [HSW] |
| 123 |
// brc (..) reg64 null [BDW+] |
| 124 |
JUMP_BINARY_BRC = (JUMP | BINARY) + 1, |
| 125 |
// (both sources) |
| 126 |
// brop (..) label16 label16 [PreBDW] |
| 127 |
// brop (..) label32 label32 [BDW+] |
| 128 |
// e.g. if, else (BDW+), goto, join |
| 129 |
JUMP_BINARY_IMM_IMM = JUMP_BINARY_BRC + 1, |
| 130 |
|
| 131 |
// send[c] (..) reg reg ex_desc desc |
| 132 |
SEND_UNARY = (SEND | HAS_DST | UNARY) + 1, |
| 133 |
// sends[c] (..) reg reg reg ex_desc desc |
| 134 |
// XE: send[c] (..) reg reg reg ex_desc desc |
| 135 |
|
| 136 |
SEND_BINARY = (SEND | HAS_DST | BINARY) + 1, |
| 137 |
|
| 138 |
// illegal or nop |
| 139 |
NULLARY = SPECIAL + 1, |
| 140 |
|
| 141 |
// SPECIFY: these two could be merged to SPECIAL_REG |
| 142 |
// since they both take a single register |
| 143 |
// |
| 144 |
// sync.<syctrl> (1) nreg |
| 145 |
// XE: |
| 146 |
// sync.<syctrl> (..) reg |
| 147 |
SYNC_UNARY = (SPECIAL | UNARY) + 2, |
| 148 |
QUINARY_SRC = (QUINARY | HAS_DST) + 1, |
| 149 |
}; |
| 150 |
// |
| 151 |
// various miscellaneous attributes about the operation |
| 152 |
enum Attr { |
| 153 |
NONE = 0, |
| 154 |
IS_BITWISE = 1, // and, asr, or, ror, rol, not, shl, shr, xor |
| 155 |
IS_SELECT = IS_BITWISE << 1, // sel (not csel) |
| 156 |
SUPPORTS_BRCTL = IS_SELECT << 1, |
| 157 |
SUPPORTS_FLAGMODIFIER = SUPPORTS_BRCTL << 1, |
| 158 |
SUPPORTS_PREDICATION = SUPPORTS_FLAGMODIFIER << 1, |
| 159 |
SUPPORTS_SATURATION = SUPPORTS_PREDICATION << 1, |
| 160 |
SUPPORTS_SRCMODS = SUPPORTS_SATURATION << 1, |
| 161 |
// aliases for combinations of predication, flag modifier, ... |
| 162 |
}; |
| 163 |
// |
| 164 |
// for various type mappings |
| 165 |
struct TypeMapping { |
| 166 |
uint32_t dsts; // convert to BitSet<Type,uint32_t> |
| 167 |
uint32_t srcs; // convert to BitSet<Type,uint32_t> |
| 168 |
}; |
| 169 |
// |
| 170 |
// virtual opcode / opcode enum value (not the machine-encoded value): |
| 171 |
// will be the same value on all platforms |
| 172 |
Op op; |
| 173 |
// |
| 174 |
// The platform for this operation; this is mainly for internal |
| 175 |
// methods. |
| 176 |
Platform platform; |
| 177 |
// |
| 178 |
// the physical opcode value encoded |
| 179 |
uint32_t opcode; // e.g. 0x1 for mov, 0x7E for nop |
| 180 |
// |
| 181 |
// the operation mnemonic; e.g. "addc" |
| 182 |
ModelString mnemonic; |
| 183 |
// |
| 184 |
// a high-level name for the operation (Name attr from BXML) |
| 185 |
// e.g. "Add With Carry" |
| 186 |
ModelString name; |
| 187 |
// |
| 188 |
// describes both the syntax and the encoding format for this |
| 189 |
// operation |
| 190 |
Format format; |
| 191 |
// |
| 192 |
// <EUOperandTypeMapping> from BXML. |
| 193 |
// (I think mov has the most ~22; expand if needed) |
| 194 |
TypeMapping typeMappings[24]; |
| 195 |
// |
| 196 |
// Wrap in an EnumBitset<OpAttr,uint32_t> to extract OpAttr's |
| 197 |
int attrs; |
| 198 |
// |
| 199 |
#if 0 |
| 200 |
constexpr OpSpec( |
| 201 |
Op _op, |
| 202 |
Platform _platform, |
| 203 |
uint32_t _opcode, |
| 204 |
const char *_mnemonic, |
| 205 |
const char *_name, |
| 206 |
Format _format, |
| 207 |
const TypeMapping _typeMappings[24], |
| 208 |
int _attrs) |
| 209 |
: op(_op), platform(_platform), opcode(_opcode), |
| 210 |
, mnemonic(_mnemonic), name(_name), |
| 211 |
format(_format), |
| 212 |
typeMappings(_typeMappings), attrs(_attrs) |
| 213 |
{ |
| 214 |
} |
| 215 |
OpSpec(const OpSpec &) = delete; |
| 216 |
#endif |
| 217 |
|
| 218 |
// returns false for reserved opcodes |
| 219 |
bool isValid() const { return !is(Op::INVALID); } |
| 220 |
// generic check of attributes the bits are 'Attr' |
| 221 |
bool hasAttrs(int a) const { return (a & attrs) != 0; } |
| 222 |
|
| 223 |
// compare the opcode more in a more readable manner than comparison |
| 224 |
bool is(Op _op) const { return op == _op; } |
| 225 |
// also disjunctive comparison |
| 226 |
bool isOneOf(Op op1, Op op2) const { return is(op1) || is(op2); } |
| 227 |
bool isOneOf(Op op1, Op op2, Op op3) const { |
| 228 |
return is(op1) || is(op2) || is(op3); |
| 229 |
} |
| 230 |
bool isOneOf(Op op1, Op op2, Op op3, Op op4) const { |
| 231 |
return is(op1) || is(op2) || is(op3) || is(op4); |
| 232 |
} |
| 233 |
|
| 234 |
////////////////////////////////////////////////////////////////////// |
| 235 |
// INSTRUCTION LEVEL IMPLICIT SYNTAX |
| 236 |
// e.g. 'nop' lacks an execution size and offset |
| 237 |
bool hasImpicitEm() const; |
| 238 |
|
| 239 |
////////////////////////////////////////////////////////////////////// |
| 240 |
// DESTINATION IMPLICIT VALUES FOR SYNTAX |
| 241 |
////////////////////////////////////////////////////////////////////// |
| 242 |
bool hasDstSubregister(bool isMacro) const; |
| 243 |
bool hasImplicitDstRegion(bool isMacro) const { |
| 244 |
Region rgn; |
| 245 |
return implicitDstRegion(rgn, isMacro); |
| 246 |
} |
| 247 |
Region implicitDstRegion(bool isMacro) const; |
| 248 |
bool implicitDstRegion(Region &rgn, bool isMacro) const; |
| 249 |
|
| 250 |
bool hasImplicitDstType() const { |
| 251 |
Type type; |
| 252 |
return implicitDstTypeVal(type); |
| 253 |
} |
| 254 |
Type implicitDstType() const { |
| 255 |
Type type = Type::INVALID; |
| 256 |
(void)implicitDstTypeVal(type); |
| 257 |
return type; |
| 258 |
} |
| 259 |
bool implicitDstTypeVal(Type &type) const; |
| 260 |
|
| 261 |
////////////////////////////////////////////////////////////////////// |
| 262 |
// SOURCE IMPLICIT VALUES FOR SYNTAX |
| 263 |
////////////////////////////////////////////////////////////////////// |
| 264 |
bool hasSrcSubregister(int srcOpIx, bool isMacro) const; |
| 265 |
|
| 266 |
// isMacro: pesky Op::MATH can sometimes be a macro (e.g. math.invm), |
| 267 |
// but typically is not (e.g. math.sqt, math.inv) |
| 268 |
bool hasImplicitSrcRegion(int srcOpIx, ExecSize es, bool isMacro) const; |
| 269 |
|
| 270 |
// The source index here corresponds to syntactic position, |
| 271 |
// not encoding position |
| 272 |
Region implicitSrcRegion(int srcOpIx, ExecSize es, bool isMacro) const; |
| 273 |
|
| 274 |
// a "default source type" is a type that we optionally place on an |
| 275 |
// operand; an example would be on a jmpi or while operand |
| 276 |
// e.g. while (..) -16 means while (..) -16:d |
| 277 |
// bool hasDefaultSrcType(int srcOpIx) const { |
| 278 |
// Type type; |
| 279 |
// return defaultSrcTypeVal(srcOpIx, type); |
| 280 |
// } |
| 281 |
// Type defaultSrcType(int srcOpIx) const { |
| 282 |
// Type type; |
| 283 |
// bool hasType = defaultSrcTypeVal(srcOpIx, type); |
| 284 |
// IGA_ASSERT(hasType, "src doesn't have default type"); |
| 285 |
// return type; |
| 286 |
// } |
| 287 |
// bool defaultSrcTypeVal(int srcOpIx, Type& type) const { |
| 288 |
// // TODO: pull from BXML tables |
| 289 |
// if (isTypedBranch()) { |
| 290 |
// // jmpi or call |
| 291 |
// type = Type::D; |
| 292 |
// return true; |
| 293 |
// } else { |
| 294 |
// type = Type::INVALID; |
| 295 |
// return false; |
| 296 |
// } |
| 297 |
// } |
| 298 |
|
| 299 |
bool isBranching() const { return (format & JUMP) != 0; } |
| 300 |
bool isBitwise() const { return hasAttrs(Attr::IS_BITWISE); } |
| 301 |
|
| 302 |
// currently branching ops that take an explicit type |
| 303 |
// in some cases we can elide this from syntax, in others we must |
| 304 |
// represent the type explicitly |
| 305 |
bool isTypedBranch() const; |
| 306 |
|
| 307 |
bool isSendFormat() const { return isOneOf(Op::SEND, Op::SENDC); } |
| 308 |
bool isSendsFormat() const { return isOneOf(Op::SENDS, Op::SENDSC); } |
| 309 |
bool isSendgFormat() const { return isOneOf(Op::SENDG, Op::SENDGC, Op::SENDGX, Op::SENDGXC); } |
| 310 |
// includes send, sends, or any other send formats |
| 311 |
bool isAnySendFormat() const { return (format & SEND) != 0; } |
| 312 |
|
| 313 |
bool isBinary() const { return (format & BINARY) != 0; } |
| 314 |
bool isTernary() const { return (format & TERNARY) != 0; } |
| 315 |
bool isQuinary() const { return (format & QUINARY) != 0; } |
| 316 |
|
| 317 |
// GED doesn't permit us to set execution offset for jmpi |
| 318 |
bool supportsQtrCtrl() const { return !is(Op::JMPI); } |
| 319 |
|
| 320 |
bool isJipAbsolute() const { return is(Op::CALLA); } |
| 321 |
|
| 322 |
bool supportsAccWrEn() const; |
| 323 |
|
| 324 |
// all ops exception illegal accept {Breakpoint} |
| 325 |
bool supportsDebugCtrl() const { return !is(Op::ILLEGAL); } |
| 326 |
|
| 327 |
bool supportsBranchCtrl() const { return hasAttrs(Attr::SUPPORTS_BRCTL); } |
| 328 |
|
| 329 |
bool supportsThreadCtrl() const { |
| 330 |
if (op == Op::NOP || op == Op::ILLEGAL || op == Op::THRYLD) |
| 331 |
return false; |
| 332 |
if (!isAnySendFormat()) |
| 333 |
return true; |
| 334 |
if (platform >= Platform::XE3) |
| 335 |
return false; |
| 336 |
return platform >= Platform::GEN9; |
| 337 |
} |
| 338 |
|
| 339 |
bool supportsPredication() const { |
| 340 |
return hasAttrs(Attr::SUPPORTS_PREDICATION); |
| 341 |
} |
| 342 |
bool supportsFlagModifier() const { |
| 343 |
return hasAttrs(Attr::SUPPORTS_FLAGMODIFIER); |
| 344 |
} |
| 345 |
bool supportsSaturation() const { |
| 346 |
return hasAttrs(Attr::SUPPORTS_SATURATION); |
| 347 |
} |
| 348 |
bool supportsSourceModifiers() const { |
| 349 |
return hasAttrs(Attr::SUPPORTS_SRCMODS); |
| 350 |
} |
| 351 |
|
| 352 |
// returns true if this instruction supports a subfunction of |
| 353 |
// some sorts; e.g. Op:MATH, Op::SEND, ... |
| 354 |
bool supportsSubfunction() const; |
| 355 |
|
| 356 |
// whether there is a destination (in syntax) |
| 357 |
bool supportsDestination() const { return (format & HAS_DST) != 0; } |
| 358 |
|
| 359 |
// we need to pass in the math function if the op is math |
| 360 |
// (use MathFC::INVALID if not applicable) |
| 361 |
unsigned getSourceCount(Subfunction sf) const; |
| 362 |
|
| 363 |
bool isVariableLatency() const; |
| 364 |
bool isFixedLatency() const; |
| 365 |
|
| 366 |
// this method determines if a source operand supports a default type |
| 367 |
// and returns it if so |
| 368 |
bool implicitSrcTypeVal(int srcOpIx, bool isImmOrLbl, Type &type) const; |
| 369 |
|
| 370 |
// An "implicit source type" is a type that should be omitted in syntax |
| 371 |
// if present, we simply warn the user (it can still mismatch the default) |
| 372 |
bool hasImplicitSrcType(int srcOpIx, bool immOrLbl) const { |
| 373 |
Type type = Type::INVALID; |
| 374 |
return implicitSrcTypeVal(srcOpIx, immOrLbl, type); |
| 375 |
} |
| 376 |
|
| 377 |
Type implicitSrcType(int srcOpIx, bool immOrLbl) const { |
| 378 |
Type type = Type::INVALID; |
| 379 |
(void)implicitSrcTypeVal(srcOpIx, immOrLbl, type); |
| 380 |
return type; |
| 381 |
} |
| 382 |
|
| 383 |
// if an instruction supports {NoDDClr,NoDDChk} |
| 384 |
bool supportsDepCtrl() const { |
| 385 |
return !isAnySendFormat() && platform < Platform::XE && !is(Op::NOP) && |
| 386 |
!is(Op::ILLEGAL); |
| 387 |
} |
| 388 |
|
| 389 |
// if an instruction and the platform supports {Fwd} in ISA encoding |
| 390 |
bool supportsFwdCtrl() const; |
| 391 |
|
| 392 |
// check if the instruction is binary (2-src) and has |
| 393 |
// ExecDataType |
| 394 |
bool isBinaryWithExecDataType() const; |
| 395 |
bool hasDstHorzStride() const; |
| 396 |
|
| 397 |
bool isDpasFormat() const { |
| 398 |
return isOneOf(Op::DPAS, Op::DPASW |
| 399 |
, |
| 400 |
Op::BDPAS |
| 401 |
); |
| 402 |
} |
| 403 |
bool isBDPAS() const { return is(Op::BDPAS); } |
| 404 |
}; // struct OpSpec |
| 405 |
} // namespace iga |
| 406 |
#endif // IGA_OPSPEC_HPP |