Debian Codegraph @

visa/iga/IGALibrary/Backend/Messages/E64/MessageDecoderLscE64.cpp

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2022-2023 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8 #include "../../../bits.hpp"
9 #include "MessageDecoderE64.hpp"
10
11 #include <tuple>
12
13 using namespace iga;
14
15 #define LSC_LOOKUP_TABLE(FIELD, OFF, LEN, TBL) \
16 lookupFromTable(FIELD, OFF, LEN, TBL, sizeof(TBL) / sizeof(TBL[0]))
17
18 ///////////////////////////
19 struct LscOpDesc : SimpleValidValue<SendOp> {
20 const char *type, *link;
21 constexpr LscOpDesc(uint32_t enc, SendOp val,
22 const char *desc, const char *syn, const char *t,
23 const char *l)
24 : SimpleValidValue<SendOp>(enc, val, desc, syn), type(t), link(l) {}
25 };
26 static constexpr LscOpDesc LSC_DP_OPCODE[]{
27 LscOpDesc{0x00, SendOp::LOAD, "load", "load vector",
28 "DP_LOAD", "71918"},
29 LscOpDesc{0x02, SendOp::LOAD_QUAD, "load_quad", "load quad (load_cmask)",
30 "DP_LOAD_CMASK", "71921"},
31 LscOpDesc{0x03, SendOp::LOAD_BLOCK2D, "load_block2d", "load 2d block array",
32 "DP_LOAD_2DBLOCK_ARRAY", "71920"},
33 //
34 LscOpDesc{0x04, SendOp::STORE, "store", "store vector",
35 "DP_STORE", "71922"},
36 LscOpDesc{0x06, SendOp::STORE_QUAD, "store_quad",
37 "store quad (store_cmask)",
38 "DP_STORE_CMASK", "71925"},
39 LscOpDesc{0x07, SendOp::STORE_BLOCK2D, "store_block2d", "store 2d block",
40 "DP_STORE_2DBLOCK", "71924"},
41 //
42 LscOpDesc{0x08, SendOp::ATOMIC_IINC, "atomic_iinc",
43 "atomic integer increment",
44 "DP_ATOMIC_INC", "71907"},
45 LscOpDesc{0x09, SendOp::ATOMIC_IDEC, "atomic_idec",
46 "atomic integer decrement",
47 "DP_ATOMIC_DEC", "71901"},
48 LscOpDesc{0x0A, SendOp::ATOMIC_LOAD, "atomic_load", "atomic load",
49 "DP_ATOMIC_LOAD", "71908"},
50 LscOpDesc{0x0B, SendOp::ATOMIC_STORE, "atomic_store",
51 "atomic store (exchange)",
52 "DP_STORE", "71922"},
53 LscOpDesc{0x0C, SendOp::ATOMIC_IADD, "atomic_iadd", "atomic integer add",
54 "DP_ATOMIC_ADD", "71898"},
55 LscOpDesc{0x0D, SendOp::ATOMIC_ISUB, "atomic_isub",
56 "atomic integer subtract",
57 "DP_ATOMIC_SUB", "71913"},
58 LscOpDesc{0x0E, SendOp::ATOMIC_SMIN, "atomic_smin",
59 "atomic signed integer minimum",
60 "DP_ATOMIC_MIN", "71910"},
61 LscOpDesc{0x0F, SendOp::ATOMIC_SMAX, "atomic_smax",
62 "atomic signed integer maximum",
63 "DP_ATOMIC_MAX", "71909"},
64 LscOpDesc{0x10, SendOp::ATOMIC_UMIN, "atomic_umin",
65 "atomic unsigned integer minimum",
66 "DP_ATOMIC_UMIN", "71915"},
67 LscOpDesc{0x11, SendOp::ATOMIC_UMAX, "atomic_umax",
68 "atomic unsigned integer maximum",
69 "DP_ATOMIC_UMAX", "71914"},
70 LscOpDesc{0x12, SendOp::ATOMIC_ICAS, "atomic_icas",
71 "atomic integer compare and swap",
72 "DP_ATOMIC_CMPXCHG", "71900"},
73 LscOpDesc{0x13, SendOp::ATOMIC_FADD, "atomic_fadd", "atomic float add",
74 "DP_ATOMIC_FADD", "71902"},
75 LscOpDesc{0x14, SendOp::ATOMIC_FSUB, "atomic_fsub",
76 "atomic float subtract",
77 "DP_ATOMIC_FSUB","71906"},
78 LscOpDesc{0x15, SendOp::ATOMIC_FMIN, "atomic_fmin", "atomic float min",
79 "DP_ATOMIC_FMIN", "71905"},
80 LscOpDesc{0x16, SendOp::ATOMIC_FMAX, "atomic_fmax", "atomic float max",
81 "DP_ATOMIC_FMAX", "71904"},
82 LscOpDesc{0x17, SendOp::ATOMIC_FCAS, "atomic_fcas",
83 "atomic float compare and swap",
84 "DP_ATOMIC_FCMPXCHG", "71903"},
85 LscOpDesc{0x18, SendOp::ATOMIC_AND, "atomic_and", "atomic and",
86 "DP_ATOMIC_AND", "71899"},
87 LscOpDesc{0x19, SendOp::ATOMIC_OR, "atomic_or", "atomic or",
88 "DP_ATOMIC_OR", "71911"},
89 LscOpDesc{0x1A, SendOp::ATOMIC_XOR, "atomic_xor", "atomic xor",
90 "DP_ATOMIC_XOR", "71916"},
91 LscOpDesc{0x1B, SendOp::LOAD_STATUS, "load_status", "load status",
92 "DP_LOAD_STATUS", "71935"},
93 LscOpDesc{0x1C, SendOp::LOAD_QUAD_STATUS, "load_quad_status",
94 "load quad status",
95 "DP_LOAD_CMASK_STATUS", "71950"},
96 // 0x1D CCS update is removed
97 LscOpDesc{0x1E, SendOp::READ_STATE, "read_state",
98 "read surface state info",
99 "DP_RSI", "71937"},
100 LscOpDesc{0x1F, SendOp::FENCE, "fence", "memory fence",
101 "DP_FENCE", "71917"},
102 // 0x20 STORE_UNCOMPRESSED_CMASK [REMOVED]
103 //
104
105 LscOpDesc{0x28, SendOp::ATOMIC_ACADD, "atomic_acadd",
106 "atomic append counter add",
107 "DP_APPENDCTR_ATOMIC_ADD", "71891"},
108 LscOpDesc{0x29, SendOp::ATOMIC_ACSUB, "atomic_acsub",
109 "atomic append counter subtract",
110 "DP_APPENDCTR_ATOMIC_SUB", "71897"},
111 LscOpDesc{0x2A, SendOp::ATOMIC_ACSTORE, "atomic_acstore",
112 "atomic append counter store",
113 "DP_APPENDCTR_ATOMIC_ST", "71896"},
114
115 LscOpDesc{0x2D, SendOp::GET_WATCHPOINT, "get_watchpoint", "get watchpoint",
116 "DP_GET_WATCHPOINT", "71942"},
117 LscOpDesc{0x2E, SendOp::SET_WATCHPOINT, "set_watchpoint", "set watchpoint",
118 "DP_SET_WATCHPOINT", "71943"},
119 //
120 // LscOpDesc{0x2F, SendOp::LOAD_ELEMENT, "load_element", "load element",
121 // "DP_LOAD_ELEMENT", "72107"},
122 // LscOpDesc{0x30, SendOp::LOAD_ELEMENT_WITH_STATUS,
123 // "load_element_with_status", "load element with a status value",
124 // "DP_LOAD_ELEMENT_STATUS", "72155"},
125
126 LscOpDesc{0x31, SendOp::LOAD_QUAD_MSRT, "load_quad_msrt",
127 "load quad from multi-sample render target",
128 "DP_LOAD_CMASK_MSRT", "73419"},
129 LscOpDesc{0x32, SendOp::STORE_QUAD_MSRT, "store_quad_msrt",
130 "store quad to multi-sample render target",
131 "DP_STORE_CMASK_MSRT", "73420"},
132 // TODO: BSPEC does not have a dedicated page for extended cache control at
133 // the moment
134 LscOpDesc{0x33, SendOp::EXTENDED_CACHE_CTRL, "extended_cache_control",
135 "extended cache control",
136 "DP_CCTRL", ""},
137 };
138
139 using LscVecSize = SimpleValidValue<int>;
140 static const LscVecSize LSC_VEC_SIZE[]{
141 LscVecSize{0x0, 1, "x1", "access 1 element per address"},
142 LscVecSize{0x1, 2, "x2", "access 2 elements per address"},
143 LscVecSize{0x2, 3, "x3", "access 3 element per address"},
144 LscVecSize{0x3, 4, "x4", "access 4 element per address"},
145 LscVecSize{0x4, 8, "x8", "access 8 element per address"},
146 LscVecSize{0x5, 16, "x16", "access 16 element per address"},
147 LscVecSize{0x6, 32, "x32", "access 32 element per address"},
148 LscVecSize{0x7, 64, "x64", "access 64 element per address"}};
149
150 static const LscDataSizeValidValue LSC_DATA_SIZE[]{
151 LscDataSizeValidValue{0x0, 8, 8, ".d8", "8b"},
152 LscDataSizeValidValue{0x1, 16, 16, ".d16", "16b"},
153 LscDataSizeValidValue{0x2, 32, 32, ".d32", "32b"},
154 LscDataSizeValidValue{0x3, 64, 64, ".d64", "64b"},
155 LscDataSizeValidValue{0x4, 8, 32, ".d8u32",
156 "8b zero-extended/truncated to 32b in GRF"},
157 LscDataSizeValidValue{0x5, 16, 32, ".d16u32",
158 "16b zero-extended/truncated to 32b in GRF"}};
159
160 ///////////////////////////////////////////////////////////////////////////////
161 // This handles LSC messages only
162 struct MessageDecoderLscE64 : MessageDecoderE64 {
163 MessageDecoderLscE64(Platform _platform, SFID _sfid, ExecSize _execSize,
164 int src0Len, int src1Len, uint64_t _desc, RegRef id0,
165 RegRef id1, DecodeResult &_result)
166 : MessageDecoderE64(_platform, _sfid, _execSize, src0Len, src1Len,
167 _desc, id0, id1, _result) {}
168
169 void decode();
170
171 private:
172 // enables us to decode stuff in a more flexible order
173 // and then we can blindly assembly the syntax at the end
174 std::string dataTypePrefixSyntax; // e.g. .d32
175 std::string vectorSuffixSyntax; // e.g. x16t (for d16x16t) or .yzw
176 std::string addrSizeSyntax; // e.g. .a32
177 std::string cacheControlSyntax; // e.g. .ca.ca.ca
178 std::string ovfSyntax; // e.g. .ovf
179 std::string extCacheControlSizeSyntax; // e.g. .64B
180 std::string extCacheControlOpSyntax; // e.g .set, .reset
181
182 SendOp op = SendOp::INVALID;
183
184 /////////////////////////////////////////////////////////////////////////////
185 void decodeUntyped(const SendOpDefinition &sOpInfo);
186
187 void addImplicitAddrTypeSURF();
188 void addDocsForAddrPayloadsUntypedLoadStoreAtomic();
189
190 void decodeDP_LOAD_STORE_STATELESS_DESC(const SendOpDefinition &sOpInfo);
191 void decodeDP_LOAD_STORE_STATEFUL_DESC(const SendOpDefinition &sOpInfo);
192
193 void decodeDP_ATOMIC_STATELESS_DESC(const SendOpDefinition &sOpInfo);
194 void decodeDP_ATOMIC_STATEFUL_DESC(const SendOpDefinition &sOpInfo);
195
196 void decodeDP_CMASK_STATELESS_DESC(const SendOpDefinition &sOpInfo);
197 void decodeDP_CMASK_STATEFUL_DESC(const SendOpDefinition &sOpInfo);
198
199 void decodeDP_2DBLOCK_DESC(const SendOpDefinition &sOpInfo);
200
201 void decodeDP_FENCE_DESC(const SendOpDefinition &sOpInfo);
202
203 void decodeTyped(const SendOpDefinition &sOpInfo);
204 void decodeDP_TYPED_CMASK_DESC(const SendOpDefinition &sOpInfo);
205 void decodeDP_TYPED_ATOMIC_DESC(const SendOpDefinition &sOpInfo);
206 void decodeDP_RSI_DESC(const SendOpDefinition &sOpInfo);
207
208 void decodeDP_WATCHPOINT_DESC();
209 void decodeDP_EXTENDED_CACHE_CTRL_DESC(const SendOpDefinition &sOpInfo);
210 ////////////////////////////////////
211 // helpers
212 void computePayloadSizesLoadStoreAtomic(const SendOpDefinition &sOpInfo);
213
214 void decodeAddrTypeSize();
215 void decodeAddrTypeUGM();
216 void decodeAddrTypeSLM();
217 void decodeAddrTypeURB();
218 void decodeAddrTypeSTATEFUL();
219 //
220 void decodeAddrScaling();
221 //
222 void decodeDataSize();
223 void decodeDataSizeWithRefs(const SendOpDefinition &sOpInfo);
224 void decodeVectorSize();
225 std::string decodeVectorSizeElems();
226 const LscDataSizeValidValue *decodeDataSizeValue();
227
228 //
229 void decodeCacheControl(SendOp sop);
230 void decodeOverfetch();
231 //
232 void decodeImmOffAddr(int off, int len);
233 void decodeImmOffCoord2D();
234 //
235 // the symbol to return in the MessageInfo structure
236 std::string symbolFromSyntax() const;
237
238 void decodeCacheControlSize();
239 void decodeCacheControlOperation();
240 }; // MessageDecoderLscE64
241
242 void MessageDecoderLscE64::decode() {
243 [[maybe_unused]] auto isValidSFID = [](SFID sfid) {
244 if (sfid == SFID::UGM || sfid == SFID::TGM || sfid == SFID::SLM ||
245 sfid == SFID::URB)
246 return true;
247 return false;
248 };
249 IGA_ASSERT(isValidSFID(sfid), "unexpected SFID");
250
251 const LscOpDesc *opDesc = LSC_LOOKUP_TABLE("SendOp", 0, 6, LSC_DP_OPCODE);
252 addReserved(6, 1);
253 if (opDesc == nullptr)
254 return;
255
256 if (opDesc->type || opDesc->link)
257 addDoc(DocRef::MSGOP, opDesc->type, opDesc->link);
258
259 result.info.op = opDesc->value;
260 result.syntax.mnemonic = opDesc->sym;
261 result.syntax.controls = ".";
262 result.syntax.controls += ToSyntax(sfid);
263
264 const SendOpDefinition &sOpInfo = lookupSendOp(opDesc->value);
265 if (!sOpInfo.isValid())
266 return;
267 if (sOpInfo.hasChMask()) {
268 result.info.addAttr(MessageInfo::Attr::HAS_CHMASK);
269 }
270
271 // no LSC messages use ind1
272 if (indDesc1 != REGREF_INVALID) {
273 error(0, 6, "IND1 is forbidden on this message");
274 }
275
276 if (sfid == SFID::TGM) {
277 result.info.addAttr(MessageInfo::Attr::TYPED);
278 decodeTyped(sOpInfo);
279 } else {
280 decodeUntyped(sOpInfo);
281 }
282
283 result.syntax.controls += dataTypePrefixSyntax + vectorSuffixSyntax +
284 addrSizeSyntax + ovfSyntax + cacheControlSyntax +
285 extCacheControlOpSyntax + extCacheControlSizeSyntax;
286
287 constructSurfaceSyntax();
288
289 result.info.symbol = sOpInfo.mnemonic;
290 result.info.description = symbolFromSyntax();
291 }
292
293 void MessageDecoderLscE64::decodeUntyped(const SendOpDefinition &sOpInfo) {
294 if (sfid == SFID::SLM) {
295 result.info.addAttr(MessageInfo::Attr::SLM);
296 }
297
298 bool stateful = false;
299 if (sOpInfo.op != SendOp::FENCE && sOpInfo.op != SendOp::EXTENDED_CACHE_CTRL) {
300 // only UGM, URB, SLM message that lacks AddrTypeSize
301 decodeAddrTypeSize();
302 stateful = result.info.addrType == AddrType::SURF;
303 }
304 if (sOpInfo.op == SendOp::EXTENDED_CACHE_CTRL) {
305 // extended cache control has A64 address type
306 addrSizeSyntax = ".a64";
307 }
308
309 switch (sOpInfo.op) {
310 case SendOp::LOAD:
311 case SendOp::LOAD_STATUS:
312 case SendOp::STORE:
313 if (stateful) {
314 decodeDP_LOAD_STORE_STATEFUL_DESC(sOpInfo);
315 } else {
316 decodeDP_LOAD_STORE_STATELESS_DESC(sOpInfo);
317 }
318 break;
319 case SendOp::LOAD_QUAD:
320 case SendOp::LOAD_QUAD_STATUS:
321 case SendOp::STORE_QUAD:
322 if (stateful) {
323 decodeDP_CMASK_STATEFUL_DESC(sOpInfo);
324 } else {
325 decodeDP_CMASK_STATELESS_DESC(sOpInfo);
326 }
327 break;
328 case SendOp::LOAD_BLOCK2D:
329 case SendOp::STORE_BLOCK2D:
330 if (stateful) {
331 error(14, 2, "AddrTypeSize must be FLAT_A64_A64 for block2d");
332 }
333 decodeDP_2DBLOCK_DESC(sOpInfo);
334 break;
335 case SendOp::FENCE:
336 decodeDP_FENCE_DESC(sOpInfo);
337 break;
338 case SendOp::GET_WATCHPOINT:
339 case SendOp::SET_WATCHPOINT:
340 decodeDP_WATCHPOINT_DESC();
341 break;
342 case SendOp::EXTENDED_CACHE_CTRL:
343 decodeDP_EXTENDED_CACHE_CTRL_DESC(sOpInfo);
344 break;
345 default:
346 if (sOpInfo.isAtomic()) {
347 if (stateful) {
348 decodeDP_ATOMIC_STATEFUL_DESC(sOpInfo);
349 } else {
350 decodeDP_ATOMIC_STATELESS_DESC(sOpInfo);
351 }
352 } else {
353 error(0, 6, "unhandled SendOp");
354 }
355 }
356 }
357
358 ///////////////////////////////////////////////////////////////////////////////
359 void MessageDecoderLscE64::addImplicitAddrTypeSURF() {
360 result.info.addrType = AddrType::SURF;
361 result.info.addrSizeBits = 32;
362 result.info.uniformBaseAddrSizeBits = 0;
363 result.info.surfaceState = indDesc0;
364 addDoc(DocRef::IND0, "DP_INDIR0_STATEFUL_DESC", "72036");
365 }
366
367 void MessageDecoderLscE64::addDocsForAddrPayloadsUntypedLoadStoreAtomic() {
368 if (result.info.addrType == AddrType::SURF && indDesc0 != REGREF_INVALID) {
369 addDoc(DocRef::IND0, "DP_INDIR0_STATEFUL_DESC", "72036");
370 } else {
371 addDoc(DocRef::IND0, "DP_INDIR0_STATELESS_DESC", "71955");
372 }
373
374 const auto transpose = getDescBits(10, 1) != 0;
375 if (transpose) {
376 // same for all transpose even stateful etc...
377 // "If the address size is A16 or A32, then the
378 // most significant bits will be unused."
379 addDoc(DocRef::SRC0, "A64_PAYLOAD_SIMT1", "71967");
380 } else if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32) {
381 if (result.info.addrSizeBits == 32) {
382 addDoc(DocRef::SRC0, "A32_PAYLOAD", "71964");
383 } else {
384 addDoc(DocRef::SRC0, "A64_PAYLOAD", "71966");
385 }
386 } else {
387 if (result.info.addrSizeBits == 32) {
388 addDoc(DocRef::SRC0, "A32_PAYLOAD_SIMT16", "71965");
389 } else {
390 addDoc(DocRef::SRC0, "A64_PAYLOAD_SIMT16", "71968");
391 }
392 }
393 }
394
395 void MessageDecoderLscE64::decodeDP_LOAD_STORE_STATELESS_DESC(
396 const SendOpDefinition &sOpInfo)
397 {
398 addDoc(DocRef::DESC, "DP_LOAD_STORE_STATELESS_DESC", "71885");
399 addDocsForAddrPayloadsUntypedLoadStoreAtomic();
400
401 // Already decoded:
402 // [5:0] Opcode
403 // [6] reserved
404 // [15:14] AddrTypeSize
405 // New fields:
406 // [10:10] Transpose
407 // [9:7] VectorSize
408 decodeVectorSize(); // includes transpose
409 // [13:11] DataSize
410 decodeDataSizeWithRefs(sOpInfo);
411 // [19:16] CacheOverride
412 decodeCacheControl(sOpInfo.op);
413 // [20] Reserved
414 addReserved(20, 1);
415 // [21] Overfetch
416 decodeOverfetch();
417 // [43:22] GlobalOffset
418 decodeImmOffAddr(22, 43 - 22 + 1);
419 // [45:44] OffsetScaling
420 decodeAddrScaling();
421 // [46] Reserved
422 addReserved(46, 1);
423
424 computePayloadSizesLoadStoreAtomic(sOpInfo);
425 }
426
427 ///////////////////////////////////////////////////////////////////////////////
428 void MessageDecoderLscE64::decodeDP_LOAD_STORE_STATEFUL_DESC(
429 const SendOpDefinition &sOpInfo)
430 {
431 addDoc(DocRef::DESC, "DP_LOAD_STORE_STATEFUL_DESC", "72045");
432 addDocsForAddrPayloadsUntypedLoadStoreAtomic();
433
434 // Already decoded:
435 // [5:0] Opcode
436 // [6] reserved
437 // [15:14] AddrTypeSize
438 // New fields:
439 // [10:10] Transpose
440 // [9:7] VectorSize
441 decodeVectorSize(); // includes transpose
442 // [13:11] DataSize
443 decodeDataSizeWithRefs(sOpInfo);
444 // [19:16] CacheOverride
445 decodeCacheControl(sOpInfo.op);
446 // [20] Reserved
447 addReserved(20, 1);
448 // [21] Overfetch
449 decodeOverfetch();
450 // [26:22] Surface State Index
451 decodeSsIdx();
452 // [43:27] GlobalOffset
453 decodeImmOffAddr(27, 43 - 27 + 1);
454 // [45:44] OffsetScaling
455 decodeAddrScaling();
456 // [46] Reserved
457 addReserved(46, 1);
458
459 computePayloadSizesLoadStoreAtomic(sOpInfo);
460 }
461
462 void MessageDecoderLscE64::decodeDP_ATOMIC_STATELESS_DESC(
463 const SendOpDefinition &sOpInfo)
464 {
465 addDoc(DocRef::DESC, "DP_ATOMIC_STATELESS_DESC", "71876");
466 addDocsForAddrPayloadsUntypedLoadStoreAtomic();
467
468 // Already decoded:
469 // [5:0] Opcode
470 // [6] reserved
471 // [15:14] AddrTypeSize
472 // New fields:
473 // [10:10] Transpose (forbidden in atmoics)
474 // [9:7] VectorSize
475 decodeVectorSize();
476 // [13:11] DataSize
477 decodeDataSizeWithRefs(sOpInfo);
478 if (result.info.isTransposed())
479 error(10, 1, "transpose forbidding on atomic operations");
480 // [19:16] CacheOverride
481 decodeCacheControl(sOpInfo.op);
482 // [21:20] Reserved (overfetch forbidding since L1 is always .uc)
483 addReserved(20, 2);
484 // [43:22] GlobalOffset
485 decodeImmOffAddr(22, 43 - 22 + 1);
486 // [45:44] OffsetScaling
487 decodeAddrScaling();
488 // [46] Reserved
489 addReserved(46, 1);
490
491 computePayloadSizesLoadStoreAtomic(sOpInfo);
492 }
493
494 void MessageDecoderLscE64::decodeDP_ATOMIC_STATEFUL_DESC(
495 const SendOpDefinition &sOpInfo)
496 {
497 addDoc(DocRef::DESC, "DP_ATOMIC_STATEFUL_DESC", "72047");
498 addDocsForAddrPayloadsUntypedLoadStoreAtomic();
499
500 // Already decoded:
501 // [5:0] Opcode
502 // [6] reserved
503 // [15:14] AddrTypeSize
504 // New fields:
505 // [10:10] Transpose (forbidden in atmoics)
506 // [9:7] VectorSize
507 decodeVectorSize(); // includes transpose
508 // [13:11] DataSize
509 decodeDataSizeWithRefs(sOpInfo);
510 // [19:16] CacheOverride
511 decodeCacheControl(sOpInfo.op);
512 // [20] Reserved (overfetch forbidden since L1 requires .uc)
513 addReserved(20, 2);
514 // [26:22] Surface State Index
515 decodeSsIdx();
516 // [43:27] GlobalOffset
517 decodeImmOffAddr(27, 43 - 27 + 1);
518 // [45:44] OffsetScaling
519 decodeAddrScaling();
520 // [46] Reserved
521 addReserved(46, 1);
522
523 computePayloadSizesLoadStoreAtomic(sOpInfo);
524 }
525
526 void MessageDecoderLscE64::decodeDP_CMASK_STATELESS_DESC(
527 const SendOpDefinition &sOpInfo) {
528 addDoc(DocRef::DESC, "DP_CMASK_STATELESS_DESC", "71874");
529 addDocsForAddrPayloadsUntypedLoadStoreAtomic();
530
531 // Already decoded:
532 // [5:0] Opcode
533 // [6] reserved
534 // [15:14] AddrTypeSize
535 // New fields:
536 // [10:7] ChMask
537 decodeVectorSize();
538 // [13:11] DataSize
539 decodeDataSizeWithRefs(sOpInfo);
540 // [19:16] CacheOverride
541 decodeCacheControl(sOpInfo.op);
542 // [20] Reserved
543 addReserved(20, 1);
544 // [21] Overfetch
545 decodeOverfetch();
546 // [43:22] GlobalOffset
547 decodeImmOffAddr(22, 43 - 22 + 1);
548 // [45:44] OffsetScaling
549 decodeAddrScaling();
550 // [46] Reserved
551 addReserved(46, 1);
552
553 computePayloadSizesLoadStoreAtomic(sOpInfo);
554 }
555
556 void MessageDecoderLscE64::decodeDP_CMASK_STATEFUL_DESC(
557 const SendOpDefinition &sOpInfo) {
558 addDoc(DocRef::DESC, "DP_CMASK_STATEFUL_DESC", "72046");
559 addDocsForAddrPayloadsUntypedLoadStoreAtomic();
560
561 // Already decoded:
562 // [5:0] Opcode
563 // [6] reserved
564 // [15:14] AddrTypeSize
565 // New fields:
566 // [10:7] ChMask
567 decodeVectorSize();
568 // [13:11] DataSize
569 decodeDataSizeWithRefs(sOpInfo);
570 // [19:16] CacheOverride
571 decodeCacheControl(sOpInfo.op);
572 // [20] Reserved
573 addReserved(20, 1);
574 // [21] Overfetch
575 decodeOverfetch();
576 // [26:22] Surface State Index
577 decodeSsIdx();
578 // [43:27] GlobalOffset
579 decodeImmOffAddr(27, 43 - 27 + 1);
580 // [45:44] OffsetScaling
581 decodeAddrScaling();
582 // [46] Reserved
583 addReserved(46, 1);
584
585 computePayloadSizesLoadStoreAtomic(sOpInfo);
586 }
587
588 void MessageDecoderLscE64::decodeDP_2DBLOCK_DESC(
589 const SendOpDefinition &sOpInfo)
590 {
591 addDoc(DocRef::DESC, "DP_2DBLOCK_DESC", "71884");
592 if (sfid == SFID::TGM) {
593 addDoc(DocRef::SRC0, "ATYPED2DBLOCK_PAYLOAD", "71983");
594 } else {
595 addDoc(DocRef::SRC0, "A2DBLOCK_PAYLOAD", "71984");
596 }
597
598 // Already decoded:
599 // [5:0] Opcode
600 // [6] Reserved
601 // [15:14] AddrTypeSize (for untyped)
602 if (sfid == SFID::TGM) {
603 decodeAddrTypeSTATEFUL(); // TGM stateful
604 }
605 // New fields:
606 // [8:7] Reserved
607 addReserved(7, 2);
608 // [10] Transpose
609 decodeField("Transpose", 10, 1, [&](uint32_t val, std::stringstream &ss) {
610 if (val)
611 vectorSuffixSyntax += "t";
612 });
613 // [9] VNNI
614 decodeField("VNNI", 9, 1, [&](uint32_t val, std::stringstream &ss) {
615 if (val)
616 vectorSuffixSyntax += "v";
617 });
618 // [13:11] DataSize
619 decodeDataSize();
620 // [19:16] CacheOverride
621 decodeCacheControl(sOpInfo.op);
622 // [21:20] Reserved
623 addReserved(20, 2);
624 // [45:22] (GlobalOffsetX,GlobalOffsetY)
625 decodeImmOffCoord2D();
626 // [46] Reserved
627 addReserved(46, 1);
628
629 computePayloadSizesLoadStoreAtomic(sOpInfo);
630 }
631
632 void MessageDecoderLscE64::decodeDP_FENCE_DESC(
633 const SendOpDefinition &sOpInfo)
634 {
635 addDoc(DocRef::DESC, "DP_FENCE_DESC", "71877");
636
637 if (result.info.execWidth > 1)
638 error(0, 6, "ExecSize should be 1");
639 else if (result.info.execWidth <= 0)
640 result.info.execWidth = 1;
641
642 addReserved(7, 1);
643
644 std::string ftMeaning, ftSym;
645 auto ft = getDescBits(8, 3);
646 switch (ft) {
647 case 0x0:
648 ftMeaning = "None";
649 ftSym = "none";
650 break;
651 case 0x1:
652 ftMeaning = "Evict (for R/W evict dirty (M to I) and invalidate clean; "
653 "for R/O invalide clean)";
654 ftSym = "evict";
655 break;
656 case 0x2:
657 ftMeaning = "Invalidate (Invalidate clean lines)";
658 ftSym = "invalidate";
659 break;
660 case 0x3:
661 ftMeaning = "Discard (for R/W invalidate dirty (M to I) without "
662 "writeback to next level; nop for R/O)";
663 ftSym = "discard";
664 break;
665 case 0x4:
666 ftMeaning = "Clean (for R/W writeback dirty to next level but keep in "
667 "cache as clean (M to V); nop for R/O)";
668 ftSym = "clean";
669 break;
670 default:
671 ftMeaning = "???";
672 ftSym = "?";
673 error(8, 3, "invalid flush op");
674 break;
675 }
676 result.syntax.controls += "." + ftSym;
677 addField("DP_FLUSH_TYPE", 8, 3, ft, ftMeaning);
678
679 std::string scMeaning, scSym;
680 auto sc = getDescBits(11, 3);
681 switch (sc) {
682 case 0x0:
683 scMeaning = "Threadgroup";
684 scSym = "group";
685 break;
686 case 0x1:
687 scMeaning = "Local (subslice)";
688 scSym = "core";
689 break;
690 case 0x2:
691 scMeaning = "Tile";
692 scSym = "tile";
693 break;
694 case 0x3:
695 scMeaning = "GPU";
696 scSym = "gpu";
697 break;
698 case 0x4:
699 scMeaning = "GPUs";
700 scSym = "gpus";
701 break;
702 case 0x5:
703 scMeaning = "System Release";
704 scSym = "sysrel";
705 break;
706 case 0x6:
707 scMeaning = "System Acquire";
708 scSym = "sysacq";
709 break;
710 default:
711 scMeaning = "???";
712 scSym = "?";
713 error(8, 3, "invalid flush scope");
714 break;
715 }
716 result.syntax.controls += "." + scSym;
717 addField("DP_FENCE_SCOPE", 11, 3, sc, scMeaning);
718
719 addReserved(14, 46 - 14 + 1);
720
721 result.syntax.layout = MessageSyntax::Layout::CONTROL;
722
723 result.info.dstLenBytes = 0;
724 result.info.src0LenBytes = BYTES_PER_REGISTER;
725 result.info.src1LenBytes = 0;
726 }
727
728 void MessageDecoderLscE64::decodeTyped(const SendOpDefinition &sOpInfo) {
729 bool opSupportsUvr = sOpInfo.op == SendOp::LOAD_QUAD ||
730 sOpInfo.op == SendOp::STORE_QUAD ||
731 sOpInfo.op == SendOp::LOAD_QUAD_MSRT ||
732 sOpInfo.op == SendOp::STORE_QUAD_MSRT ||
733 sOpInfo.op == SendOp::LOAD_QUAD_STATUS ||
734 sOpInfo.op == SendOp::LOAD_BLOCK2D ||
735 sOpInfo.op == SendOp::STORE_BLOCK2D ||
736 sOpInfo.op == SendOp::STORE_UNCOMPRESSED_QUAD ||
737 sOpInfo.isAtomic();
738 if (opSupportsUvr) {
739 result.info.attributeSet |= MessageInfo::Attr::HAS_UVRLOD;
740 }
741
742 switch (sOpInfo.op) {
743 case SendOp::FENCE:
744 decodeDP_FENCE_DESC(sOpInfo);
745 break;
746 case SendOp::READ_STATE:
747 decodeDP_RSI_DESC(sOpInfo);
748 break;
749 case SendOp::LOAD_QUAD:
750 case SendOp::STORE_QUAD:
751 case SendOp::LOAD_QUAD_MSRT:
752 case SendOp::STORE_QUAD_MSRT:
753 case SendOp::LOAD_QUAD_STATUS:
754 decodeDP_TYPED_CMASK_DESC(sOpInfo);
755 break;
756 case SendOp::LOAD_BLOCK2D:
757 case SendOp::STORE_BLOCK2D:
758 decodeDP_2DBLOCK_DESC(sOpInfo);
759 break;
760 default:
761 if (sOpInfo.isAtomic()) {
762 decodeDP_TYPED_ATOMIC_DESC(sOpInfo);
763 } else {
764 error(0, 6, "invalid op for TGM");
765 }
766 }
767 }
768
769 void MessageDecoderLscE64::decodeDP_TYPED_CMASK_DESC(
770 const SendOpDefinition &sOpInfo)
771 {
772 addDoc(DocRef::DESC, "DP_TYPED_CMASK_DESC", "71882");
773 if (execSize == ExecSize::SIMD32 || execSize == ExecSize::INVALID) {
774 addDoc(DocRef::SRC0, "A32_PAYLOAD_TYPED", "71953");
775 } else {
776 addDoc(DocRef::SRC0, "A32_PAYLOAD_TYPED_SIMT16", "71952");
777 }
778
779 addImplicitAddrTypeSURF();
780
781 // Already decoded:
782 // [5:0] Opcode
783 // [6] reserved (EnableLSCBacking)
784 // New fields:
785 // [13:11] SurfaceTypeHint
786 decodeSurfaceTypeHint();
787 // [10:7] ChMask
788 decodeVectorSize();
789 // [14] AddressInputFormat
790 decodeField("AddressInputFormat", 14, 1,
791 [&] (uint32_t val, std::stringstream &ss) {
792 addrSizeSyntax = (val == 0 ? ".a32" : ".a16");
793 result.info.addrSizeBits = (val == 0 ? 32 : 16);
794 ss << (val == 0 ? "AIF32" : "AIF16");
795 });
796 // [15] DataReturnFormat
797 decodeField("DataReturnFormat", 15, 1,
798 [&] (uint32_t val, std::stringstream &ss) {
799 dataTypePrefixSyntax = (val == 0 ? ".d32" : ".d16");
800 result.info.elemSizeBitsRegFile = (val == 0 ? 32 : 16);
801 result.info.elemSizeBitsMemory = result.info.elemSizeBitsRegFile;
802 ss << (val == 0 ? "DRF32" : "DRF16");
803 });
804 // [19:16] CacheOverride
805 decodeCacheControl(sOpInfo.op);
806 // [21:20] Reserved
807 addReserved(20, 2);
808 // [26:22] Surface State Index
809 decodeSsIdx();
810 // [29:27] Reserved
811 addReserved(27, 3);
812 // [41:30] UVR offsets (R, V, U)
813 decodeUvrOffsets();
814 // [46:42] Reserved (no IND1 either for TGM)
815 addReserved(42, 46 - 42 + 1);
816
817 computePayloadSizesLoadStoreAtomic(sOpInfo);
818 }
819
820 void MessageDecoderLscE64::decodeDP_TYPED_ATOMIC_DESC(
821 const SendOpDefinition &sOpInfo)
822 {
823 addDoc(DocRef::DESC, "DP_TYPED_ATOMIC_DESC", "71883");
824 if (execSize == ExecSize::SIMD32 || execSize == ExecSize::INVALID) {
825 addDoc(DocRef::SRC0, "A32_PAYLOAD_TYPED", "71953");
826 } else {
827 addDoc(DocRef::SRC0, "A32_PAYLOAD_TYPED_SIMT16", "71952");
828 }
829
830 addImplicitAddrTypeSURF();
831
832 // Already decoded:
833 // [5:0] Opcode
834 // [6] reserved
835 // New fields:
836 // [10:10] Transpose (forbidden in atmoics)
837 // [9:7] VectorSize DP_VECTOR_SIZE
838 decodeVectorSize(); // should be V1 and non-transpose
839 // [13:11] DataSize DP_DATA_SIZE
840 decodeDataSizeWithRefs(sOpInfo);
841 if (result.info.elemsPerAddr != 1)
842 error(9, 3, "atomics should be V1");
843 if (result.info.isTransposed())
844 error(9, 3, "atomics must be non-transposed");
845 // [15:14] AddrTypeSize DP_GLOBAL_ADDRESS_TYPE_SIZE
846 decodeAddrTypeSTATEFUL();
847 // [19:16] CacheOverride DP_CACHE_ATOMIC
848 decodeCacheControl(sOpInfo.op);
849 // [21:20] Reserved
850 addReserved(20, 2);
851 // [26:22] Surface State Index
852 decodeSsIdx();
853 // [29:27] Reserved
854 addReserved(27, 3);
855 // [41:30] UVR offsets (R, V, U)
856 decodeUvrOffsets();
857 // [46:42] Reserved
858 addReserved(42, 46 - 42 + 1);
859
860 computePayloadSizesLoadStoreAtomic(sOpInfo);
861 }
862 void MessageDecoderLscE64::decodeDP_RSI_DESC(
863 const SendOpDefinition &sOpInfo)
864 {
865 addDocs(DocRef::DESC, "DP_RSI_DESC", "71938",
866 DocRef::SRC0, "DP_ASTATE_INFO_PAYLOAD", "71980",
867 DocRef::DST, "DP_STATE_INFO_PAYLOAD", "71990");
868
869 addImplicitAddrTypeSURF();
870
871 // Already decoded:
872 // [5:0] Opcode
873 // [6] reserved
874 // New fields:
875 // [9:7] RSI Sub-Opcode
876 decodeField("RSISubOpcode", 7, 3, [&](uint32_t val, std::stringstream &ss) {
877 if (val != 0)
878 error(7, 3, "only 0 supported as RSI subop");
879 });
880 // [13:10] Reserved
881 addReserved(10, 4);
882 // [15:14] AddrTypeSize DP_GLOBAL_ADDRESS_TYPE_SIZE
883 decodeAddrTypeSTATEFUL();
884 // [21:16] Reserved
885 addReserved(16, 21 - 16 + 1);
886 // [26:22] Surface State Index
887 decodeSsIdx();
888 // [46:27] Reserved
889 addReserved(27, 46 - 27 + 1);
890
891 result.info.dstLenBytes = BYTES_PER_REGISTER;
892 result.info.src0LenBytes = 16; // 4 DW (U, V, R, LoD) (apparently)
893 result.info.src1LenBytes = 0;
894 }
895
896 void MessageDecoderLscE64::decodeDP_EXTENDED_CACHE_CTRL_DESC(
897 const SendOpDefinition &sOpInfo) {
898 addDoc(DocRef::DESC, "DP_CCTRL_DESC", "74342");
899
900 // [19:16] cache policy
901 // [15:13] reserved
902 // [12:11] cache control size
903 // [10:7] cache control operation
904 // [6] reserved
905
906 decodeCacheControl(sOpInfo.op);
907 addReserved(13, 3);
908 decodeCacheControlSize();
909 decodeCacheControlOperation();
910 addReserved(6, 1);
911 }
912
913
914 void MessageDecoderLscE64::decodeDP_WATCHPOINT_DESC() {
915 bool isGet = result.info.op == SendOp::GET_WATCHPOINT;
916 if (isGet) {
917 addDocs(DocRef::DESC, "DP_WATCHPOINT_DESC", "71944",
918 DocRef::SRC0, "DP_GET_WATCHPOINT_PAYLOAD", "71979");
919 } else {
920 addDocs(DocRef::DESC, "DP_WATCHPOINT_DESC", "71944",
921 DocRef::SRC0, "DP_GET_WATCHPOINT_PAYLOAD", "71981");
922 }
923 if (result.info.execWidth <= 0) {
924 result.info.execWidth = 1;
925 } else if (result.info.execWidth != 1) {
926 error(0, 6, "ExecSize should be 1");
927 }
928 if (indDesc0 != REGREF_INVALID) {
929 error(0, 6, "IND0 is forbidden on this message");
930 }
931
932 decodeField("WatchpointRegister", 7, 3,
933 [&](uint32_t enc, std::stringstream &ss) {
934 ss << "register " << enc;
935 std::stringstream wss;
936 wss << "." << addrSizeSyntax << ".w" << enc;
937 result.syntax.controls += wss.str();
938 });
939 // addReserved(6, 1); (caller adds)
940 addReserved(10, 4);
941 // addrType (handled by caller)
942 addReserved(16, 46 - 16 + 1);
943
944 result.info.dstLenBytes = 0;
945 if (isGet) {
946 result.info.dstLenBytes = 10; // [74:0]
947 }
948 result.info.src0LenBytes = 0;
949 result.info.src1LenBytes = 0;
950 if (!isGet) {
951 result.info.src1LenBytes = 10; // [74:0]
952 }
953 }
954
955 ////////////////////////////////////////////////////////////////////////////
956 void MessageDecoderLscE64::computePayloadSizesLoadStoreAtomic(
957 const SendOpDefinition &sOpInfo)
958 {
959 bool isBlock2d = result.info.op == SendOp::LOAD_BLOCK2D ||
960 result.info.op == SendOp::STORE_BLOCK2D;
961 bool isLoadStatus = result.info.op == SendOp::LOAD_STATUS ||
962 result.info.op == SendOp::LOAD_QUAD_STATUS;
963
964 if (result.info.execWidth < 0) {
965 if (result.info.isTransposed() || isBlock2d) {
966 result.info.execWidth = 1;
967 } else {
968 result.info.execWidth = 32;
969 }
970 // guess execution size
971 warning(0, 6, "assuming ExecSize (", result.info.execWidth, ")");
972 }
973
974 int dataBytes = 0;
975
976 if (isBlock2d) {
977 dataBytes = -1; // unknown (buried in the payload header)
978 if (sfid == SFID::TGM) {
979 result.info.src0LenBytes = 30;
980 } else {
981 result.info.src0LenBytes = 31; // payload slightly larger for ugm
982 }
983 } else if (isLoadStatus) {
984 dataBytes = 2 * 64; // 1 bit per dword => 2 GRF (HW seems to round up to SIMD32)
985 int effectiveExecSize = std::max(16, result.info.execWidth);
986 result.info.src0LenBytes = result.info.addrSizeBits / 8 * effectiveExecSize;
987 } else if (result.info.isTransposed()) {
988 result.info.src0LenBytes = result.info.addrSizeBits / 8;
989 dataBytes = result.info.elemSizeBitsRegFile * result.info.elemsPerAddr / 8;
990 } else {
991 // things like SIMD4 will round up to SIMD16 at least
992 // (SIMD1 transpose does not but is handled above)
993 int effectiveExecSize = std::max(16, result.info.execWidth);
994 result.info.src0LenBytes = result.info.addrSizeBits / 8 * effectiveExecSize;
995 int dataBytesPerComp =
996 result.info.elemSizeBitsRegFile * result.info.execWidth / 8;
997 if (dataBytesPerComp < BYTES_PER_REGISTER && result.info.elemsPerAddr > 1) {
998 // e.g. SIMT4 with v2 => round up to full registers since the
999 // layout is oddball
1000 dataBytesPerComp = BYTES_PER_REGISTER;
1001 }
1002 dataBytes = dataBytesPerComp * result.info.elemsPerAddr;
1003 }
1004
1005 // for TGM, if src0Len was given; then override the size
1006 // e.g. :6 on SIMD32 typed would imply u, v, r
1007 if (sfid == SFID::TGM && src0Len > 0)
1008 result.info.src0LenBytes = src0Len * BYTES_PER_REGISTER;
1009
1010 if (result.info.isLoad()) {
1011 result.info.dstLenBytes = dataBytes;
1012 result.info.src1LenBytes = 0;
1013 } else if (result.info.isStore()) {
1014 result.info.dstLenBytes = 0;
1015 result.info.src1LenBytes = dataBytes;
1016 } else if (result.info.isAtomic()) {
1017 result.info.dstLenBytes = dataBytes;
1018 result.info.src1LenBytes = dataBytes * sOpInfo.numAtomicArgs();
1019 }
1020
1021 // append counter takes no address but the data payload in src0
1022 bool isAppendCounter = sOpInfo.op == SendOp::ATOMIC_ACADD ||
1023 sOpInfo.op == SendOp::ATOMIC_ACSUB ||
1024 sOpInfo.op == SendOp::ATOMIC_ACSTORE;
1025 if (isAppendCounter) {
1026 result.info.src0LenBytes = dataBytes;
1027 result.info.src1LenBytes = 0;
1028 }
1029 }
1030
1031 void MessageDecoderLscE64::decodeAddrTypeSize() {
1032 if (sfid == SFID::UGM) {
1033 decodeAddrTypeUGM();
1034 } else if (sfid == SFID::SLM) {
1035 decodeAddrTypeSLM();
1036 } else if (sfid == SFID::URB) {
1037 decodeAddrTypeURB();
1038 } else if (sfid == SFID::TGM) {
1039 decodeAddrTypeSTATEFUL();
1040 } else {
1041 IGA_ASSERT_FALSE("sfid should be LSC untyped");
1042 }
1043 }
1044 static std::string determineId0Meaning(const RegRef ind0,
1045 const char *symbol,
1046 const char *indicesAre) {
1047 std::stringstream ss;
1048 ss << symbol << ": " << indicesAre;
1049 if (ind0 != REGREF_INVALID) {
1050 ss << " with "
1051 "uniform a64 in "
1052 "s"
1053 << ind0.regNum << "." << ind0.subRegNum
1054 << " added to each";
1055 }
1056 return ss.str();
1057 }
1058
1059 enum GlbAddrType {
1060 FLAT_A64_A32U = 0,
1061 FLAT_A64_A32S = 1,
1062 FLAT_A64_A64 = 2,
1063 STATEFUL_A32 = 3,
1064 };
1065
1066 void MessageDecoderLscE64::decodeAddrTypeSTATEFUL() {
1067 auto enc = getDescBits(14, 2);
1068 std::string meaning;
1069 switch (enc) {
1070 case GlbAddrType::STATEFUL_A32:
1071 addrSizeSyntax = ".a32";
1072 meaning = "STATEFUL_A32 (id0 is surface state pointer whose "
1073 "surface base address is added to a32 indices)";
1074 break;
1075 default:
1076 meaning = "?";
1077 error(14, 2, "invalid address type");
1078 }
1079 addField("AddrTypeSize", 14, 2, enc, meaning);
1080 }
1081
1082 void MessageDecoderLscE64::decodeAddrTypeUGM() {
1083 auto enc = getDescBits(14, 2);
1084 std::string meaning;
1085 switch (enc) {
1086 case GlbAddrType::FLAT_A64_A32U:
1087 addrSizeSyntax = ".a32u";
1088 result.info.addrType = AddrType::FLAT;
1089 result.info.addrSizeBits = 32;
1090 result.info.uniformBase = indDesc0;
1091 result.info.uniformBaseAddrSizeBits = 64;
1092 meaning = determineId0Meaning(indDesc0, "FLAT_A64_A32U",
1093 "a32 unsigned offsets (zero-extended to a64)");
1094 break;
1095 case GlbAddrType::FLAT_A64_A32S:
1096 addrSizeSyntax = ".a32s";
1097 result.info.addrType = AddrType::FLAT;
1098 result.info.addrSizeBits = 32;
1099 result.info.uniformBase = indDesc0;
1100 result.info.uniformBaseAddrSizeBits = 64;
1101 result.info.signExtendIndices = true;
1102 meaning = determineId0Meaning(indDesc0, "FLAT_A64_A32S",
1103 "a32 signed offsets (sign-extened to a64)");
1104 break;
1105 case GlbAddrType::FLAT_A64_A64:
1106 addrSizeSyntax = ".a64";
1107 result.info.addrType = AddrType::FLAT;
1108 result.info.addrSizeBits = 64;
1109 result.info.uniformBaseAddrSizeBits = 64;
1110 result.info.uniformBase = indDesc0;
1111 meaning = determineId0Meaning(indDesc0, "FLAT_A64_A64", "a64 offsets");
1112 break;
1113 case GlbAddrType::STATEFUL_A32:
1114 addrSizeSyntax = ".a32";
1115 result.info.addrType = AddrType::SURF;
1116 result.info.addrSizeBits = 32;
1117 result.info.uniformBaseAddrSizeBits = 0;
1118 result.info.surfaceState = indDesc0;
1119 meaning = "STATEFUL_A32 (id0 is a surface state pointer, and the a32 "
1120 "offset are added to that surface state's base pointer)";
1121 break;
1122 default:
1123 error(14, 2, "invalid address type");
1124 }
1125 addField("DP_ADDR_TYPE_SIZE", 14, 2, enc, meaning);
1126 }
1127
1128 void MessageDecoderLscE64::decodeAddrTypeSLM() {
1129 auto enc = getDescBits(14, 2);
1130 enum {
1131 FLAT_A32_A32 = 0,
1132 };
1133
1134 result.info.addrType = AddrType::FLAT;
1135 result.info.addrSizeBits = 32;
1136 result.info.uniformBase = indDesc0;
1137 result.info.uniformBaseAddrSizeBits = 32;
1138
1139 addrSizeSyntax = ".a32";
1140
1141 std::string meaning;
1142 switch (enc) {
1143 case FLAT_A32_A32:
1144 meaning = determineId0Meaning(indDesc0, "FLAT_A32_A32", "a32 offsets");
1145 break;
1146 default:
1147 error(14, 2, "invalid address type");
1148 }
1149
1150 addField("DP_ADDR_TYPE_SIZE", 14, 2, enc, meaning);
1151 }
1152
1153 void MessageDecoderLscE64::decodeAddrTypeURB() {
1154 auto enc = getDescBits(14, 2);
1155 enum {
1156 GLOBAL_A32_A32 = 0,
1157 };
1158
1159 result.info.addrType = AddrType::FLAT;
1160 result.info.addrSizeBits = 32;
1161 result.info.uniformBase = indDesc0;
1162 result.info.uniformBaseAddrSizeBits = 32;
1163
1164 addrSizeSyntax = ".a32";
1165
1166 std::string meaning;
1167 switch (enc) {
1168 case GLOBAL_A32_A32:
1169 meaning = "GLOBAL_A32_A32 "
1170 "(id0 is a uniform a32 global base added to a32 indices)";
1171 break;
1172 default:
1173 error(14, 2, "invalid address type");
1174 }
1175
1176 addField("DP_ADDR_TYPE_SIZE", 14, 2, enc, meaning);
1177 }
1178
1179 void MessageDecoderLscE64::decodeAddrScaling() {
1180 if (result.info.elemSizeBitsMemory == 0)
1181 error(44, 2, "need to decode data size first");
1182 if (result.info.elemsPerAddr == 0 &&
1183 // a chmask can have message chan have 0 channels (e.g. render target)
1184 // that doesn't hit this path, but we shouldn't assert unless
1185 // we really need to
1186 !result.info.hasAttr(MessageInfo::Attr::HAS_CHMASK))
1187 error(44, 2, "need to decode vector size first");
1188 if (result.info.elemsPerAddr == 0)
1189 warning(7, 2, "empty chmask in LSC message");
1190 //
1191 auto enc = getDescBits(44, 2);
1192 std::stringstream meaning;
1193 if (enc == 0) {
1194 meaning << "unscaled indices";
1195 result.info.addrScaling = 1;
1196 } else if (result.info.elemsPerAddr == 0) {
1197 meaning << "(undefined behavior)";
1198 } else {
1199 auto sc = (1 << (enc - 1));
1200 auto vsz = result.info.elemsPerAddr;
1201 auto scBytes = result.info.elemSizeBitsMemory / 8 * vsz;
1202 meaning << "scale by " << sc << "X data*vecsize (" << scBytes << ")";
1203 if (scBytes > 32) {
1204 error(44, 2, "total scale amount must be <= 32B");
1205 }
1206 if ((vsz & (vsz - 1)) != 0) {
1207 warning(44, 2,
1208 "vector size must be a power of two to scale "
1209 "(V3 not supported)");
1210 }
1211 result.info.addrScaling = scBytes;
1212 result.syntax.scale += fmtHexSigned(scBytes) + "*";
1213 }
1214 addField("Offset Scaling", 44, 2, enc, meaning.str());
1215 }
1216
1217 void MessageDecoderLscE64::decodeDataSize() {
1218 const auto *dszDesc = decodeDataSizeValue();
1219 if (dszDesc) {
1220 dataTypePrefixSyntax = dszDesc->sym;
1221 } else {
1222 dataTypePrefixSyntax = ".d??";
1223 }
1224 }
1225
1226 void MessageDecoderLscE64::decodeDataSizeWithRefs(
1227 const SendOpDefinition &sOpInfo)
1228 {
1229 decodeDataSize();
1230
1231 auto addDataPayloadD8U32 = [&]() {
1232 auto kind = result.info.isLoad() ? DocRef::DST : DocRef::SRC1;
1233 if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32)
1234 addDoc(kind, "D8U32_PAYLOAD", "71978");
1235 else
1236 addDoc(kind, "D8U32_PAYLOAD_SIMT16", "74736");
1237 };
1238 auto addDataPayloadD16U32 = [&]() {
1239 auto kind = result.info.isLoad() ? DocRef::DST : DocRef::SRC1;
1240 if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32)
1241 addDoc(kind, "D16U32_PAYLOAD", "71969");
1242 else
1243 addDoc(kind, "D16U32_PAYLOAD_SIMT16", "71993");
1244 };
1245 auto addDataPayloadD32 = [&]() {
1246 auto kind = result.info.isLoad() ? DocRef::DST : DocRef::SRC1;
1247 if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32)
1248 addDoc(kind, "D32_PAYLOAD", "71970");
1249 else
1250 addDoc(kind, "D32_PAYLOAD_SIMT16", "71971");
1251 };
1252 auto addDataPayloadD64 = [&]() {
1253 auto kind = result.info.isLoad() ? DocRef::DST : DocRef::SRC1;
1254 if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32)
1255 addDoc(kind, "D64_PAYLOAD", "71974");
1256 else
1257 addDoc(kind, "D64_PAYLOAD_SIMT16", "71975");
1258 };
1259
1260 bool d16u32 =
1261 result.info.elemSizeBitsMemory == 16 &&
1262 result.info.elemSizeBitsRegFile == 32;
1263 bool d8u32 =
1264 result.info.elemSizeBitsMemory == 8 &&
1265 result.info.elemSizeBitsRegFile == 32;
1266 if (sOpInfo.isAtomic()) {
1267 if (d16u32) {
1268 addDataPayloadD16U32(); // dst return payload
1269 if (sOpInfo.numAtomicArgs() == 2) { // ternary atomics
1270 if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32)
1271 addDoc(DocRef::SRC1, "D16U32_2SRC_ATM_PAYLOAD", "71996");
1272 else
1273 addDoc(DocRef::SRC1, "D16U32_2SRC_ATM_PAYLOAD_SIMT16", "71997");
1274 } // else binary atomic has same format for src1 as dst; unary lacks src1
1275 } else if (result.info.elemSizeBitsRegFile == 32) {
1276 addDataPayloadD32(); // return payload
1277 if (sOpInfo.numAtomicArgs() == 2) {
1278 if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32)
1279 addDoc(DocRef::SRC1, "D32_2SRC_ATM_PAYLOAD", "71972");
1280 else
1281 addDoc(DocRef::SRC1, "D32_2SRC_ATM_PAYLOAD_SIMT16", "71973");
1282 } // else binary atomic has same format for src1 as dst; unary lacks src1
1283 } else if (result.info.elemSizeBitsRegFile == 64) {
1284 addDataPayloadD64(); // dst return payload
1285 if (sOpInfo.numAtomicArgs() == 2) {
1286 if (execSize == ExecSize::INVALID || execSize == ExecSize::SIMD32)
1287 addDoc(DocRef::SRC1, "D64_2SRC_ATM_PAYLOAD", "71976");
1288 else
1289 addDoc(DocRef::SRC1, "D64_2SRC_ATM_PAYLOAD_SIMT16", "71977");
1290 } // else src1 has same format as dst or is absent
1291 }
1292 } else if (result.info.isTransposed()) {
1293 auto kind = result.info.isLoad() ? DocRef::DST : DocRef::SRC1;
1294 if (result.info.elemSizeBitsRegFile == 32) {
1295 addDoc(kind, "D32_TRANSPOSED_PAYLOAD", "71988");
1296 } else if (result.info.elemSizeBitsRegFile == 64) {
1297 addDoc(kind, "D64_TRANSPOSED_PAYLOAD", "71989");
1298 }
1299 } else { // non-atomic (load or store)
1300 if (d8u32) {
1301 addDataPayloadD8U32();
1302 } else if (d16u32) {
1303 addDataPayloadD16U32();
1304 } else if (result.info.elemSizeBitsRegFile == 32) {
1305 addDataPayloadD32();
1306 } else if (result.info.elemSizeBitsRegFile == 64) {
1307 addDataPayloadD64();
1308 }
1309 }
1310 }
1311
1312 void MessageDecoderLscE64::decodeVectorSize() {
1313 if (result.info.hasAttr(MessageInfo::Attr::HAS_CHMASK)) {
1314 vectorSuffixSyntax = decodeVectorSizeCmask("xyzw");
1315 } else {
1316 vectorSuffixSyntax = decodeVectorSizeElems();
1317 }
1318 }
1319
1320 std::string MessageDecoderLscE64::decodeVectorSizeElems() {
1321 const auto *e = LSC_LOOKUP_TABLE("Vector Size", 7, 3, LSC_VEC_SIZE);
1322 if (e == nullptr) {
1323 return "?";
1324 }
1325 auto trnps = getDescBits(10, 1);
1326 addField("Transpose", 10, 1, trnps,
1327 trnps ? "Transposed" : "Non-transposed");
1328 result.info.elemsPerAddr = e->value;
1329
1330 std::string sym = (e->value != 1) ? e->sym : "";
1331
1332 if (trnps) {
1333 if (result.info.execWidth == 0)
1334 result.info.execWidth = 1;
1335
1336 sym += "t"; // append t to get "x16t"
1337 result.info.addAttr(MessageInfo::Attr::TRANSPOSED);
1338 switch (result.info.op) {
1339 case SendOp::LOAD:
1340 case SendOp::LOAD_BLOCK2D:
1341 case SendOp::LOAD_STATUS:
1342 case SendOp::STORE:
1343 case SendOp::STORE_BLOCK2D:
1344 break;
1345 default:
1346 warning(10, 1, "transpose not supported on this send op");
1347 }
1348 if (execSize != ExecSize::SIMD1) {
1349 warning(10, 1, "transpose messages should be SIMD1");
1350 }
1351 }
1352
1353 return sym;
1354 }
1355
1356 const LscDataSizeValidValue *MessageDecoderLscE64::decodeDataSizeValue() {
1357 const auto *e = LSC_LOOKUP_TABLE("Data Size", 11, 3, LSC_DATA_SIZE);
1358 if (e != nullptr) {
1359 result.info.elemSizeBitsMemory = e->bitsInMem;
1360 result.info.elemSizeBitsRegFile = e->bitsInReg;
1361 }
1362 return e;
1363 }
1364
1365 void MessageDecoderLscE64::decodeCacheControl(SendOp sop) {
1366 const auto *ccDesc = decodeCacheControlValue(sop);
1367 if (ccDesc) {
1368 if (ccDesc->encoding != 0)
1369 cacheControlSyntax = ccDesc->sym;
1370
1371 result.info.cachingL1 = ccDesc->l1;
1372 result.info.cachingL2 = ccDesc->l2;
1373 result.info.cachingL3 = ccDesc->l3;
1374 } else {
1375 cacheControlSyntax = ".?";
1376 }
1377 }
1378
1379 void MessageDecoderLscE64::decodeOverfetch() {
1380 decodeField("Overfetch", 21, 1, [&] (uint32_t val, std::stringstream &ss) {
1381 ss << (val ? "LSC opportunistically fetches up to 256B" : "");
1382 if (val)
1383 ovfSyntax = ".ovf";
1384 });
1385 }
1386
1387 enum CacheControlSize {
1388 CCSIZE64B = 0,
1389 CCSIZE128B = 1,
1390 CCSIZE192B = 2,
1391 CCSIZE256B = 3,
1392 };
1393
1394
1395 void MessageDecoderLscE64::decodeCacheControlSize() {
1396 auto enc = getDescBits(11, 2);
1397 std::string meaning;
1398 switch(enc) {
1399 case CacheControlSize::CCSIZE64B:
1400 meaning = "Operation affects single 64B cache line";
1401 extCacheControlSizeSyntax = ".64B";
1402 break;
1403 case CacheControlSize::CCSIZE128B:
1404 meaning = "Operation affects 128B; two cache lines";
1405 extCacheControlSizeSyntax = ".128B";
1406 break;
1407 case CacheControlSize::CCSIZE192B:
1408 meaning = "Operation affects 192B; three cache lines";
1409 extCacheControlSizeSyntax = ".192B";
1410 break;
1411 case CacheControlSize::CCSIZE256B:
1412 meaning = "Operation affects 256B; four cache lines";
1413 extCacheControlSizeSyntax = ".256B";
1414 break;
1415 }
1416 addField("CacheControlSize", 11, 2, enc, meaning);
1417 }
1418
1419 enum CacheControlOperation {
1420 SET = 0,
1421 RESET = 1,
1422 };
1423
1424 void MessageDecoderLscE64::decodeCacheControlOperation() {
1425 auto enc = getDescBits(7, 4);
1426 std::string meaning;
1427 switch(enc) {
1428 case CacheControlOperation::SET:
1429 meaning = "Set dirty bits to one, set data to zero";
1430 extCacheControlOpSyntax = ".set";
1431 break;
1432 case CacheControlOperation::RESET:
1433 meaning = "Set dirty bits to zero";
1434 extCacheControlOpSyntax = ".reset";
1435 break;
1436 default:
1437 meaning = "??";
1438 break;
1439 }
1440 addField("CacheControlOperation", 7, 4, enc, meaning);
1441 }
1442
1443
1444 void MessageDecoderLscE64::decodeImmOffAddr(int off, int len) {
1445 if (result.info.elemSizeBitsMemory == 0) {
1446 error(off, len, "invalid data size (cannot compute imm off size)");
1447 return; // errors
1448 }
1449 int immOff = getDescBitsSigned(off, len);
1450 // encoded as elements, scale to bytes
1451 result.info.immediateOffset = immOff * result.info.elemSizeBitsMemory / 8;
1452
1453 if (result.info.immediateOffset != 0) {
1454 result.syntax.immOffset = fmtHexSigned(result.info.immediateOffset);
1455 }
1456
1457 std::stringstream mss;
1458 mss << "add " << immOff << " elements to each index";
1459 addField("AddrImmOff", off, len, getDescBits(off, len), mss.str());
1460 }
1461
1462 void MessageDecoderLscE64::decodeImmOffCoord2D() {
1463 if (result.info.elemSizeBitsMemory == 0) {
1464 error(22, 12, "cannot decode imm off with invalid data size");
1465 return;
1466 }
1467 auto decodeCoordOff = [&](const char *field, const char *which, int off) {
1468 uint32_t immOffU = getDescBits(off, 12);
1469 int immOffElems = getSignedBits<int32_t>(immOffU, 0, 12);
1470 //
1471 std::stringstream mss;
1472 mss << "add " << immOffElems << " elements to " << which << "-coordinate";
1473 addField(field, off, 12, immOffU, mss.str());
1474 return immOffElems;
1475 };
1476 result.info.immediateOffsetBlock2dX =
1477 decodeCoordOff("CoordImmOff2D.X", "X", 22);
1478 result.info.immediateOffsetBlock2dY =
1479 decodeCoordOff("CoordImmOff2D.Y", "Y", 34);
1480 if (result.info.immediateOffsetBlock2dX ||
1481 result.info.immediateOffsetBlock2dY) {
1482 std::stringstream ss;
1483 ss << "(";
1484 ss << fmtHexSigned(result.info.immediateOffsetBlock2dX);
1485 ss << ",";
1486 ss << fmtHexSigned(result.info.immediateOffsetBlock2dY);
1487 ss << ")";
1488 result.syntax.immOffset = ss.str();
1489 }
1490 }
1491
1492 ///////////////////////////////////////////////////////////////////////////////
1493 std::string MessageDecoderLscE64::symbolFromSyntax() const {
1494 std::stringstream sym;
1495 sym << result.syntax.mnemonic;
1496 if (!result.syntax.controls.empty())
1497 sym << result.syntax.controls;
1498 if (!result.syntax.surface.empty()) {
1499 sym << " ";
1500 sym << result.syntax.surface;
1501 } else if (!result.syntax.isControl()) {
1502 sym << " ";
1503 }
1504
1505 if (!result.syntax.isControl()) {
1506 sym << "[";
1507 bool printed = false;
1508 if (indDesc0 != REGREF_INVALID && result.info.addrType == AddrType::FLAT) {
1509 sym << "s" << indDesc0.regNum << "." << indDesc0.subRegNum;
1510 printed = true;
1511 }
1512 if (result.info.src0LenBytes > 0) {
1513 if (printed)
1514 sym << "+";
1515 if (!result.syntax.scale.empty()) {
1516 sym << result.syntax.scale;
1517 }
1518 sym << "src0";
1519 printed = true;
1520 }
1521 if (!result.syntax.immOffset.empty()) {
1522 if (result.syntax.immOffset[0] != '-')
1523 sym << "+";
1524 sym << result.syntax.immOffset;
1525 }
1526 sym << "]";
1527 } else {
1528 sym << " src0";
1529 }
1530
1531 return sym.str();
1532 } // symbolFromSyntax
1533
1534 void iga::DecodeMessageLscE64(Platform platform, SFID sfid, ExecSize execSize,
1535 int src0Len, int src1Len, uint64_t desc,
1536 RegRef id0, RegRef id1, DecodeResult &result) {
1537 MessageDecoderLscE64 mdec {platform, sfid, execSize, src0Len, src1Len,
1538 desc, id0, id1, result};
1539 mdec.decode();
1540 if (result.errors.empty()) {
1541 mdec.checkBytesLen("src0", result.info.src0LenBytes, src0Len);
1542 mdec.checkBytesLen("src1", result.info.src1LenBytes, src1Len);
1543 }
1544 }