| 1 |
/*========================== begin_copyright_notice ============================ |
| 2 |
|
| 3 |
Copyright (C) 2020-2021 Intel Corporation |
| 4 |
|
| 5 |
SPDX-License-Identifier: MIT |
| 6 |
|
| 7 |
============================= end_copyright_notice ===========================*/ |
| 8 |
|
| 9 |
#include "OpSpec.hpp" |
| 10 |
#include "../asserts.hpp" |
| 11 |
|
| 12 |
using namespace iga; |
| 13 |
|
| 14 |
bool OpSpec::hasImpicitEm() const { |
| 15 |
switch (op) { |
| 16 |
case Op::SYNC: |
| 17 |
case Op::NOP: |
| 18 |
case Op::ILLEGAL: |
| 19 |
case Op::JMPI: |
| 20 |
case Op::WAIT: |
| 21 |
case Op::THRYLD: |
| 22 |
return true; |
| 23 |
default: |
| 24 |
return false; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
bool OpSpec::hasDstSubregister(bool isMacro) const { |
| 29 |
if (isDpasFormat()) |
| 30 |
return false; |
| 31 |
return !isMacro && !isAnySendFormat(); |
| 32 |
} |
| 33 |
|
| 34 |
Region OpSpec::implicitDstRegion(bool isMacro) const { |
| 35 |
Region rgn = Region::INVALID; |
| 36 |
bool hasRgn = implicitDstRegion(rgn, isMacro); |
| 37 |
IGA_ASSERT(hasRgn, "dst does not have an implicit region"); |
| 38 |
return rgn; |
| 39 |
} |
| 40 |
|
| 41 |
bool OpSpec::implicitDstRegion(Region &rgn, bool isMacro) const { |
| 42 |
if (isAnySendFormat()) { |
| 43 |
if (platform >= Platform::XE3) { |
| 44 |
rgn = Region::INVALID; |
| 45 |
return true; |
| 46 |
} |
| 47 |
rgn = Region::DST1; |
| 48 |
return true; |
| 49 |
} else if (isTypedBranch()) { |
| 50 |
// call and ret have an implicit <1> as well |
| 51 |
rgn = Region::DST1; |
| 52 |
return true; |
| 53 |
} else if (isMacro) { |
| 54 |
// e.g. madm and math.invm/sqrtm |
| 55 |
rgn = Region::DST1; |
| 56 |
return true; |
| 57 |
} else if (isDpasFormat()) { |
| 58 |
rgn = Region::DST1; |
| 59 |
return true; |
| 60 |
} else { |
| 61 |
rgn = Region::INVALID; |
| 62 |
return false; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
bool OpSpec::implicitDstTypeVal(Type &type) const { |
| 67 |
if (isAnySendFormat() && platform >= Platform::XE3) { |
| 68 |
type = Type::INVALID; |
| 69 |
return true; |
| 70 |
} |
| 71 |
if (isSendFormat() && platform >= Platform::GEN8) { |
| 72 |
type = Type::UD; |
| 73 |
if (platform >= Platform::XE) { |
| 74 |
type = Type::UB; |
| 75 |
} |
| 76 |
return true; |
| 77 |
} else if (isTypedBranch()) { |
| 78 |
type = Type::D; |
| 79 |
return true; |
| 80 |
} |
| 81 |
type = Type::INVALID; |
| 82 |
return false; |
| 83 |
} |
| 84 |
|
| 85 |
bool OpSpec::hasSrcSubregister(int srcOpIx, bool isMacro) const { |
| 86 |
// only src2 of dpas has a subregister |
| 87 |
if (isDpasFormat() && srcOpIx < 2) |
| 88 |
return false; |
| 89 |
// from the formatter used to use: |
| 90 |
// emitSubReg = !os.isAnySendFormat() && (os.op != Op::BRC || srcIx != 1) |
| 91 |
// => why BRC? |
| 92 |
// send instructions and math macros (including madm) don't emit |
| 93 |
// subregisters |
| 94 |
return !isAnySendFormat() && !isMacro; |
| 95 |
} |
| 96 |
|
| 97 |
bool OpSpec::hasImplicitSrcRegion(int srcOpIx, ExecSize es, |
| 98 |
bool isMacro) const { |
| 99 |
if (isAnySendFormat() && platform >= Platform::XE3) { |
| 100 |
// Xe3 uses INVALID as a "default" |
| 101 |
// OpSpec::implicitSrcRegion uses Region::INVALID as no implicit |
| 102 |
// src region ==> make an exception for this case |
| 103 |
return true; |
| 104 |
} |
| 105 |
return implicitSrcRegion(srcOpIx, es, isMacro) != Region::INVALID; |
| 106 |
} |
| 107 |
Region OpSpec::implicitSrcRegion(int srcOpIx, ExecSize execSize, |
| 108 |
bool isMacro) const { |
| 109 |
// TODO: fold this into implicitSrcRegionPtr and elide the macro hacking |
| 110 |
if (isAnySendFormat() && platform >= Platform::XE3) |
| 111 |
return Region::INVALID; |
| 112 |
// |
| 113 |
// TODO: this needs to work off the table from BXML |
| 114 |
if (isSendFormat() && platform < Platform::XE) { |
| 115 |
return Region::SRC010; |
| 116 |
} else if (isMacro) { |
| 117 |
if (isTernary()) { |
| 118 |
// ternary macro: e.g. madm |
| 119 |
if (srcOpIx == 2) { |
| 120 |
return Region::SRCXX1; |
| 121 |
} else { |
| 122 |
if (execSize == ExecSize::SIMD1) { |
| 123 |
return Region::SRC0X0; |
| 124 |
} else if (platform >= Platform::XE) { |
| 125 |
return Region::SRC1X0; |
| 126 |
} else { |
| 127 |
return Region::SRC2X1; |
| 128 |
} |
| 129 |
} |
| 130 |
} else { |
| 131 |
// basic macro: e.g. math.invm ... |
| 132 |
// math doesn't have implicit region on XE+ |
| 133 |
if (platform >= Platform::XE) |
| 134 |
return Region::INVALID; |
| 135 |
if (execSize == ExecSize::SIMD1) |
| 136 |
return Region::SRC010; |
| 137 |
else |
| 138 |
return Region::SRC221; |
| 139 |
} |
| 140 |
} else if (isSendFormat() || isSendsFormat()) { |
| 141 |
// no regions on send's |
| 142 |
return Region::SRC010; |
| 143 |
} else if (isDpasFormat()) { |
| 144 |
if (srcOpIx == 2) { |
| 145 |
// only an implicit region on src1 |
| 146 |
return Region::SRCXX1; |
| 147 |
} else { |
| 148 |
return Region::SRC1X0; |
| 149 |
} |
| 150 |
} else { |
| 151 |
if (platform >= Platform::XE && isBranching()) |
| 152 |
return Region::SRC110; |
| 153 |
|
| 154 |
if (srcOpIx == 0) { |
| 155 |
switch (op) { |
| 156 |
case Op::JMPI: |
| 157 |
case Op::CALL: |
| 158 |
case Op::CALLA: |
| 159 |
case Op::BRD: |
| 160 |
return Region::SRC010; |
| 161 |
// GED won't let us set 221 |
| 162 |
case Op::BRC: |
| 163 |
return Region::SRC221; |
| 164 |
case Op::RET: { |
| 165 |
if (platform >= Platform::XE) |
| 166 |
return Region::SRC010; |
| 167 |
else |
| 168 |
return Region::SRC221; |
| 169 |
} |
| 170 |
case Op::SYNC: |
| 171 |
return Region::SRC010; |
| 172 |
default:; // fallthrough to return nullptr |
| 173 |
} |
| 174 |
} else if (srcOpIx == 1) { |
| 175 |
// Encoder encodes Src0 into Src1, we have to lie here; |
| 176 |
// <2;2,1> gets manually set in Src0 explicitly by |
| 177 |
// the encoder, this is just for Src1 |
| 178 |
switch (op) { |
| 179 |
case Op::BRC: |
| 180 |
case Op::CALL: |
| 181 |
case Op::CALLA: |
| 182 |
return Region::SRC010; |
| 183 |
default:; // fallthrough to return nullptr |
| 184 |
} |
| 185 |
} |
| 186 |
return Region::INVALID; |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
bool OpSpec::isTypedBranch() const { |
| 191 |
// TODO: reduce this set as we are able to normalize bits |
| 192 |
return op == Op::BRD || op == Op::BRC || op == Op::RET || op == Op::JMPI || |
| 193 |
op == Op::CALL || op == Op::CALLA; |
| 194 |
} |
| 195 |
|
| 196 |
bool OpSpec::supportsAccWrEn() const { |
| 197 |
return |
| 198 |
// AccWrCtrl is removed from XeHPC |
| 199 |
(platform <= Platform::XE_HPG) && !supportsBranchCtrl() && |
| 200 |
!isBranching() && !isAnySendFormat() && !is(Op::NOP) && !is(Op::ILLEGAL); |
| 201 |
} |
| 202 |
|
| 203 |
bool OpSpec::supportsSubfunction() const { |
| 204 |
return supportsBranchCtrl() || |
| 205 |
isAnySendFormat() || |
| 206 |
op == Op::MATH || |
| 207 |
op == Op::SYNC || |
| 208 |
op == Op::BFN || |
| 209 |
op == Op::SHFL || |
| 210 |
op == Op::LFSR || |
| 211 |
op == Op::DNSCL || |
| 212 |
isDpasFormat(); |
| 213 |
} |
| 214 |
|
| 215 |
bool OpSpec::supportsFwdCtrl() const { |
| 216 |
if (!isDpasFormat()) |
| 217 |
return false; |
| 218 |
if (platform > Platform::XE3) |
| 219 |
return true; |
| 220 |
return false; |
| 221 |
} |
| 222 |
|
| 223 |
bool OpSpec::isBinaryWithExecDataType() const { |
| 224 |
if (platform >= Platform::XE3P_XPC && |
| 225 |
isBinary()) |
| 226 |
return true; |
| 227 |
return false; |
| 228 |
} |
| 229 |
|
| 230 |
bool OpSpec::hasDstHorzStride() const { |
| 231 |
return !isDpasFormat(); |
| 232 |
} |
| 233 |
|
| 234 |
unsigned OpSpec::getSourceCount(Subfunction sf) const { |
| 235 |
if (is(Op::MATH)) { |
| 236 |
IGA_ASSERT(sf.isValid(), "invalid math function"); |
| 237 |
return GetSourceCount(sf.math); |
| 238 |
} else if (format & UNARY) |
| 239 |
return 1; |
| 240 |
else if (format & BINARY) |
| 241 |
return 2; |
| 242 |
else if (format & TERNARY) |
| 243 |
return 3; |
| 244 |
else if (format & QUINARY) |
| 245 |
return 5; |
| 246 |
else |
| 247 |
return 0; |
| 248 |
} |
| 249 |
|
| 250 |
bool OpSpec::isVariableLatency() const { |
| 251 |
return isAnySendFormat() || |
| 252 |
(is(Op::MATH) && platform < Platform::XE_HPC) // XeHPC+ math is fixed |
| 253 |
|| isDpasFormat(); |
| 254 |
} |
| 255 |
|
| 256 |
bool OpSpec::isFixedLatency() const { |
| 257 |
switch (op) { |
| 258 |
case Op::SYNC: |
| 259 |
case Op::ILLEGAL: |
| 260 |
case Op::NOP: |
| 261 |
// these get shot down after DepChk |
| 262 |
return false; |
| 263 |
default: |
| 264 |
return !isVariableLatency(); |
| 265 |
} |
| 266 |
} |
| 267 |
|
| 268 |
bool OpSpec::implicitSrcTypeVal(int srcOpIx, bool isImmOrLbl, |
| 269 |
Type &type) const { |
| 270 |
if (isAnySendFormat() && platform >= Platform::XE3) { |
| 271 |
return false; |
| 272 |
} |
| 273 |
// TODO: pull from BXML data (ideally somehow in the syntax) |
| 274 |
if (isTypedBranch()) { |
| 275 |
// branches no longer take types in XE |
| 276 |
if (platform >= Platform::XE) { |
| 277 |
type = Type::INVALID; |
| 278 |
return true; |
| 279 |
} |
| 280 |
// e.g. jmpi, call, or brc |
| 281 |
// jmpi r12.3:d |
| 282 |
// brd r12.3:d |
| 283 |
// we make the |
| 284 |
if (op == Op::BRC) { |
| 285 |
// brc r12.3[:d] null[:ud] |
| 286 |
// brc LABEL[:d] LABEL[:d] |
| 287 |
type = srcOpIx == 0 || isImmOrLbl ? Type::D : Type::UD; |
| 288 |
} else { |
| 289 |
type = Type::D; |
| 290 |
} |
| 291 |
return true; |
| 292 |
} else if (isBranching()) { |
| 293 |
// if, else, endif, while, break, cont, goto, join, ... |
| 294 |
// let GED pick the defaults |
| 295 |
type = Type::INVALID; |
| 296 |
return true; |
| 297 |
} else if (isSendFormat() && platform < Platform::XE) { |
| 298 |
// TRB: we don't print the type on send instructions unless it's |
| 299 |
// not :ud, this allows us to phase out types on send operands |
| 300 |
// while meaningless, apparently there is a requirement on SKL |
| 301 |
// requiring the sampler to read the type from the operand. |
| 302 |
// |
| 303 |
// Types on sends are totally gone in XE. |
| 304 |
type = Type::UD; |
| 305 |
return true; |
| 306 |
} else if (isAnySendFormat()) { |
| 307 |
// for sends src0 is :ud, src1 has no type bits |
| 308 |
if (platform < Platform::XE) { |
| 309 |
type = srcOpIx == 0 ? Type::UD : Type::INVALID; |
| 310 |
} else { |
| 311 |
type = Type::UB; |
| 312 |
} |
| 313 |
return true; |
| 314 |
} else if (is(Op::SYNC)) { |
| 315 |
// sync imm32 has ud type |
| 316 |
// sync reg32 type is required |
| 317 |
// sync null type is ommitted |
| 318 |
if (isImmOrLbl) { |
| 319 |
type = Type::UD; |
| 320 |
return true; |
| 321 |
} |
| 322 |
type = Type::INVALID; |
| 323 |
return false; |
| 324 |
} else { |
| 325 |
type = Type::INVALID; |
| 326 |
return false; |
| 327 |
} |
| 328 |
} |