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 #include <sstream>
10 #include <fstream>
11 #include <functional>
12 #include <regex>
13
14 #include "visa_igc_common_header.h"
15 #include "Common_ISA.h"
16 #include "Common_ISA_util.h"
17 #include "Common_ISA_framework.h"
18 #include "JitterDataStruct.h"
19 #include "KernelInfo.h"
20 #include "VISAKernel.h"
21 #include "Attributes.hpp"
22 #include "Timer.h"
23 #include "FlowGraph.h"
24 #include "BuildIR.h"
25 #include "Optimizer.h"
26 #include "BinaryEncoding.h"
27 #include "BinaryEncodingCNL.h"
28 #include "Common_BinaryEncoding.h"
29 #include "DebugInfo.h"
30 #include "BinaryEncodingIGA.h"
31 #include "IsaDisassembly.h"
32 #include "LocalScheduler/SWSB_G4IR.h"
33 #include "visa/include/RelocationInfo.h"
34 #include "InstSplit.h"
35
36 #if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64))
37 #include <windows.h>
38 #endif
39
40 #include <cctype>
41
42 using namespace CisaFramework;
43 using namespace vISA;
44 #define SIZE_VALUE m_kernel_data_size
45 #define SIZE_VALUE_INST m_instruction_size
46
47 #define IS_GEN_PATH (mBuildOption == VISA_BUILDER_GEN)
48 #define IS_BOTH_PATH (mBuildOption == VISA_BUILDER_BOTH)
49 #define IS_GEN_BOTH_PATH (mBuildOption == VISA_BUILDER_GEN || mBuildOption == VISA_BUILDER_BOTH)
50 #define IS_VISA_BOTH_PATH (mBuildOption == VISA_BUILDER_VISA || mBuildOption == VISA_BUILDER_BOTH)
51
52
PACK_EXEC_SIZE(unsigned int & size,VISA_EMask_Ctrl eMask)53 static void PACK_EXEC_SIZE(unsigned int &size, VISA_EMask_Ctrl eMask)
54 {
55 size |= eMask << 4;
56 }
57
ADD_OPND(int & num_operands,VISA_opnd ** opnd,VISA_opnd * topnd)58 static void ADD_OPND(int &num_operands, VISA_opnd **opnd, VISA_opnd * topnd)
59 {
60 if (topnd != NULL)
61 {
62 opnd[num_operands++] = topnd;
63 }
64 }
65
66 #define ERROR_PRINT(error_msg) std::cerr << error_msg << "\n"
CHECK_NUM_OPNDS(VISA_INST_Desc * instDesc,int numOperands,int predOpnds)67 static int CHECK_NUM_OPNDS(VISA_INST_Desc *instDesc, int numOperands, int predOpnds)
68 {
69 if ((instDesc->opnd_num -predOpnds) != numOperands)
70 {
71 ERROR_PRINT("Number of parameters does not match");
72 std::cerr << "LINE: " << __LINE__ << std::endl;
73 std::cerr << "FUNCTION: " << __FUNCTION__ << std::endl;
74 assert(0);
75 return VISA_FAILURE;
76 }
77 return VISA_SUCCESS;
78 }
GET_NUM_PRED_DESC_OPNDS(int & predOpnd,VISA_INST_Desc * inst_desc_temp)79 static void GET_NUM_PRED_DESC_OPNDS(int &predOpnd, VISA_INST_Desc *inst_desc_temp)
80 {
81 predOpnd = 0;
82 for (int i = 0; i < inst_desc_temp->opnd_num; i++)
83 {
84 if (inst_desc_temp->opnd_desc[i].opnd_type == OPND_EXECSIZE ||
85 inst_desc_temp->opnd_desc[i].opnd_type == OPND_PRED)
86 predOpnd++;
87 }
88 }
89
getHeightWidth(G4_Type type,unsigned int numberElements,unsigned short & dclWidth,unsigned short & dclHeight,int & totalByteSize)90 static void getHeightWidth(
91 G4_Type type,
92 unsigned int numberElements,
93 unsigned short& dclWidth,
94 unsigned short& dclHeight,
95 int& totalByteSize)
96 {
97 dclWidth = 1, dclHeight = 1;
98 totalByteSize = numberElements * TypeSize(type);
99 if (totalByteSize <= (int)numEltPerGRF<Type_UB>())
100 {
101 dclWidth = (uint16_t)numberElements;
102 }
103 else {
104 // here we assume that the start point of the var is the beginning of a GRF?
105 // so subregister must be 0?
106 dclWidth = numEltPerGRF<Type_UB>() / TypeSize(type);
107 dclHeight = totalByteSize / numEltPerGRF<Type_UB>();
108 if (totalByteSize % numEltPerGRF<Type_UB>() != 0) {
109 dclHeight++;
110 }
111 }
112 }
113
114
115 #if defined(_DEBUG) || defined(_INTERNAL)
116 #define START_ASSERT_CHECK 1
117 #else
118 #define START_ASSERT_CHECK 0
119 #endif
120
121 #define GET_G4_OPNG(obj) (obj != NULL) ? obj->g4opnd : NULL
122
calculateTotalInputSize()123 int VISAKernelImpl::calculateTotalInputSize()
124 {
125 for (unsigned int i = 0; i < m_builder->getInputCount(); i++)
126 {
127 input_info_t * temp = m_builder->getInputArg(i);
128 if (m_inputSize < (unsigned int)(temp->offset + temp->size))
129 {
130 m_inputSize = temp->offset + temp->size;
131 }
132 }
133 return VISA_SUCCESS;
134 }
135
compileFastPath()136 int VISAKernelImpl::compileFastPath()
137 {
138 int status = VISA_SUCCESS;
139
140 assert(
141 (getIsKernel() || getIsPayload() ||
142 (m_kernelAttrs->isKernelAttrSet(Attributes::ATTR_ArgSize) &&
143 m_kernelAttrs->isKernelAttrSet(Attributes::ATTR_RetValSize))) &&
144 "vISA: input for function must have attributes ArgSize and RetValSize!");
145
146 if (getIsKernel())
147 {
148 status = calculateTotalInputSize();
149 }
150
151 if (status != VISA_SUCCESS)
152 {
153 return status;
154 }
155
156 IR_Builder& builder = *m_builder;
157 builder.predefinedVarRegAssignment((uint8_t)m_inputSize);
158 builder.expandPredefinedVars();
159 builder.resizePredefinedStackVars();
160 status = compileTillOptimize();
161 return status;
162 }
163
replaceFCOpcodes(IR_Builder & builder)164 void replaceFCOpcodes(IR_Builder& builder)
165 {
166 for (G4_BB* bb : builder.kernel.fg)
167 {
168 if (bb->size() > 0)
169 {
170 // pseudo_fc_call/ret would always be last
171 // instruction in BB so only look at back
172 // of instlist.
173 G4_INST* lastInstInBB = bb->back();
174
175 if (lastInstInBB->opcode() == G4_pseudo_fc_call)
176 {
177 lastInstInBB->asCFInst()->pseudoCallToCall();
178 }
179 else if (lastInstInBB->opcode() == G4_pseudo_fc_ret)
180 {
181 lastInstInBB->asCFInst()->pseudoRetToRet();
182 }
183 }
184 }
185 }
186
setDeclAlignment(G4_Declare * dcl,VISA_Align align)187 static void setDeclAlignment(G4_Declare* dcl, VISA_Align align)
188 {
189 switch (align)
190 {
191 case ALIGN_BYTE: //no alignment;
192 case ALIGN_WORD: dcl->setSubRegAlign(Any); break;
193 case ALIGN_DWORD: dcl->setSubRegAlign(Even_Word); break;
194 case ALIGN_QWORD: dcl->setSubRegAlign(Four_Word); break;
195 case ALIGN_OWORD: dcl->setSubRegAlign(Eight_Word); break;
196 case ALIGN_GRF:
197 dcl->setSubRegAlign(GRFALIGN);
198 break;
199 case ALIGN_2_GRF:
200 dcl->setSubRegAlign(GRFALIGN);
201 dcl->setEvenAlign();
202 break;
203 case ALIGN_HWORD: dcl->setSubRegAlign(Sixteen_Word); break;
204 case ALIGN_32WORD:
205 dcl->setSubRegAlign(GRFALIGN);
206 if (getGRFSize() == 32)
207 {
208 dcl->setEvenAlign();
209 }
210 break;
211 case ALIGN_64WORD: //64bytes GRF aligned
212 assert(getGRFSize() == 64);
213 dcl->setSubRegAlign(ThirtyTwo_Word);
214 dcl->setEvenAlign();
215 break;
216 default: assert(false && "Incorrect vISA alignment"); break;
217 }
218 }
219
compileTillOptimize()220 int VISAKernelImpl::compileTillOptimize()
221 {
222 if (m_options->getOption(vISA_splitInstructions))
223 {
224 InstSplitPass instSplit(m_builder);
225 instSplit.run();
226 }
227
228 // For separate compilation run compilation till RA then return
229 {
230 TIME_SCOPE(CFG)
231 m_kernel->fg.constructFlowGraph(m_builder->instList);
232 }
233
234 // move the options into the function, like LIR
235
236 Optimizer optimizer(*m_kernelMem, *m_builder, *m_kernel, m_kernel->fg);
237
238 return optimizer.optimization();
239 }
240
adjustIndirectCallOffset()241 void VISAKernelImpl::adjustIndirectCallOffset()
242 {
243 // the call code sequence done at Optimizer::expandIndirectCallWithRegTarget
244 // is:
245 // add r2.0 -IP call_target
246 // add r2.0 r2.0 -32
247 // call r1.0 r2.0
248 // -32 is hardcoded. But SWSB could've inserted sync instructions between
249 // call and add. So we need to re-adjust the offset
250
251 for (auto bb : m_kernel->fg)
252 {
253 if (bb->empty())
254 continue;
255
256 // At this point G4_pseudo_fcall may be converted to G4_call
257 if (bb->back()->isCall() || bb->back()->isFCall())
258 {
259 G4_INST* fcall = bb->back();
260 if (fcall->getSrc(0)->isGreg() || fcall->getSrc(0)->isA0())
261 {
262 // for every indirect call, count # of instructions inserted
263 // between call and the first add
264 uint64_t sync_offset = 0;
265 G4_INST* first_add = nullptr;
266 INST_LIST::reverse_iterator it = bb->rbegin();
267 // skip call itself
268 ++it;
269 for (; it != bb->rend(); ++it)
270 {
271 G4_INST* inst = *it;
272 G4_opcode op = inst->opcode();
273 if (op == G4_sync_allrd || op == G4_sync_allwr)
274 {
275 inst->setNoCompacted();
276 sync_offset += 16;
277 continue;
278 }
279 else if (op == G4_sync_nop) {
280 inst->setCompacted();
281 sync_offset += 8;
282 continue;
283 }
284 else if (op == G4_add)
285 {
286 if (first_add == nullptr)
287 {
288 first_add = inst;
289 continue;
290 }
291 else
292 {
293 break;
294 }
295 }
296 // instructions between call and add could only be
297 // sync.nop, sync.allrd or sync.allwr
298 assert(0);
299 }
300 assert(first_add->getSrc(1)->isImm());
301 int64_t adjust_off = first_add->getSrc(1)->asImm()->getInt() - sync_offset;
302 first_add->setSrc(m_builder->createImm(adjust_off, Type_D), 1);
303 }
304 }
305 }
306 }
307
compilePostOptimize()308 void VISAKernelImpl::compilePostOptimize()
309 {
310
311 if (getOptions()->getOption(vISA_AddKernelID))
312 {
313 // gt debugger requires a dummy mov as first
314 // executable instruction in compiled kernel.
315 // No other instruction must be prepended
316 // to the kernel before UUID mov.
317 uint64_t kernelID = m_kernel->fg.insertDummyUUIDMov();
318 m_kernel->setKernelID(kernelID);
319 }
320
321 m_kernel->evalAddrExp();
322
323 if (getOptions()->getOption(vISA_DumpRegInfo))
324 {
325 m_kernel->dump();
326 m_kernel->emitRegInfo();
327 }
328
329 if (getOptions()->getOption(vISA_setStartBreakPoint))
330 {
331 auto getFirstNonLabelInst = [this]()
332 {
333 unsigned int skip = 0, skipCount = 0;
334 if (m_kernel->fg.builder->needsToLoadLocalID())
335 ++skip;
336 if (m_kernel->fg.builder->needsToLoadCrossThreadConstantData())
337 ++skip;
338 for (auto bb : m_kernel->fg)
339 {
340 if (skipCount++ < skip)
341 continue;
342 for (auto inst : *bb)
343 {
344 if (inst->isLabel())
345 {
346 continue;
347 }
348 return inst;
349 }
350 }
351 return (G4_INST*) nullptr;
352 };
353
354 G4_INST* inst = getFirstNonLabelInst();
355 if (inst != nullptr)
356 {
357 inst->setOptionOn(InstOpt_BreakPoint);
358 }
359 }
360 }
361
encodeAndEmit(unsigned int & binarySize)362 void* VISAKernelImpl::encodeAndEmit(unsigned int& binarySize)
363 {
364 void* binary = NULL;
365
366 //
367 // Entry point to LIR conversion & transformations
368 //
369 startTimer(TimerID::ENCODE_AND_EMIT);
370 if (m_builder->useIGAEncoder())
371 {
372 auto r = EncodeKernelIGA(*m_kernelMem, *m_kernel, m_asmName);
373 binary = r.binary;
374 binarySize = (unsigned)r.binaryLen;
375
376 if (isFCCallableKernel() || isFCCallerKernel())
377 {
378 computeFCInfo();
379
380 // After retuning from replaceFCOpcodes, kernel
381 // will have all pseudo_fccall and pseudo_fcret
382 // opcodes replaced with the usual call
383 // and ret opcodes.
384 replaceFCOpcodes(*m_builder);
385 }
386 }
387 else
388 {
389 BinaryEncodingBase* pBinaryEncoding = NULL;
390
391 if (getGenxPlatform() >= GENX_ICLLP && m_options->getOption(vISA_BXMLEncoder))
392 {
393 pBinaryEncoding = new BinaryEncodingCNL(*m_kernelMem, *m_kernel, m_asmName);
394 }
395 else
396 {
397 pBinaryEncoding = new BinaryEncoding(*m_kernelMem, *m_kernel, m_asmName);
398 }
399
400 pBinaryEncoding->DoAll();
401
402 if (isFCCallableKernel() || isFCCallerKernel())
403 {
404 computeFCInfo(pBinaryEncoding);
405
406 // After retuning from replaceFCOpcodes, kernel
407 // will have all pseudo_fccall and pseudo_fcret
408 // opcodes replaced with the usual call
409 // and ret opcodes.
410 replaceFCOpcodes(*m_builder);
411 }
412
413
414 /*
415 In DLL mode we copy content in to memory buffer
416 when vISA_GenerateBinary is specified we dump out .dat file
417 */
418
419 binary = pBinaryEncoding->EmitBinary(binarySize);
420
421 pBinaryEncoding->computeBinaryOffsets();
422
423 for (auto bb : m_kernel->fg)
424 {
425 for (auto inst : *bb)
426 {
427 if (inst->getBinInst())
428 inst->setGenOffset(inst->getBinInst()->GetGenOffset());
429 else
430 inst->setGenOffset(UNDEFINED_GEN_OFFSET);
431 }
432 }
433
434 delete pBinaryEncoding;
435 }
436
437 // perform any necessary relocation
438 m_kernel->doRelocation(binary, binarySize);
439
440
441 // Update instruction offset in register access maps.
442 if (m_builder->hasSWSB() &&
443 (isFCCallableKernel() || isFCCallerKernel() || isFCComposableKernel())) {
444 auto FCPI = m_builder->getFCPatchInfo();
445 auto &FirstAccess = FCPI->RegFirstAccessList;
446 auto &LastAccess = FCPI->RegLastAccessList;
447 #if defined(DEBUG_VERBOSE_ON)
448 std::cerr << "FirstAccess:\n";
449 #endif
450 for (auto MI = FirstAccess.begin(),
451 ME = FirstAccess.end(); MI != ME; ++MI) {
452 auto Inst = MI->Inst;
453 MI->Offset = unsigned(Inst->getGenOffset());
454 #if defined(DEBUG_VERBOSE_ON)
455 fprintf(stderr, "r%03u.%s", MI->first,
456 (MI->Type == FCPatchingInfo::RegAccessType::Fully_Def ? "def" :
457 "use"));
458 if (MI->Token != (unsigned short)(-1))
459 fprintf(stderr, ", $%u", MI->Token);
460 fprintf(stderr, ":");
461 MI->Inst->dump();
462 #endif
463 }
464 #if defined(DEBUG_VERBOSE_ON)
465 std::cerr << "LastAccess:\n";
466 #endif
467 for (auto MI = LastAccess.begin(),
468 ME = LastAccess.end(); MI != ME; ++MI) {
469 auto Inst = MI->Inst;
470 MI->Offset = unsigned(Inst->getGenOffset());
471 #if defined(DEBUG_VERBOSE_ON)
472 fprintf(stderr, "r%03u.%s", MI->first,
473 (MI->Type == FCPatchingInfo::RegAccessType::Fully_Def ? "def" :
474 "use"));
475 if (MI->Token != (unsigned short)(-1))
476 fprintf(stderr, ", $%u", MI->Token);
477 fprintf(stderr, ":");
478 MI->Inst->dump();
479 #endif
480 }
481 }
482
483 if (m_options->getOption(vISA_PrintASMCount))
484 {
485 m_builder->criticalMsgStream() << " Kernel " << m_kernel->getName() << " : " <<
486 m_kernel->getAsmCount() << " asm instructions\n";
487 }
488 stopTimer(TimerID::ENCODE_AND_EMIT);
489
490 #if defined(_DEBUG) && (defined(_WIN32) || defined(_WIN64))
491 if (m_options->getOption(vISA_DebugConsoleDump)) {
492 std::basic_ostringstream<char> debugBuff;
493 m_kernel->emitDeviceAsm(debugBuff, nullptr, 0);
494 debugBuff.flush();
495 OutputDebugStringA(debugBuff.str().c_str());
496 }
497 #endif
498
499 if (getOptions()->getOption(vISA_GenerateKernelInfo))
500 {
501 auto kernel = getKernel();
502 m_kernelInfo = new KERNEL_INFO();
503
504 m_kernelInfo->name = kernel->getName();
505
506 BB_LIST_ITER bbItEnd = kernel->fg.end();
507 for (auto bbIt = kernel->fg.begin();
508 bbIt != bbItEnd;
509 bbIt++)
510 {
511 G4_BB* bb = (*bbIt);
512 for (auto inst : bb->getInstList())
513 {
514 auto loc = inst->getLocation();
515 if (loc == nullptr) continue;
516 auto dstRg = inst->getDst();
517 if (dstRg == nullptr) continue;
518 auto decl = dstRg->getTopDcl();
519 if (decl == nullptr) continue;
520 //auto reg = decl->getRegVar();
521
522 VarInfo* varInfo = nullptr;
523
524 if ((varInfo = m_kernelInfo->AddVarInfo(decl->getName())) != nullptr)
525 {
526 varInfo->lineNb = loc->getLineNo();
527 varInfo->srcFilename = loc->getSrcFilename();
528 varInfo->isSpill = decl->isSpilled();
529 // fixed values == const variable?
530 varInfo->isConst = dstRg->isImm();
531 varInfo->promoted2GRF = dstRg->isGreg();
532 varInfo->size = decl->getByteSize();
533
534 varInfo->type = (short)decl->getElemType();
535
536 //varInfo->isUniform = N\A
537 //varInfo->addrModel = N\A
538 //varInfo->memoryAccess = N\A
539 //varInfo->bc_count = N\A
540 //varInfo->bc_sameBank = N\A
541 //varInfo->bc_twoSrc = N\A
542 }
543 }
544 }
545 }
546
547 if (m_options->getOption(vISA_outputToFile))
548 {
549 std::stringstream ss;
550 ss << m_asmName << ".asm";
551 std::string filePath = ss.str();
552 if (allowDump(*m_options, filePath))
553 {
554 std::ofstream krnlOutput(filePath, std::ofstream::out);
555 if (!krnlOutput) {
556 std::cerr << filePath << ": failed to open file\n";
557 }
558 else {
559 m_kernel->emitDeviceAsm(krnlOutput, binary, binarySize);
560 }
561 }
562 }
563
564 recordFinalizerInfo();
565
566 return binary;
567 }
568
recordFinalizerInfo()569 void VISAKernelImpl::recordFinalizerInfo()
570 {
571 if (m_builder->getJitInfo())
572 {
573 m_builder->getJitInfo()->numAsmCount = m_kernel->getAsmCount();
574 m_builder->getJitInfo()->numGRFTotal = m_kernel->getNumRegTotal();
575 m_builder->getJitInfo()->numThreads = m_kernel->getNumThreads();
576 }
577 }
578
InitializeFastPath()579 int VISAKernelImpl::InitializeFastPath()
580 {
581 m_kernelMem = new vISA::Mem_Manager(4096);
582
583 m_kernel = new (m_mem) G4_Kernel(
584 m_instListNodeAllocator,
585 *m_kernelMem,
586 m_options,
587 m_kernelAttrs,
588 m_major_version,
589 m_minor_version);
590 m_kernel->setName(m_name.c_str());
591
592 if (getOptions()->getOption(vISA_GenerateDebugInfo))
593 {
594 m_kernel->getKernelDebugInfo()->setVISAKernel(this);
595 }
596
597 if (getOptions()->getOption(vISA_EnableCompilerStats))
598 {
599 m_compilerStats.Enable(false);
600 }
601 m_jitInfo = (FINALIZER_INFO*)m_mem.alloc(sizeof(FINALIZER_INFO));
602
603 void* addr = m_kernelMem->alloc(sizeof(class IR_Builder));
604 m_builder = new(addr)IR_Builder(getGenxPlatform(), m_instListNodeAllocator,
605 *m_kernel,
606 *m_kernelMem,
607 m_options,
608 getCISABuilder(),
609 m_jitInfo,
610 getCISABuilder()->getWATable());
611
612 m_builder->setType(m_type);
613 m_builder->getcompilerStats().Link(m_compilerStats);
614 initCompilerStats();
615
616 return VISA_SUCCESS;
617 }
618
CopyVars(VISAKernelImpl * from)619 void VISAKernelImpl::CopyVars(VISAKernelImpl* from)
620 {
621 m_builder->dclpool.getDeclareList() = from->m_builder->dclpool.getDeclareList();
622 }
623
InitializeKernel(const char * kernel_name)624 int VISAKernelImpl::InitializeKernel(const char *kernel_name)
625 {
626 int status = VISA_SUCCESS;
627 m_num_pred_vars = Get_CISA_PreDefined_Var_Count();
628 setName(kernel_name);
629 if (IS_GEN_BOTH_PATH)
630 {
631 status = InitializeFastPath();
632 }
633
634 CISABuildPreDefinedDecls();
635
636 return status;
637 }
638
639 // This is done for all vISA Compiler Statistics. This is done so that a
640 // statistic is initialized to false/0 even if the corresponding optimization
641 // did not execute. This enables the the statistic to be printed out even if
642 // the optimization did not happen.
initCompilerStats()643 void VISAKernelImpl::initCompilerStats()
644 {
645 m_compilerStats.Init(CompilerStats::numGRFSpillStr(), CompilerStats::type_int64);
646 m_compilerStats.Init(CompilerStats::numGRFFillStr(), CompilerStats::type_int64);
647 m_compilerStats.Init(CompilerStats::numSendStr(), CompilerStats::type_int64);
648 m_compilerStats.Init(CompilerStats::numCyclesStr(), CompilerStats::type_int64);
649 #if COMPILER_STATS_ENABLE
650 m_compilerStats.Init("PreRASchedulerForPressure", CompilerStats::type_bool);
651 m_compilerStats.Init("PreRASchedulerForLatency", CompilerStats::type_bool);
652 m_compilerStats.Init("IsRAsuccessful", CompilerStats::type_bool);
653 m_compilerStats.Init("IsTrivialRA", CompilerStats::type_bool);
654 m_compilerStats.Init("IsLocalRA", CompilerStats::type_bool);
655 m_compilerStats.Init("IsHybridRA", CompilerStats::type_bool);
656 m_compilerStats.Init("IsGlobalRA", CompilerStats::type_bool);
657 #endif // COMPILER_STATS_ENABLE
658 }
659
CISABuildPreDefinedDecls()660 int VISAKernelImpl::CISABuildPreDefinedDecls()
661 {
662 for (unsigned int i = 0; i < m_num_pred_vars; i++)
663 {
664 auto predefId = mapExternalToInternalPreDefVar(i);
665 CISA_GEN_VAR* decl = (CISA_GEN_VAR *)m_mem.alloc(sizeof(CISA_GEN_VAR));
666 decl->type = GENERAL_VAR;
667 decl->index = m_var_info_count++;
668 decl->genVar.name_index =-1;
669 decl->genVar.attribute_count = 0;
670 decl->genVar.attributes = NULL;
671 decl->genVar.alias_index = 0;
672 decl->genVar.alias_offset = 0;
673
674 if (predefId != PreDefinedVarsInternal::VAR_LAST)
675 {
676 // Going to create a G4 declaration here, and at compile time set the
677 // register allocation since this is when number of inputs will be known.
678 if (IS_GEN_BOTH_PATH)
679 {
680 G4_Declare *dcl = m_builder->preDefVars.getPreDefinedVar(predefId);
681 decl->genVar.dcl = dcl;
682 }
683 if (IS_VISA_BOTH_PATH)
684 {
685 std::string varName(getPredefinedVarString(predefId));
686 std::string alias = "V" + std::to_string(i);
687 decl->genVar.name_index = addStringPool(varName);
688 if (m_options->getOption(vISA_isParseMode))
689 {
690 setNameIndexMap(alias, decl, true);
691 setNameIndexMap(varName, decl, true);
692 }
693 }
694 }
695 addVarInfoToList(decl);
696 }
697
698 //SLM T0/Global Vars
699 for (int i = 0; i < (int) Get_CISA_PreDefined_Surf_Count(); i++)
700 {
701 //string_pool_lookup_and_insert(name, SURFACE_VAR, ISA_TYPE_ADDR);
702 VISA_SurfaceVar* decl = (VISA_SurfaceVar *)m_mem.alloc(sizeof(CISA_GEN_VAR));
703 ////memset(decl, 0, sizeof(CISA_GEN_VAR));
704 decl->type = SURFACE_VAR;
705 decl->index = m_surface_count++;
706 decl->stateVar.attributes = NULL;
707 decl->stateVar.attribute_count = 0;
708 decl->stateVar.name_index = -1;
709 if (IS_VISA_BOTH_PATH)
710 {
711 const char* name = vISAPreDefSurf[i].name;
712 decl->stateVar.name_index = addStringPool(std::string(name));
713 setNameIndexMap(std::string(name), decl, true);
714 }
715 if (IS_GEN_BOTH_PATH)
716 {
717 if (i == PREDEFINED_SURFACE_T252)
718 {
719 decl->stateVar.dcl = m_builder->getBuiltinT252();
720 }
721 else if (i == PREDEFINED_SURFACE_SCRATCH)
722 {
723 decl->stateVar.dcl = m_builder->getBuiltinScratchSurface();
724 }
725 else
726 {
727 decl->stateVar.dcl = m_builder->createDeclareNoLookup(
728 "",
729 G4_GRF,
730 1,
731 1,
732 Type_UD);
733 }
734 }
735 addSurface(decl);
736 }
737
738 createBindlessSampler();
739
740 return VISA_SUCCESS;
741 }
742
createBindlessSampler()743 void VISAKernelImpl::createBindlessSampler()
744 {
745 m_bindlessSampler = (VISA_SamplerVar *)m_mem.alloc(sizeof(CISA_GEN_VAR));
746 m_bindlessSampler->type = SAMPLER_VAR;
747 m_bindlessSampler->index = 31;
748 m_bindlessSampler->stateVar.attributes = NULL;
749 m_bindlessSampler->stateVar.attribute_count = 0;
750
751 if (IS_VISA_BOTH_PATH)
752 {
753 const char* name = BINDLESS_SAMPLER_NAME;
754 m_bindlessSampler->stateVar.name_index = addStringPool(std::string(name));
755 setNameIndexMap(std::string(name), m_bindlessSampler, true);
756 }
757 if (IS_GEN_BOTH_PATH)
758 {
759 m_bindlessSampler->stateVar.dcl = m_builder->getBuiltinBindlessSampler();
760 }
761 }
762
createReservedKeywordSet()763 void VISAKernelImpl::createReservedKeywordSet() {
764 for (int i = 0; i < ISA_NUM_OPCODE; i++) {
765 const VISA_INST_Desc &desc = CISA_INST_table[i];
766 if (desc.name != nullptr)
767 reservedNames.insert(desc.name);
768 int subOpsLen = 0;
769 const ISA_SubInst_Desc *subOps = getSubInstTable(desc.opcode, subOpsLen);
770 if (subOps != nullptr) {
771 // e.g. ops like ISA_SVM have a sub-table of operations
772 for (int si = 0; si < subOpsLen; si++) {
773 // some tables have padding and empty ops; a nullptr name indicates that
774 if (subOps[si].name != nullptr)
775 reservedNames.insert(subOps[si].name);
776 }
777 }
778 }
779
780 // a mishmash of some of the other reserved words from the lexical
781 // specification
782 reservedNames.insert("FILE");
783 reservedNames.insert("LOC");
784 reservedNames.insert("flat");
785 reservedNames.insert("bti");
786 reservedNames.insert("bss");
787 reservedNames.insert("ss");
788 }
789
isReservedName(const std::string & nm) const790 bool VISAKernelImpl::isReservedName(const std::string &nm) const {
791 auto opItr = reservedNames.find(nm);
792 return (opItr != reservedNames.end());
793 }
794
ensureVariableNameUnique(const char * & varName)795 void VISAKernelImpl::ensureVariableNameUnique(const char *&varName)
796 {
797 // legalize the LLVM name to vISA standards; some examples follow:
798 // given ==> we fix it to this
799 // 1. "0" ==> "_0" (LLVM name)
800 // 2. "add.i.i" ==> "add_i_i" (LLVM compound name)
801 // 3. "mul" ==> "mul_" (vISA keyword)
802 // 4. suppose both variable "x" and "x0" exist
803 // "x" ==> "x_1" (since "x0" already used)
804 // "x0" ==> "x0_1" (it's a dumb suffixing strategy)
805 std::stringstream escdName;
806
807 // step 1
808 if (isdigit(varName[0]))
809 escdName << '_';
810
811 // step 2
812 for (size_t i = 0, slen = strlen(varName); i < slen; i++) {
813 char c = varName[i];
814 if (!isalnum(c)) {
815 c = '_';
816 }
817 escdName << c;
818 }
819
820 // case 3: "mul" ==> "mul_"
821 while (isReservedName(escdName.str()))
822 escdName << '_';
823
824 // case 4: if "x" already exists, then use "x_#" where # is 0,1,..
825 std::string varNameS = escdName.str();
826 if (varNames.find(varNameS) != varNames.end()) {
827 // not unqiue, add a counter until it is unique
828 int instance = 0;
829 do {
830 std::stringstream ss;
831 ss << escdName.str() << '_' << instance++;
832 varNameS = ss.str();
833 } while (varNames.find(varNameS) != varNames.end());
834 }
835 varNames.insert(varNameS);
836
837 char *buf = (char*)m_mem.alloc(varNameS.size() + 1);
838 memcpy_s(buf, varNameS.size(), varNameS.c_str(), varNameS.size());
839 buf[varNameS.size()] = 0;
840 varName = buf;
841 }
842
generateVariableName(Common_ISA_Var_Class Ty,const char * & varName)843 void VISAKernelImpl::generateVariableName(Common_ISA_Var_Class Ty, const char *&varName)
844 {
845 if (!m_options->getOption(vISA_GenerateISAASM) && !IsAsmWriterMode())
846 {
847 // variable name is a don't care if we are not outputting vISA assembly
848 return;
849 }
850
851 bool asmInput = m_options->getOption(vISA_isParseMode);
852 if (varName && *varName)
853 {
854 // if a custom name is given, then ensure it's unique;
855 // if it's not, we will suffix it
856 // Note that it's not legal for asm input since we allow duplicate variable names if they are in different scope {...}
857 if (!asmInput)
858 {
859 ensureVariableNameUnique(varName);
860 }
861 return;
862 }
863
864 // fall back onto a generic naming scheme
865 // e.g. _V## for generic variables, etc...
866 auto createAnonVarName = [&] (char pfx, unsigned index, int fillW) {
867 std::stringstream ss;
868 ss << pfx << std::setfill('0') << std::setw(fillW) << index;
869 size_t slen = (size_t)ss.tellp();
870 char *buf = (char *)m_mem.alloc(slen + 1);
871 memcpy_s(buf, slen + 1, ss.str().c_str(), slen);
872 buf[slen] = 0;
873 return buf;
874 };
875
876 switch (Ty) {
877 case Common_ISA_Var_Class::GENERAL_VAR:
878 varName = createAnonVarName('V', varNameCount++, 4);
879 break;
880 case Common_ISA_Var_Class::PREDICATE_VAR:
881 varName = createAnonVarName('P', predicateNameCount++, 2);
882 break;
883 case Common_ISA_Var_Class::ADDRESS_VAR:
884 varName = createAnonVarName('A', addressNameCount++, 2);
885 break;
886 case Common_ISA_Var_Class::SURFACE_VAR:
887 varName = createAnonVarName('T', surfaceNameCount++, 3);
888 break;
889 case Common_ISA_Var_Class::SAMPLER_VAR:
890 varName = createAnonVarName('S', samplerNameCount++, 3);
891 break;
892 default:
893 varName = createAnonVarName('X', unknownNameCount++, 2);
894 break;
895 }
896
897 // ensure that our auto-generated name is unique
898 // i.e. suffix the variable if input already uses this name
899 ensureVariableNameUnique(varName);
900 }
901
getVarName(VISA_GenVar * decl) const902 std::string VISAKernelImpl::getVarName(VISA_GenVar* decl) const
903 {
904 return getVarName((CISA_GEN_VAR*)decl);
905 }
getVarName(VISA_PredVar * decl) const906 std::string VISAKernelImpl::getVarName(VISA_PredVar* decl) const
907 {
908 return getVarName((CISA_GEN_VAR*)decl);
909 }
getVarName(VISA_AddrVar * decl) const910 std::string VISAKernelImpl::getVarName(VISA_AddrVar* decl) const
911 {
912 return getVarName((CISA_GEN_VAR*)decl);
913 }
getVarName(VISA_SurfaceVar * decl) const914 std::string VISAKernelImpl::getVarName(VISA_SurfaceVar* decl) const
915 {
916 return getVarName((CISA_GEN_VAR*)decl);
917 }
getVarName(VISA_SamplerVar * decl) const918 std::string VISAKernelImpl::getVarName(VISA_SamplerVar* decl) const
919 {
920 return getVarName((CISA_GEN_VAR*)decl);
921 }
922
getVectorOperandName(VISA_VectorOpnd * opnd,bool showRegion) const923 std::string VISAKernelImpl::getVectorOperandName(VISA_VectorOpnd* opnd, bool showRegion) const
924 {
925 VISAKernel_format_provider fmt(this);
926 return printVectorOperand(&fmt, opnd, m_options, showRegion);
927 }
928
getPredicateOperandName(VISA_PredOpnd * opnd) const929 std::string VISAKernelImpl::getPredicateOperandName(VISA_PredOpnd* opnd) const
930 {
931 VISAKernel_format_provider fmt(this);
932 return printVectorOperand(&fmt, opnd, m_options, false);
933 }
934
CreateVISAGenVar(VISA_GenVar * & decl,const char * varName,int numberElements,VISA_Type dataType,VISA_Align varAlign,VISA_GenVar * parentDecl,int aliasOffset)935 int VISAKernelImpl::CreateVISAGenVar(
936 VISA_GenVar *& decl, const char *varName, int numberElements, VISA_Type dataType,
937 VISA_Align varAlign, VISA_GenVar *parentDecl, int aliasOffset)
938 {
939 TIME_SCOPE(VISA_BUILDER_CREATE_VAR);
940
941 if (varName == nullptr)
942 varName = "";
943 decl = (VISA_GenVar *)m_mem.alloc(sizeof(VISA_GenVar));
944 decl->type = GENERAL_VAR;
945 var_info_t *info = &decl->genVar;
946
947 generateVariableName(decl->type, varName);
948
949 if (m_options->getOption(vISA_isParseMode) && !setNameIndexMap(varName, decl))
950 {
951 assert(0);
952 return VISA_FAILURE;
953 }
954
955 m_GenVarToNameMap[decl] = varName;
956
957 info->bit_properties = (uint8_t)dataType;
958 info->bit_properties += varAlign << 4;
959
960 info->num_elements = (uint16_t)numberElements;
961 info->alias_offset = 0;
962 info->alias_index = 0;
963 info->alias_scope_specifier = 0;
964
965 if (parentDecl)
966 {
967 info->alias_offset = (uint16_t)aliasOffset;
968 info->alias_index = parentDecl->index;
969 }
970
971 info->attribute_capacity = 0;
972 info->attribute_count = 0;
973 info->attributes = NULL;
974
975 decl->index = m_var_info_count++;
976
977 if (IS_GEN_BOTH_PATH)
978 {
979 G4_Type type = GetGenTypeFromVISAType(dataType);
980 unsigned short dclWidth = 1, dclHeight = 1;
981 int totalByteSize = 0;
982 getHeightWidth(type, numberElements, dclWidth, dclHeight, totalByteSize);
983
984 info->dcl = m_builder->createDeclareNoLookup(
985 createStringCopy(varName, m_mem),
986 G4_GRF,
987 dclWidth,
988 dclHeight,
989 type);
990
991 if (parentDecl)
992 {
993 var_info_t *aliasDcl = &parentDecl->genVar;
994 info->dcl->setAliasDeclare(aliasDcl->dcl, aliasOffset);
995
996 // check if parent declare is one of the predefined
997 if (parentDecl->index < Get_CISA_PreDefined_Var_Count())
998 {
999 m_builder->preDefVars.setHasPredefined(
1000 mapExternalToInternalPreDefVar(parentDecl->index), true);
1001 }
1002 }
1003
1004 // force subalign to be GRF if total size is larger than or equal to GRF
1005 if ((info->dcl->getSubRegAlign() != GRFALIGN) ||
1006 (varAlign == (getGRFSize() == 64 ? ALIGN_64WORD : ALIGN_32WORD)) ||
1007 (varAlign == ALIGN_2_GRF))
1008 {
1009 setDeclAlignment(info->dcl, varAlign);
1010 }
1011
1012 info->name_index = -1;
1013 }
1014
1015 if (IS_VISA_BOTH_PATH || m_options->getOption(vISA_GenerateDebugInfo) || IsAsmWriterMode())
1016 {
1017 info->name_index = addStringPool(std::string(varName));
1018 addVarInfoToList(decl);
1019
1020 // Write asm variable decl to stream
1021 if (IsAsmWriterMode())
1022 {
1023 VISAKernel_format_provider fmt(this);
1024 m_CISABuilder->m_ssIsaAsm << printVariableDecl(&fmt, m_printDeclIndex.var_index++, getOptions()) << "\n";
1025 }
1026 }
1027
1028 return VISA_SUCCESS;
1029 }
1030
CreateVISAAddrVar(VISA_AddrVar * & decl,const char * varName,unsigned int numberElements)1031 int VISAKernelImpl::CreateVISAAddrVar(
1032 VISA_AddrVar *& decl, const char *varName, unsigned int numberElements)
1033 {
1034 TIME_SCOPE(VISA_BUILDER_CREATE_VAR);
1035
1036 decl = (VISA_AddrVar *)m_mem.alloc(sizeof(VISA_AddrVar));
1037 ////memset(decl, 0, sizeof(VISA_AddrVar));
1038 decl->type = ADDRESS_VAR;
1039
1040 if (m_options->getOption(vISA_isParseMode) && !setNameIndexMap(std::string(varName), decl))
1041 {
1042 assert(0);
1043 return VISA_FAILURE;
1044 }
1045
1046 addr_info_t * addr = &decl->addrVar;
1047 generateVariableName(decl->type, varName);
1048
1049 m_GenVarToNameMap[decl] = varName;
1050
1051 decl->index = m_addr_info_count++;
1052 if (IS_GEN_BOTH_PATH)
1053 {
1054 addr->dcl = m_builder->createDeclareNoLookup(
1055 createStringCopy(varName, m_mem),
1056 G4_ADDRESS,
1057 (uint16_t)numberElements,
1058 1,
1059 Type_UW);
1060 addr->name_index = -1;
1061 }
1062
1063 addr->num_elements = (uint16_t)numberElements;
1064 addr->attribute_capacity = 0;
1065 addr->attribute_count = 0;
1066 addr->attributes = NULL;
1067
1068 if (IS_VISA_BOTH_PATH || m_options->getOption(vISA_GenerateDebugInfo) || IsAsmWriterMode())
1069 {
1070 addr->name_index = addStringPool(std::string(varName));
1071 addAddrToList(decl);
1072
1073 if (IsAsmWriterMode())
1074 {
1075 VISAKernel_format_provider fmt(this);
1076 m_CISABuilder->m_ssIsaAsm << printAddressDecl(m_CISABuilder->m_header, &fmt, m_printDeclIndex.addr_index++) << "\n";
1077 }
1078 }
1079
1080 return VISA_SUCCESS;
1081 }
1082
CreateVISAPredVar(VISA_PredVar * & decl,const char * varName,unsigned short numberElements)1083 int VISAKernelImpl::CreateVISAPredVar(
1084 VISA_PredVar *& decl, const char* varName, unsigned short numberElements)
1085 {
1086 TIME_SCOPE(VISA_BUILDER_CREATE_VAR);
1087
1088 decl = (VISA_PredVar *)m_mem.alloc(sizeof(VISA_PredVar));
1089 ////memset(decl, 0, sizeof(VISA_PredVar));
1090 decl->type = PREDICATE_VAR;
1091
1092 const int MAX_VISA_PRED_SIZE = 32;
1093 MUST_BE_TRUE(numberElements <= MAX_VISA_PRED_SIZE, "number of flags must be <= 32");
1094
1095 if (m_options->getOption(vISA_isParseMode) && !setNameIndexMap(std::string(varName), decl))
1096 {
1097 assert(0);
1098 return VISA_FAILURE;
1099 }
1100 generateVariableName(decl->type, varName);
1101
1102 m_GenVarToNameMap[decl] = varName;
1103
1104 pred_info_t * pred = &decl->predVar;
1105
1106 decl->index = COMMON_ISA_NUM_PREDEFINED_PRED + m_pred_info_count++;
1107 pred->num_elements = numberElements;
1108 pred->attribute_capacity = 0;
1109 pred->attribute_count = 0;
1110 pred->attributes = NULL;
1111 if (IS_GEN_BOTH_PATH)
1112 {
1113 pred->dcl = m_builder->createFlag(numberElements, createStringCopy(varName, m_mem));
1114 pred->name_index = -1;
1115 }
1116 if (IS_VISA_BOTH_PATH || m_options->getOption(vISA_GenerateDebugInfo) || IsAsmWriterMode())
1117 {
1118 pred->name_index = addStringPool(std::string(varName));
1119 addPredToList(decl);
1120 }
1121
1122 if (IsAsmWriterMode())
1123 {
1124 VISAKernel_format_provider fmt(this);
1125 m_CISABuilder->m_ssIsaAsm << printPredicateDecl(&fmt, m_printDeclIndex.pred_index++) << "\n";
1126 }
1127
1128 return VISA_SUCCESS;
1129 }
1130
CreateStateVar(CISA_GEN_VAR * & decl,Common_ISA_Var_Class type,const char * varName,unsigned int numberElements)1131 int VISAKernelImpl::CreateStateVar(
1132 CISA_GEN_VAR *&decl, Common_ISA_Var_Class type, const char* varName, unsigned int numberElements)
1133 {
1134 TIME_SCOPE(VISA_BUILDER_CREATE_VAR);
1135
1136 decl = (CISA_GEN_VAR *)m_mem.alloc(sizeof(CISA_GEN_VAR));
1137 ////memset(decl, 0, sizeof(CISA_GEN_VAR));
1138 decl->type = type;
1139
1140 if (m_options->getOption(vISA_isParseMode) && !setNameIndexMap(std::string(varName), decl))
1141 {
1142 assert(0);
1143 return VISA_FAILURE;
1144 }
1145 generateVariableName(decl->type, varName);
1146
1147 m_GenVarToNameMap[decl] = varName;
1148
1149 state_info_t * state = &decl->stateVar;
1150 state->attribute_capacity = 0;
1151 state->attribute_count = 0;
1152 state->attributes = NULL;
1153 state->num_elements = (uint16_t)numberElements;
1154 if (IS_GEN_BOTH_PATH)
1155 {
1156 state->dcl = m_builder->createDeclareNoLookup(
1157 createStringCopy(varName, m_mem),
1158 G4_GRF,
1159 (uint16_t)numberElements,
1160 1,
1161 Type_UD);
1162 state->name_index = -1;
1163 }
1164
1165 switch (type)
1166 {
1167 case SAMPLER_VAR:
1168 decl->index = m_sampler_count++;
1169 break;
1170 case SURFACE_VAR:
1171 decl->index = m_surface_count++;
1172 break;
1173 default:
1174 assert(0);
1175 return VISA_FAILURE;
1176 }
1177
1178 if (IS_VISA_BOTH_PATH || m_options->getOption(vISA_GenerateDebugInfo) || IsAsmWriterMode())
1179 {
1180 state->name_index = addStringPool(std::string(varName));
1181 switch (type)
1182 {
1183 case SAMPLER_VAR:
1184 {
1185 addSampler(decl);
1186 if (IsAsmWriterMode())
1187 {
1188 VISAKernel_format_provider fmt(this);
1189 m_CISABuilder->m_ssIsaAsm << printSamplerDecl(&fmt, m_printDeclIndex.sampler_index++) << "\n";
1190 }
1191 break;
1192 }
1193 case SURFACE_VAR:
1194 {
1195 addSurface(decl);
1196 if (IsAsmWriterMode())
1197 {
1198 VISAKernel_format_provider fmt(this);
1199 unsigned numPreDefinedSurfs = Get_CISA_PreDefined_Surf_Count();
1200 m_CISABuilder->m_ssIsaAsm << printSurfaceDecl(&fmt, m_printDeclIndex.surface_index++, numPreDefinedSurfs) << "\n";
1201 }
1202 break;
1203 }
1204 default:
1205 assert(0);
1206 return VISA_FAILURE;
1207 }
1208 }
1209
1210 return VISA_SUCCESS;
1211 }
1212
CreateVISASamplerVar(VISA_SamplerVar * & decl,const char * name,unsigned int numberElements)1213 int VISAKernelImpl::CreateVISASamplerVar(
1214 VISA_SamplerVar *&decl, const char* name, unsigned int numberElements)
1215 {
1216 return CreateStateVar((CISA_GEN_VAR *&)decl, SAMPLER_VAR, name, numberElements);
1217 }
1218
CreateVISASurfaceVar(VISA_SurfaceVar * & decl,const char * name,unsigned int numberElements)1219 int VISAKernelImpl::CreateVISASurfaceVar(
1220 VISA_SurfaceVar *&decl, const char* name, unsigned int numberElements)
1221 {
1222 return CreateStateVar((CISA_GEN_VAR *&)decl, SURFACE_VAR, name, numberElements);
1223 }
1224
CreateVISALabelVar(VISA_LabelOpnd * & opnd,const char * name,VISA_Label_Kind kind)1225 int VISAKernelImpl::CreateVISALabelVar(VISA_LabelOpnd *& opnd, const char* name, VISA_Label_Kind kind)
1226 {
1227 TIME_SCOPE(VISA_BUILDER_CREATE_VAR);
1228
1229 opnd = (VISA_LabelOpnd *)m_mem.alloc(sizeof(VISA_LabelOpnd));
1230
1231 if (IS_GEN_BOTH_PATH)
1232 {
1233 //needs to be persistent since label opnd can be used multiple times
1234 if (getIsFunction())
1235 {
1236 std::string fname = "L_f" + std::to_string(m_functionId) + "_" + name;
1237 opnd->g4opnd = m_builder->createLabel(fname, kind);
1238 }
1239 else
1240 {
1241 std::string kname(name);
1242 opnd->g4opnd = m_builder->createLabel(kname, kind);
1243 }
1244 if (kind == LABEL_SUBROUTINE)
1245 {
1246 ((G4_Label*)opnd->g4opnd)->setFuncLabel(true);
1247 }
1248 else
1249 {
1250 ((G4_Label*)opnd->g4opnd)->setFuncLabel(false);
1251
1252 if (kind == LABEL_FC)
1253 {
1254 // Need to do this here because label kind
1255 // from VISA is not propagated to G4 IR
1256 // directly.
1257 ((G4_Label*)opnd->g4opnd)->setFCLabel(true);
1258 }
1259 }
1260 }
1261 if (IS_VISA_BOTH_PATH)
1262 {
1263 label_info_t *lbl = (label_info_t *)m_mem.alloc(sizeof(label_info_t));
1264 lbl->name_index = addStringPool(std::string(name));
1265 lbl->kind = kind;
1266 m_label_info_list.push_back(lbl);
1267
1268 opnd->_opnd.other_opnd = m_label_count++;
1269
1270 VISA_INST_Desc *inst_desc = NULL;
1271
1272 if (kind == LABEL_BLOCK)
1273 {
1274 inst_desc = &CISA_INST_table[ISA_LABEL];
1275 opnd->tag = ISA_LABEL;
1276 }
1277 else
1278 {
1279 inst_desc = &CISA_INST_table[ISA_SUBROUTINE];
1280 opnd->tag = ISA_SUBROUTINE;
1281 }
1282
1283 opnd->opnd_type = CISA_OPND_OTHER;
1284 opnd->size = (uint16_t)Get_VISA_Type_Size((VISA_Type)inst_desc->opnd_desc[0].data_type);
1285 //opnd->tag = inst_desc->opnd_desc[0].opnd_type;
1286 lbl->attribute_capacity = 0;
1287 lbl->attribute_count = 0;
1288 lbl->attributes = NULL;
1289
1290 m_label_info_size += lbl->getSizeInBinary();
1291 }
1292
1293 return VISA_SUCCESS;
1294 }
1295
AddKernelAttribute(const char * attrName,int size,const void * valueBuffer)1296 int VISAKernelImpl::AddKernelAttribute(const char* attrName, int size, const void *valueBuffer)
1297 {
1298 attribute_info_t* attr = (attribute_info_t*)m_mem.alloc(sizeof(attribute_info_t));
1299 Attributes::ID attrID = Attributes::getAttributeID(attrName);
1300
1301 ASSERT_USER(Attributes::isKernelAttr(attrID), "Not a kernel attribute");
1302
1303 if (attrID == Attributes::ATTR_OutputAsmPath)
1304 {
1305 if (m_options->getOption(vISA_AsmFileNameOverridden))
1306 {
1307 const char *asmName = nullptr;
1308 m_options->getOption(VISA_AsmFileName, asmName);
1309 if (asmName != nullptr)
1310 {
1311 m_asmName = asmName;
1312 }
1313 else
1314 {
1315 m_asmName = "";
1316 }
1317 }
1318 else
1319 {
1320 std::string str((const char *)valueBuffer);
1321 if (m_options->getOption(vISA_dumpToCurrentDir))
1322 {
1323 auto found = str.find_last_of(DIR_WIN32_SEPARATOR);
1324 if (found == std::string::npos)
1325 {
1326 found = str.find_last_of(DIR_UNIX_SEPARATOR);
1327 }
1328
1329 if (found != std::string::npos)
1330 {
1331 str = str.substr(found + 1);
1332 }
1333 }
1334 m_asmName = sanitizePathString(str);
1335
1336 size_t found = m_asmName.find(".asm");
1337 if (found != std::string::npos)
1338 {
1339 m_asmName.erase(found, m_asmName.length());
1340 }
1341 m_options->setOptionInternally(VISA_AsmFileName, m_asmName.c_str());
1342 }
1343 }
1344
1345 attr->size = (uint8_t)size;
1346 if (Attributes::isInt32(attrID))
1347 {
1348 attr->isInt = true;
1349 switch (attr->size)
1350 {
1351 case 0: attr->value.intVal = 1; break;
1352 case 1: attr->value.intVal = *((int8_t *)valueBuffer); break;
1353 case 2: attr->value.intVal = *((int16_t*)valueBuffer); break;
1354 case 4: attr->value.intVal = *((int32_t*)valueBuffer); break;
1355 default:
1356 ASSERT_USER(false, "Unsupported attribute size");
1357 break;
1358 }
1359 m_kernelAttrs->setKernelAttr(attrID, attr->value.intVal);
1360 }
1361 else if (Attributes::isBool(attrID))
1362 {
1363 attr->isInt = true; // treat bool as int in attribute_info_t
1364 attr->value.intVal = 1;
1365 m_kernelAttrs->setKernelAttr(attrID, true);
1366 }
1367 else if (Attributes::isCStr(attrID))
1368 {
1369 attr->isInt = false;
1370 if (size > 0)
1371 {
1372 char *tmp = (char*)m_mem.alloc(size + 1);
1373 memcpy_s(tmp, size + 1, valueBuffer, size + 1);
1374 attr->value.stringVal = tmp;
1375 }
1376 else
1377 {
1378 attr->value.stringVal = (const char*)"";
1379 }
1380 m_kernelAttrs->setKernelAttr(attrID, attr->value.stringVal);
1381 }
1382 else
1383 {
1384 MUST_BE_TRUE(false, "Unsupported kernel attribute!");
1385 }
1386
1387 if (attrID == Attributes::ATTR_Target)
1388 {
1389 if (attr->value.intVal == 0)
1390 {
1391 // ToDo: remove setTarget() call, internal code should use getKernelType() instead
1392 m_options->setTarget(VISA_CM);
1393 m_kernel->setKernelType(VISA_CM);
1394 }
1395 else if (attr->value.intVal == 1)
1396 {
1397 m_options->setTarget(VISA_3D);
1398 m_kernel->setKernelType(VISA_3D);
1399 }
1400 else
1401 {
1402 ASSERT_USER(false, "Invalid kernel target attribute.");
1403 }
1404 }
1405
1406 if (attrID == Attributes::ATTR_Callable)
1407 {
1408 setFCCallableKernel(true);
1409 }
1410 else if (attrID == Attributes::ATTR_Caller)
1411 {
1412 setFCCallerKernel(true);
1413 }
1414 else if (attrID == Attributes::ATTR_Composable)
1415 {
1416 setFCComposableKernel(true);
1417 if (IS_GEN_BOTH_PATH)
1418 {
1419 m_builder->getFCPatchInfo()->setFCComposableKernel(true);
1420 }
1421 m_options->setOption(vISA_loadThreadPayload, false);
1422 }
1423 else if (attrID == Attributes::ATTR_Entry)
1424 {
1425 m_builder->getFCPatchInfo()->setIsEntryKernel(true);
1426 m_options->setOption(vISA_loadThreadPayload, true);
1427 }
1428 else if (attrID == Attributes::ATTR_RetValSize)
1429 {
1430 if (IS_GEN_BOTH_PATH)
1431 {
1432 if (m_builder->getRetVarSize() < attr->value.intVal)
1433 {
1434 m_builder->setRetVarSize((unsigned short)(attr->value.intVal));
1435 }
1436 }
1437 }
1438 else if (attrID == Attributes::ATTR_ArgSize)
1439 {
1440 if (IS_GEN_BOTH_PATH)
1441 {
1442 if (m_builder->getArgSize() < attr->value.intVal)
1443 {
1444 m_builder->setArgSize((unsigned short)(attr->value.intVal));
1445 }
1446 }
1447 }
1448
1449 addAttribute(attrName, attr);
1450
1451 if (IsAsmWriterMode())
1452 {
1453 // Print attribute
1454 VISAKernel_format_provider fmt(this);
1455 m_CISABuilder->m_ssIsaAsm << ".kernel_attr " << printOneAttribute(&fmt, attr) << "\n";
1456 }
1457
1458 return VISA_SUCCESS;
1459 }
1460
1461 // If AllocMaxNum == 0, return pointer to next attribute and advance attribute count;
1462 // otherwise, resize attributes with AllocMaxNum and return the base of the whole attributes.
allocAttributeImpl(CISA_GEN_VAR * Dcl,uint32_t AllocMaxNum)1463 attribute_info_t* VISAKernelImpl::allocAttributeImpl(CISA_GEN_VAR* Dcl, uint32_t AllocMaxNum)
1464 {
1465 const uint32_t DefaultCapInc = 4; // default size for capacity
1466
1467 unsigned char* pCap = nullptr;
1468 unsigned char* pCnt = nullptr;
1469 attribute_info_t** pAttributes = nullptr;
1470 switch (Dcl->type)
1471 {
1472 case GENERAL_VAR:
1473 pCap = &(Dcl->genVar.attribute_capacity);
1474 pCnt = &(Dcl->genVar.attribute_count);
1475 pAttributes = &(Dcl->genVar.attributes);
1476 break;
1477 case ADDRESS_VAR:
1478 pCap = &(Dcl->addrVar.attribute_capacity);
1479 pCnt = &(Dcl->addrVar.attribute_count);
1480 pAttributes = &(Dcl->addrVar.attributes);
1481 break;
1482 case PREDICATE_VAR:
1483 pCap = &(Dcl->predVar.attribute_capacity);
1484 pCnt = &(Dcl->predVar.attribute_count);
1485 pAttributes = &(Dcl->predVar.attributes);
1486 break;
1487 case SAMPLER_VAR:
1488 pCap = &(Dcl->stateVar.attribute_capacity);
1489 pCnt = &(Dcl->stateVar.attribute_count);
1490 pAttributes = &(Dcl->stateVar.attributes);
1491 break;
1492 case SURFACE_VAR:
1493 pCap = &(Dcl->stateVar.attribute_capacity);
1494 pCnt = &(Dcl->stateVar.attribute_count);
1495 pAttributes = &(Dcl->stateVar.attributes);
1496 break;
1497 case LABEL_VAR:
1498 pCap = &(Dcl->labelVar.attribute_capacity);
1499 pCnt = &(Dcl->labelVar.attribute_count);
1500 pAttributes = &(Dcl->labelVar.attributes);
1501 break;
1502 default:
1503 assert(0);
1504 return nullptr;
1505 }
1506
1507 uint32_t currCap = (*pCap);
1508 uint32_t currCnt = (*pCnt);
1509 attribute_info_t* currAttr = (*pAttributes);
1510 if (AllocMaxNum == 0 && currCap > currCnt)
1511 {
1512 (*pCnt) = currCnt + 1;
1513 return &currAttr[currCnt];
1514 }
1515 else if (AllocMaxNum > 0 && currCap >= AllocMaxNum)
1516 {
1517 return currAttr;
1518 }
1519
1520 uint32_t newCap = (AllocMaxNum == 0) ? (currCap + DefaultCapInc) : AllocMaxNum;
1521 attribute_info_t* newAttr = (attribute_info_t*)m_mem.alloc(sizeof(attribute_info_t) * newCap);
1522 if (currCnt > 0)
1523 {
1524 uint32_t bytesToCopy = sizeof(attribute_info_t) * currCnt;
1525 memcpy_s(newAttr, bytesToCopy, currAttr, bytesToCopy);
1526 }
1527
1528 (*pCap) = newCap;
1529 (*pAttributes) = newAttr;
1530 if (AllocMaxNum > 0)
1531 {
1532 return newAttr;
1533 }
1534 (*pCnt) = currCnt + 1;
1535 return &newAttr[currCnt];
1536 }
1537
AddAttributeToVarGeneric(CISA_GEN_VAR * decl,const char * attrName,unsigned int size,const void * val)1538 int VISAKernelImpl::AddAttributeToVarGeneric(
1539 CISA_GEN_VAR *decl, const char* attrName, unsigned int size, const void *val)
1540 {
1541 TIME_SCOPE(VISA_BUILDER_CREATE_VAR);
1542
1543 attribute_info_t* attr = allocAttribute(decl);
1544 attr->nameIndex = addStringPool(std::string(attrName));
1545 Attributes::ID aID = Attributes::getAttributeID(attrName);
1546 ASSERT_USER(Attributes::isVarAttr(aID), "ERROR: unknown var attribute");
1547
1548 attr->size = (uint8_t)size;
1549 if (Attributes::isInt32(aID))
1550 {
1551 attr->isInt = true;
1552 attr->value.intVal = val ? *((int*)val) : 0;
1553 assert(attr->size <= 4 && "Int32 attribute has a value of 4 bytes at most!");
1554 }
1555 else if (Attributes::isBool(aID))
1556 {
1557 attr->isInt = true; // treat bool as int in attribute_info_t
1558 attr->value.intVal = 1;
1559 }
1560 else if (Attributes::isCStr(aID))
1561 {
1562 attr->isInt = false;
1563 char* temp = (char *)m_mem.alloc(size+1); // null-ending C-string
1564 memcpy_s(temp, size, val, size);
1565 temp[size] = 0;
1566 attr->value.stringVal = (const char*)temp;
1567 }
1568 else
1569 {
1570 MUST_BE_TRUE(false, "ERROR: unexpected variable attribute");
1571 }
1572
1573 switch (decl->type)
1574 {
1575 case GENERAL_VAR:
1576 {
1577 if (IS_GEN_BOTH_PATH)
1578 {
1579 auto rootDcl = decl->genVar.dcl->getRootDeclare();
1580 if (Attributes::isAttribute(Attributes::ATTR_Input, attrName) ||
1581 Attributes::isAttribute(Attributes::ATTR_Input_Output, attrName))
1582 {
1583 rootDcl->setLiveIn();
1584 }
1585 if (Attributes::isAttribute(Attributes::ATTR_Output, attrName) ||
1586 Attributes::isAttribute(Attributes::ATTR_Input_Output, attrName))
1587 {
1588 rootDcl->setLiveOut();
1589 }
1590 if (Attributes::isAttribute(Attributes::ATTR_NoWidening, attrName))
1591 {
1592 rootDcl->setDoNotWiden();
1593 }
1594 if (Attributes::isAttribute(Attributes::ATTR_DoNotSpill, attrName))
1595 {
1596 rootDcl->setDoNotSpill();
1597 }
1598 if (Attributes::isAttribute(Attributes::ATTR_PayloadLiveOut, attrName))
1599 {
1600 rootDcl->setPayloadLiveOut();
1601 }
1602 }
1603 break;
1604 }
1605 case ADDRESS_VAR:
1606 {
1607 m_address_info_size += attr->getSizeInBinary();
1608 break;
1609 }
1610 case PREDICATE_VAR:
1611 {
1612 m_predicate_info_size += attr->getSizeInBinary();
1613 break;
1614 }
1615 case SAMPLER_VAR:
1616 {
1617 m_sampler_info_size += attr->getSizeInBinary();
1618 break;
1619 }
1620 case SURFACE_VAR:
1621 {
1622 break;
1623 }
1624 case LABEL_VAR:
1625 {
1626 m_label_info_size += attr->getSizeInBinary();
1627 break;
1628 }
1629 default:
1630 assert(0);
1631 return VISA_FAILURE;
1632 }
1633
1634 return VISA_SUCCESS;
1635 }
1636
AddAttributeToVar(VISA_PredVar * decl,const char * name,unsigned int size,void * val)1637 int VISAKernelImpl::AddAttributeToVar(
1638 VISA_PredVar *decl, const char* name, unsigned int size, void *val)
1639 {
1640 return AddAttributeToVarGeneric((CISA_GEN_VAR *)decl, name, size, val);
1641 }
1642
AddAttributeToVar(VISA_SurfaceVar * decl,const char * name,unsigned int size,void * val)1643 int VISAKernelImpl::AddAttributeToVar(
1644 VISA_SurfaceVar *decl, const char* name, unsigned int size, void *val)
1645 {
1646 return AddAttributeToVarGeneric((CISA_GEN_VAR *)decl, name, size, val);
1647 }
1648
AddAttributeToVar(VISA_GenVar * decl,const char * name,unsigned int size,void * val)1649 int VISAKernelImpl::AddAttributeToVar(
1650 VISA_GenVar *decl, const char* name, unsigned int size, void *val)
1651 {
1652 return AddAttributeToVarGeneric((CISA_GEN_VAR *)decl, name, size, val);
1653 }
1654
AddAttributeToVar(VISA_AddrVar * decl,const char * name,unsigned int size,void * val)1655 int VISAKernelImpl::AddAttributeToVar(
1656 VISA_AddrVar *decl, const char* name, unsigned int size, void *val)
1657 {
1658 return AddAttributeToVarGeneric((CISA_GEN_VAR *)decl, name, size, val);
1659 }
1660
addVarInfoToList(CISA_GEN_VAR * t)1661 void VISAKernelImpl::addVarInfoToList(CISA_GEN_VAR * t)
1662 {
1663 m_var_info_list.push_back(t);
1664 }
1665
addSampler(CISA_GEN_VAR * state)1666 void VISAKernelImpl::addSampler(CISA_GEN_VAR * state)
1667 {
1668 m_sampler_info_list.push_back(state);
1669 m_sampler_info_size += state->stateVar.getSizeInBinary();
1670 }
1671
addSurface(CISA_GEN_VAR * state)1672 void VISAKernelImpl::addSurface(CISA_GEN_VAR * state)
1673 {
1674 m_surface_info_list.push_back(state);
1675 }
1676
addAddrToList(CISA_GEN_VAR * addr)1677 void VISAKernelImpl::addAddrToList(CISA_GEN_VAR * addr)
1678 {
1679 m_addr_info_list.push_back(addr);
1680 m_address_info_size += addr->addrVar.getSizeInBinary();
1681 }
1682
addPredToList(CISA_GEN_VAR * pred)1683 void VISAKernelImpl::addPredToList(CISA_GEN_VAR * pred)
1684 {
1685 m_pred_info_list.push_back(pred);
1686 m_predicate_info_size += pred->predVar.getSizeInBinary();
1687 }
1688
addAttribute(const char * inputName,attribute_info_t * attrTemp)1689 void VISAKernelImpl::addAttribute(const char *inputName, attribute_info_t *attrTemp)
1690 {
1691 attrTemp->nameIndex = addStringPool(std::string(inputName));
1692 m_attribute_info_list.push_back(attrTemp);
1693 m_attribute_count++;
1694 m_attribute_info_size += attrTemp->getSizeInBinary();
1695 }
1696
GetInputClass(Common_ISA_Var_Class var_class)1697 Common_ISA_Input_Class VISAKernelImpl::GetInputClass(Common_ISA_Var_Class var_class)
1698 {
1699 if (var_class == GENERAL_VAR)
1700 return INPUT_GENERAL;
1701
1702 if (var_class == SAMPLER_VAR)
1703 return INPUT_SAMPLER;
1704
1705 if (var_class == SURFACE_VAR)
1706 return INPUT_SURFACE;
1707
1708 return INPUT_UNKNOWN;
1709 }
1710
CreateVISAInputVar(CISA_GEN_VAR * decl,uint16_t offset,uint16_t size,uint8_t implicitKind)1711 int VISAKernelImpl::CreateVISAInputVar(
1712 CISA_GEN_VAR *decl, uint16_t offset, uint16_t size, uint8_t implicitKind)
1713 {
1714 TIME_SCOPE(VISA_BUILDER_CREATE_VAR);
1715
1716 unsigned int status = VISA_SUCCESS;
1717 input_info_t * input = (input_info_t *)m_mem.alloc(sizeof(input_info_t));
1718 input->kind = GetInputClass(decl->type);
1719 input->kind |= implicitKind << 3;
1720 input->setImplicitKind(implicitKind);
1721 input->index = decl->index;
1722 input->offset = offset;
1723 input->size = size;
1724
1725 if (IS_GEN_BOTH_PATH)
1726 {
1727 G4_Declare *dcl = NULL;
1728 switch (decl->type)
1729 {
1730 case GENERAL_VAR:
1731 {
1732 dcl = decl->genVar.dcl;
1733 break;
1734 }
1735 case SAMPLER_VAR:
1736 case SURFACE_VAR:
1737 {
1738 dcl = decl->stateVar.dcl;
1739 break;
1740 }
1741 default:
1742 {
1743 status = VISA_FAILURE;
1744 break;
1745 }
1746 }
1747
1748 if (status == VISA_SUCCESS)
1749 {
1750 m_builder->bindInputDecl(dcl, offset);
1751 }
1752 input->dcl = dcl;
1753 //used in asm generation
1754 m_builder->addInputArg(input);
1755 }
1756 if (IS_VISA_BOTH_PATH || IsAsmWriterMode())
1757 {
1758
1759 if ((input->kind & 0x3) == INPUT_UNKNOWN) {
1760 fprintf(stderr, "Wrong input variable is used");
1761 status = VISA_FAILURE;
1762 }
1763 else
1764 {
1765 m_input_info_list.push_back(input);
1766 m_input_count++;
1767 m_input_info_size += input->getSizeInBinary();
1768
1769 if (IsAsmWriterMode())
1770 {
1771 // Print input var
1772 VISAKernel_format_provider fmt(this);
1773 m_CISABuilder->m_ssIsaAsm << printFuncInput(&fmt, m_printDeclIndex.input_index++, getIsKernel(), getOptions()) << "\n";
1774 }
1775 }
1776 }
1777
1778 // save the G4_declare of "R1" input in builder
1779 if (offset == getGRFSize() && size == getGRFSize() && m_builder)
1780 {
1781 m_builder->setInputR1(input->dcl);
1782 }
1783
1784 return status;
1785 }
1786
CreateVISAImplicitInputVar(VISA_GenVar * decl,unsigned short offset,unsigned short size,unsigned short kind)1787 int VISAKernelImpl::CreateVISAImplicitInputVar(
1788 VISA_GenVar *decl, unsigned short offset, unsigned short size, unsigned short kind)
1789 {
1790 return CreateVISAInputVar((CISA_GEN_VAR *)decl, offset, size, (uint8_t)kind);
1791 }
1792
CreateVISAInputVar(VISA_GenVar * decl,unsigned short offset,unsigned short size)1793 int VISAKernelImpl::CreateVISAInputVar(
1794 VISA_GenVar *decl, unsigned short offset, unsigned short size)
1795 {
1796 return CreateVISAInputVar((CISA_GEN_VAR *)decl, offset, size, INPUT_EXPLICIT);
1797 }
1798
CreateVISAInputVar(VISA_SamplerVar * decl,unsigned short offset,unsigned short size)1799 int VISAKernelImpl::CreateVISAInputVar(
1800 VISA_SamplerVar *decl, unsigned short offset, unsigned short size)
1801 {
1802 return CreateVISAInputVar((CISA_GEN_VAR *)decl, offset, size, INPUT_EXPLICIT);
1803 }
1804
CreateVISAInputVar(VISA_SurfaceVar * decl,unsigned short offset,unsigned short size)1805 int VISAKernelImpl::CreateVISAInputVar(
1806 VISA_SurfaceVar *decl, unsigned short offset, unsigned short size)
1807 {
1808 return CreateVISAInputVar((CISA_GEN_VAR *)decl, offset, size, INPUT_EXPLICIT);
1809 }
1810
1811 /************* OPERANDS CREATION START ******************/
CreateVISAAddressSrcOperand(VISA_VectorOpnd * & opnd,VISA_AddrVar * decl,unsigned int offset,unsigned int width)1812 int VISAKernelImpl::CreateVISAAddressSrcOperand(
1813 VISA_VectorOpnd *&opnd, VISA_AddrVar *decl, unsigned int offset, unsigned int width)
1814 {
1815 return CreateVISAAddressOperand(opnd, decl, offset, width, false);
1816 }
1817
CreateVISAAddressDstOperand(VISA_VectorOpnd * & opnd,VISA_AddrVar * decl,unsigned int offset)1818 int VISAKernelImpl::CreateVISAAddressDstOperand(
1819 VISA_VectorOpnd *&opnd, VISA_AddrVar *decl, unsigned int offset)
1820 {
1821 return CreateVISAAddressOperand(opnd, decl, offset, 1, true);
1822 }
CreateVISAAddressOperand(VISA_VectorOpnd * & cisa_opnd,VISA_AddrVar * decl,unsigned int offset,unsigned int width,bool isDst)1823 int VISAKernelImpl::CreateVISAAddressOperand(
1824 VISA_VectorOpnd *&cisa_opnd, VISA_AddrVar *decl,
1825 unsigned int offset, unsigned int width, bool isDst)
1826 {
1827 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
1828
1829 cisa_opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
1830 if (IS_GEN_BOTH_PATH)
1831 {
1832 G4_Declare *dcl = decl->addrVar.dcl;
1833
1834 if (!isDst)
1835 {
1836 // FIXME: This does not adhere to the vISA spec, which allows <0;N,1> regions where
1837 // N is < exec size
1838 const RegionDesc* rd = width > 1 ?
1839 m_builder->getRegionStride1() : m_builder->getRegionScalar();
1840 cisa_opnd->g4opnd = m_builder->createSrc(
1841 dcl->getRegVar(),
1842 0,
1843 (uint16_t)offset,
1844 rd,
1845 dcl->getElemType());
1846 }
1847 else
1848 {
1849 cisa_opnd->g4opnd = m_builder->createDst(
1850 dcl->getRegVar(),
1851 0, //opnd->opnd_val.addr_opnd.index, // should we use 0 here?
1852 (uint16_t)offset,
1853 1,
1854 dcl->getElemType());
1855 }
1856 }
1857 if (IS_VISA_BOTH_PATH)
1858 {
1859 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
1860 cisa_opnd->tag = OPERAND_ADDRESS;
1861 cisa_opnd->_opnd.v_opnd.tag = OPERAND_ADDRESS;
1862 cisa_opnd->_opnd.v_opnd.opnd_val.addr_opnd.index = (uint16_t)decl->index;
1863 cisa_opnd->_opnd.v_opnd.opnd_val.addr_opnd.offset = (uint8_t)offset;
1864 cisa_opnd->_opnd.v_opnd.opnd_val.addr_opnd.width =
1865 Get_VISA_Exec_Size_From_Raw_Size(width & 0x1F);
1866 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
1867
1868 }
1869
1870 return VISA_SUCCESS;
1871 }
1872
CreateVISAAddressOfOperandGeneric(VISA_VectorOpnd * & cisa_opnd,CISA_GEN_VAR * decl,unsigned int offset)1873 int VISAKernelImpl::CreateVISAAddressOfOperandGeneric(
1874 VISA_VectorOpnd *&cisa_opnd, CISA_GEN_VAR *decl, unsigned int offset)
1875 {
1876 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
1877
1878 int status = VISA_SUCCESS;
1879 cisa_opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
1880
1881 if (IS_GEN_BOTH_PATH)
1882 {
1883 G4_Declare *src0Dcl = NULL;
1884 switch (decl->type)
1885 {
1886 case GENERAL_VAR:
1887 {
1888 src0Dcl = decl->genVar.dcl;
1889 break;
1890 }
1891 case SAMPLER_VAR:
1892 case SURFACE_VAR:
1893 {
1894 src0Dcl = decl->stateVar.dcl;
1895 break;
1896 }
1897 default:
1898 assert(0);
1899 return VISA_FAILURE;
1900 }
1901
1902 // set up to the top level dcl to be addressed
1903 src0Dcl->setAddressed();
1904 m_kernel->setHasAddrTaken(true);
1905 G4_Declare *parentDcl = src0Dcl->getAliasDeclare();
1906 while (parentDcl) {
1907 parentDcl->setAddressed();
1908 parentDcl = parentDcl->getAliasDeclare();
1909 }
1910 cisa_opnd->g4opnd = m_builder->createAddrExp(
1911 src0Dcl->getRegVar(),
1912 offset,
1913 Type_UW);
1914 }
1915 if (IS_VISA_BOTH_PATH)
1916 {
1917 //memset(cisa_opnd,0,sizeof(VISA_opnd));
1918 switch (decl->type)
1919 {
1920 case GENERAL_VAR:
1921 {
1922 cisa_opnd->tag = OPERAND_GENERAL;
1923 cisa_opnd->_opnd.v_opnd.tag = OPERAND_GENERAL;
1924 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.index = decl->index;
1925 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.row_offset = offset / numEltPerGRF<Type_UB>();
1926 VISA_Type type = decl->genVar.getType();
1927 unsigned int typeSize = TypeSize(GetGenTypeFromVISAType(type));
1928 assert((offset % typeSize) == 0);
1929 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.col_offset = (offset % numEltPerGRF<Type_UB>())/typeSize;
1930
1931
1932 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.region =
1933 (unsigned short)Get_CISA_Region_Val(0);
1934 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.region |=
1935 ((unsigned short)Get_CISA_Region_Val(1)) << 4;
1936 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.region |=
1937 ((unsigned short)Get_CISA_Region_Val(0)) << 8;
1938 break;
1939 }
1940 case SAMPLER_VAR:
1941 case SURFACE_VAR:
1942 {
1943 cisa_opnd->tag = OPERAND_STATE;
1944 cisa_opnd->_opnd.v_opnd.tag = OPERAND_STATE;
1945 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.index = (uint16_t)decl->index;
1946 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.offset = (uint8_t)offset;
1947 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.opnd_class = decl->type;
1948 if (decl->type == SAMPLER_VAR)
1949 {
1950 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.opnd_class = STATE_OPND_SAMPLER;
1951 }
1952 else if (decl->type == SURFACE_VAR)
1953 {
1954 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.opnd_class = STATE_OPND_SURFACE;
1955 }
1956 break;
1957 }
1958 default:
1959 MUST_BE_TRUE(false, "ERROR: unexpected variable class");
1960 break;
1961 }
1962
1963 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
1964 cisa_opnd->index = decl->index;
1965 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
1966 }
1967 return status;
1968 }
1969
CreateVISAAddressOfOperand(VISA_VectorOpnd * & cisa_opnd,VISA_GenVar * decl,unsigned int offset)1970 int VISAKernelImpl::CreateVISAAddressOfOperand(
1971 VISA_VectorOpnd *&cisa_opnd, VISA_GenVar *decl, unsigned int offset)
1972 {
1973 return CreateVISAAddressOfOperandGeneric(cisa_opnd, decl, offset);
1974 }
CreateVISAAddressOfOperand(VISA_VectorOpnd * & cisa_opnd,VISA_SurfaceVar * decl,unsigned int offset)1975 int VISAKernelImpl::CreateVISAAddressOfOperand(
1976 VISA_VectorOpnd *&cisa_opnd, VISA_SurfaceVar *decl, unsigned int offset)
1977 {
1978 return CreateVISAAddressOfOperandGeneric(cisa_opnd, decl, offset);
1979 }
1980
CreateVISAIndirectGeneralOperand(VISA_VectorOpnd * & cisa_opnd,VISA_AddrVar * cisa_decl,VISA_Modifier mod,unsigned int addrOffset,unsigned short immediateOffset,unsigned short verticalStride,unsigned short width,unsigned short horizontalStride,VISA_Type type,bool isDst)1981 int VISAKernelImpl::CreateVISAIndirectGeneralOperand(
1982 VISA_VectorOpnd *& cisa_opnd, VISA_AddrVar *cisa_decl, VISA_Modifier mod,
1983 unsigned int addrOffset, unsigned short immediateOffset,
1984 unsigned short verticalStride, unsigned short width, unsigned short horizontalStride,
1985 VISA_Type type, bool isDst)
1986 {
1987 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
1988
1989 cisa_opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
1990
1991 if (IS_GEN_BOTH_PATH)
1992 {
1993 G4_Declare *dcl = cisa_decl->addrVar.dcl;
1994 if (!isDst)
1995 {
1996 if (verticalStride == MAX_UWORD_VALUE)
1997 verticalStride = UNDEFINED_SHORT;
1998
1999 const RegionDesc *rd = m_builder->createRegionDesc(verticalStride, width, horizontalStride);
2000 G4_SrcModifier g4_mod = GetGenSrcModFromVISAMod(mod);
2001 G4_SrcRegRegion* src = m_builder->createIndirectSrc(
2002 g4_mod,
2003 dcl->getRegVar(),
2004 0,
2005 (uint16_t)addrOffset,
2006 rd,
2007 GetGenTypeFromVISAType(type),
2008 immediateOffset);
2009 cisa_opnd->g4opnd = src;
2010 }
2011 else
2012 {
2013 auto dst = m_builder->createIndirectDst(
2014 dcl->getRegVar(),
2015 (uint16_t)addrOffset,
2016 horizontalStride,
2017 GetGenTypeFromVISAType(type),
2018 immediateOffset);
2019
2020 cisa_opnd->g4opnd = dst;
2021 }
2022 }
2023 if (IS_VISA_BOTH_PATH)
2024 {
2025 //memset(cisa_opnd,0,sizeof(VISA_opnd));
2026
2027 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
2028 cisa_opnd->tag = OPERAND_INDIRECT;
2029 cisa_opnd->_opnd.v_opnd.tag = OPERAND_INDIRECT;
2030 cisa_opnd->_opnd.v_opnd.opnd_val.indirect_opnd.index = (uint16_t)cisa_decl->index;
2031 cisa_opnd->_opnd.v_opnd.opnd_val.indirect_opnd.addr_offset = (uint8_t)addrOffset;
2032 cisa_opnd->_opnd.v_opnd.opnd_val.indirect_opnd.indirect_offset = immediateOffset;
2033 cisa_opnd->_opnd.v_opnd.opnd_val.indirect_opnd.bit_property = type;
2034
2035 if (!isDst)
2036 {
2037 cisa_opnd->_opnd.v_opnd.opnd_val.indirect_opnd.region =
2038 Create_CISA_Region(verticalStride,width,horizontalStride); // Get_CISA_Region_Val(horizontal_stride) <<8;
2039
2040 cisa_opnd->_opnd.v_opnd.tag += mod<<3;
2041 }else
2042 {
2043 cisa_opnd->_opnd.v_opnd.opnd_val.indirect_opnd.region =
2044 Get_CISA_Region_Val(horizontalStride) << 8;
2045 }
2046
2047 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
2048 }
2049
2050 return VISA_SUCCESS;
2051 }
2052
CreateVISAIndirectSrcOperand(VISA_VectorOpnd * & cisa_opnd,VISA_AddrVar * cisa_decl,VISA_Modifier mod,unsigned int addrOffset,short immediateOffset,unsigned short verticalStride,unsigned short width,unsigned short horizontalStride,VISA_Type type)2053 int VISAKernelImpl::CreateVISAIndirectSrcOperand(
2054 VISA_VectorOpnd *& cisa_opnd, VISA_AddrVar *cisa_decl,
2055 VISA_Modifier mod, unsigned int addrOffset, short immediateOffset,
2056 unsigned short verticalStride, unsigned short width, unsigned short horizontalStride,
2057 VISA_Type type)
2058 {
2059 return CreateVISAIndirectGeneralOperand(
2060 cisa_opnd, cisa_decl, mod, addrOffset, immediateOffset,
2061 verticalStride, width, horizontalStride, type, false);
2062 }
2063
CreateVISAIndirectDstOperand(VISA_VectorOpnd * & cisa_opnd,VISA_AddrVar * decl,unsigned int addrOffset,short immediateOffset,unsigned short horizontalStride,VISA_Type type)2064 int VISAKernelImpl::CreateVISAIndirectDstOperand(
2065 VISA_VectorOpnd *& cisa_opnd, VISA_AddrVar *decl,
2066 unsigned int addrOffset, short immediateOffset,
2067 unsigned short horizontalStride, VISA_Type type)
2068 {
2069 return CreateVISAIndirectGeneralOperand(
2070 cisa_opnd, decl, MODIFIER_NONE, addrOffset, immediateOffset, -1, -1, horizontalStride, type, true);
2071 }
2072
CreateVISAIndirectOperandVxH(VISA_VectorOpnd * & cisa_opnd,VISA_AddrVar * decl,unsigned int addrOffset,short immediateOffset,VISA_Type type)2073 int VISAKernelImpl::CreateVISAIndirectOperandVxH(
2074 VISA_VectorOpnd *& cisa_opnd, VISA_AddrVar *decl,
2075 unsigned int addrOffset, short immediateOffset, VISA_Type type)
2076 {
2077 return CreateVISAIndirectGeneralOperand(
2078 cisa_opnd, decl, MODIFIER_NONE, addrOffset, immediateOffset, -1, 1, 0, type, false);
2079 }
2080
CreateVISAPredicateSrcOperand(VISA_VectorOpnd * & opnd,VISA_PredVar * decl,unsigned int size)2081 int VISAKernelImpl::CreateVISAPredicateSrcOperand(
2082 VISA_VectorOpnd *& opnd, VISA_PredVar *decl, unsigned int size)
2083 {
2084 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2085
2086 int status = VISA_SUCCESS;
2087
2088 assert(decl->type == PREDICATE_VAR && "expect a predicate variable");
2089
2090 opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
2091
2092 if (IS_GEN_BOTH_PATH)
2093 {
2094 G4_Declare *dcl = decl->predVar.dcl;
2095 const RegionDesc *rd = m_builder->getRegionScalar();
2096
2097 G4_Type type = Type_UW;
2098
2099 if (size == 32)
2100 type = Type_UD;
2101
2102 opnd->g4opnd = m_builder->createSrc(
2103 dcl->getRegVar(),
2104 0,
2105 0,
2106 rd,
2107 type);
2108 }
2109 if (IS_VISA_BOTH_PATH)
2110 {
2111 status = CreateVISAPredicateOperandvISA((VISA_PredOpnd *&)opnd, decl, PredState_NO_INVERSE, PRED_CTRL_NON);
2112 }
2113
2114 return status;
2115 }
2116
CreateVISAPredicateDstOperand(VISA_VectorOpnd * & opnd,VISA_PredVar * decl,uint32_t size)2117 int VISAKernelImpl::CreateVISAPredicateDstOperand(
2118 VISA_VectorOpnd *& opnd, VISA_PredVar *decl, uint32_t size)
2119 {
2120 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2121
2122 int status = VISA_SUCCESS;
2123
2124 opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
2125 if (IS_GEN_BOTH_PATH)
2126 {
2127 G4_Declare *dcl = decl->predVar.dcl;
2128
2129 opnd->g4opnd = m_builder->createDst(
2130 dcl->getRegVar(),
2131 0,
2132 0,
2133 1,
2134 size == 32 ? Type_UD : Type_UW);
2135 }
2136 if (IS_VISA_BOTH_PATH)
2137 {
2138 status = CreateVISAPredicateOperandvISA((VISA_PredOpnd *&)opnd, decl, PredState_NO_INVERSE, PRED_CTRL_NON);
2139 }
2140
2141 return status;
2142 }
2143
CreateVISAPredicateOperandvISA(VISA_PredOpnd * & cisa_opnd,VISA_PredVar * decl,VISA_PREDICATE_STATE state,VISA_PREDICATE_CONTROL cntrl)2144 int VISAKernelImpl::CreateVISAPredicateOperandvISA(
2145 VISA_PredOpnd *& cisa_opnd, VISA_PredVar *decl,
2146 VISA_PREDICATE_STATE state, VISA_PREDICATE_CONTROL cntrl)
2147 {
2148 int status = VISA_SUCCESS;
2149 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
2150 cisa_opnd->tag = OPERAND_PREDICATE;
2151 cisa_opnd->_opnd.v_opnd.tag = OPERAND_PREDICATE;
2152
2153 cisa_opnd->index = decl->index;
2154 PredicateOpnd predOpnd(decl->index, state, cntrl);
2155 cisa_opnd->_opnd.v_opnd.opnd_val.pred_opnd.index = predOpnd.getPredInBinary();
2156 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
2157 return status;
2158 }
2159
CreateVISAPredicateOperand(VISA_PredOpnd * & cisa_opnd,VISA_PredVar * decl,VISA_PREDICATE_STATE state,VISA_PREDICATE_CONTROL cntrl)2160 int VISAKernelImpl::CreateVISAPredicateOperand(
2161 VISA_PredOpnd *& cisa_opnd, VISA_PredVar *decl,
2162 VISA_PREDICATE_STATE state, VISA_PREDICATE_CONTROL cntrl)
2163 {
2164 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2165
2166 cisa_opnd = static_cast<VISA_PredOpnd *>(getOpndFromPool());
2167 if (IS_GEN_BOTH_PATH)
2168 {
2169 G4_Declare *dcl = decl->predVar.dcl;
2170 #if START_ASSERT_CHECK
2171 if (dcl == NULL)
2172 {
2173 assert(0);
2174 return VISA_FAILURE;
2175 }
2176 #endif
2177 // with bool size in bytes was incorrect, now that it's correct it returns "correct"
2178 // number of elements. Except it thinks each element is a two bytes.
2179 // we want each element in as a boolean.
2180 G4_Predicate_Control predCtrl =
2181 m_builder->vISAPredicateToG4Predicate(cntrl, G4_ExecSize(dcl->getNumberFlagElements()));
2182
2183 cisa_opnd->g4opnd = m_builder->createPredicate(
2184 (state == PredState_INVERSE) ? PredState_Minus : PredState_Plus,
2185 dcl->getRegVar(),
2186 0,
2187 predCtrl);
2188 }
2189 if (IS_VISA_BOTH_PATH)
2190 {
2191 CreateVISAPredicateOperandvISA(cisa_opnd, decl, state, cntrl);
2192 }
2193
2194 return VISA_SUCCESS;
2195 }
2196
CreateVISASrcOperand(VISA_VectorOpnd * & cisa_opnd,VISA_GenVar * cisa_decl,VISA_Modifier mod,unsigned short vStride,unsigned short width,unsigned short hStride,unsigned char rowOffset,unsigned char colOffset)2197 int VISAKernelImpl::CreateVISASrcOperand(VISA_VectorOpnd *& cisa_opnd, VISA_GenVar *cisa_decl, VISA_Modifier mod, unsigned short vStride, unsigned short width, unsigned short hStride,
2198 unsigned char rowOffset, unsigned char colOffset)
2199 {
2200 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2201
2202 cisa_opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
2203 if (IS_GEN_BOTH_PATH)
2204 {
2205 if (cisa_decl->index < Get_CISA_PreDefined_Var_Count())
2206 {
2207 cisa_opnd->g4opnd = CommonISABuildPreDefinedSrc(cisa_decl->index, vStride, width, hStride, rowOffset, colOffset, mod);
2208 }
2209 else
2210 {
2211
2212 //create reg region
2213 G4_Declare *dcl = cisa_decl->genVar.dcl;
2214 const RegionDesc *rd = m_builder->createRegionDesc(vStride, width, hStride);
2215 G4_SrcModifier g4_mod = GetGenSrcModFromVISAMod(mod);
2216
2217 cisa_opnd->g4opnd = m_builder->createSrcRegRegion(g4_mod, Direct, dcl->getRegVar(), rowOffset, colOffset, rd, dcl->getElemType());
2218 }
2219 }
2220 if (IS_VISA_BOTH_PATH)
2221 {
2222 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
2223 cisa_opnd->tag = OPERAND_GENERAL; //<--- I think this is redundant at this point.
2224 cisa_opnd->_opnd.v_opnd.tag = OPERAND_GENERAL;
2225 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.index = cisa_decl->index;
2226 cisa_opnd->index = cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.index;
2227 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.row_offset = rowOffset;
2228 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.col_offset = colOffset;
2229 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.region = Create_CISA_Region(vStride, width, hStride);
2230
2231 cisa_opnd->_opnd.v_opnd.tag += mod<<3;
2232
2233 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
2234 }
2235
2236 return VISA_SUCCESS;
2237 }
2238
CreateVISADstOperand(VISA_VectorOpnd * & cisa_opnd,VISA_GenVar * cisa_decl,unsigned short hStride,unsigned char rowOffset,unsigned char colOffset)2239 int VISAKernelImpl::CreateVISADstOperand(VISA_VectorOpnd *&cisa_opnd, VISA_GenVar *cisa_decl, unsigned short hStride,
2240 unsigned char rowOffset, unsigned char colOffset)
2241 {
2242 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2243
2244 cisa_opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
2245 if (IS_GEN_BOTH_PATH)
2246 {
2247 G4_Declare *dcl = cisa_decl->genVar.dcl;
2248
2249 // replace vISA %null variable with a null dst to avoid confusing later passes
2250 G4_Declare *nullVar = m_builder->preDefVars.getPreDefinedVar(PreDefinedVarsInternal::VAR_NULL);
2251 if (dcl == nullVar)
2252 {
2253 cisa_opnd->g4opnd = m_builder->createNullDst(dcl->getElemType());
2254 }
2255 else
2256 {
2257 cisa_opnd->g4opnd = m_builder->createDst(dcl->getRegVar(), rowOffset, colOffset, hStride, dcl->getElemType());
2258 }
2259 }
2260
2261 if (IS_VISA_BOTH_PATH)
2262 {
2263
2264 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
2265 cisa_opnd->tag = OPERAND_GENERAL; //<--- I think this is redundant at this point.
2266 cisa_opnd->_opnd.v_opnd.tag = OPERAND_GENERAL;
2267 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.index = cisa_decl->index;
2268 cisa_opnd->index = cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.index;
2269 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.row_offset = rowOffset;
2270 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.col_offset = colOffset;
2271 cisa_opnd->_opnd.v_opnd.opnd_val.gen_opnd.region = Get_CISA_Region_Val(hStride) << 8;
2272
2273 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
2274 }
2275
2276 return VISA_SUCCESS;
2277 }
2278
CreateVISAImmediate(VISA_VectorOpnd * & cisa_opnd,const void * value,VISA_Type isaType)2279 int VISAKernelImpl::CreateVISAImmediate(VISA_VectorOpnd*& cisa_opnd, const void* value, VISA_Type isaType)
2280 {
2281 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2282
2283 cisa_opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
2284 if (IS_GEN_BOTH_PATH)
2285 {
2286 G4_Type g4type = GetGenTypeFromVISAType(isaType);
2287
2288 if (isaType == ISA_TYPE_Q) {
2289 cisa_opnd->g4opnd = m_builder->createImmWithLowerType(*static_cast<const int64_t*>(value), Type_Q);
2290 }
2291 else if (isaType == ISA_TYPE_UQ) {
2292 cisa_opnd->g4opnd = m_builder->createImmWithLowerType(*static_cast<const int64_t*>(value), Type_UQ);
2293 }
2294 else if (isaType == ISA_TYPE_DF)
2295 {
2296 cisa_opnd->g4opnd = m_builder->createDFImm(*static_cast<const double*>(value));
2297 }
2298 else if (isaType == ISA_TYPE_F)
2299 {
2300 cisa_opnd->g4opnd = m_builder->createImm(*static_cast<const float*>(value));
2301 }
2302 else if (isaType == ISA_TYPE_HF)
2303 {
2304 cisa_opnd->g4opnd = m_builder->createImmWithLowerType(*static_cast<const unsigned*>(value), Type_HF);
2305 }
2306 else
2307 {
2308 int64_t tmpValue = typecastVals(value, isaType);
2309 cisa_opnd->g4opnd = m_builder->createImmWithLowerType(
2310 tmpValue, g4type);
2311 }
2312 }
2313 if (IS_VISA_BOTH_PATH)
2314 {
2315 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
2316 cisa_opnd->tag = OPERAND_IMMEDIATE;
2317 cisa_opnd->_opnd.v_opnd.tag = OPERAND_IMMEDIATE;
2318 cisa_opnd->_opnd.v_opnd.opnd_val.const_opnd.type = isaType;
2319
2320 int size = CISATypeTable[isaType].typeSize;
2321
2322 if (size == 0)
2323 {
2324 assert(0);
2325 return VISA_FAILURE;
2326 }
2327 if (isaType == ISA_TYPE_DF)
2328 {
2329 cisa_opnd->_opnd.v_opnd.opnd_val.const_opnd._val.dval = *static_cast<const double*>(value);
2330 }
2331 else if (isaType == ISA_TYPE_F)
2332 {
2333 cisa_opnd->_opnd.v_opnd.opnd_val.const_opnd._val.fval = *static_cast<const float*>(value);
2334 }
2335 else if (isaType == ISA_TYPE_Q || isaType == ISA_TYPE_UQ)
2336 {
2337 cisa_opnd->_opnd.v_opnd.opnd_val.const_opnd._val.lval = *static_cast<const uint64_t*>(value);
2338 }
2339 else if (isaType == ISA_TYPE_V || isaType == ISA_TYPE_UV)
2340 {
2341 int size = Get_VISA_Type_Size(isaType);
2342 memcpy_s(&cisa_opnd->_opnd.v_opnd.opnd_val.const_opnd._val, size, value, size);
2343 }
2344 else
2345 {
2346 int64_t tmpValue = typecastVals(value, isaType);
2347 cisa_opnd->_opnd.v_opnd.opnd_val.const_opnd._val.lval = tmpValue;
2348 }
2349 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
2350 }
2351
2352 return VISA_SUCCESS;
2353 }
2354
CreateVISAStateOperand(VISA_VectorOpnd * & cisa_opnd,CISA_GEN_VAR * decl,Common_ISA_State_Opnd_Class opndClass,uint8_t size,unsigned char offset,bool useAsDst)2355 int VISAKernelImpl::CreateVISAStateOperand(VISA_VectorOpnd *&cisa_opnd, CISA_GEN_VAR *decl, Common_ISA_State_Opnd_Class opndClass, uint8_t size, unsigned char offset, bool useAsDst)
2356 {
2357 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2358
2359 cisa_opnd = static_cast<VISA_VectorOpnd *>(getOpndFromPool());
2360 if (IS_GEN_BOTH_PATH)
2361 {
2362 G4_Declare *dcl = decl->stateVar.dcl;
2363
2364 if (!useAsDst)
2365 {
2366 // pre-defined surface
2367 if (opndClass == STATE_OPND_SURFACE &&
2368 decl->index < Get_CISA_PreDefined_Surf_Count())
2369 {
2370 int64_t immVal = Get_PreDefined_Surf_Index(decl->index);
2371 if (immVal == PREDEF_SURF_252)
2372 {
2373 // we have to keep it as a variable
2374 cisa_opnd->g4opnd = m_builder->createSrcRegRegion(m_builder->getBuiltinT252(), m_builder->getRegionScalar());
2375 }
2376 else
2377 {
2378 if (m_options->getOption(vISA_noncoherentStateless) && immVal == PREDEF_SURF_255)
2379 {
2380 immVal = PREDEF_SURF_253;
2381 }
2382 cisa_opnd->g4opnd = m_builder->createImm(immVal, Type_UD);
2383 }
2384 }
2385 else
2386 {
2387
2388 cisa_opnd->g4opnd = m_builder->createSrc(
2389 dcl->getRegVar(),
2390 0,
2391 offset,
2392 size == 1 ? m_builder->getRegionScalar() : m_builder->getRegionStride1(),
2393 dcl->getElemType());
2394 }
2395 }
2396 else
2397 {
2398 cisa_opnd->g4opnd = m_builder->createDst(
2399 dcl->getRegVar(),
2400 0,
2401 offset,
2402 1,
2403 dcl->getElemType());
2404 }
2405 }
2406 if (IS_VISA_BOTH_PATH)
2407 {
2408
2409 cisa_opnd->opnd_type = CISA_OPND_VECTOR;
2410 cisa_opnd->tag = OPERAND_STATE;
2411 cisa_opnd->_opnd.v_opnd.tag = OPERAND_STATE;
2412
2413 cisa_opnd->index = decl->index;
2414 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.index = (unsigned short)(cisa_opnd->index);
2415 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.offset = offset;
2416 cisa_opnd->_opnd.v_opnd.opnd_val.state_opnd.opnd_class = opndClass;
2417 cisa_opnd->size = (uint16_t)cisa_opnd->_opnd.v_opnd.getSizeInBinary();
2418 }
2419
2420 return VISA_SUCCESS;
2421 }
2422
CreateVISAStateOperand(VISA_VectorOpnd * & opnd,VISA_SurfaceVar * decl,uint8_t size,unsigned char offset,bool useAsDst)2423 int VISAKernelImpl::CreateVISAStateOperand(VISA_VectorOpnd *&opnd, VISA_SurfaceVar *decl, uint8_t size, unsigned char offset, bool useAsDst)
2424 {
2425 return CreateVISAStateOperand(opnd, (CISA_GEN_VAR*)decl, STATE_OPND_SURFACE, size, offset, useAsDst);
2426 }
2427
CreateVISAStateOperand(VISA_VectorOpnd * & opnd,VISA_SurfaceVar * decl,unsigned char offset,bool useAsDst)2428 int VISAKernelImpl::CreateVISAStateOperand(VISA_VectorOpnd *&opnd, VISA_SurfaceVar *decl, unsigned char offset, bool useAsDst)
2429 {
2430 return CreateVISAStateOperand(opnd, (CISA_GEN_VAR*)decl, STATE_OPND_SURFACE, 1, offset, useAsDst);
2431 }
2432
CreateVISAStateOperand(VISA_VectorOpnd * & opnd,VISA_SamplerVar * decl,unsigned char offset,bool useAsDst)2433 int VISAKernelImpl::CreateVISAStateOperand(VISA_VectorOpnd *&opnd, VISA_SamplerVar *decl, unsigned char offset, bool useAsDst)
2434 {
2435 return CreateVISAStateOperand(opnd, (CISA_GEN_VAR*)decl, STATE_OPND_SAMPLER, 1, offset, useAsDst);
2436 }
2437
CreateVISAStateOperand(VISA_VectorOpnd * & opnd,VISA_SamplerVar * decl,uint8_t size,unsigned char offset,bool useAsDst)2438 int VISAKernelImpl::CreateVISAStateOperand(VISA_VectorOpnd *&opnd, VISA_SamplerVar *decl, uint8_t size, unsigned char offset, bool useAsDst)
2439 {
2440 return CreateVISAStateOperand(opnd, (CISA_GEN_VAR*)decl, STATE_OPND_SAMPLER, size, offset, useAsDst);
2441 }
2442
2443 //size should be 8 since it's a vISA spec.
2444 //size was added because VME doesn't adhere to our spec.
CreateVISARawOperand(VISA_RawOpnd * & cisa_opnd,VISA_GenVar * decl,unsigned short offset)2445 int VISAKernelImpl::CreateVISARawOperand(VISA_RawOpnd *& cisa_opnd, VISA_GenVar *decl, unsigned short offset)
2446 {
2447 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2448
2449 cisa_opnd = static_cast<VISA_RawOpnd *>(getOpndFromPool());
2450 cisa_opnd->opnd_type = CISA_OPND_RAW;
2451 cisa_opnd->tag = NUM_OPERAND_CLASS;
2452 cisa_opnd->index = decl->index;
2453 cisa_opnd->_opnd.r_opnd.index = cisa_opnd->index;
2454 cisa_opnd->_opnd.r_opnd.offset = offset;
2455 cisa_opnd->size = sizeof(cisa_opnd->_opnd.r_opnd.index) + sizeof(cisa_opnd->_opnd.r_opnd.offset);
2456 cisa_opnd->decl = decl;
2457
2458 return VISA_SUCCESS;
2459 }
2460
2461 // size == 1 means we want scalar region
2462 // FIXME: this is really a bug, rawOpnd should always occupy at least 1 GRF.
2463 // We should fix the vISA spec for this
2464 // [noTypeChange: keep the original type. This likely needs refactoring]
CreateGenRawSrcOperand(VISA_RawOpnd * & cisa_opnd)2465 int VISAKernelImpl::CreateGenRawSrcOperand(VISA_RawOpnd *& cisa_opnd)
2466 {
2467 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2468
2469 if (cisa_opnd->index==0)
2470 {
2471 return CreateGenNullRawOperand(cisa_opnd, false);
2472 }
2473
2474 unsigned short offset = cisa_opnd->_opnd.r_opnd.offset;
2475
2476 G4_Declare *dcl = cisa_opnd->decl->genVar.dcl;
2477
2478 const RegionDesc *rd = m_builder->getRegionStride1();
2479 G4_Type type = dcl->getElemType();
2480 short row_offset = offset / numEltPerGRF<Type_UB>();
2481 short col_offset = (offset % numEltPerGRF<Type_UB>()) / TypeSize(type);
2482
2483 cisa_opnd->g4opnd = m_builder->createSrc(
2484 dcl->getRegVar(),
2485 row_offset,
2486 col_offset,
2487 rd,
2488 type);
2489
2490 return VISA_SUCCESS;
2491 }
2492
CreateGenRawDstOperand(VISA_RawOpnd * & cisa_opnd)2493 int VISAKernelImpl::CreateGenRawDstOperand(VISA_RawOpnd *& cisa_opnd)
2494 {
2495 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2496
2497 if (cisa_opnd->index == 0) {
2498 return CreateGenNullRawOperand(cisa_opnd, true);
2499 }
2500
2501 unsigned short offset = cisa_opnd->_opnd.r_opnd.offset;
2502
2503 //if (IS_GEN_BOTH_PATH) //will only be called in GEN or BOTH path
2504 {
2505 G4_Declare *dcl = cisa_opnd->decl->genVar.dcl;
2506
2507 {
2508 short row_offset = offset/numEltPerGRF<Type_UB>();
2509 short col_offset = (offset%numEltPerGRF<Type_UB>())/dcl->getElemSize();
2510
2511 cisa_opnd->g4opnd = m_builder->createDst(
2512 dcl->getRegVar(),
2513 row_offset,
2514 col_offset,
2515 1,
2516 dcl->getElemType());
2517 }
2518 }
2519
2520 return VISA_SUCCESS;
2521 }
2522
CreateStateInstUse(VISA_StateOpndHandle * & cisa_opnd,unsigned int index)2523 int VISAKernelImpl::CreateStateInstUse(VISA_StateOpndHandle *&cisa_opnd, unsigned int index)
2524 {
2525 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2526
2527 cisa_opnd->_opnd.other_opnd = index;
2528 cisa_opnd->opnd_type = CISA_OPND_OTHER;
2529 cisa_opnd->size = (uint16_t)Get_VISA_Type_Size(ISA_TYPE_UB);
2530 cisa_opnd->tag = ISA_TYPE_UB;
2531
2532 return VISA_SUCCESS;
2533 }
CreateStateInstUseFastPath(VISA_StateOpndHandle * & cisa_opnd,CISA_GEN_VAR * decl)2534 int VISAKernelImpl::CreateStateInstUseFastPath(VISA_StateOpndHandle *&cisa_opnd, CISA_GEN_VAR *decl)
2535 {
2536 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2537
2538 unsigned int status = VISA_SUCCESS;
2539 G4_Declare *dcl = decl->stateVar.dcl;
2540
2541 Common_ISA_Var_Class type = decl->type;
2542
2543 switch (type)
2544 {
2545 case SAMPLER_VAR:
2546 {
2547 cisa_opnd->g4opnd = m_builder->createSrc(dcl->getRegVar(), 0, 0, m_builder->getRegionScalar(), Type_UD);
2548 break;
2549 }
2550 case SURFACE_VAR:
2551 {
2552 uint16_t surf_id = (uint16_t)decl->index;
2553 if (surf_id >= Get_CISA_PreDefined_Surf_Count())
2554 {
2555 cisa_opnd->g4opnd = m_builder->createSrc(dcl->getRegVar(), 0, 0,
2556 m_builder->getRegionScalar(), Type_UD);
2557 }
2558 else // predefined
2559 {
2560 if (dcl == m_builder->getBuiltinT252())
2561 {
2562 cisa_opnd->g4opnd = m_builder->createSrcRegRegion(m_builder->getBuiltinT252(),
2563 m_builder->getRegionScalar());
2564 }
2565 else if (dcl == m_builder->getBuiltinScratchSurface())
2566 {
2567 cisa_opnd->g4opnd = m_builder->createSrcRegRegion(m_builder->getBuiltinScratchSurface(),
2568 m_builder->getRegionScalar());
2569 }
2570 else
2571 {
2572 int64_t immVal = Get_PreDefined_Surf_Index(decl->index);
2573 if (m_options->getOption(vISA_noncoherentStateless) && immVal == PREDEF_SURF_255)
2574 {
2575 immVal = PREDEF_SURF_253;
2576 }
2577 cisa_opnd->g4opnd = m_builder->createImm(immVal, Type_UD);
2578 }
2579 }
2580 break;
2581 }
2582 default:
2583 {
2584 assert(0);
2585 status = VISA_FAILURE;
2586 break;
2587 }
2588 }
2589
2590 return status;
2591 }
CreateVISAStateOperandHandle(VISA_StateOpndHandle * & opnd,VISA_SurfaceVar * decl)2592 int VISAKernelImpl::CreateVISAStateOperandHandle(VISA_StateOpndHandle *&opnd, VISA_SurfaceVar *decl)
2593 {
2594 int status = VISA_SUCCESS;
2595 opnd = static_cast<VISA_StateOpndHandle *>(getOpndFromPool());
2596 if (IS_GEN_BOTH_PATH)
2597 {
2598 status = CreateStateInstUseFastPath(opnd, (CISA_GEN_VAR *)decl);
2599 }
2600 if (IS_VISA_BOTH_PATH && status == VISA_SUCCESS)
2601 {
2602 status = CreateStateInstUse(opnd, decl->index);
2603 }
2604 return status;
2605 }
2606
CreateVISAStateOperandHandle(VISA_StateOpndHandle * & opnd,VISA_SamplerVar * decl)2607 int VISAKernelImpl::CreateVISAStateOperandHandle(VISA_StateOpndHandle *&opnd, VISA_SamplerVar *decl)
2608 {
2609 int status = VISA_SUCCESS;
2610 opnd = static_cast<VISA_StateOpndHandle *>(getOpndFromPool());
2611 if (IS_GEN_BOTH_PATH)
2612 {
2613 status = CreateStateInstUseFastPath(opnd, (CISA_GEN_VAR *)decl);
2614 }
2615 if (IS_VISA_BOTH_PATH && status == VISA_SUCCESS)
2616 {
2617 status = CreateStateInstUse(opnd, decl->index);
2618 }
2619 return status;
2620 }
2621
CreateVISANullRawOperand(VISA_RawOpnd * & cisa_opnd,bool isDst)2622 int VISAKernelImpl::CreateVISANullRawOperand(VISA_RawOpnd *& cisa_opnd, bool isDst)
2623 {
2624 TIME_SCOPE(VISA_BUILDER_CREATE_OPND);
2625
2626 cisa_opnd = static_cast<VISA_RawOpnd *>(getOpndFromPool());
2627 cisa_opnd->opnd_type = CISA_OPND_RAW;
2628 cisa_opnd->tag = NUM_OPERAND_CLASS;
2629 cisa_opnd->index = 0;
2630 cisa_opnd->_opnd.r_opnd.index = cisa_opnd->index;
2631 cisa_opnd->_opnd.r_opnd.offset = 0;
2632 cisa_opnd->size = sizeof(cisa_opnd->_opnd.r_opnd.index) + sizeof(cisa_opnd->_opnd.r_opnd.offset);
2633
2634 int ret = CreateGenNullRawOperand(cisa_opnd, isDst);
2635 return ret;
2636 }
2637
2638 /**
2639 * It's expected that the null raw operands had already been pre-allocated.
2640 */
CreateGenNullRawOperand(VISA_RawOpnd * & cisa_opnd,bool isDst)2641 int VISAKernelImpl::CreateGenNullRawOperand(VISA_RawOpnd *& cisa_opnd, bool isDst)
2642 {
2643 if (IS_GEN_BOTH_PATH)
2644 {
2645 if (isDst)
2646 {
2647 cisa_opnd->g4opnd = m_builder->createNullDst(Type_UD);
2648 }
2649 else
2650 {
2651 cisa_opnd->g4opnd = m_builder->createNullSrc(Type_UD);
2652 }
2653 }
2654
2655 return VISA_SUCCESS;
2656 }
2657
GetPredefinedVar(VISA_GenVar * & predDcl,PreDefined_Vars varName)2658 int VISAKernelImpl::GetPredefinedVar(VISA_GenVar *&predDcl, PreDefined_Vars varName)
2659 {
2660 int status = VISA_SUCCESS;
2661 predDcl = (VISA_GenVar*)getGenVar(varName);
2662 return status;
2663 }
2664
GetPredefinedSurface(VISA_SurfaceVar * & predDcl,PreDefined_Surface surfaceName)2665 int VISAKernelImpl::GetPredefinedSurface(VISA_SurfaceVar *&predDcl, PreDefined_Surface surfaceName)
2666 {
2667 int status = VISA_SUCCESS;
2668 predDcl = (VISA_SurfaceVar*)(m_surface_info_list[surfaceName]);
2669 return status;
2670 }
2671
GetBindlessSampler(VISA_SamplerVar * & samplerDcl)2672 int VISAKernelImpl::GetBindlessSampler(VISA_SamplerVar *&samplerDcl)
2673 {
2674 int status = VISA_SUCCESS;
2675 samplerDcl = m_bindlessSampler;
2676 return status;
2677 }
2678 /************* OPERANDS CREATION END ******************/
2679
2680 /************* START APPEND APIS **********************/
AppendVISAArithmeticInst(ISA_Opcode opcode,VISA_PredOpnd * pred,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1,VISA_VectorOpnd * src2)2681 int VISAKernelImpl::AppendVISAArithmeticInst(
2682 ISA_Opcode opcode, VISA_PredOpnd *pred, bool satMode,
2683 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
2684 VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1, VISA_VectorOpnd *src2)
2685 {
2686 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
2687
2688 AppendVISAInstCommon();
2689
2690 int status = VISA_SUCCESS;
2691 if (IS_GEN_BOTH_PATH)
2692 {
2693 const G4_Sat g4SatMode = satMode ? g4::SAT : g4::NOSAT;
2694 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
2695 if ((tmpDst->g4opnd->getType() == Type_DF) &&
2696 ((opcode == ISA_DIV) || // keeping ISA_DIV at the moment for IGC
2697 (opcode == ISA_DIVM)))
2698 {
2699 status = m_builder->translateVISAArithmeticDoubleInst(
2700 opcode, executionSize, emask, g4Pred, g4SatMode,
2701 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd, src1->g4opnd); // IEEE
2702 }
2703 else if (tmpDst->g4opnd->getType() == Type_DF && opcode == ISA_INV)
2704 {
2705 // src0_opnd is divisor
2706 status = m_builder->translateVISAArithmeticDoubleInst(
2707 opcode, executionSize, emask, g4Pred, g4SatMode,
2708 tmpDst->g4opnd->asDstRegRegion(), NULL, src0->g4opnd); // IEEE
2709 }
2710 else if (tmpDst->g4opnd->getType() == Type_F && opcode == ISA_DIVM)
2711 {
2712 status = m_builder->translateVISAArithmeticSingleDivideIEEEInst(
2713 opcode, executionSize, emask, g4Pred, g4SatMode, nullptr,
2714 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd, src1->g4opnd); // IEEE
2715 }
2716 else if (tmpDst->g4opnd->getType() == Type_F && opcode == ISA_SQRTM)
2717 {
2718 status = m_builder->translateVISAArithmeticSingleSQRTIEEEInst(
2719 opcode, executionSize, emask, g4Pred, g4SatMode, nullptr,
2720 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd); // IEEE
2721 }
2722 else if (tmpDst->g4opnd->getType() == Type_DF && (opcode == ISA_SQRT || opcode == ISA_SQRTM))
2723 {
2724 status = m_builder->translateVISAArithmeticDoubleSQRTInst(
2725 opcode, executionSize, emask, g4Pred, g4SatMode, nullptr,
2726 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd);
2727 }
2728 else
2729 {
2730 status = m_builder->translateVISAArithmeticInst(
2731 opcode, executionSize, emask, g4Pred, g4SatMode, nullptr,
2732 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd, GET_G4_OPNG(src1), GET_G4_OPNG(src2), NULL);
2733 }
2734 }
2735 if (IS_VISA_BOTH_PATH)
2736 {
2737 int num_pred_desc_operands = 2; //accounting for exec_size and pred_id in descriptor
2738 int num_operands = 0;
2739 VISA_INST_Desc *inst_desc = NULL;
2740 VISA_opnd *opnd[4];
2741 VISA_opnd *dst = tmpDst;
2742
2743 inst_desc = &CISA_INST_table[opcode];
2744 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
2745 VISA_Modifier mod = MODIFIER_NONE;
2746
2747 if (satMode)
2748 {
2749 mod = MODIFIER_SAT;
2750 dst = (VISA_opnd *)m_mem.alloc(sizeof(VISA_opnd));
2751 *dst = *tmpDst;
2752 dst->_opnd.v_opnd.tag += mod<<3;
2753 }
2754
2755 ADD_OPND(num_operands, opnd, dst);
2756
2757 ADD_OPND(num_operands, opnd, src0);
2758
2759 ADD_OPND(num_operands, opnd, src1);
2760
2761 ADD_OPND(num_operands, opnd, src2);
2762
2763 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
2764
2765 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
2766 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
2767
2768 unsigned char size = executionSize;
2769 size += emask << 4;
2770 inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
2771 addInstructionToEnd(inst);
2772 }
2773
2774 return status;
2775 }
2776
AppendVISAArithmeticInst(ISA_Opcode opcode,VISA_PredOpnd * pred,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0)2777 int VISAKernelImpl::AppendVISAArithmeticInst(
2778 ISA_Opcode opcode, VISA_PredOpnd *pred, bool satMode, VISA_EMask_Ctrl emask,
2779 VISA_Exec_Size executionSize, VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0)
2780 {
2781 return AppendVISAArithmeticInst(opcode, pred, satMode, emask, executionSize, tmpDst, src0, NULL, NULL);
2782 }
2783
AppendVISAArithmeticInst(ISA_Opcode opcode,VISA_PredOpnd * pred,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1)2784 int VISAKernelImpl::AppendVISAArithmeticInst(
2785 ISA_Opcode opcode, VISA_PredOpnd *pred, bool satMode, VISA_EMask_Ctrl emask,
2786 VISA_Exec_Size executionSize, VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1)
2787 {
2788 return AppendVISAArithmeticInst(opcode, pred, satMode, emask, executionSize, tmpDst, src0, src1, NULL);
2789 }
2790
AppendVISATwoDstArithmeticInst(ISA_Opcode opcode,VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * dst1,VISA_VectorOpnd * carry_borrow,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1)2791 int VISAKernelImpl::AppendVISATwoDstArithmeticInst(
2792 ISA_Opcode opcode, VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
2793 VISA_VectorOpnd *dst1, VISA_VectorOpnd *carry_borrow, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1)
2794 {
2795 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
2796
2797 AppendVISAInstCommon();
2798
2799 int status = VISA_SUCCESS;
2800
2801 if (IS_GEN_BOTH_PATH)
2802 {
2803 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
2804 status = m_builder->translateVISAArithmeticInst(
2805 opcode, executionSize, emask, g4Pred, g4::NOSAT, nullptr,
2806 dst1->g4opnd->asDstRegRegion(), src0->g4opnd, src1->g4opnd, NULL,
2807 carry_borrow->g4opnd->asDstRegRegion());
2808 }
2809 if (IS_VISA_BOTH_PATH)
2810 {
2811 int num_pred_desc_operands = 2; //accounting for exec_size and pred_id in descriptor
2812 int num_operands = 0;
2813 VISA_INST_Desc *inst_desc = NULL;
2814 VISA_opnd *opnd[4];
2815
2816 inst_desc = &CISA_INST_table[opcode];
2817 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
2818
2819 if (opcode != ISA_ADDC && opcode != ISA_SUBB)
2820 {
2821 assert(0);
2822 std::cerr << "ONLY ADDC AND SUBB are supported by this API\n";
2823 return VISA_FAILURE;
2824 }
2825
2826 ADD_OPND(num_operands, opnd, dst1);
2827
2828 ADD_OPND(num_operands, opnd, carry_borrow);
2829
2830 ADD_OPND(num_operands, opnd, src0);
2831
2832 ADD_OPND(num_operands, opnd, src1);
2833
2834 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
2835
2836 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
2837 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
2838
2839 unsigned char size = executionSize;
2840 size += emask << 4;
2841 status = inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
2842 addInstructionToEnd(inst);
2843 }
2844
2845 return status;
2846 }
2847
AppendVISALogicOrShiftInst(ISA_Opcode opcode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_PredVar * dst,VISA_PredVar * src0,VISA_PredVar * src1)2848 int VISAKernelImpl::AppendVISALogicOrShiftInst(
2849 ISA_Opcode opcode, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
2850 VISA_PredVar *dst, VISA_PredVar *src0, VISA_PredVar *src1)
2851 {
2852 VISA_VectorOpnd *dstOpnd = NULL;
2853 VISA_VectorOpnd *src0Opnd = NULL;
2854 VISA_VectorOpnd *src1Opnd = NULL;
2855 uint32_t exSize = Get_VISA_Exec_Size(executionSize);
2856 CreateVISAPredicateDstOperand(dstOpnd, dst, exSize);
2857 CreateVISAPredicateSrcOperand(src0Opnd, src0, exSize);
2858 if (src1 != NULL)
2859 CreateVISAPredicateSrcOperand(src1Opnd, src1, exSize);
2860
2861 return AppendVISALogicOrShiftInst(opcode, NULL, false, emask, executionSize,
2862 dstOpnd, src0Opnd, src1Opnd, NULL, NULL);
2863 }
2864
AppendVISALogicOrShiftInst(ISA_Opcode opcode,VISA_PredOpnd * pred,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1,VISA_VectorOpnd * src2,VISA_VectorOpnd * src3)2865 int VISAKernelImpl::AppendVISALogicOrShiftInst(
2866 ISA_Opcode opcode, VISA_PredOpnd *pred, bool satMode,
2867 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
2868 VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1,
2869 VISA_VectorOpnd *src2, VISA_VectorOpnd *src3)
2870 {
2871 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
2872
2873 AppendVISAInstCommon();
2874
2875 int status = VISA_SUCCESS;
2876
2877 if (IS_GEN_BOTH_PATH)
2878 {
2879 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
2880 status = m_builder->translateVISALogicInst(opcode, g4Pred,
2881 satMode ? g4::SAT : g4::NOSAT, executionSize, emask,
2882 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd, GET_G4_OPNG(src1), GET_G4_OPNG(src2), GET_G4_OPNG(src3));
2883 }
2884 if (IS_VISA_BOTH_PATH)
2885 {
2886 int num_pred_desc_operands = 2; //accounting for exec_size and pred_id in descriptor
2887 int num_operands = 0;
2888 VISA_INST_Desc *inst_desc = NULL;
2889 VISA_opnd *opnd[5];
2890 inst_desc = &CISA_INST_table[opcode];
2891 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
2892 VISA_Modifier mod = MODIFIER_NONE;
2893
2894 VISA_opnd *dst = tmpDst;
2895 if (satMode)
2896 {
2897 if (tmpDst == NULL)
2898 {
2899 ERROR_PRINT("Destination for Arithmetic Instruction is NULL");
2900 assert(0);
2901 return VISA_FAILURE;
2902 }
2903 mod = MODIFIER_SAT;
2904 dst = (VISA_opnd *)m_mem.alloc(sizeof(VISA_opnd));
2905 *dst = *tmpDst;
2906 dst->_opnd.v_opnd.tag += mod<<3;
2907 }
2908
2909 ADD_OPND(num_operands, opnd, dst);
2910
2911 ADD_OPND(num_operands, opnd, src0);
2912
2913 ADD_OPND(num_operands, opnd, src1);
2914
2915 ADD_OPND(num_operands, opnd, src2);
2916
2917 ADD_OPND(num_operands, opnd, src3);
2918
2919 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
2920
2921 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
2922
2923 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
2924
2925 unsigned char size = executionSize;
2926 size += emask << 4;
2927 inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
2928 addInstructionToEnd(inst);
2929 }
2930
2931 return status;
2932 }
2933
AppendVISAAddrAddInst(VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * dst,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1)2934 int VISAKernelImpl::AppendVISAAddrAddInst(
2935 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
2936 VISA_VectorOpnd *dst, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1)
2937 {
2938 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
2939
2940 AppendVISAInstCommon();
2941
2942 int status = VISA_SUCCESS;
2943 if (IS_GEN_BOTH_PATH)
2944 {
2945 status = m_builder->translateVISAAddrInst(ISA_ADDR_ADD, executionSize, emask, dst->g4opnd->asDstRegRegion(), src0->g4opnd, src1->g4opnd);
2946 }
2947 if (IS_VISA_BOTH_PATH)
2948 {
2949 int num_pred_desc_operands = 0; //accounting for exec_size and pred_id in descriptor
2950 int num_operands = 0;
2951 VISA_INST_Desc *inst_desc = NULL;
2952 VISA_opnd *opnd[4];
2953 ISA_Opcode opcode = ISA_ADDR_ADD;
2954 inst_desc = &CISA_INST_table[opcode];
2955 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
2956
2957 ADD_OPND(num_operands, opnd, dst);
2958
2959 ADD_OPND(num_operands, opnd, src0);
2960
2961 ADD_OPND(num_operands, opnd, src1);
2962
2963 #if START_ASSERT_CHECK
2964 if ((inst_desc->opnd_num -num_pred_desc_operands) != num_operands)
2965 {
2966 ERROR_PRINT("Number of parameters does not match");
2967 std::cerr<<"LINE: "<<__LINE__<<std::endl;
2968 std::cerr<<"FUNCTION: "<<__FUNCTION__<<std::endl;
2969 assert(0);
2970 return VISA_FAILURE;
2971 }
2972 #endif
2973
2974 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
2975
2976 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
2977
2978 unsigned char size = executionSize;
2979 size += emask << 4;
2980 status = inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
2981 addInstructionToEnd(inst);
2982 }
2983
2984 return status;
2985 }
2986
AppendVISAMinMaxInst(CISA_MIN_MAX_SUB_OPCODE subOpcode,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1)2987 int VISAKernelImpl::AppendVISAMinMaxInst(
2988 CISA_MIN_MAX_SUB_OPCODE subOpcode, bool satMode,
2989 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
2990 VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1)
2991 {
2992 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
2993
2994 AppendVISAInstCommon();
2995
2996 int status = VISA_SUCCESS;
2997
2998 if (IS_GEN_BOTH_PATH)
2999 {
3000 status = m_builder->translateVISADataMovementInst(
3001 ISA_FMINMAX, subOpcode, NULL, executionSize, emask,
3002 satMode ? g4::SAT : g4::NOSAT,
3003 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd, src1->g4opnd);
3004 }
3005 if (IS_VISA_BOTH_PATH)
3006 {
3007 int num_operands = 0;
3008 VISA_INST_Desc *inst_desc = NULL;
3009 VISA_opnd *opnd[4];
3010 ISA_Opcode opcode = ISA_FMINMAX;
3011 inst_desc = &CISA_INST_table[opcode];
3012 int num_pred_desc_operands = 0;
3013 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc); //accounting for exec_size and pred_id in descriptor
3014 VISA_Modifier mod = MODIFIER_NONE;
3015
3016 VISA_opnd *dst = tmpDst;
3017 if (satMode)
3018 {
3019 if (tmpDst == NULL)
3020 {
3021 ERROR_PRINT("Destination for Arithmetic Instruction is NULL");
3022 assert(0);
3023 return VISA_FAILURE;
3024 }
3025 mod = MODIFIER_SAT;
3026 dst = (VISA_opnd *)m_mem.alloc(sizeof(VISA_opnd));
3027 *dst = *tmpDst;
3028 dst->_opnd.v_opnd.tag += mod<<3;
3029 }
3030
3031 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOpcode));
3032
3033 ADD_OPND(num_operands, opnd, dst);
3034
3035 ADD_OPND(num_operands, opnd, src0);
3036
3037 ADD_OPND(num_operands, opnd, src1);
3038
3039 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
3040
3041 unsigned char size = executionSize;
3042 size += emask << 4;
3043 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3044 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
3045 addInstructionToEnd(inst);
3046 }
3047
3048 return status;
3049 }
3050
AppendVISAPredicateMove(VISA_VectorOpnd * dst,VISA_PredVar * src0)3051 int VISAKernelImpl::AppendVISAPredicateMove(VISA_VectorOpnd *dst, VISA_PredVar *src0)
3052 {
3053 VISA_VectorOpnd *src0Opnd = NULL;
3054 CreateVISAPredicateSrcOperand(src0Opnd, src0, 1);
3055 return AppendVISADataMovementInst(ISA_MOV, NULL, false, vISA_EMASK_M1_NM, EXEC_SIZE_1, dst, src0Opnd, NULL);
3056 }
3057
AppendVISASetP(VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_PredVar * dst,VISA_VectorOpnd * src0)3058 int VISAKernelImpl::AppendVISASetP(
3059 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize, VISA_PredVar *dst, VISA_VectorOpnd *src0)
3060 {
3061 uint32_t exSize = Get_VISA_Exec_Size(executionSize);
3062 VISA_VectorOpnd *dstOpnd = NULL;
3063 CreateVISAPredicateDstOperand(dstOpnd, dst, exSize);
3064 return AppendVISADataMovementInst(ISA_SETP, NULL, false, emask, executionSize, dstOpnd, src0);
3065 }
3066
AppendVISADataMovementInst(ISA_Opcode opcode,VISA_PredOpnd * pred,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0)3067 int VISAKernelImpl::AppendVISADataMovementInst(
3068 ISA_Opcode opcode, VISA_PredOpnd *pred, bool satMode, VISA_EMask_Ctrl emask,
3069 VISA_Exec_Size executionSize, VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0)
3070 {
3071 return AppendVISADataMovementInst(opcode, pred, satMode, emask, executionSize, tmpDst, src0, NULL);
3072 }
AppendVISADataMovementInst(ISA_Opcode opcode,VISA_PredOpnd * pred,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1)3073 int VISAKernelImpl::AppendVISADataMovementInst(
3074 ISA_Opcode opcode, VISA_PredOpnd *pred, bool satMode, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
3075 VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1)
3076 {
3077 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3078
3079 AppendVISAInstCommon();
3080 int status = VISA_SUCCESS;
3081
3082 if (IS_GEN_BOTH_PATH)
3083 {
3084 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
3085 status = m_builder->translateVISADataMovementInst(opcode, CISA_DM_FMIN /*ignored */,
3086 g4Pred, executionSize, emask, satMode ? g4::SAT : g4::NOSAT,
3087 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd, GET_G4_OPNG(src1));
3088 }
3089 if (IS_VISA_BOTH_PATH)
3090 {
3091 int num_operands = 0;
3092 VISA_INST_Desc *inst_desc = NULL;
3093 VISA_opnd *opnd[4];
3094 inst_desc = &CISA_INST_table[opcode];
3095 int num_pred_desc_operands = 0;
3096 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc); //accounting for exec_size and pred_id in descriptor
3097 VISA_Modifier mod = MODIFIER_NONE;
3098
3099 VISA_opnd *dst = tmpDst;
3100 if (satMode)
3101 {
3102 if (tmpDst == NULL)
3103 {
3104 ERROR_PRINT("Destination for Arithmetic Instruction is NULL");
3105 assert(0);
3106 return VISA_FAILURE;
3107 }
3108 mod = MODIFIER_SAT;
3109 dst = (VISA_opnd *)m_mem.alloc(sizeof(VISA_opnd));
3110 *dst = *tmpDst;
3111 dst->_opnd.v_opnd.tag += mod<<3;
3112 }
3113
3114 ADD_OPND(num_operands, opnd, dst);
3115
3116 ADD_OPND(num_operands, opnd, src0);
3117
3118 ADD_OPND(num_operands, opnd, src1);
3119
3120 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
3121
3122 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3123
3124 unsigned char size = executionSize;
3125 size += emask << 4;
3126 CisaFramework::CisaInst* inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3127 inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
3128 addInstructionToEnd(inst);
3129 }
3130
3131 return status;
3132 }
3133
AppendVISAComparisonInst(VISA_Cond_Mod sub_op,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * dstOpnd,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1)3134 int VISAKernelImpl::AppendVISAComparisonInst(
3135 VISA_Cond_Mod sub_op, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
3136 VISA_VectorOpnd *dstOpnd, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1)
3137 {
3138 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3139
3140 AppendVISAInstCommon();
3141
3142 int status = VISA_SUCCESS;
3143
3144 if (IS_GEN_BOTH_PATH)
3145 {
3146 status = m_builder->translateVISACompareInst(ISA_CMP, executionSize, emask, sub_op,
3147 dstOpnd->g4opnd->asDstRegRegion(), src0->g4opnd, src1->g4opnd);
3148 }
3149
3150 if (IS_VISA_BOTH_PATH)
3151 {
3152 ISA_Opcode opcode = ISA_CMP;
3153 VISA_INST_Desc *inst_desc = NULL;
3154 VISA_opnd *opnd[4];
3155 int num_pred_desc_operands = 1;
3156 inst_desc = &CISA_INST_table[opcode];
3157 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
3158 int num_operands = 0;
3159
3160 //rel op
3161 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, sub_op));
3162
3163 ADD_OPND(num_operands, opnd, dstOpnd);
3164
3165 ADD_OPND(num_operands, opnd, src0);
3166
3167 ADD_OPND(num_operands, opnd, src1);
3168
3169 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
3170
3171 unsigned char size = executionSize;
3172 size += emask << 4;
3173 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3174 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
3175 addInstructionToEnd(inst);
3176 }
3177
3178 return status;
3179 }
AppendVISAComparisonInst(VISA_Cond_Mod sub_op,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_PredVar * dstDcl,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1)3180 int VISAKernelImpl::AppendVISAComparisonInst(VISA_Cond_Mod sub_op, VISA_EMask_Ctrl emask,
3181 VISA_Exec_Size executionSize, VISA_PredVar *dstDcl, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1)
3182 {
3183 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3184
3185 AppendVISAInstCommon();
3186
3187 int status = VISA_SUCCESS;
3188 uint32_t exSize = Get_VISA_Exec_Size(executionSize);
3189 VISA_VectorOpnd *dst = NULL;
3190 CreateVISAPredicateDstOperand(dst, dstDcl, exSize);
3191 if (IS_GEN_BOTH_PATH)
3192 {
3193 status = m_builder->translateVISACompareInst(ISA_CMP, executionSize, emask, sub_op, dstDcl->predVar.dcl, src0->g4opnd, src1->g4opnd);
3194 }
3195 if (IS_VISA_BOTH_PATH)
3196 {
3197 ISA_Opcode opcode = ISA_CMP;
3198 VISA_INST_Desc *inst_desc = NULL;
3199 VISA_opnd *opnd[4];
3200 int num_pred_desc_operands = 1;
3201 inst_desc = &CISA_INST_table[opcode];
3202 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
3203 int num_operands = 0;
3204
3205 //rel op
3206 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, sub_op));
3207
3208 ADD_OPND(num_operands, opnd, dst);
3209
3210 ADD_OPND(num_operands, opnd, src0);
3211
3212 ADD_OPND(num_operands, opnd, src1);
3213
3214 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
3215
3216 unsigned char size = executionSize;
3217 size += emask << 4;
3218 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3219 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
3220 addInstructionToEnd(inst);
3221 }
3222
3223 return status;
3224 }
3225
AppendVISACFGotoInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_LabelOpnd * label)3226 int VISAKernelImpl::AppendVISACFGotoInst(
3227 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize, VISA_LabelOpnd *label)
3228 {
3229 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3230
3231 AppendVISAInstCommon();
3232
3233 int status = VISA_SUCCESS;
3234
3235 if (IS_GEN_BOTH_PATH)
3236 {
3237 G4_Predicate* g4Pred = (pred != NULL) ? pred->g4opnd->asPredicate() : NULL;
3238
3239 G4_Label* g4Lbl = (G4_Label*)label->g4opnd;
3240 status = m_builder->translateVISAGotoInst(g4Pred, executionSize, emask, g4Lbl);
3241 }
3242 if (IS_VISA_BOTH_PATH)
3243 {
3244 int num_operands = 0;
3245 VISA_INST_Desc* inst_desc = NULL;
3246 inst_desc = &CISA_INST_table[ISA_GOTO];
3247 VISA_opnd* opnd[1];
3248
3249 if (!label)
3250 {
3251 assert(0);
3252 return VISA_FAILURE;
3253 }
3254
3255 ADD_OPND(num_operands, opnd, label);
3256
3257 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3258 CisaFramework::CisaInst* inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3259
3260 unsigned char size = executionSize;
3261 size += emask << 4;
3262 inst->createCisaInstruction(ISA_GOTO, size, 0, predOpnd, opnd, num_operands, inst_desc);
3263 addInstructionToEnd(inst);
3264 }
3265
3266 return status;
3267 }
3268
AppendVISACFJmpInst(VISA_PredOpnd * pred,VISA_LabelOpnd * label)3269 int VISAKernelImpl::AppendVISACFJmpInst(VISA_PredOpnd *pred, VISA_LabelOpnd *label)
3270 {
3271 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3272
3273 AppendVISAInstCommon();
3274
3275 int status = VISA_SUCCESS;
3276 if (IS_GEN_BOTH_PATH)
3277 {
3278 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
3279 status = m_builder->translateVISACFJumpInst(g4Pred, (G4_Label*)label->g4opnd);
3280 }
3281 if (IS_VISA_BOTH_PATH)
3282 {
3283 VISA_INST_Desc *inst_desc = NULL;
3284 VISA_opnd * opnd[1];
3285 inst_desc = &CISA_INST_table[ISA_JMP];
3286 opnd[0] = label;
3287
3288 if (label == NULL)
3289 {
3290 assert(0);
3291 return VISA_FAILURE;
3292 }
3293
3294 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3295
3296 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3297
3298 unsigned char size = EXEC_SIZE_1;
3299 size += vISA_EMASK_M1 << 4;
3300 inst->createCisaInstruction(ISA_JMP, size, 0, predOpnd, opnd, 1, inst_desc);
3301
3302 addInstructionToEnd(inst);
3303 }
3304
3305 return status;
3306 }
3307
AppendVISACFCallInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_LabelOpnd * label)3308 int VISAKernelImpl::AppendVISACFCallInst(
3309 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize, VISA_LabelOpnd *label)
3310 {
3311 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3312
3313 AppendVISAInstCommon();
3314
3315 int status = VISA_SUCCESS;
3316 if (IS_GEN_BOTH_PATH)
3317 {
3318 if (isFCCallerKernel())
3319 {
3320 m_builder->getFCPatchInfo()->setHasFCCalls(true);
3321 }
3322 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
3323 status = m_builder->translateVISACFCallInst(executionSize, emask, g4Pred, (G4_Label*)label->g4opnd);
3324 }
3325 if (IS_VISA_BOTH_PATH)
3326 {
3327 VISA_INST_Desc *inst_desc = NULL;
3328 VISA_opnd * opnd[1];
3329 inst_desc = &CISA_INST_table[ISA_CALL];
3330 opnd[0] = label;
3331
3332 if (label == NULL)
3333 {
3334 assert(0);
3335 return VISA_FAILURE;
3336 }
3337
3338 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3339 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3340
3341 unsigned char size = executionSize;
3342 size += emask << 4;
3343 inst->createCisaInstruction(ISA_CALL, size, 0, predOpnd, opnd, 1, inst_desc);
3344
3345 addInstructionToEnd(inst);
3346 }
3347
3348 return status;
3349 }
3350
AppendVISACFRetInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize)3351 int VISAKernelImpl::AppendVISACFRetInst(VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize)
3352 {
3353 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3354
3355 AppendVISAInstCommon();
3356
3357 int status = VISA_SUCCESS;
3358 if (IS_GEN_BOTH_PATH)
3359 {
3360 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
3361 if (isFCCallableKernel())
3362 {
3363 m_builder->getFCPatchInfo()->setIsCallableKernel(true);
3364 }
3365 status = m_builder->translateVISACFRetInst(executionSize, emask, g4Pred);
3366 }
3367 if (IS_VISA_BOTH_PATH)
3368 {
3369 VISA_INST_Desc *inst_desc = NULL;
3370 ISA_Opcode opcode = ISA_RET;
3371 inst_desc = &CISA_INST_table[opcode];
3372
3373 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3374
3375 CisaFramework::CisaInst* inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3376 unsigned char size = executionSize;
3377 size += emask << 4;
3378 inst->createCisaInstruction(opcode, size, 0, predOpnd, NULL, 0, inst_desc);
3379 addInstructionToEnd(inst);
3380 }
3381
3382 return status;
3383 }
3384
AppendVISACFLabelInst(VISA_LabelOpnd * label)3385 int VISAKernelImpl::AppendVISACFLabelInst(VISA_LabelOpnd *label)
3386 {
3387 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3388
3389 AppendVISAInstCommon();
3390
3391 int status = VISA_SUCCESS;
3392 if (IS_GEN_BOTH_PATH)
3393 {
3394 status = m_builder->translateVISACFLabelInst((G4_Label*)label->g4opnd);
3395 }
3396 if (IS_VISA_BOTH_PATH)
3397 {
3398 VISA_INST_Desc *inst_desc = NULL;
3399 VISA_opnd *opnd[1] = {label};
3400 inst_desc = &CISA_INST_table[(ISA_Opcode)label->tag];
3401
3402 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3403 inst->createCisaInstruction((ISA_Opcode)label->tag, 1, 0, PredicateOpnd::getNullPred(), opnd, 1, inst_desc);
3404 addInstructionToEnd(inst);
3405 }
3406
3407 return status;
3408 }
3409
AppendVISACFFunctionCallInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,std::string funcName,unsigned char argSize,unsigned char returnSize)3410 int VISAKernelImpl::AppendVISACFFunctionCallInst(
3411 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask,
3412 VISA_Exec_Size executionSize, std::string funcName,
3413 unsigned char argSize, unsigned char returnSize)
3414 {
3415 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3416
3417 AppendVISAInstCommon();
3418
3419 int status = VISA_SUCCESS;
3420 if (IS_GEN_BOTH_PATH)
3421 {
3422 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
3423 status = m_builder->translateVISACFFCallInst(executionSize, emask, g4Pred, funcName, argSize, returnSize);
3424 }
3425 if (IS_VISA_BOTH_PATH)
3426 {
3427 VISA_INST_Desc *inst_desc = NULL;
3428 VISA_opnd *opnd[3]; //should be more than enough
3429 int num_pred_desc_operands = 2;
3430 ISA_Opcode opcode = ISA_FCALL;
3431 inst_desc = &CISA_INST_table[opcode];
3432 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
3433
3434 // create an entry in string pool with the given function name
3435 uint32_t funcId = addStringPool(funcName);
3436 int num_operands = 0;
3437
3438 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, funcId));
3439
3440 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, argSize));
3441
3442 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, returnSize));
3443
3444 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
3445
3446 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3447 /*
3448 Making a copy of descriptor adn setting correct number of operands.
3449 This is used later to calculate total size of the buffer.
3450 */
3451 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3452
3453 unsigned char size = executionSize;
3454 size += emask << 4;
3455 inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
3456 addInstructionToEnd(inst);
3457 }
3458
3459 return status;
3460 }
3461
AppendVISACFIndirectFuncCallInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * funcAddr,uint8_t argSize,uint8_t returnSize)3462 int VISAKernelImpl::AppendVISACFIndirectFuncCallInst(
3463 VISA_PredOpnd *pred,
3464 VISA_EMask_Ctrl emask,
3465 VISA_Exec_Size executionSize,
3466 VISA_VectorOpnd* funcAddr,
3467 uint8_t argSize, uint8_t returnSize)
3468 {
3469 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3470
3471 AppendVISAInstCommon();
3472
3473 int status = VISA_SUCCESS;
3474 if (IS_GEN_BOTH_PATH)
3475 {
3476 G4_Predicate * g4Pred = pred ? pred->g4opnd->asPredicate() : nullptr;
3477 status = m_builder->translateVISACFIFCallInst(executionSize, emask, g4Pred, funcAddr->g4opnd,
3478 argSize, returnSize);
3479 }
3480 if (IS_VISA_BOTH_PATH)
3481 {
3482 VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_IFCALL];
3483 VISA_opnd *opnd[3]; //should be more then enough
3484 int num_pred_desc_operands = 2;
3485 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
3486 int num_operands = 0;
3487
3488 opnd[num_operands] = funcAddr;
3489 ++num_operands;
3490
3491 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, argSize));
3492
3493 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, returnSize));
3494
3495 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
3496
3497 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3498
3499 /*
3500 Making a copy of descriptor adn setting correct number of operands.
3501 This is used later to calculate total size of the buffer.
3502 */
3503 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3504
3505 unsigned char size = executionSize;
3506 size += emask << 4;
3507 inst->createCisaInstruction(ISA_IFCALL, size, 0, predOpnd, opnd, num_operands, inst_desc);
3508 addInstructionToEnd(inst);
3509 }
3510
3511 return status;
3512 }
3513
AppendVISACFSymbolInst(std::string symbolName,VISA_VectorOpnd * dst)3514 int VISAKernelImpl::AppendVISACFSymbolInst(std::string symbolName, VISA_VectorOpnd* dst)
3515 {
3516 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3517
3518 AppendVISAInstCommon();
3519
3520 int status = VISA_SUCCESS;
3521 if (IS_GEN_BOTH_PATH)
3522 {
3523 status = m_builder->translateVISACFSymbolInst(symbolName, (G4_DstRegRegion*)dst->g4opnd);
3524 }
3525 if (IS_VISA_BOTH_PATH)
3526 {
3527 VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_FADDR];
3528 VISA_opnd *opnd[3]; //should be more than enough
3529 int num_operands = 0;
3530
3531 // create an entry in string pool with the given symbolName
3532 uint32_t name_idx = addStringPool(symbolName);
3533 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(0, num_operands, inst_desc, name_idx));
3534
3535 opnd[num_operands] = dst;
3536 ++num_operands;
3537
3538 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3539
3540 inst->createCisaInstruction(ISA_FADDR, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
3541 addInstructionToEnd(inst);
3542 }
3543
3544 return status;
3545 }
3546
AppendVISACFFunctionRetInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize)3547 int VISAKernelImpl::AppendVISACFFunctionRetInst(VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize)
3548 {
3549 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3550
3551 AppendVISAInstCommon();
3552
3553 int status = VISA_SUCCESS;
3554 if (IS_GEN_BOTH_PATH)
3555 {
3556 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
3557 status = m_builder->translateVISACFFretInst(executionSize, emask, g4Pred);
3558 }
3559 if (IS_VISA_BOTH_PATH)
3560 {
3561 VISA_INST_Desc *inst_desc = NULL;
3562 ISA_Opcode opcode = ISA_FRET;
3563 inst_desc = &CISA_INST_table[opcode];
3564
3565 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3566
3567 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3568 unsigned char size = executionSize;
3569 size += emask << 4;
3570 inst->createCisaInstruction(opcode, size, 0, predOpnd, NULL, 0, inst_desc);
3571 addInstructionToEnd(inst);
3572 }
3573
3574 return status;
3575 }
3576
AppendVISACFSwitchJMPInst(VISA_VectorOpnd * index,unsigned char labelCount,VISA_LabelOpnd ** labels)3577 int VISAKernelImpl::AppendVISACFSwitchJMPInst(VISA_VectorOpnd *index, unsigned char labelCount, VISA_LabelOpnd **labels)
3578 {
3579 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3580
3581 AppendVISAInstCommon();
3582
3583 int status = VISA_SUCCESS;
3584 if (IS_GEN_BOTH_PATH)
3585 {
3586 G4_Label* labelsArray[50];
3587 if (labelCount >= 50)
3588 {
3589 assert(0);
3590 status = VISA_FAILURE;
3591 }
3592 else
3593 {
3594 for (int i = 0; i < labelCount; i++)
3595 {
3596 labelsArray[i] = (G4_Label*)labels[i]->g4opnd;
3597 }
3598 status = m_builder->translateVISACFSwitchInst(index->g4opnd, labelCount, labelsArray);
3599 }
3600 }
3601 if (IS_VISA_BOTH_PATH)
3602 {
3603 VISA_INST_Desc* inst_desc_temp = NULL;
3604 VISA_INST_Desc* inst_desc = (VISA_INST_Desc*)m_mem.alloc(sizeof(VISA_INST_Desc));
3605 int num_pred_desc_operands = 1;
3606 unsigned int num_operands = 0;
3607 ISA_Opcode opcode = ISA_SWITCHJMP;
3608 inst_desc_temp = &CISA_INST_table[opcode];
3609 *inst_desc = CISA_INST_table[opcode];
3610 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc_temp);
3611
3612 VISA_opnd* opnd[35];
3613
3614 if (index == NULL || labelCount == 0 || labels == NULL)
3615 {
3616 assert(0);
3617 return VISA_FAILURE;
3618 }
3619
3620 opnd[num_operands] = CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc_temp, labelCount);
3621 ++num_operands;
3622 opnd[num_operands] = index;
3623 ++num_operands;
3624
3625 std::copy_n(labels, labelCount, opnd + num_operands);
3626 /*
3627 Making a copy of descriptor adn setting correct number of operands.
3628 This is used later to calculate total size of the buffer.
3629 */
3630 inst_desc->opnd_num = num_pred_desc_operands + labelCount + num_operands;
3631
3632 CisaFramework::CisaInst* inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3633
3634 unsigned char size = EXEC_SIZE_1;
3635 size += vISA_EMASK_M1 << 4;
3636 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, labelCount + num_operands, inst_desc);
3637
3638 addInstructionToEnd(inst);
3639 }
3640
3641 return status;
3642 }
3643
AppendVISASurfAccessDwordAtomicInst(VISA_PredOpnd * pred,VISAAtomicOps subOpc,bool is16Bit,VISA_EMask_Ctrl eMask,VISA_Exec_Size execSize,VISA_StateOpndHandle * surface,VISA_RawOpnd * offsets,VISA_RawOpnd * src0,VISA_RawOpnd * src1,VISA_RawOpnd * dst)3644 int VISAKernelImpl::AppendVISASurfAccessDwordAtomicInst(
3645 VISA_PredOpnd *pred,
3646 VISAAtomicOps subOpc,
3647 bool is16Bit,
3648 VISA_EMask_Ctrl eMask,
3649 VISA_Exec_Size execSize,
3650 VISA_StateOpndHandle *surface,
3651 VISA_RawOpnd *offsets,
3652 VISA_RawOpnd *src0,
3653 VISA_RawOpnd *src1,
3654 VISA_RawOpnd *dst)
3655 {
3656 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3657
3658 AppendVISAInstCommon();
3659
3660 int status = VISA_SUCCESS;
3661
3662 if (IS_GEN_BOTH_PATH) {
3663 CreateGenRawSrcOperand(offsets);
3664 CreateGenRawSrcOperand(src0);
3665 CreateGenRawSrcOperand(src1);
3666 CreateGenRawDstOperand(dst);
3667 status = m_builder
3668 ->translateVISADwordAtomicInst(subOpc, is16Bit,
3669 pred ? pred->g4opnd->asPredicate() : 0,
3670 execSize, eMask,
3671 surface->g4opnd,
3672 offsets->g4opnd->asSrcRegRegion(),
3673 src0->g4opnd->asSrcRegRegion(),
3674 src1->g4opnd->asSrcRegRegion(),
3675 dst->g4opnd->asDstRegRegion());
3676 }
3677
3678 if (IS_VISA_BOTH_PATH) {
3679 ISA_Opcode opcode = ISA_DWORD_ATOMIC;
3680 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
3681
3682 VISA_opnd *ops[6];
3683 int numOps = 0;
3684
3685 uint8_t OpAnd16BitTag = uint8_t(subOpc) | uint8_t((is16Bit ? 1 : 0) << 5);
3686 ADD_OPND(numOps, ops, CreateOtherOpnd(OpAnd16BitTag, ISA_TYPE_UB));
3687 ADD_OPND(numOps, ops, surface);
3688 ADD_OPND(numOps, ops, offsets);
3689 ADD_OPND(numOps, ops, src0);
3690 ADD_OPND(numOps, ops, src1);
3691 ADD_OPND(numOps, ops, dst);
3692
3693 CisaFramework::CisaInst * inst
3694 = new(m_mem) CisaFramework::CisaInst(m_mem);
3695
3696 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3697
3698 // Pack execution size & mask
3699 unsigned size = execSize;
3700 PACK_EXEC_SIZE(size, eMask);
3701
3702 inst->createCisaInstruction(opcode, (uint8_t)size, 0, predOpnd, ops, numOps, instDesc);
3703 addInstructionToEnd(inst);
3704 }
3705
3706 return status;
3707 }
3708
AppendVISASurfAccessGatherScatterInst(ISA_Opcode opcode,VISA_EMask_Ctrl emask,GATHER_SCATTER_ELEMENT_SIZE elementSize,VISA_Exec_Size executionSize,VISA_StateOpndHandle * surface,VISA_VectorOpnd * globalOffset,VISA_RawOpnd * elementOffset,VISA_RawOpnd * srcDst)3709 int VISAKernelImpl::AppendVISASurfAccessGatherScatterInst(
3710 ISA_Opcode opcode, VISA_EMask_Ctrl emask, GATHER_SCATTER_ELEMENT_SIZE elementSize,
3711 VISA_Exec_Size executionSize, VISA_StateOpndHandle *surface,
3712 VISA_VectorOpnd *globalOffset, VISA_RawOpnd *elementOffset, VISA_RawOpnd *srcDst)
3713 {
3714 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3715
3716 AppendVISAInstCommon();
3717
3718 int status = VISA_SUCCESS;
3719
3720 if (IS_GEN_BOTH_PATH)
3721 {
3722 CreateGenRawSrcOperand(elementOffset);
3723 auto offset = elementOffset->g4opnd->asSrcRegRegion();
3724 if (opcode == ISA_GATHER)
3725 {
3726 CreateGenRawDstOperand(srcDst); //gather: srcDst is dst
3727 status = m_builder->translateVISAGatherInst(emask, false, elementSize, executionSize,
3728 surface->g4opnd, globalOffset->g4opnd, offset, srcDst->g4opnd->asDstRegRegion());
3729 }
3730 else
3731 {
3732 CreateGenRawSrcOperand(srcDst); //scatter: srcDst is src
3733 status = m_builder->translateVISAScatterInst(emask, elementSize, executionSize,
3734 surface->g4opnd, globalOffset->g4opnd, offset, srcDst->g4opnd->asSrcRegRegion());
3735 }
3736 }
3737 if (IS_VISA_BOTH_PATH)
3738 {
3739 VISA_INST_Desc *inst_desc = NULL;
3740 VISA_opnd *opnd[8];
3741 int num_pred_desc_operands = 0;
3742 inst_desc = &CISA_INST_table[opcode];
3743 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
3744 int num_operands = 0;
3745
3746 unsigned int numberOfElements = 0;
3747
3748 //elt_size
3749 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, elementSize));
3750
3751 if (opcode == ISA_GATHER)
3752 {
3753 //ignored
3754 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, 0));
3755 }
3756
3757 //elt_size
3758 switch (executionSize)
3759 {
3760 case EXEC_SIZE_8:
3761 numberOfElements = 0;
3762 break;
3763 case EXEC_SIZE_16:
3764 numberOfElements = 1;
3765 break;
3766 case EXEC_SIZE_1:
3767 numberOfElements= 2;
3768 break;
3769 default:
3770 MUST_BE_TRUE(false, "Invalid Number of Elements for Gather/Scatter.");
3771 return false;
3772 }
3773
3774 numberOfElements += emask<<4;
3775 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, numberOfElements));
3776
3777 //surface
3778 ADD_OPND(num_operands, opnd, surface);
3779
3780 //global offset
3781 ADD_OPND(num_operands, opnd, globalOffset);
3782
3783 //element offset
3784 ADD_OPND(num_operands, opnd, elementOffset);
3785
3786 //dst/src
3787 ADD_OPND(num_operands, opnd, srcDst);
3788
3789 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
3790
3791 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3792
3793 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
3794 addInstructionToEnd(inst);
3795 }
3796
3797 return status;
3798 }
3799
AppendVISASurfAccessGather4Scatter4TypedInst(ISA_Opcode opcode,VISA_PredOpnd * pred,VISAChannelMask _chMask,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_StateOpndHandle * surface,VISA_RawOpnd * uOffset,VISA_RawOpnd * vOffset,VISA_RawOpnd * rOffset,VISA_RawOpnd * lod,VISA_RawOpnd * dst)3800 int VISAKernelImpl::AppendVISASurfAccessGather4Scatter4TypedInst(
3801 ISA_Opcode opcode,
3802 VISA_PredOpnd *pred,
3803 VISAChannelMask _chMask,
3804 VISA_EMask_Ctrl emask,
3805 VISA_Exec_Size executionSize,
3806 VISA_StateOpndHandle *surface,
3807 VISA_RawOpnd *uOffset,
3808 VISA_RawOpnd *vOffset,
3809 VISA_RawOpnd *rOffset,
3810 VISA_RawOpnd *lod,
3811 VISA_RawOpnd *dst)
3812 {
3813 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3814
3815 AppendVISAInstCommon();
3816
3817 int status = VISA_SUCCESS;
3818 ChannelMask chMask = ChannelMask::createFromAPI(_chMask);
3819
3820 if (IS_GEN_BOTH_PATH)
3821 {
3822 G4_Predicate * g4Pred = (pred != NULL) ? pred->g4opnd->asPredicate() : NULL;
3823 CreateGenRawSrcOperand(uOffset);
3824 CreateGenRawSrcOperand(vOffset);
3825 CreateGenRawSrcOperand(rOffset);
3826 CreateGenRawSrcOperand(lod);
3827 if (opcode == ISA_GATHER4_TYPED) {
3828 CreateGenRawDstOperand(dst);
3829 status = m_builder->translateVISAGather4TypedInst(g4Pred, emask, chMask, surface->g4opnd, executionSize, uOffset->g4opnd->asSrcRegRegion(), vOffset->g4opnd->asSrcRegRegion(), rOffset->g4opnd->asSrcRegRegion(), lod->g4opnd->asSrcRegRegion(), dst->g4opnd->asDstRegRegion());
3830 } else {
3831 ASSERT_USER(opcode == ISA_SCATTER4_TYPED, "Invalid opcode for typed gather4/scatter4!");
3832 CreateGenRawSrcOperand(dst);
3833 status = m_builder->translateVISAScatter4TypedInst(g4Pred, emask, chMask, surface->g4opnd, executionSize, uOffset->g4opnd->asSrcRegRegion(), vOffset->g4opnd->asSrcRegRegion(), rOffset->g4opnd->asSrcRegRegion(), lod->g4opnd->asSrcRegRegion(), dst->g4opnd->asSrcRegRegion());
3834 }
3835 }
3836 if (IS_VISA_BOTH_PATH)
3837 {
3838 VISA_INST_Desc *inst_desc = NULL;
3839 VISA_opnd *opnd[8];
3840 int num_operands = 0;
3841 inst_desc = &CISA_INST_table[opcode];
3842
3843 ADD_OPND(num_operands, opnd, CreateOtherOpnd(chMask.getBinary(opcode),
3844 ISA_TYPE_UB));
3845 ADD_OPND(num_operands, opnd, surface);
3846 ADD_OPND(num_operands, opnd, uOffset);
3847 ADD_OPND(num_operands, opnd, vOffset);
3848 ADD_OPND(num_operands, opnd, rOffset);
3849 ADD_OPND(num_operands, opnd, lod);
3850 ADD_OPND(num_operands, opnd, dst);
3851
3852 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
3853
3854 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3855 unsigned size = executionSize;
3856 PACK_EXEC_SIZE(size, emask);
3857
3858 int status = inst->createCisaInstruction(opcode, (uint8_t)size, 0, predOpnd, opnd, num_operands, inst_desc);
3859 if (status != VISA_SUCCESS)
3860 {
3861 assert(0);
3862 return status;
3863 }
3864 addInstructionToEnd(inst);
3865 }
3866
3867 return status;
3868 }
3869
AppendVISASurfAccessGather4Scatter4ScaledInst(ISA_Opcode opcode,VISA_PredOpnd * pred,VISA_EMask_Ctrl eMask,VISA_Exec_Size execSize,VISAChannelMask channelMask,VISA_StateOpndHandle * surface,VISA_VectorOpnd * globalOffset,VISA_RawOpnd * offsets,VISA_RawOpnd * dstSrc)3870 int VISAKernelImpl::AppendVISASurfAccessGather4Scatter4ScaledInst(
3871 ISA_Opcode opcode,
3872 VISA_PredOpnd *pred,
3873 VISA_EMask_Ctrl eMask,
3874 VISA_Exec_Size execSize,
3875 VISAChannelMask channelMask,
3876 VISA_StateOpndHandle *surface,
3877 VISA_VectorOpnd *globalOffset,
3878 VISA_RawOpnd *offsets,
3879 VISA_RawOpnd *dstSrc)
3880 {
3881 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3882
3883 AppendVISAInstCommon();
3884
3885 int status = VISA_SUCCESS;
3886 ChannelMask chMask = ChannelMask::createFromAPI(channelMask);
3887
3888 if (IS_GEN_BOTH_PATH) {
3889 ASSERT_USER(opcode == ISA_GATHER4_SCALED ||
3890 opcode == ISA_SCATTER4_SCALED,
3891 "Unknown opcode for scaled message!");
3892
3893 CreateGenRawSrcOperand(offsets);
3894 if (opcode == ISA_GATHER4_SCALED)
3895 {
3896 CreateGenRawDstOperand(dstSrc);
3897 }
3898 else
3899 {
3900 CreateGenRawSrcOperand(dstSrc);
3901 }
3902 if (opcode == ISA_GATHER4_SCALED) {
3903 status = m_builder
3904 ->translateVISAGather4ScaledInst(pred ? pred->g4opnd->asPredicate() : 0,
3905 execSize, eMask,
3906 chMask,
3907 surface->g4opnd,
3908 globalOffset->g4opnd,
3909 offsets->g4opnd->asSrcRegRegion(),
3910 dstSrc->g4opnd->asDstRegRegion());
3911 } else {
3912 status = m_builder
3913 ->translateVISAScatter4ScaledInst(pred ? pred->g4opnd->asPredicate() : 0,
3914 execSize, eMask,
3915 chMask,
3916 surface->g4opnd,
3917 globalOffset->g4opnd,
3918 offsets->g4opnd->asSrcRegRegion(),
3919 dstSrc->g4opnd->asSrcRegRegion());
3920 }
3921 }
3922
3923 if (IS_VISA_BOTH_PATH) {
3924 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
3925 VISA_opnd *ops[6];
3926 int numOps = 0;
3927
3928 ADD_OPND(numOps, ops, CreateOtherOpnd(chMask.getBinary(opcode),
3929 ISA_TYPE_UB));
3930 ADD_OPND(numOps, ops, CreateOtherOpnd(0, ISA_TYPE_UW));
3931 ADD_OPND(numOps, ops, surface);
3932 ADD_OPND(numOps, ops, globalOffset);
3933 ADD_OPND(numOps, ops, offsets);
3934 ADD_OPND(numOps, ops, dstSrc);
3935
3936 CisaFramework::CisaInst * inst
3937 = new (m_mem) CisaFramework::CisaInst(m_mem);
3938
3939 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
3940
3941 // Pack execution size & mask
3942 unsigned size = execSize;
3943 PACK_EXEC_SIZE(size, eMask);
3944
3945 inst->createCisaInstruction(opcode, (uint8_t)size, 0, predOpnd, ops, numOps, instDesc);
3946 addInstructionToEnd(inst);
3947 }
3948
3949 return status;
3950 }
3951
AppendVISASurfAccessScatterScaledInst(ISA_Opcode opcode,VISA_PredOpnd * pred,VISA_EMask_Ctrl eMask,VISA_Exec_Size execSize,VISA_SVM_Block_Num numBlocks,VISA_StateOpndHandle * surface,VISA_VectorOpnd * globalOffset,VISA_RawOpnd * offsets,VISA_RawOpnd * dstSrc)3952 int VISAKernelImpl::AppendVISASurfAccessScatterScaledInst(
3953 ISA_Opcode opcode,
3954 VISA_PredOpnd *pred,
3955 VISA_EMask_Ctrl eMask,
3956 VISA_Exec_Size execSize,
3957 VISA_SVM_Block_Num numBlocks,
3958 VISA_StateOpndHandle *surface,
3959 VISA_VectorOpnd *globalOffset,
3960 VISA_RawOpnd *offsets,
3961 VISA_RawOpnd *dstSrc)
3962 {
3963 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
3964
3965 AppendVISAInstCommon();
3966
3967 int status = VISA_SUCCESS;
3968
3969 if (IS_GEN_BOTH_PATH) {
3970 ASSERT_USER(opcode == ISA_GATHER_SCALED ||
3971 opcode == ISA_SCATTER_SCALED,
3972 "Unknown opcode for scaled message!");
3973
3974 CreateGenRawSrcOperand(offsets);
3975 if (opcode == ISA_GATHER_SCALED)
3976 {
3977 CreateGenRawDstOperand(dstSrc);
3978 }
3979 else
3980 {
3981 CreateGenRawSrcOperand(dstSrc);
3982 }
3983 if (opcode == ISA_GATHER_SCALED) {
3984 status = m_builder
3985 ->translateVISAGatherScaledInst(pred ? pred->g4opnd->asPredicate() : 0,
3986 execSize, eMask,
3987 numBlocks,
3988 surface->g4opnd,
3989 globalOffset->g4opnd,
3990 offsets->g4opnd->asSrcRegRegion(),
3991 dstSrc->g4opnd->asDstRegRegion());
3992 } else {
3993 status = m_builder
3994 ->translateVISAScatterScaledInst(pred ? pred->g4opnd->asPredicate() : 0,
3995 execSize, eMask,
3996 numBlocks,
3997 surface->g4opnd,
3998 globalOffset->g4opnd,
3999 offsets->g4opnd->asSrcRegRegion(),
4000 dstSrc->g4opnd->asSrcRegRegion());
4001 }
4002 }
4003
4004 if (IS_VISA_BOTH_PATH) {
4005 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
4006 VISA_opnd *ops[7];
4007 int numOps = 0;
4008
4009 ADD_OPND(numOps, ops, CreateOtherOpnd(0, ISA_TYPE_UB));
4010 ADD_OPND(numOps, ops, CreateOtherOpnd(numBlocks, ISA_TYPE_UB));
4011 ADD_OPND(numOps, ops, CreateOtherOpnd(0, ISA_TYPE_UW));
4012 ADD_OPND(numOps, ops, surface);
4013 ADD_OPND(numOps, ops, globalOffset);
4014 ADD_OPND(numOps, ops, offsets);
4015 ADD_OPND(numOps, ops, dstSrc);
4016
4017 CisaFramework::CisaInst * inst
4018 = new (m_mem) CisaFramework::CisaInst(m_mem);
4019
4020 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
4021 // Pack execution size & mask
4022 unsigned size = execSize;
4023 PACK_EXEC_SIZE(size, eMask);
4024
4025 inst->createCisaInstruction(opcode, (uint8_t)size, 0, predOpnd, ops, numOps, instDesc);
4026 addInstructionToEnd(inst);
4027 }
4028
4029 return status;
4030 }
4031
AppendVISASurfAccessMediaLoadStoreInst(ISA_Opcode opcode,MEDIA_LD_mod modifier,VISA_StateOpndHandle * surface,unsigned char blockWidth,unsigned char blockHeight,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset,VISA_RawOpnd * srcDst,CISA_PLANE_ID plane)4032 int VISAKernelImpl::AppendVISASurfAccessMediaLoadStoreInst(
4033 ISA_Opcode opcode,
4034 MEDIA_LD_mod modifier,
4035 VISA_StateOpndHandle *surface,
4036 unsigned char blockWidth,
4037 unsigned char blockHeight,
4038 VISA_VectorOpnd *xOffset,
4039 VISA_VectorOpnd *yOffset,
4040 VISA_RawOpnd *srcDst,
4041 CISA_PLANE_ID plane)
4042 {
4043 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4044
4045 AppendVISAInstCommon();
4046
4047 int status = VISA_SUCCESS;
4048
4049 if (IS_GEN_BOTH_PATH)
4050 {
4051 if (opcode == ISA_MEDIA_LD)
4052 {
4053 CreateGenRawDstOperand(srcDst); //srcDst: dst
4054 status = m_builder->translateVISAMediaLoadInst(modifier, surface->g4opnd, plane, blockWidth, blockHeight,
4055 xOffset->g4opnd, yOffset->g4opnd, srcDst->g4opnd->asDstRegRegion());
4056 }
4057 else
4058 {
4059 if (opcode!=ISA_MEDIA_ST)
4060 {
4061 CreateGenRawDstOperand(srcDst); //srcDst: dst
4062 }
4063 else
4064 {
4065 CreateGenRawSrcOperand(srcDst); //srcDst: src
4066 }
4067 status = m_builder->translateVISAMediaStoreInst((MEDIA_ST_mod)modifier, surface->g4opnd, plane, blockWidth,
4068 blockHeight, xOffset->g4opnd, yOffset->g4opnd, srcDst->g4opnd->asSrcRegRegion());
4069 }
4070 }
4071 if (IS_VISA_BOTH_PATH)
4072 {
4073 VISA_INST_Desc *inst_desc = NULL;
4074 VISA_opnd *opnd[8];
4075 int num_pred_desc_operands = 0;
4076 inst_desc = &CISA_INST_table[opcode];
4077 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4078 int num_operands = 0;
4079
4080 //modifiers
4081 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, modifier));
4082 //surface
4083 ADD_OPND(num_operands, opnd, surface);
4084
4085 //plane
4086 //right now there is VISA and implementation missmatch
4087 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, plane));
4088
4089 //block width
4090 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, blockWidth));
4091
4092 //block height
4093 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, blockHeight));
4094
4095 //x_offset_opnd
4096 ADD_OPND(num_operands, opnd, xOffset);
4097
4098 //y_offset_opnd
4099 ADD_OPND(num_operands, opnd, yOffset);
4100
4101 //raw_opnd
4102 ADD_OPND(num_operands, opnd, srcDst);
4103
4104 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4105
4106 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4107 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4108 addInstructionToEnd(inst);
4109 }
4110
4111 return status;
4112 }
4113
AppendVISASvmGeneralBlockInst(VISA_Oword_Num size,bool unaligned,VISA_VectorOpnd * address,VISA_RawOpnd * srcDst,vISA::Mem_Manager & mem,bool isReadOnly)4114 static CisaFramework::CisaInst* AppendVISASvmGeneralBlockInst(
4115 VISA_Oword_Num size,
4116 bool unaligned,
4117 VISA_VectorOpnd* address,
4118 VISA_RawOpnd *srcDst,
4119 vISA::Mem_Manager& mem,
4120 bool isReadOnly)
4121 {
4122 VISA_opnd* opnd[4] = {NULL, NULL, address, srcDst};
4123 unsigned char pack[2] = {static_cast<unsigned char>(isReadOnly ? SVM_BLOCK_LD : SVM_BLOCK_ST), static_cast<unsigned char>(size | (unaligned ? 0x80 : 0))};
4124 for (unsigned i = 0; i < lengthOf(pack); i++)
4125 {
4126 opnd[i] = (VISA_opnd*)mem.alloc(sizeof(VISA_opnd));
4127 opnd[i]->_opnd.other_opnd = pack[i];
4128 opnd[i]->opnd_type = CISA_OPND_OTHER;
4129 opnd[i]->size = sizeof(pack[i]);
4130 /// opnd[i]->tag = TYPE_UB;
4131 }
4132
4133 CisaFramework::CisaInst* inst = new(mem)CisaFramework::CisaInst(mem);
4134 inst->createCisaInstruction(ISA_SVM, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, lengthOf(opnd), &CISA_INST_table[ISA_SVM]);
4135 return inst;
4136 }
4137
AppendVISASvmGeneralScatterInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size execSize,unsigned char blockSize,unsigned char numBlocks,VISA_RawOpnd * address,VISA_RawOpnd * srcDst,bool isRead)4138 CisaFramework::CisaInst* VISAKernelImpl::AppendVISASvmGeneralScatterInst(
4139 VISA_PredOpnd* pred,
4140 VISA_EMask_Ctrl emask,
4141 VISA_Exec_Size execSize,
4142 unsigned char blockSize,
4143 unsigned char numBlocks,
4144 VISA_RawOpnd* address,
4145 VISA_RawOpnd *srcDst,
4146 bool isRead)
4147 {
4148 // NOT TIMED: shared by scatter/gather
4149
4150 VISA_INST_Desc *inst_desc = NULL;
4151 VISA_opnd *opnd[10];
4152 SVMSubOpcode subOp = isRead ? SVM_GATHER : SVM_SCATTER;
4153 inst_desc = &CISA_INST_table[ISA_SVM];
4154 int num_operands = 0;
4155 unsigned char size = execSize;
4156 size += emask << 4;
4157
4158 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
4159
4160 // execSize and pred are not handled uniformly for some reason
4161 ADD_OPND(num_operands, opnd, CreateOtherOpnd(subOp, ISA_TYPE_UB));
4162 ADD_OPND(num_operands, opnd, CreateOtherOpnd(blockSize, ISA_TYPE_UB));
4163 ADD_OPND(num_operands, opnd, CreateOtherOpnd(numBlocks, ISA_TYPE_UB));
4164
4165 ADD_OPND(num_operands, opnd, address);
4166 ADD_OPND(num_operands, opnd, srcDst);
4167
4168 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4169
4170 inst->createCisaInstruction(ISA_SVM, size, 0, predOpnd, opnd, num_operands, inst_desc);
4171 return inst;
4172 }
4173
AppendVISASvmBlockLoadInst(VISA_Oword_Num size,bool unaligned,VISA_VectorOpnd * address,VISA_RawOpnd * srcDst)4174 int VISAKernelImpl::AppendVISASvmBlockLoadInst(
4175 VISA_Oword_Num size,
4176 bool unaligned,
4177 VISA_VectorOpnd* address,
4178 VISA_RawOpnd *srcDst)
4179 {
4180 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4181
4182 AppendVISAInstCommon();
4183
4184 int status = VISA_SUCCESS;
4185
4186 if (IS_GEN_BOTH_PATH)
4187 {
4188 CreateGenRawDstOperand(srcDst); //dst for load
4189 status = m_builder->translateVISASVMBlockReadInst(size, unaligned, address->g4opnd->asSrcRegRegion(),
4190 srcDst->g4opnd->asDstRegRegion());
4191 }
4192 if (IS_VISA_BOTH_PATH)
4193 {
4194 addInstructionToEnd(AppendVISASvmGeneralBlockInst(size, unaligned, address, srcDst, m_mem, true /* read */));
4195 }
4196
4197 return status;
4198 }
4199
AppendVISASvmBlockStoreInst(VISA_Oword_Num size,bool unaligned,VISA_VectorOpnd * address,VISA_RawOpnd * srcDst)4200 int VISAKernelImpl::AppendVISASvmBlockStoreInst(VISA_Oword_Num size, bool unaligned, VISA_VectorOpnd* address, VISA_RawOpnd *srcDst)
4201 {
4202 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4203
4204 AppendVISAInstCommon();
4205
4206 int status = VISA_SUCCESS;
4207
4208 if (IS_GEN_BOTH_PATH)
4209 {
4210 CreateGenRawSrcOperand(srcDst); //src for store
4211 status = m_builder->translateVISASVMBlockWriteInst(size, address->g4opnd->asSrcRegRegion(),
4212 srcDst->g4opnd->asSrcRegRegion());
4213 }
4214
4215 if (IS_VISA_BOTH_PATH)
4216 {
4217 addInstructionToEnd(AppendVISASvmGeneralBlockInst(size, unaligned, address, srcDst, m_mem, false /* write */));
4218 }
4219
4220 return status;
4221 }
4222
AppendVISASvmGatherInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_SVM_Block_Type blockType,VISA_SVM_Block_Num numBlocks,VISA_RawOpnd * address,VISA_RawOpnd * srcDst)4223 int VISAKernelImpl::AppendVISASvmGatherInst(
4224 VISA_PredOpnd *pred,
4225 VISA_EMask_Ctrl emask,
4226 VISA_Exec_Size executionSize,
4227 VISA_SVM_Block_Type blockType,
4228 VISA_SVM_Block_Num numBlocks,
4229 VISA_RawOpnd* address,
4230 VISA_RawOpnd* srcDst)
4231 {
4232 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4233
4234 AppendVISAInstCommon();
4235
4236 int status = VISA_SUCCESS;
4237 if (IS_GEN_BOTH_PATH)
4238 {
4239 CreateGenRawSrcOperand(address);
4240 CreateGenRawDstOperand(srcDst); // dst for gather
4241 G4_Predicate * g4Pred = (pred != NULL) ? pred->g4opnd->asPredicate() : NULL;
4242 status = m_builder->translateVISASVMScatterReadInst(executionSize, emask, g4Pred, blockType, numBlocks,
4243 address->g4opnd->asSrcRegRegion(), srcDst->g4opnd->asDstRegRegion());
4244 }
4245
4246 if (IS_VISA_BOTH_PATH)
4247 {
4248 addInstructionToEnd(AppendVISASvmGeneralScatterInst(pred, emask, executionSize, blockType, numBlocks, address, srcDst, true /* read */));
4249 }
4250
4251 return status;
4252 }
4253
AppendVISASvmScatterInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_SVM_Block_Type blockType,VISA_SVM_Block_Num numBlocks,VISA_RawOpnd * address,VISA_RawOpnd * srcDst)4254 int VISAKernelImpl::AppendVISASvmScatterInst(
4255 VISA_PredOpnd *pred,
4256 VISA_EMask_Ctrl emask,
4257 VISA_Exec_Size executionSize,
4258 VISA_SVM_Block_Type blockType,
4259 VISA_SVM_Block_Num numBlocks,
4260 VISA_RawOpnd* address,
4261 VISA_RawOpnd* srcDst)
4262 {
4263 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4264
4265 AppendVISAInstCommon();
4266
4267 int status = VISA_SUCCESS;
4268 if (IS_GEN_BOTH_PATH)
4269 {
4270 CreateGenRawSrcOperand(address);
4271 CreateGenRawSrcOperand(srcDst); // src for scatter
4272 G4_Predicate * g4Pred = (pred != NULL) ? pred->g4opnd->asPredicate() : NULL;
4273 status = m_builder->translateVISASVMScatterWriteInst(executionSize, emask, g4Pred, blockType, numBlocks,
4274 address->g4opnd->asSrcRegRegion(), srcDst->g4opnd->asSrcRegRegion());
4275 }
4276
4277 if (IS_VISA_BOTH_PATH)
4278 {
4279 addInstructionToEnd(AppendVISASvmGeneralScatterInst(pred, emask, executionSize, blockType, numBlocks, address, srcDst, false /* write */));
4280 }
4281
4282 return status;
4283 }
4284
AppendVISASvmAtomicInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISAAtomicOps op,unsigned short bitwidth,VISA_RawOpnd * address,VISA_RawOpnd * src0,VISA_RawOpnd * src1,VISA_RawOpnd * dst)4285 int VISAKernelImpl::AppendVISASvmAtomicInst(
4286 VISA_PredOpnd *pred,
4287 VISA_EMask_Ctrl emask,
4288 VISA_Exec_Size executionSize,
4289 VISAAtomicOps op,
4290 unsigned short bitwidth,
4291 VISA_RawOpnd* address,
4292 VISA_RawOpnd* src0,
4293 VISA_RawOpnd* src1,
4294 VISA_RawOpnd* dst)
4295 {
4296 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4297
4298 AppendVISAInstCommon();
4299
4300 int status = VISA_SUCCESS;
4301 if (IS_GEN_BOTH_PATH)
4302 {
4303 CreateGenRawSrcOperand(address);
4304 CreateGenRawSrcOperand(src0);
4305 CreateGenRawSrcOperand(src1);
4306 CreateGenRawDstOperand(dst);
4307 G4_Predicate * g4Pred = (pred != NULL) ? pred->g4opnd->asPredicate() : NULL;
4308 status = m_builder->translateVISASVMAtomicInst(
4309 static_cast<VISAAtomicOps>(op), bitwidth, executionSize, emask,
4310 g4Pred, address->g4opnd->asSrcRegRegion(),
4311 src0->g4opnd->asSrcRegRegion(), src1->g4opnd->asSrcRegRegion(),
4312 dst->g4opnd->asDstRegRegion());
4313 }
4314
4315 if (IS_VISA_BOTH_PATH)
4316 {
4317 VISA_INST_Desc *inst_desc = NULL;
4318 VISA_opnd *opnd[10];
4319 inst_desc = &CISA_INST_table[ISA_SVM];
4320 int num_operands = 0;
4321 ADD_OPND(num_operands, opnd, CreateOtherOpnd(SVM_ATOMIC, ISA_TYPE_UB));
4322 uint8_t BitwidthTag = uint8_t(op);
4323 switch (bitwidth)
4324 {
4325 case 16: BitwidthTag |= 0x20; break;
4326 case 64: BitwidthTag |= 0x40; break;
4327 };
4328 ADD_OPND(num_operands, opnd, CreateOtherOpnd(BitwidthTag, ISA_TYPE_UB));
4329 ADD_OPND(num_operands, opnd, address);
4330 ADD_OPND(num_operands, opnd, src0);
4331 ADD_OPND(num_operands, opnd, src1);
4332 ADD_OPND(num_operands, opnd, dst);
4333
4334 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4335
4336 unsigned char size = executionSize;
4337 size += emask << 4;
4338
4339 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
4340
4341 inst->createCisaInstruction(ISA_SVM, size, 0, predOpnd, opnd, num_operands, inst_desc);
4342 addInstructionToEnd(inst);
4343 }
4344
4345 return status;
4346 }
4347
PackCisaInsnForSVMGather4Scatter4Scaled(unsigned subOpc,VISA_PredOpnd * pred,VISA_EMask_Ctrl eMask,VISA_Exec_Size executionSize,ChannelMask chMask,VISA_VectorOpnd * address,VISA_RawOpnd * offsets,VISA_RawOpnd * srcOrDst)4348 CisaFramework::CisaInst *VISAKernelImpl::PackCisaInsnForSVMGather4Scatter4Scaled(
4349 unsigned subOpc,
4350 VISA_PredOpnd *pred,
4351 VISA_EMask_Ctrl eMask,
4352 VISA_Exec_Size executionSize,
4353 ChannelMask chMask,
4354 VISA_VectorOpnd *address,
4355 VISA_RawOpnd *offsets,
4356 VISA_RawOpnd *srcOrDst)
4357 {
4358 // no TIME_SCOPE here; caller times scope
4359
4360 VISA_INST_Desc *instDesc = &CISA_INST_table[ISA_SVM];
4361 VISA_opnd *ops[6];
4362 int numOps = 0;
4363
4364 ADD_OPND(numOps, ops, CreateOtherOpnd(subOpc, ISA_TYPE_UB));
4365 ADD_OPND(numOps, ops, CreateOtherOpnd(chMask.getBinary(ISA_SVM),
4366 ISA_TYPE_UB));
4367 ADD_OPND(numOps, ops, CreateOtherOpnd(0, ISA_TYPE_UW));
4368
4369 ADD_OPND(numOps, ops, address);
4370 ADD_OPND(numOps, ops, offsets);
4371 ADD_OPND(numOps, ops, srcOrDst);
4372
4373 CisaFramework::CisaInst *insn
4374 = new (m_mem) CisaFramework::CisaInst(m_mem);
4375
4376 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
4377 // Pack executionSize & eMask
4378 unsigned size = executionSize;
4379 PACK_EXEC_SIZE(size, eMask);
4380
4381 insn->createCisaInstruction(ISA_SVM, (uint8_t)size, 0, predOpnd, ops, numOps,
4382 instDesc);
4383
4384 return insn;
4385 }
4386
AppendVISASvmGather4ScaledInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl eMask,VISA_Exec_Size executionSize,VISAChannelMask channelMask,VISA_VectorOpnd * address,VISA_RawOpnd * offsets,VISA_RawOpnd * dst)4387 int VISAKernelImpl::AppendVISASvmGather4ScaledInst(
4388 VISA_PredOpnd *pred,
4389 VISA_EMask_Ctrl eMask,
4390 VISA_Exec_Size executionSize,
4391 VISAChannelMask channelMask,
4392 VISA_VectorOpnd *address,
4393 VISA_RawOpnd *offsets,
4394 VISA_RawOpnd *dst)
4395 {
4396 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4397
4398 AppendVISAInstCommon();
4399
4400 int status = VISA_SUCCESS;
4401
4402 ChannelMask chMask = ChannelMask::createFromAPI(channelMask);
4403
4404 if (IS_GEN_BOTH_PATH) {
4405 CreateGenRawSrcOperand(offsets);
4406 CreateGenRawDstOperand(dst);
4407 status = m_builder
4408 ->translateVISASVMGather4ScaledInst(executionSize, eMask,
4409 chMask,
4410 pred ? pred->g4opnd->asPredicate() : 0,
4411 address->g4opnd,
4412 offsets->g4opnd->asSrcRegRegion(),
4413 dst->g4opnd->asDstRegRegion());
4414 }
4415
4416 if (IS_VISA_BOTH_PATH) {
4417 addInstructionToEnd(
4418 PackCisaInsnForSVMGather4Scatter4Scaled(SVM_GATHER4SCALED,
4419 pred, eMask, executionSize,
4420 chMask,
4421 address, offsets, dst));
4422 }
4423
4424 return status;
4425 }
4426
AppendVISASvmScatter4ScaledInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl eMask,VISA_Exec_Size executionSize,VISAChannelMask channelMask,VISA_VectorOpnd * address,VISA_RawOpnd * offsets,VISA_RawOpnd * src)4427 int VISAKernelImpl::AppendVISASvmScatter4ScaledInst(
4428 VISA_PredOpnd *pred,
4429 VISA_EMask_Ctrl eMask,
4430 VISA_Exec_Size executionSize,
4431 VISAChannelMask channelMask,
4432 VISA_VectorOpnd *address,
4433 VISA_RawOpnd *offsets,
4434 VISA_RawOpnd *src)
4435 {
4436 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4437
4438 AppendVISAInstCommon();
4439
4440 int status = VISA_SUCCESS;
4441
4442 ChannelMask chMask = ChannelMask::createFromAPI(channelMask);
4443
4444 if (IS_GEN_BOTH_PATH) {
4445 CreateGenRawSrcOperand(offsets);
4446 CreateGenRawSrcOperand(src);
4447 status = m_builder->translateVISASVMScatter4ScaledInst(
4448 executionSize, eMask,
4449 chMask,
4450 pred ? pred->g4opnd->asPredicate() : 0,
4451 address->g4opnd,
4452 offsets->g4opnd->asSrcRegRegion(),
4453 src->g4opnd->asSrcRegRegion());
4454 }
4455
4456 if (IS_VISA_BOTH_PATH) {
4457 addInstructionToEnd(
4458 PackCisaInsnForSVMGather4Scatter4Scaled(
4459 SVM_SCATTER4SCALED,
4460 pred, eMask, executionSize,
4461 chMask,
4462 address, offsets, src));
4463 }
4464
4465 return status;
4466 }
4467
AppendVISASurfAccessOwordLoadStoreInst(ISA_Opcode opcode,VISA_EMask_Ctrl emask,VISA_StateOpndHandle * surface,VISA_Oword_Num size,VISA_VectorOpnd * offset,VISA_RawOpnd * srcDst)4468 int VISAKernelImpl::AppendVISASurfAccessOwordLoadStoreInst(
4469 ISA_Opcode opcode, VISA_EMask_Ctrl emask,
4470 VISA_StateOpndHandle *surface, VISA_Oword_Num size,
4471 VISA_VectorOpnd *offset, VISA_RawOpnd *srcDst)
4472 {
4473 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4474
4475 AppendVISAInstCommon();
4476
4477 int status = VISA_SUCCESS;
4478
4479 if (IS_GEN_BOTH_PATH)
4480 {
4481 if (opcode == ISA_OWORD_ST)
4482 {
4483 CreateGenRawSrcOperand(srcDst);
4484 status = m_builder->translateVISAOwordStoreInst(
4485 surface->g4opnd, size, offset->g4opnd,
4486 srcDst->g4opnd->asSrcRegRegion());
4487 }else
4488 {
4489 CreateGenRawDstOperand(srcDst); //srcDst: dst
4490 status = m_builder->translateVISAOwordLoadInst(
4491 opcode, false, surface->g4opnd, size, offset->g4opnd,
4492 srcDst->g4opnd->asDstRegRegion());
4493 }
4494 }
4495 if (IS_VISA_BOTH_PATH)
4496 {
4497 VISA_INST_Desc *inst_desc = NULL;
4498 VISA_opnd *opnd[5];
4499 inst_desc = &CISA_INST_table[opcode];
4500 int num_operands = 0;
4501 int num_pred_desc_operands = 0;
4502 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4503
4504 //size
4505 opnd[num_operands] = (VISA_opnd *)m_mem.alloc(sizeof(VISA_opnd));
4506 opnd[num_operands]->_opnd.other_opnd = size;
4507 opnd[num_operands]->opnd_type = CISA_OPND_OTHER;
4508 opnd[num_operands]->size =
4509 (uint16_t)Get_VISA_Type_Size((VISA_Type)inst_desc->opnd_desc[num_operands].data_type);
4510 opnd[num_operands]->tag =
4511 (uint8_t)inst_desc->opnd_desc[num_operands].opnd_type;
4512 num_operands++;
4513
4514 //ignored
4515 if (opcode == ISA_OWORD_LD || opcode == ISA_OWORD_LD_UNALIGNED)
4516 {
4517 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, 0));
4518 }
4519
4520 ADD_OPND(num_operands, opnd, surface);
4521 ADD_OPND(num_operands, opnd, offset);
4522 ADD_OPND(num_operands, opnd, srcDst);
4523
4524 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4525
4526 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4527 inst->createCisaInstruction(opcode, EXEC_SIZE_1 , 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4528 addInstructionToEnd(inst);
4529 }
4530
4531 return status;
4532 }
4533
AppendVISASILoad(VISA_StateOpndHandle * surface,VISAChannelMask _channel,bool isSIMD16,VISA_RawOpnd * uOffset,VISA_RawOpnd * vOffset,VISA_RawOpnd * rOffset,VISA_RawOpnd * dst)4534 int VISAKernelImpl::AppendVISASILoad(
4535 VISA_StateOpndHandle *surface, VISAChannelMask _channel, bool isSIMD16,
4536 VISA_RawOpnd *uOffset, VISA_RawOpnd *vOffset, VISA_RawOpnd *rOffset, VISA_RawOpnd *dst)
4537 {
4538 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4539
4540 AppendVISAInstCommon();
4541
4542 int status = VISA_SUCCESS;
4543 ChannelMask channel = ChannelMask::createFromAPI(_channel);
4544
4545 if (IS_GEN_BOTH_PATH)
4546 {
4547 uint8_t simdMode = isSIMD16 ? 16: 8;
4548 CreateGenRawSrcOperand(uOffset);
4549 CreateGenRawSrcOperand(vOffset);
4550 CreateGenRawSrcOperand(rOffset);
4551 CreateGenRawDstOperand(dst);
4552 status = m_builder->translateVISASamplerInst(
4553 simdMode, surface->g4opnd, NULL, channel, channel.getNumEnabledChannels(),
4554 uOffset->g4opnd, vOffset->g4opnd, rOffset->g4opnd, dst->g4opnd->asDstRegRegion());
4555 }
4556 if (IS_VISA_BOTH_PATH)
4557 {
4558 VISA_INST_Desc *inst_desc = NULL;
4559 VISA_opnd *opnd[8];
4560 int num_pred_desc_operands = 0;
4561 ISA_Opcode opcode = ISA_LOAD;
4562 inst_desc = &CISA_INST_table[opcode];
4563 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4564 int num_operands = 0;
4565
4566 unsigned mode = channel.getBinary(opcode);
4567
4568 if (isSIMD16)
4569 mode += 0x1<<4;
4570
4571 // mode
4572 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(0, num_operands, inst_desc, mode));
4573
4574 ADD_OPND(num_operands, opnd, surface);
4575 ADD_OPND(num_operands, opnd, uOffset);
4576 ADD_OPND(num_operands, opnd, vOffset);
4577 ADD_OPND(num_operands, opnd, rOffset);
4578 ADD_OPND(num_operands, opnd, dst);
4579
4580 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4581
4582 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4583
4584 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0 , PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4585 addInstructionToEnd(inst);
4586 }
4587
4588 return status;
4589 }
4590
AppendVISASISample(VISA_EMask_Ctrl emask,VISA_StateOpndHandle * surface,VISA_StateOpndHandle * sampler,VISAChannelMask _channel,bool isSIMD16,VISA_RawOpnd * uOffset,VISA_RawOpnd * vOffset,VISA_RawOpnd * rOffset,VISA_RawOpnd * dst)4591 int VISAKernelImpl::AppendVISASISample(
4592 VISA_EMask_Ctrl emask, VISA_StateOpndHandle *surface, VISA_StateOpndHandle *sampler,
4593 VISAChannelMask _channel, bool isSIMD16,
4594 VISA_RawOpnd *uOffset, VISA_RawOpnd *vOffset, VISA_RawOpnd *rOffset, VISA_RawOpnd *dst)
4595 {
4596 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4597
4598 AppendVISAInstCommon();
4599
4600 int status = VISA_SUCCESS;
4601 ChannelMask channel = ChannelMask::createFromAPI(_channel);
4602
4603 if (IS_GEN_BOTH_PATH)
4604 {
4605 uint8_t simdMode = (isSIMD16)?16:8;
4606 CreateGenRawSrcOperand(uOffset);
4607 CreateGenRawSrcOperand(vOffset);
4608 CreateGenRawSrcOperand(rOffset);
4609 CreateGenRawDstOperand(dst); // srcDst: src
4610 status = m_builder->translateVISASamplerInst(
4611 simdMode, surface->g4opnd, sampler->g4opnd,
4612 channel, channel.getNumEnabledChannels(),
4613 uOffset->g4opnd, vOffset->g4opnd, rOffset->g4opnd, dst->g4opnd->asDstRegRegion());
4614 }
4615 if (IS_VISA_BOTH_PATH)
4616 {
4617 VISA_INST_Desc *inst_desc = NULL;
4618 VISA_opnd *opnd[8];
4619 int num_pred_desc_operands = 0;
4620 ISA_Opcode opcode = ISA_SAMPLE;
4621 inst_desc = &CISA_INST_table[opcode];
4622 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4623 int num_operands = 0;
4624
4625 unsigned mode = channel.getBinary(opcode);
4626
4627 if (isSIMD16)
4628 mode += 0x1<<4;
4629
4630 // mode
4631 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(0, num_operands, inst_desc, mode));
4632 ADD_OPND(num_operands, opnd, sampler);
4633 ADD_OPND(num_operands, opnd, surface);
4634 ADD_OPND(num_operands, opnd, uOffset);
4635 ADD_OPND(num_operands, opnd, vOffset);
4636 ADD_OPND(num_operands, opnd, rOffset);
4637 ADD_OPND(num_operands, opnd, dst);
4638
4639 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4640
4641 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0 , PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4642 addInstructionToEnd(inst);
4643 }
4644
4645 return status;
4646 }
4647
AppendVISASISampleUnorm(VISA_StateOpndHandle * surface,VISA_StateOpndHandle * sampler,VISAChannelMask _channel,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * deltaU,VISA_VectorOpnd * deltaV,VISA_RawOpnd * dst,CHANNEL_OUTPUT_FORMAT _output)4648 int VISAKernelImpl::AppendVISASISampleUnorm(
4649 VISA_StateOpndHandle *surface, VISA_StateOpndHandle *sampler, VISAChannelMask _channel,
4650 VISA_VectorOpnd *uOffset, VISA_VectorOpnd *vOffset,
4651 VISA_VectorOpnd *deltaU, VISA_VectorOpnd *deltaV,
4652 VISA_RawOpnd *dst, CHANNEL_OUTPUT_FORMAT _output)
4653 {
4654 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4655
4656 AppendVISAInstCommon();
4657
4658 int status = VISA_SUCCESS;
4659 ChannelMask channel = ChannelMask::createFromAPI(_channel);
4660
4661 if (IS_GEN_BOTH_PATH)
4662 {
4663 CreateGenRawDstOperand(dst); //srcDst: src
4664 status = m_builder->translateVISASamplerNormInst(
4665 surface->g4opnd, sampler->g4opnd, channel, channel.getNumEnabledChannels(),
4666 deltaU->g4opnd, uOffset->g4opnd, deltaV->g4opnd, vOffset->g4opnd,
4667 dst->g4opnd->asDstRegRegion());
4668 }
4669 if (IS_VISA_BOTH_PATH)
4670 {
4671 VISA_INST_Desc *inst_desc = NULL;
4672 VISA_opnd *opnd[8];
4673 int num_pred_desc_operands = 0;
4674 ISA_Opcode opcode = ISA_SAMPLE_UNORM;
4675 inst_desc = &CISA_INST_table[opcode];
4676 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4677 int num_operands = 0;
4678
4679 //mode
4680 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(0, num_operands, inst_desc, channel.getBinary(opcode, _output)));
4681
4682 ADD_OPND(num_operands, opnd, sampler);
4683 ADD_OPND(num_operands, opnd, surface);
4684 ADD_OPND(num_operands, opnd, uOffset);
4685 ADD_OPND(num_operands, opnd, vOffset);
4686 ADD_OPND(num_operands, opnd, deltaU);
4687 ADD_OPND(num_operands, opnd, deltaV);
4688 ADD_OPND(num_operands, opnd, dst);
4689
4690 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4691
4692 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4693
4694 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4695 addInstructionToEnd(inst);
4696 }
4697
4698 return status;
4699 }
4700
AppendVISAWaitInst(VISA_VectorOpnd * mask)4701 int VISAKernelImpl::AppendVISAWaitInst(VISA_VectorOpnd* mask)
4702 {
4703 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4704
4705 AppendVISAInstCommon();
4706
4707 int status = VISA_SUCCESS;
4708
4709 if (IS_GEN_BOTH_PATH)
4710 {
4711 status = m_builder->translateVISAWaitInst(mask != NULL ? mask->g4opnd : NULL);
4712 }
4713 if (IS_VISA_BOTH_PATH)
4714 {
4715 VISA_INST_Desc *inst_desc = NULL;
4716 VISA_opnd* opnd[1];
4717 int num_pred_desc_operands = 0;
4718 inst_desc = &CISA_INST_table[ISA_WAIT];
4719 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4720 int num_operands = 0;
4721
4722 if (mask == nullptr)
4723 {
4724 int val = 0;
4725 CreateVISAImmediate(mask, &val, ISA_TYPE_UD);
4726 }
4727
4728 ADD_OPND(num_operands, opnd, mask);
4729
4730 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4731
4732 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4733
4734 inst->createCisaInstruction(ISA_WAIT, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4735 addInstructionToEnd(inst);
4736 }
4737
4738 return status;
4739 }
4740
4741
AppendVISASyncInst(ISA_Opcode opcode,unsigned char mask)4742 int VISAKernelImpl::AppendVISASyncInst(ISA_Opcode opcode, unsigned char mask)
4743 {
4744 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4745
4746 AppendVISAInstCommon();
4747
4748 int status = VISA_SUCCESS;
4749
4750 if (IS_GEN_BOTH_PATH)
4751 {
4752 status = m_builder->translateVISASyncInst(opcode, mask);
4753 }
4754 if (IS_VISA_BOTH_PATH)
4755 {
4756 VISA_INST_Desc *inst_desc = NULL;
4757 VISA_opnd* opnd[1];
4758 int num_pred_desc_operands = 0;
4759 inst_desc = &CISA_INST_table[opcode];
4760 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4761 int num_operands = 0;
4762
4763 if (opcode == ISA_FENCE)
4764 {
4765 //number of registers to send
4766 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, mask));
4767 }
4768
4769 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4770
4771 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4772
4773 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4774 addInstructionToEnd(inst);
4775 }
4776
4777 return status;
4778 }
4779
AppendVISASplitBarrierInst(bool isSignal)4780 int VISAKernelImpl::AppendVISASplitBarrierInst(bool isSignal)
4781 {
4782 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4783
4784 AppendVISAInstCommon();
4785
4786 int status = VISA_SUCCESS;
4787
4788 if (IS_GEN_BOTH_PATH)
4789 {
4790 status = m_builder->translateVISASplitBarrierInst(isSignal);
4791 }
4792
4793 if (IS_VISA_BOTH_PATH)
4794 {
4795 VISA_INST_Desc *inst_desc = NULL;
4796 VISA_opnd* opnd[1];
4797 int num_pred_desc_operands = 0;
4798 inst_desc = &CISA_INST_table[ISA_SBARRIER];
4799 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4800 int num_operands = 0;
4801
4802 uint8_t mode = isSignal ? 1 : 0;
4803 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, mode));
4804
4805 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4806
4807 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4808
4809 inst->createCisaInstruction(ISA_SBARRIER, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
4810 addInstructionToEnd(inst);
4811 }
4812
4813 return status;
4814 }
4815
AppendVISAMiscFileInst(const char * fileName)4816 int VISAKernelImpl::AppendVISAMiscFileInst(const char *fileName)
4817 {
4818 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4819
4820 AppendVISAInstCommon();
4821
4822 int status = VISA_SUCCESS;
4823
4824 if (IS_GEN_BOTH_PATH)
4825 {
4826 size_t fileLen = strlen(fileName) + 1;
4827 char *newFile = (char*)m_mem.alloc(fileLen);
4828 m_builder->curFile = newFile;
4829 strcpy_s(newFile, fileLen, fileName);
4830 }
4831 if (IS_VISA_BOTH_PATH)
4832 {
4833 VISA_INST_Desc *inst_desc = NULL;
4834 VISA_opnd* opnd[1];
4835 ISA_Opcode opcode = ISA_FILE;
4836 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4837
4838 inst_desc = &CISA_INST_table[opcode];
4839
4840 opnd[0] = (VISA_opnd*)m_mem.alloc(sizeof(VISA_opnd));
4841 opnd[0]->_opnd.other_opnd = addStringPool(std::string(fileName));
4842 opnd[0]->opnd_type = CISA_OPND_OTHER;
4843
4844 opnd[0]->size = Get_VISA_Type_Size((VISA_Type)inst_desc->opnd_desc[0].data_type);
4845 opnd[0]->tag = (uint8_t)inst_desc->opnd_desc[0].opnd_type;
4846 inst->createCisaInstruction(opcode, 1, 0, PredicateOpnd::getNullPred(), opnd, 1, inst_desc);
4847 addInstructionToEnd(inst);
4848 }
4849
4850 return status;
4851 }
4852
AppendVISADebugLinePlaceholder()4853 int VISAKernelImpl::AppendVISADebugLinePlaceholder()
4854 {
4855 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4856
4857 // AppendVISAInstCommon();
4858
4859 int status = VISA_SUCCESS;
4860
4861 if (IS_GEN_BOTH_PATH)
4862 {
4863 m_builder->generateDebugInfoPlaceholder();
4864 }
4865
4866 return status;
4867 }
4868
AppendVISAMiscLOC(unsigned int lineNumber)4869 int VISAKernelImpl::AppendVISAMiscLOC(unsigned int lineNumber)
4870 {
4871 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4872
4873 AppendVISAInstCommon();
4874
4875 int status = VISA_SUCCESS;
4876
4877 if (IS_GEN_BOTH_PATH)
4878 {
4879 m_builder->curLine = lineNumber;
4880 }
4881 if (IS_VISA_BOTH_PATH)
4882 {
4883 VISA_INST_Desc *inst_desc = NULL;
4884 VISA_opnd* opnd[1];
4885 ISA_Opcode opcode = ISA_LOC;
4886 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4887
4888 inst_desc = &CISA_INST_table[opcode];
4889
4890 opnd[0] = (VISA_opnd*)m_mem.alloc(sizeof(VISA_opnd));
4891 opnd[0]->_opnd.other_opnd = lineNumber;
4892 opnd[0]->opnd_type = CISA_OPND_OTHER;
4893
4894 opnd[0]->size = Get_VISA_Type_Size((VISA_Type)inst_desc->opnd_desc[0].data_type);
4895 opnd[0]->tag = (uint8_t)inst_desc->opnd_desc[0].opnd_type;
4896 inst->createCisaInstruction(opcode, 1, 0, PredicateOpnd::getNullPred(), opnd, 1, inst_desc);
4897 addInstructionToEnd(inst);
4898 }
4899
4900 return status;
4901 }
4902
AppendVISAMiscRawSend(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,unsigned char modifiers,unsigned int exMsgDesc,unsigned char srcSize,unsigned char dstSize,VISA_VectorOpnd * desc,VISA_RawOpnd * src,VISA_RawOpnd * dst)4903 int VISAKernelImpl::AppendVISAMiscRawSend(
4904 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize, unsigned char modifiers,
4905 unsigned int exMsgDesc, unsigned char srcSize, unsigned char dstSize, VISA_VectorOpnd *desc,
4906 VISA_RawOpnd *src, VISA_RawOpnd *dst)
4907 {
4908 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4909
4910 AppendVISAInstCommon();
4911
4912 int status = VISA_SUCCESS;
4913
4914 if (IS_GEN_BOTH_PATH)
4915 {
4916 CreateGenRawSrcOperand(src);
4917 CreateGenRawDstOperand(dst);
4918 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
4919 dst->g4opnd->asDstRegRegion()->setType(executionSize == EXEC_SIZE_16 ? Type_UW : Type_UD);
4920
4921 status = m_builder->translateVISARawSendInst(g4Pred, executionSize,
4922 emask, modifiers, exMsgDesc, srcSize, dstSize, desc->g4opnd,
4923 src->g4opnd->asSrcRegRegion(), dst->g4opnd->asDstRegRegion());
4924 }
4925 if (IS_VISA_BOTH_PATH)
4926 {
4927 VISA_INST_Desc *inst_desc = NULL;
4928 VISA_opnd *opnd[7];
4929 ISA_Opcode opcode = ISA_RAW_SEND;
4930 int num_pred_desc_operands = 0;
4931 inst_desc = &CISA_INST_table[opcode];
4932 int num_operands = 0;
4933
4934 //modifier
4935 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, modifiers));
4936
4937 num_pred_desc_operands = 2;
4938 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
4939
4940 //exMsgDesc
4941 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, exMsgDesc));
4942 //number of registers to send
4943 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, srcSize));
4944 //Number of registers expected returned
4945 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, dstSize));
4946 //Message Descriptor
4947 ADD_OPND(num_operands, opnd, desc);
4948 //Source
4949 ADD_OPND(num_operands, opnd, src);
4950 //Destination
4951 ADD_OPND(num_operands, opnd, dst);
4952
4953 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
4954
4955 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
4956
4957 unsigned char size = executionSize;
4958 size += emask << 4;
4959
4960 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
4961
4962 inst->createCisaInstruction(opcode, size, modifiers, predOpnd, opnd, num_operands, inst_desc);
4963 addInstructionToEnd(inst);
4964 }
4965
4966 return status;
4967 }
4968
AppendVISAMiscRawSends(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,unsigned char modifiers,unsigned ffid,VISA_VectorOpnd * exMsgDesc,unsigned char src0Size,unsigned char src1Size,unsigned char dstSize,VISA_VectorOpnd * desc,VISA_RawOpnd * src0,VISA_RawOpnd * src1,VISA_RawOpnd * dst,bool hasEOT)4969 int VISAKernelImpl::AppendVISAMiscRawSends(
4970 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize, unsigned char modifiers,
4971 unsigned ffid, VISA_VectorOpnd *exMsgDesc,
4972 unsigned char src0Size, unsigned char src1Size, unsigned char dstSize,
4973 VISA_VectorOpnd *desc,
4974 VISA_RawOpnd *src0, VISA_RawOpnd *src1, VISA_RawOpnd *dst, bool hasEOT)
4975 {
4976 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
4977
4978 AppendVISAInstCommon();
4979
4980 int status = VISA_SUCCESS;
4981
4982 if (IS_GEN_BOTH_PATH)
4983 {
4984 CreateGenRawSrcOperand(src0);
4985 CreateGenRawSrcOperand(src1);
4986 CreateGenRawDstOperand(dst);
4987 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
4988 dst->g4opnd->asDstRegRegion()->setType(Type_UD);
4989
4990 status = m_builder->translateVISARawSendsInst(g4Pred, executionSize,
4991 emask, modifiers, exMsgDesc->g4opnd,
4992 src0Size, src1Size, dstSize,
4993 desc->g4opnd, src0->g4opnd, src1->g4opnd, dst->g4opnd->asDstRegRegion(), ffid, hasEOT);
4994 }
4995 if (IS_VISA_BOTH_PATH)
4996 {
4997 VISA_INST_Desc *inst_desc = NULL;
4998 VISA_opnd *opnd[12]; // TODO: avoid hard-coding
4999 ISA_Opcode opcode = ISA_RAW_SENDS;
5000 int num_pred_desc_operands = 0;
5001 inst_desc = &CISA_INST_table[opcode];
5002 int num_operands = 0;
5003
5004 //modifier
5005 if (hasEOT)
5006 {
5007 // bits[1]: EOT flag
5008 modifiers |= 0x2;
5009 }
5010 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, modifiers));
5011
5012 num_pred_desc_operands = 2;
5013 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5014
5015 //number of source register 0 to send
5016 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, src0Size));
5017 //number of source register 1 to send
5018 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, src1Size));
5019 //Number of destination registers expected returned
5020 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, dstSize));
5021 //SFID
5022 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, ffid));
5023 //exMsgDesc
5024 ADD_OPND(num_operands, opnd, exMsgDesc);
5025 //Message Descriptor
5026 ADD_OPND(num_operands, opnd, desc);
5027 //Source 0
5028 ADD_OPND(num_operands, opnd, src0);
5029 //Source 1
5030 ADD_OPND(num_operands, opnd, src1);
5031 //Destination
5032 ADD_OPND(num_operands, opnd, dst);
5033
5034 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5035
5036 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5037
5038 unsigned char size = executionSize;
5039 size += emask << 4;
5040
5041 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
5042
5043 inst->createCisaInstruction(opcode, size, modifiers, predOpnd, opnd, num_operands, inst_desc);
5044 addInstructionToEnd(inst);
5045 }
5046
5047 return status;
5048 }
5049
AppendVISAMiscVME_FBR(VISA_StateOpndHandle * surface,VISA_RawOpnd * UNIInput,VISA_RawOpnd * FBRInput,VISA_VectorOpnd * FBRMbMode,VISA_VectorOpnd * FBRSubMbShape,VISA_VectorOpnd * FBRSubPredMode,VISA_RawOpnd * output)5050 int VISAKernelImpl::AppendVISAMiscVME_FBR(
5051 VISA_StateOpndHandle *surface, VISA_RawOpnd *UNIInput,
5052 VISA_RawOpnd *FBRInput, VISA_VectorOpnd* FBRMbMode, VISA_VectorOpnd *FBRSubMbShape,
5053 VISA_VectorOpnd *FBRSubPredMode, VISA_RawOpnd *output)
5054 {
5055 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5056
5057 AppendVISAInstCommon();
5058
5059 int status = VISA_SUCCESS;
5060
5061 if (IS_GEN_BOTH_PATH)
5062 {
5063 CreateGenRawSrcOperand(UNIInput);
5064 CreateGenRawSrcOperand(FBRInput);
5065 CreateGenRawDstOperand(output);
5066 status = m_builder->translateVISAVmeFbrInst(surface->g4opnd, UNIInput->g4opnd, FBRInput->g4opnd,
5067 FBRMbMode->g4opnd, FBRSubMbShape->g4opnd, FBRSubPredMode->g4opnd, output->g4opnd->asDstRegRegion());
5068 }
5069 if (IS_VISA_BOTH_PATH)
5070 {
5071 VISA_INST_Desc *inst_desc = NULL;
5072 VISA_opnd *opnd[7];
5073 int num_pred_desc_operands = 0;
5074 ISA_Opcode opcode = ISA_VME_FBR;
5075 inst_desc = &CISA_INST_table[opcode];
5076 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5077 int num_operands = 0;
5078
5079 //UNIinput
5080 ADD_OPND(num_operands, opnd, UNIInput);
5081 //fbr_input
5082 ADD_OPND(num_operands, opnd, FBRInput);
5083 //surface
5084 ADD_OPND(num_operands, opnd, surface);
5085 //FBRMbMode
5086 ADD_OPND(num_operands, opnd, FBRMbMode);
5087 //FBRSubMbShape
5088 ADD_OPND(num_operands, opnd, FBRSubMbShape);
5089 //FBRSubPredMode
5090 ADD_OPND(num_operands, opnd, FBRSubPredMode);
5091 //output
5092 ADD_OPND(num_operands, opnd, output);
5093
5094 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5095
5096 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5097
5098 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
5099 addInstructionToEnd(inst);
5100 }
5101
5102 return status;
5103 }
5104
AppendVISAMiscVME_IME(VISA_StateOpndHandle * surface,unsigned char streamMode,unsigned char searchControlMode,VISA_RawOpnd * UNIInput,VISA_RawOpnd * IMEInput,VISA_RawOpnd * ref0,VISA_RawOpnd * ref1,VISA_RawOpnd * costCenter,VISA_RawOpnd * output)5105 int VISAKernelImpl::AppendVISAMiscVME_IME(
5106 VISA_StateOpndHandle *surface, unsigned char streamMode, unsigned char searchControlMode, VISA_RawOpnd *UNIInput,
5107 VISA_RawOpnd *IMEInput, VISA_RawOpnd *ref0, VISA_RawOpnd *ref1, VISA_RawOpnd *costCenter, VISA_RawOpnd *output)
5108 {
5109 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5110
5111 AppendVISAInstCommon();
5112
5113 int status = VISA_SUCCESS;
5114
5115 if (IS_GEN_BOTH_PATH)
5116 {
5117 CreateGenRawSrcOperand(UNIInput);
5118 CreateGenRawSrcOperand(IMEInput);
5119 CreateGenRawSrcOperand(ref0);
5120 CreateGenRawSrcOperand(ref1);
5121 CreateGenRawSrcOperand(costCenter);
5122 CreateGenRawDstOperand(output);
5123 status = m_builder->translateVISAVmeImeInst(
5124 streamMode, searchControlMode, surface->g4opnd,
5125 UNIInput->g4opnd, IMEInput->g4opnd, ref0->g4opnd, ref1->g4opnd,
5126 costCenter->g4opnd, output->g4opnd->asDstRegRegion());
5127 }
5128 if (IS_VISA_BOTH_PATH)
5129 {
5130 VISA_INST_Desc *inst_desc = NULL;
5131 VISA_opnd *opnd[9];
5132 int num_pred_desc_operands = 0;
5133 ISA_Opcode opcode = ISA_VME_IME;
5134 inst_desc = &CISA_INST_table[opcode];
5135 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5136 int num_operands = 0;
5137
5138 //streamMode
5139 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, streamMode));
5140 //searchCtrl
5141 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, searchControlMode));
5142 //input
5143 ADD_OPND(num_operands, opnd, UNIInput);
5144 //ime_input
5145 ADD_OPND(num_operands, opnd, IMEInput);
5146 //surface
5147 ADD_OPND(num_operands, opnd, surface);
5148 //ref0
5149 ADD_OPND(num_operands, opnd, ref0);
5150 //ref1
5151 ADD_OPND(num_operands, opnd, ref1);
5152 //CostCenter
5153 ADD_OPND(num_operands, opnd, costCenter);
5154 //output
5155 ADD_OPND(num_operands, opnd, output);
5156
5157 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5158
5159 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5160
5161 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
5162 addInstructionToEnd(inst);
5163 }
5164
5165 return status;
5166 }
5167
AppendVISAMiscVME_SIC(VISA_StateOpndHandle * surface,VISA_RawOpnd * UNIInput,VISA_RawOpnd * SICInput,VISA_RawOpnd * output)5168 int VISAKernelImpl::AppendVISAMiscVME_SIC(
5169 VISA_StateOpndHandle *surface, VISA_RawOpnd *UNIInput, VISA_RawOpnd *SICInput, VISA_RawOpnd *output)
5170 {
5171 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5172
5173 AppendVISAInstCommon();
5174
5175 int status = VISA_SUCCESS;
5176
5177 if (IS_GEN_BOTH_PATH)
5178 {
5179 CreateGenRawSrcOperand(UNIInput);
5180 CreateGenRawSrcOperand(SICInput);
5181 CreateGenRawDstOperand(output);
5182 status = m_builder->translateVISAVmeSicInst(surface->g4opnd, UNIInput->g4opnd, SICInput->g4opnd, output->g4opnd->asDstRegRegion());
5183 }
5184 if (IS_VISA_BOTH_PATH)
5185 {
5186 VISA_INST_Desc *inst_desc = NULL;
5187 VISA_opnd *opnd[4];
5188 int num_pred_desc_operands = 0;
5189 ISA_Opcode opcode = ISA_VME_SIC;
5190 inst_desc = &CISA_INST_table[opcode];
5191 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5192 int num_operands = 0;
5193
5194 ADD_OPND(num_operands, opnd, UNIInput);
5195 ADD_OPND(num_operands, opnd, SICInput);
5196 ADD_OPND(num_operands, opnd, surface);
5197 ADD_OPND(num_operands, opnd, output);
5198
5199 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5200
5201 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5202
5203 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
5204 addInstructionToEnd(inst);
5205 }
5206
5207 return status;
5208 }
5209
5210
AppendVISAMiscVME_IDM(VISA_StateOpndHandle * surface,VISA_RawOpnd * UNIInput,VISA_RawOpnd * IDMInput,VISA_RawOpnd * output)5211 int VISAKernelImpl::AppendVISAMiscVME_IDM(
5212 VISA_StateOpndHandle *surface, VISA_RawOpnd *UNIInput, VISA_RawOpnd *IDMInput, VISA_RawOpnd *output)
5213 {
5214 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5215
5216 AppendVISAInstCommon();
5217
5218 int status = VISA_SUCCESS;
5219
5220 if (IS_GEN_BOTH_PATH)
5221 {
5222 CreateGenRawSrcOperand(UNIInput);
5223 CreateGenRawSrcOperand(IDMInput);
5224 CreateGenRawDstOperand(output);
5225 status = m_builder->translateVISAVmeIdmInst(
5226 surface->g4opnd, UNIInput->g4opnd, IDMInput->g4opnd, output->g4opnd->asDstRegRegion());
5227 }
5228 if (IS_VISA_BOTH_PATH)
5229 {
5230 VISA_INST_Desc *inst_desc = NULL;
5231 VISA_opnd *opnd[4];
5232 int num_pred_desc_operands = 0;
5233 ISA_Opcode opcode = ISA_VME_SIC;
5234 inst_desc = &CISA_INST_table[opcode];
5235 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5236 int num_operands = 0;
5237
5238 ADD_OPND(num_operands, opnd, UNIInput);
5239 ADD_OPND(num_operands, opnd, IDMInput);
5240 ADD_OPND(num_operands, opnd, surface);
5241 ADD_OPND(num_operands, opnd, output);
5242
5243 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5244
5245 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5246
5247 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
5248 addInstructionToEnd(inst);
5249 }
5250
5251 return status;
5252 }
5253
AppendVISAMEAVS(VISA_StateOpndHandle * surface,VISA_StateOpndHandle * sampler,VISAChannelMask _chMask,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * deltaU,VISA_VectorOpnd * deltaV,VISA_VectorOpnd * u2d,VISA_VectorOpnd * v2d,VISA_VectorOpnd * groupID,VISA_VectorOpnd * verticalBlockNumber,OutputFormatControl cntrl,AVSExecMode execMode,VISA_VectorOpnd * iefBypass,VISA_RawOpnd * dst)5254 int VISAKernelImpl::AppendVISAMEAVS(
5255 VISA_StateOpndHandle *surface, VISA_StateOpndHandle *sampler, VISAChannelMask _chMask, VISA_VectorOpnd *uOffset,
5256 VISA_VectorOpnd *vOffset, VISA_VectorOpnd *deltaU, VISA_VectorOpnd *deltaV, VISA_VectorOpnd *u2d,
5257 VISA_VectorOpnd *v2d, VISA_VectorOpnd *groupID, VISA_VectorOpnd *verticalBlockNumber, OutputFormatControl cntrl,
5258 AVSExecMode execMode, VISA_VectorOpnd *iefBypass, VISA_RawOpnd *dst)
5259 {
5260 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5261
5262 AppendVISAInstCommon();
5263
5264 int status = VISA_SUCCESS;
5265 ChannelMask chMask = ChannelMask::createFromAPI(_chMask);
5266 if (IS_GEN_BOTH_PATH)
5267 {
5268 CreateGenRawDstOperand(dst);
5269 unsigned numChannelsEnabled = 0;
5270 numChannelsEnabled = chMask.getNumEnabledChannels();
5271
5272 status = m_builder->translateVISAAvsInst(surface->g4opnd, sampler->g4opnd, chMask, numChannelsEnabled,
5273 GET_G4_OPNG(deltaU), uOffset->g4opnd, GET_G4_OPNG(deltaV), GET_G4_OPNG(vOffset),
5274 GET_G4_OPNG(u2d), GET_G4_OPNG(groupID), GET_G4_OPNG(verticalBlockNumber), cntrl, GET_G4_OPNG(v2d),
5275 execMode, GET_G4_OPNG(iefBypass), dst->g4opnd->asDstRegRegion());
5276 }
5277 if (IS_VISA_BOTH_PATH)
5278 {
5279 VISA_INST_Desc *inst_desc = NULL;
5280 VISA_opnd *opnd[32];
5281 int num_pred_desc_operands = 0;
5282 ISA_Opcode opcode = ISA_AVS;
5283 inst_desc = &CISA_INST_table[opcode];
5284 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5285 int num_operands = 0;
5286
5287 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, chMask.getBinary(ISA_AVS)));
5288 ADD_OPND(num_operands, opnd, sampler);
5289 ADD_OPND(num_operands, opnd, surface);
5290 ADD_OPND(num_operands, opnd, uOffset);
5291 ADD_OPND(num_operands, opnd, vOffset);
5292 ADD_OPND(num_operands, opnd, deltaU);
5293 ADD_OPND(num_operands, opnd, deltaV);
5294 ADD_OPND(num_operands, opnd, u2d);
5295 ADD_OPND(num_operands, opnd, groupID);
5296 ADD_OPND(num_operands, opnd, verticalBlockNumber);
5297 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, cntrl));
5298 ADD_OPND(num_operands, opnd, v2d);
5299 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, execMode));
5300 ADD_OPND(num_operands, opnd, iefBypass);
5301 ADD_OPND(num_operands, opnd, dst);
5302
5303 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5304
5305 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5306
5307 inst->createCisaInstruction(opcode, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
5308 addInstructionToEnd(inst);
5309 }
5310
5311 return status;
5312 }
5313 /************* END APPEND APIS ************************/
AppendVISA3dSamplerMsgGeneric(ISA_Opcode opcode,VISASampler3DSubOpCode subOpcode,bool pixelNullMask,bool cpsEnable,bool uniformSampler,VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,ChannelMask srcChannel,VISA_VectorOpnd * aoffimmi,VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_RawOpnd * dst,unsigned int numMsgSpecificOpnds,VISA_RawOpnd ** opndArray)5314 int VISAKernelImpl::AppendVISA3dSamplerMsgGeneric(
5315 ISA_Opcode opcode,
5316 VISASampler3DSubOpCode subOpcode,
5317 bool pixelNullMask,
5318 bool cpsEnable,
5319 bool uniformSampler,
5320 VISA_PredOpnd * pred,
5321 VISA_EMask_Ctrl emask,
5322 VISA_Exec_Size executionSize,
5323 ChannelMask srcChannel,
5324 VISA_VectorOpnd *aoffimmi,
5325 VISA_StateOpndHandle *sampler,
5326 VISA_StateOpndHandle *surface,
5327 VISA_RawOpnd *dst,
5328 unsigned int numMsgSpecificOpnds,
5329 VISA_RawOpnd **opndArray)
5330 {
5331 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5332
5333 AppendVISAInstCommon();
5334
5335 int status = VISA_SUCCESS;
5336 bool isLoad = (subOpcode == VISA_3D_LD_MCS || subOpcode == VISA_3D_LD ||
5337 subOpcode == VISA_3D_LD2DMS_W || subOpcode == VISA_3D_LD_LZ);
5338 bool isSample4 = (subOpcode == VISA_3D_GATHER4 ||
5339 subOpcode == VISA_3D_GATHER4_C ||
5340 (m_builder->hasGather4PO() && subOpcode == VISA_3D_GATHER4_PO) ||
5341 (m_builder->hasGather4PO() && subOpcode == VISA_3D_GATHER4_PO_C)
5342 );
5343
5344 if (IS_GEN_BOTH_PATH)
5345 {
5346 CreateGenRawDstOperand(dst);
5347 G4_SrcRegRegion* g4params[32];
5348
5349 for (unsigned int i = 0; i< numMsgSpecificOpnds; ++i)
5350 {
5351 #if START_ASSERT_CHECK
5352 if (opndArray[i] == NULL)
5353 {
5354 assert(0);
5355 return VISA_FAILURE;
5356 }
5357 #endif
5358 CreateGenRawSrcOperand(opndArray[i]);
5359 g4params[i] = opndArray[i]->g4opnd->asSrcRegRegion();
5360 }
5361 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
5362
5363 if (isLoad)
5364 {
5365 status = m_builder->translateVISALoad3DInst(subOpcode, pixelNullMask,
5366 g4Pred, executionSize,
5367 emask, srcChannel,
5368 aoffimmi->g4opnd, surface->g4opnd,
5369 dst->g4opnd->asDstRegRegion(),
5370 (uint8_t)numMsgSpecificOpnds,
5371 g4params);
5372 }
5373 else if (isSample4)
5374 {
5375 status = m_builder->translateVISAGather3dInst(subOpcode, pixelNullMask,
5376 g4Pred, executionSize,
5377 emask, srcChannel,
5378 aoffimmi->g4opnd, sampler->g4opnd,
5379 surface->g4opnd,
5380 dst->g4opnd->asDstRegRegion(),
5381 numMsgSpecificOpnds, g4params);
5382 }
5383 else
5384 {
5385 status = m_builder->translateVISASampler3DInst(subOpcode, pixelNullMask,
5386 cpsEnable, uniformSampler, g4Pred, executionSize,
5387 emask, srcChannel,
5388 aoffimmi->g4opnd, sampler->g4opnd,
5389 surface->g4opnd,
5390 dst->g4opnd->asDstRegRegion(),
5391 numMsgSpecificOpnds, g4params);
5392 }
5393 }
5394 if (IS_VISA_BOTH_PATH)
5395 {
5396 VISA_INST_Desc *inst_desc = (VISA_INST_Desc*)m_mem.alloc(sizeof(VISA_INST_Desc));
5397 *inst_desc = CISA_INST_table[opcode];
5398 VISA_opnd *opnd[30];
5399 int num_pred_desc_operands = 0;
5400 int num_operands = 0;
5401
5402 // subOP, pixel null mask and CPS LOD compensation enable.
5403 // Bit 0-4 : subOp
5404 // Bit 5 : pixelNullMask
5405 // Bit 6 : cpsEnable
5406 int value = subOpcode + (pixelNullMask ? 1 << 5 : 0)
5407 + (cpsEnable ? 1 << 6 : 0);
5408 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, value));
5409
5410 num_pred_desc_operands = 2;
5411 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5412
5413 uint8_t channelVal = isSample4 ? (uint8_t) srcChannel.convertToSrcChannel() : (uint8_t) srcChannel.getBinary(opcode);
5414 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, channelVal));
5415
5416 //aoffimmi
5417 ADD_OPND(num_operands, opnd, aoffimmi);
5418
5419 //sampler
5420 if (opcode == ISA_3D_SAMPLE ||
5421 opcode == ISA_3D_GATHER4)
5422 {
5423 ADD_OPND(num_operands, opnd, sampler);
5424 }
5425
5426 //surface
5427 ADD_OPND(num_operands, opnd, surface);
5428
5429 //dst
5430 ADD_OPND(num_operands, opnd, dst);
5431 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, numMsgSpecificOpnds));
5432
5433 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5434
5435 for (unsigned int i = 0; i < numMsgSpecificOpnds; i++)
5436 {
5437 if (opndArray[i] == NULL)
5438 {
5439 assert(0);
5440 return VISA_FAILURE;
5441 }
5442 ADD_OPND(num_operands, opnd, opndArray[i]);
5443 }
5444
5445 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5446
5447 unsigned char size = executionSize;
5448 size += emask << 4;
5449
5450 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
5451
5452 inst_desc->opnd_num = num_pred_desc_operands + num_operands;
5453
5454 inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
5455 addInstructionToEnd(inst);
5456 }
5457
5458 return status;
5459 }
5460
AppendVISA3dSampler(VISASampler3DSubOpCode subOpcode,bool pixelNullMask,bool cpsEnable,bool uniformSampler,VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISAChannelMask srcChannel,VISA_VectorOpnd * aoffimmi,VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_RawOpnd * dst,int numMsgSpecificOpnds,VISA_RawOpnd ** opndArray)5461 int VISAKernelImpl::AppendVISA3dSampler(
5462 VISASampler3DSubOpCode subOpcode,
5463 bool pixelNullMask,
5464 bool cpsEnable,
5465 bool uniformSampler,
5466 VISA_PredOpnd *pred,
5467 VISA_EMask_Ctrl emask,
5468 VISA_Exec_Size executionSize,
5469 VISAChannelMask srcChannel,
5470 VISA_VectorOpnd *aoffimmi,
5471 VISA_StateOpndHandle *sampler,
5472 VISA_StateOpndHandle *surface,
5473 VISA_RawOpnd *dst,
5474 int numMsgSpecificOpnds,
5475 VISA_RawOpnd **opndArray)
5476 {
5477 ISA_Opcode opcode = ISA_3D_SAMPLE; // generate Gen IR for opndArray and dst in below func
5478 return AppendVISA3dSamplerMsgGeneric(
5479 opcode,
5480 subOpcode,
5481 pixelNullMask,
5482 cpsEnable,
5483 uniformSampler,
5484 pred,
5485 emask,
5486 executionSize,
5487 ChannelMask::createFromAPI(srcChannel),
5488 aoffimmi,
5489 sampler,
5490 surface,
5491 dst,
5492 numMsgSpecificOpnds,
5493 opndArray);
5494 }
5495
AppendVISA3dLoad(VISASampler3DSubOpCode subOpcode,bool pixelNullMask,VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISAChannelMask srcChannel,VISA_VectorOpnd * aoffimmi,VISA_StateOpndHandle * surface,VISA_RawOpnd * dst,int numMsgSpecificOpnds,VISA_RawOpnd ** opndArray)5496 int VISAKernelImpl::AppendVISA3dLoad(
5497 VISASampler3DSubOpCode subOpcode,
5498 bool pixelNullMask,
5499 VISA_PredOpnd *pred,
5500 VISA_EMask_Ctrl emask,
5501 VISA_Exec_Size executionSize,
5502 VISAChannelMask srcChannel,
5503 VISA_VectorOpnd *aoffimmi,
5504 VISA_StateOpndHandle *surface,
5505 VISA_RawOpnd *dst,
5506 int numMsgSpecificOpnds,
5507 VISA_RawOpnd **opndArray)
5508 {
5509 ISA_Opcode opcode = ISA_3D_LOAD; // generate Gen IR for opndArray and dst in below func
5510 return AppendVISA3dSamplerMsgGeneric(
5511 opcode,
5512 subOpcode,
5513 pixelNullMask,
5514 /*cpsEnable*/false,
5515 /*uniformSampler*/true,
5516 pred,
5517 emask,
5518 executionSize,
5519 ChannelMask::createFromAPI(srcChannel),
5520 aoffimmi,
5521 NULL,
5522 surface,
5523 dst,
5524 numMsgSpecificOpnds,
5525 opndArray);
5526 }
5527
AppendVISA3dGather4(VISASampler3DSubOpCode subOpcode,bool pixelNullMask,VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISASourceSingleChannel srcChannel,VISA_VectorOpnd * aoffimmi,VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_RawOpnd * dst,int numMsgSpecificOpnds,VISA_RawOpnd ** opndArray)5528 int VISAKernelImpl::AppendVISA3dGather4(
5529 VISASampler3DSubOpCode subOpcode,
5530 bool pixelNullMask,
5531 VISA_PredOpnd *pred,
5532 VISA_EMask_Ctrl emask,
5533 VISA_Exec_Size executionSize,
5534 VISASourceSingleChannel srcChannel,
5535 VISA_VectorOpnd *aoffimmi,
5536 VISA_StateOpndHandle *sampler,
5537 VISA_StateOpndHandle *surface,
5538 VISA_RawOpnd *dst,
5539 int numMsgSpecificOpnds,
5540 VISA_RawOpnd **opndArray)
5541 {
5542 ISA_Opcode opcode = ISA_3D_GATHER4; // generate Gen IR for opndArray and dst in below func
5543 return AppendVISA3dSamplerMsgGeneric(
5544 opcode,
5545 subOpcode,
5546 pixelNullMask,
5547 /*cpsEnable*/false,
5548 /*uniformSampler*/true,
5549 pred,
5550 emask,
5551 executionSize,
5552 ChannelMask::createFromSingleChannel(srcChannel),
5553 aoffimmi,
5554 sampler,
5555 surface,
5556 dst,
5557 numMsgSpecificOpnds,
5558 opndArray);
5559 }
5560
AppendVISA3dInfo(VISASampler3DSubOpCode subOpcode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISAChannelMask srcChannels,VISA_StateOpndHandle * surface,VISA_RawOpnd * lod,VISA_RawOpnd * dst)5561 int VISAKernelImpl::AppendVISA3dInfo(
5562 VISASampler3DSubOpCode subOpcode, VISA_EMask_Ctrl emask,
5563 VISA_Exec_Size executionSize, VISAChannelMask srcChannels,
5564 VISA_StateOpndHandle *surface,
5565 VISA_RawOpnd *lod, VISA_RawOpnd *dst)
5566 {
5567 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5568
5569 AppendVISAInstCommon();
5570
5571 int status = VISA_SUCCESS;
5572 ChannelMask channels = ChannelMask::createFromAPI(srcChannels);
5573 if (IS_GEN_BOTH_PATH)
5574 {
5575 CreateGenRawDstOperand(dst);
5576 G4_SrcRegRegion * lodg4 = NULL;
5577 if (subOpcode == VISA_3D_RESINFO)
5578 {
5579 CreateGenRawSrcOperand(lod);
5580 lodg4 = lod->g4opnd->asSrcRegRegion();
5581 status = m_builder->translateVISAResInfoInst(executionSize, emask, channels, surface->g4opnd, lodg4,
5582 dst->g4opnd->asDstRegRegion());
5583 }
5584 else
5585 {
5586 status = m_builder->translateVISASampleInfoInst(executionSize, emask, channels, surface->g4opnd,
5587 dst->g4opnd->asDstRegRegion());
5588 }
5589 }
5590 if (IS_VISA_BOTH_PATH)
5591 {
5592 if (subOpcode != VISA_3D_RESINFO && subOpcode != VISA_3D_SAMPLEINFO)
5593 {
5594 assert(0);
5595 return VISA_FAILURE;
5596 }
5597
5598 ISA_Opcode opcode = ISA_3D_INFO;
5599 VISA_INST_Desc *inst_desc = (VISA_INST_Desc*)m_mem.alloc(sizeof(VISA_INST_Desc));
5600 *inst_desc = CISA_INST_table[opcode];
5601 VISA_opnd *opnd[30];
5602 int num_pred_desc_operands = 0;
5603 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5604 int num_operands = 0;
5605
5606 //subOP
5607 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOpcode));
5608 //channel
5609 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, channels.getBinary(opcode)));
5610
5611 ADD_OPND(num_operands, opnd, surface);
5612 if (subOpcode == VISA_3D_RESINFO)
5613 {
5614 ADD_OPND(num_operands, opnd, lod);
5615 //opnd_num used in binary emiter, so need to have correct value.
5616 inst_desc = (VISA_INST_Desc*)m_mem.alloc(sizeof(VISA_INST_Desc));
5617 *inst_desc = CISA_INST_table[opcode];
5618 inst_desc->opnd_num++;
5619 }
5620 ADD_OPND(num_operands, opnd, dst);
5621
5622 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5623
5624 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5625
5626 unsigned char size = executionSize;
5627 size += emask << 4;
5628
5629 num_pred_desc_operands = 1;
5630 inst_desc->opnd_num = num_pred_desc_operands + num_operands;
5631
5632 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
5633 addInstructionToEnd(inst);
5634 }
5635
5636 return status;
5637 }
5638
AppendVISA3dRTWrite(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * renderTargetIndex,vISA_RT_CONTROLS cntrls,VISA_StateOpndHandle * surface,VISA_RawOpnd * r1Header,VISA_VectorOpnd * sampleIndex,uint8_t numMsgSpecificOpnds,VISA_RawOpnd ** opndArray)5639 int VISAKernelImpl::AppendVISA3dRTWrite(
5640 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
5641 VISA_VectorOpnd* renderTargetIndex, vISA_RT_CONTROLS cntrls,
5642 VISA_StateOpndHandle *surface, VISA_RawOpnd *r1Header,
5643 VISA_VectorOpnd *sampleIndex, uint8_t numMsgSpecificOpnds,
5644 VISA_RawOpnd **opndArray)
5645 {
5646 return AppendVISA3dRTWriteCPS(pred, emask, executionSize, renderTargetIndex, cntrls, surface, r1Header, sampleIndex, NULL, numMsgSpecificOpnds, opndArray);
5647 }
AppendVISA3dRTWriteCPS(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * renderTargetIndex,vISA_RT_CONTROLS cntrls,VISA_StateOpndHandle * surface,VISA_RawOpnd * r1Header,VISA_VectorOpnd * sampleIndex,VISA_VectorOpnd * cPSCounter,uint8_t numMsgSpecificOpnds,VISA_RawOpnd ** opndArray)5648 int VISAKernelImpl::AppendVISA3dRTWriteCPS(
5649 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
5650 VISA_VectorOpnd* renderTargetIndex, vISA_RT_CONTROLS cntrls,
5651 VISA_StateOpndHandle *surface, VISA_RawOpnd *r1Header,
5652 VISA_VectorOpnd *sampleIndex, VISA_VectorOpnd *cPSCounter,
5653 uint8_t numMsgSpecificOpnds, VISA_RawOpnd **opndArray)
5654 {
5655 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5656
5657 AppendVISAInstCommon();
5658
5659 int status = VISA_SUCCESS;
5660
5661 if (IS_GEN_BOTH_PATH)
5662 {
5663 G4_SrcRegRegion* g4params[32];
5664
5665 #if START_ASSERT_CHECK
5666 if (numMsgSpecificOpnds >= 32)
5667 {
5668 assert(0);
5669 return VISA_FAILURE;
5670 }
5671 #endif
5672 for (unsigned int i = 0; i< numMsgSpecificOpnds; ++i)
5673 {
5674 #if START_ASSERT_CHECK
5675 if (opndArray[i] == nullptr)
5676 {
5677 assert(0);
5678 return VISA_FAILURE;
5679 }
5680 #endif
5681 CreateGenRawSrcOperand(opndArray[i]);
5682 g4params[i] = opndArray[i]->g4opnd->asSrcRegRegion();
5683 }
5684
5685 #if START_ASSERT_CHECK
5686 if (cPSCounter && !cPSCounter->g4opnd)
5687 {
5688 assert(0);
5689 return VISA_FAILURE;
5690 }
5691 #endif
5692 G4_SrcRegRegion *cPSCounterOpnd = (cPSCounter) ? cPSCounter->g4opnd->asSrcRegRegion(): nullptr;
5693 G4_SrcRegRegion *sampleIndexOpnd = (cntrls.isSampleIndex) ? sampleIndex->g4opnd->asSrcRegRegion() : nullptr;
5694 G4_Operand *renderTargetIndexOpnd = (cntrls.RTIndexPresent) ? renderTargetIndex->g4opnd : nullptr;
5695 G4_SrcRegRegion *r1HeaderOpnd = nullptr;
5696
5697 if (r1Header)
5698 {
5699 CreateGenRawSrcOperand(r1Header);
5700 r1HeaderOpnd = r1Header->g4opnd->asSrcRegRegion();
5701 }
5702
5703 G4_Predicate * g4Pred = pred ? pred->g4opnd->asPredicate() : nullptr;
5704
5705 {
5706 status = m_builder->translateVISARTWrite3DInst(g4Pred, executionSize, emask,
5707 surface->g4opnd, r1HeaderOpnd, renderTargetIndexOpnd, cntrls, sampleIndexOpnd, cPSCounterOpnd, numMsgSpecificOpnds, g4params);
5708 }
5709 }
5710 if (IS_VISA_BOTH_PATH)
5711 {
5712 ISA_Opcode opcode = ISA_3D_RT_WRITE;
5713 VISA_INST_Desc *inst_desc = (VISA_INST_Desc*)m_mem.alloc(sizeof(VISA_INST_Desc));
5714 *inst_desc = CISA_INST_table[opcode];
5715 VISA_opnd *opnd[30];
5716 int num_pred_desc_operands = 2;
5717 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5718 int num_operands = 0;
5719 bool isCPSCounter = (cPSCounter)? true: false;
5720
5721 int mode = ((int)cntrls.isNullRT << 12) |
5722 ((int)cntrls.isSampleIndex << 11) |
5723 ((int)cntrls.isCoarseMode << 10) |
5724 ((int)cntrls.isPerSample << 9) |
5725 ((int)(isCPSCounter) << 8) |
5726 ((int)cntrls.isLastWrite << 7) |
5727 ((int)cntrls.isStencil << 6) |
5728 ((int)cntrls.zPresent << 5) |
5729 ((int)cntrls.oMPresent << 4) |
5730 ((int)cntrls.s0aPresent << 3) |
5731 ((int)cntrls.RTIndexPresent << 2);
5732
5733 //mode
5734 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, mode));
5735 //surface
5736 ADD_OPND(num_operands, opnd, surface);
5737
5738 //r1Header
5739 ADD_OPND(num_operands, opnd, r1Header);
5740
5741 if (cntrls.isSampleIndex)
5742 ADD_OPND(num_operands, opnd, sampleIndex);
5743
5744 if (cPSCounter)
5745 ADD_OPND(num_operands, opnd, cPSCounter);
5746
5747 if (cntrls.RTIndexPresent)
5748 ADD_OPND(num_operands, opnd, renderTargetIndex);
5749
5750 for (int i = 0; i < numMsgSpecificOpnds; i++, num_operands++)
5751 {
5752 if (opndArray[i] == nullptr)
5753 {
5754 assert(0);
5755 return VISA_FAILURE;
5756 }
5757 opnd[num_operands] = opndArray[i];
5758 }
5759
5760 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5761
5762 unsigned char size = executionSize;
5763 size += emask << 4;
5764
5765 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
5766
5767 inst_desc->opnd_num = num_pred_desc_operands + num_operands;
5768
5769 inst->createCisaInstruction(opcode, size, 0 , predOpnd, opnd, num_operands, inst_desc);
5770 addInstructionToEnd(inst);
5771 }
5772 return status;
5773 }
5774
AppendVISA3dURBWrite(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,unsigned char numberOutputParams,VISA_RawOpnd * channelMask,unsigned short globalOffset,VISA_RawOpnd * URBHandle,VISA_RawOpnd * perSlotOffset,VISA_RawOpnd * vertexData)5775 int VISAKernelImpl::AppendVISA3dURBWrite(
5776 VISA_PredOpnd *pred, VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
5777 unsigned char numberOutputParams, VISA_RawOpnd *channelMask,
5778 unsigned short globalOffset, VISA_RawOpnd *URBHandle,
5779 VISA_RawOpnd *perSlotOffset, VISA_RawOpnd *vertexData)
5780 {
5781 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5782
5783 AppendVISAInstCommon();
5784
5785 int status = VISA_SUCCESS;
5786
5787 if (IS_GEN_BOTH_PATH)
5788 {
5789 CreateGenRawSrcOperand(channelMask);
5790 CreateGenRawSrcOperand(URBHandle);
5791 CreateGenRawSrcOperand(perSlotOffset);
5792 CreateGenRawSrcOperand(vertexData);
5793 G4_Predicate * g4Pred = (pred != NULL)? pred->g4opnd->asPredicate() : NULL;
5794 status = m_builder->translateVISAURBWrite3DInst(g4Pred, executionSize, emask,
5795 numberOutputParams, globalOffset, channelMask->g4opnd->asSrcRegRegion(), URBHandle->g4opnd->asSrcRegRegion(),
5796 perSlotOffset->g4opnd->asSrcRegRegion(), vertexData->g4opnd->asSrcRegRegion());
5797 }
5798 if (IS_VISA_BOTH_PATH)
5799 {
5800 ISA_Opcode opcode = ISA_3D_URB_WRITE;
5801 VISA_INST_Desc *inst_desc = (VISA_INST_Desc*)m_mem.alloc(sizeof(VISA_INST_Desc));
5802 *inst_desc = CISA_INST_table[opcode];
5803 VISA_opnd *opnd[30];
5804 int num_pred_desc_operands = 2;
5805 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5806 int num_operands = 0;
5807
5808 //number output operands
5809 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, numberOutputParams));
5810 //channel mask
5811 ADD_OPND(num_operands, opnd, channelMask);
5812 //globalOffset
5813 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, globalOffset));
5814 //urb handle
5815 ADD_OPND(num_operands, opnd, URBHandle);
5816 //per slot offset
5817 ADD_OPND(num_operands, opnd, perSlotOffset);
5818 //vertex data
5819 ADD_OPND(num_operands, opnd, vertexData);
5820
5821 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5822
5823 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5824
5825 unsigned char size = executionSize;
5826 size += emask << 4;
5827
5828 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
5829
5830 inst_desc->opnd_num = num_pred_desc_operands + num_operands;
5831
5832 inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
5833 addInstructionToEnd(inst);
5834 }
5835
5836 return status;
5837 }
5838
AppendVISA3dTypedAtomic(VISAAtomicOps subOp,bool is16Bit,VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_StateOpndHandle * surface,VISA_RawOpnd * u,VISA_RawOpnd * v,VISA_RawOpnd * r,VISA_RawOpnd * lod,VISA_RawOpnd * src0,VISA_RawOpnd * src1,VISA_RawOpnd * dst)5839 int VISAKernelImpl::AppendVISA3dTypedAtomic(
5840 VISAAtomicOps subOp, bool is16Bit, VISA_PredOpnd *pred,
5841 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
5842 VISA_StateOpndHandle *surface, VISA_RawOpnd *u, VISA_RawOpnd *v,
5843 VISA_RawOpnd *r, VISA_RawOpnd *lod, VISA_RawOpnd *src0, VISA_RawOpnd *src1,
5844 VISA_RawOpnd *dst)
5845 {
5846 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5847
5848 AppendVISAInstCommon();
5849
5850 int status = VISA_SUCCESS;
5851
5852 if (IS_GEN_BOTH_PATH)
5853 {
5854 CreateGenRawSrcOperand(u);
5855 CreateGenRawSrcOperand(v);
5856 CreateGenRawSrcOperand(r);
5857 CreateGenRawSrcOperand(lod);
5858 CreateGenRawSrcOperand(src0);
5859 CreateGenRawSrcOperand(src1);
5860 CreateGenRawDstOperand(dst);
5861 G4_Predicate * g4Pred = (pred != nullptr) ? pred->g4opnd->asPredicate() : nullptr;
5862 status = m_builder->translateVISATypedAtomicInst(
5863 subOp, is16Bit, g4Pred, emask, executionSize, surface->g4opnd,
5864 u->g4opnd->asSrcRegRegion(), v->g4opnd->asSrcRegRegion(),
5865 r->g4opnd->asSrcRegRegion(), lod->g4opnd->asSrcRegRegion(),
5866 src0->g4opnd->asSrcRegRegion(), src1->g4opnd->asSrcRegRegion(),
5867 dst->g4opnd->asDstRegRegion());
5868 }
5869
5870 if (IS_VISA_BOTH_PATH)
5871 {
5872 ISA_Opcode opcode = ISA_3D_TYPED_ATOMIC;
5873 VISA_INST_Desc *inst_desc = &CISA_INST_table[opcode];
5874 VISA_opnd *opnd[30];
5875 int num_pred_desc_operands = 0;
5876 int num_operands = 0;
5877
5878 //number output operands
5879 uint8_t OpAnd16BitTag = uint8_t(subOp) | uint8_t((is16Bit ? 1 : 0) << 5);
5880 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, OpAnd16BitTag));
5881 num_pred_desc_operands = 2;
5882 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
5883 //surface
5884 ADD_OPND(num_operands, opnd, surface);
5885 //u
5886 ADD_OPND(num_operands, opnd, u);
5887 //v
5888 ADD_OPND(num_operands, opnd, v);
5889 //r
5890 ADD_OPND(num_operands, opnd, r);
5891 //lod
5892 ADD_OPND(num_operands, opnd, lod);
5893 //src0
5894 ADD_OPND(num_operands, opnd, src0);
5895 //src1
5896 ADD_OPND(num_operands, opnd, src1);
5897 //dst
5898 ADD_OPND(num_operands, opnd, dst);
5899
5900 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5901
5902 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5903
5904 unsigned char size = executionSize;
5905 size += emask << 4;
5906
5907 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
5908
5909 inst_desc->opnd_num = num_pred_desc_operands + num_operands;
5910
5911 inst->createCisaInstruction(opcode, size, 0, predOpnd, opnd, num_operands, inst_desc);
5912 addInstructionToEnd(inst);
5913 }
5914
5915 return status;
5916 }
5917
AppendVISAVABooleanCentroid(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * vSize,VISA_VectorOpnd * hSize,VISA_RawOpnd * dst)5918 int VISAKernelImpl::AppendVISAVABooleanCentroid(
5919 VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
5920 VISA_VectorOpnd *vOffset, VISA_VectorOpnd *vSize, VISA_VectorOpnd *hSize, VISA_RawOpnd *dst)
5921 {
5922 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5923
5924 AppendVISAInstCommon();
5925
5926 int status = VISA_SUCCESS;
5927
5928 ISA_VA_Sub_Opcode subOp = BoolCentroid_FOPCODE;
5929 if (IS_GEN_BOTH_PATH)
5930 {
5931 CreateGenRawDstOperand(dst);
5932 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
5933 status = m_builder->translateVISASamplerVAGenericInst(surface->g4opnd, NULL, uOffset->g4opnd,
5934 vOffset->g4opnd, vSize->g4opnd, hSize->g4opnd, NULL, 0, 0, subOp,
5935 dstOpnd, dstOpnd->getType(), 16 * dstOpnd->getBase()->asRegVar()->getDeclare()->getElemSize());
5936 }
5937 if (IS_VISA_BOTH_PATH)
5938 {
5939 ISA_Opcode opcode = ISA_VA;
5940 VISA_INST_Desc *inst_desc = &CISA_INST_table[opcode];
5941 VISA_opnd *opnd[30];
5942 int num_pred_desc_operands = 0;
5943 int num_operands = 0;
5944
5945 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOp));
5946 ADD_OPND(num_operands, opnd, surface);
5947 ADD_OPND(num_operands, opnd, uOffset);
5948 ADD_OPND(num_operands, opnd, vOffset);
5949 ADD_OPND(num_operands, opnd, vSize);
5950 ADD_OPND(num_operands, opnd, hSize);
5951 ADD_OPND(num_operands, opnd, dst);
5952
5953 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
5954
5955 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
5956
5957 unsigned char size = EXEC_SIZE_1;
5958
5959 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
5960 addInstructionToEnd(inst);
5961 }
5962
5963 return status;
5964 }
5965
AppendVISAVACentroid(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * vSize,VISA_RawOpnd * dst)5966 int VISAKernelImpl::AppendVISAVACentroid(
5967 VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
5968 VISA_VectorOpnd *vOffset, VISA_VectorOpnd *vSize, VISA_RawOpnd *dst)
5969 {
5970 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
5971
5972 AppendVISAInstCommon();
5973
5974 int status = VISA_SUCCESS;
5975
5976 ISA_VA_Sub_Opcode subOp = Centroid_FOPCODE;
5977 if (IS_GEN_BOTH_PATH)
5978 {
5979 CreateGenRawDstOperand(dst);
5980 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
5981 status = m_builder->translateVISASamplerVAGenericInst(surface->g4opnd, NULL, uOffset->g4opnd,
5982 vOffset->g4opnd, vSize->g4opnd, NULL, NULL, 0, 0, subOp,
5983 dstOpnd, dstOpnd->getType(), 32 * dstOpnd->getBase()->asRegVar()->getDeclare()->getElemSize());
5984 }
5985 if (IS_VISA_BOTH_PATH)
5986 {
5987 ISA_Opcode opcode = ISA_VA;
5988 VISA_INST_Desc *inst_desc = &CISA_INST_table[opcode];
5989 VISA_opnd *opnd[30];
5990 int num_pred_desc_operands = 0;
5991 int num_operands = 0;
5992
5993 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOp));
5994 ADD_OPND(num_operands, opnd, surface);
5995 ADD_OPND(num_operands, opnd, uOffset);
5996 ADD_OPND(num_operands, opnd, vOffset);
5997 ADD_OPND(num_operands, opnd, vSize);
5998 ADD_OPND(num_operands, opnd, dst);
5999
6000 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6001
6002 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6003
6004 unsigned char size = EXEC_SIZE_1;
6005
6006 inst->createCisaInstruction(opcode, size, 0 , PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
6007 addInstructionToEnd(inst);
6008 }
6009
6010 return status;
6011 }
6012
AppendVISAVAConvolve(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,CONVExecMode execMode,bool isBigKernel,VISA_RawOpnd * dst)6013 int VISAKernelImpl::AppendVISAVAConvolve(
6014 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6015 VISA_VectorOpnd *vOffset, CONVExecMode execMode, bool isBigKernel, VISA_RawOpnd *dst)
6016 {
6017 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6018
6019 AppendVISAInstCommon();
6020
6021 int status = VISA_SUCCESS;
6022
6023 ISA_VA_Sub_Opcode subOp = Convolve_FOPCODE;
6024 if (IS_GEN_BOTH_PATH)
6025 {
6026 CreateGenRawDstOperand(dst);
6027 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6028 unsigned int dstSize = conv_exec_mode_size[execMode] * dstOpnd->getBase()->asRegVar()->getDeclare()->getElemSize();
6029 status = m_builder->translateVISASamplerVAGenericInst(surface->g4opnd, sampler->g4opnd, uOffset->g4opnd,
6030 vOffset->g4opnd, NULL, NULL, NULL, 0, execMode, subOp,
6031 dstOpnd, dstOpnd->getType(), dstSize, isBigKernel);
6032 }
6033 if (IS_VISA_BOTH_PATH)
6034 {
6035 ISA_Opcode opcode = ISA_VA;
6036 VISA_INST_Desc *inst_desc = &CISA_INST_table[opcode];
6037 VISA_opnd *opnd[30];
6038 int num_pred_desc_operands = 0;
6039 int num_operands = 0;
6040 uint8_t properties = execMode;
6041 properties = properties | (isBigKernel << 4);
6042 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOp));
6043 ADD_OPND(num_operands, opnd, sampler);
6044 ADD_OPND(num_operands, opnd, surface);
6045 ADD_OPND(num_operands, opnd, uOffset);
6046 ADD_OPND(num_operands, opnd, vOffset);
6047 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
6048 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, properties, true, subOp));
6049 ADD_OPND(num_operands, opnd, dst);
6050
6051 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6052
6053 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6054
6055 unsigned char size = EXEC_SIZE_1;
6056
6057 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
6058 addInstructionToEnd(inst);
6059 }
6060
6061 return status;
6062 }
6063
AppendVISAVAErodeDilate(EDMode mode,VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,EDExecMode execMode,VISA_RawOpnd * dst)6064 int VISAKernelImpl::AppendVISAVAErodeDilate(
6065 EDMode mode, VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6066 VISA_VectorOpnd *vOffset, EDExecMode execMode, VISA_RawOpnd *dst)
6067 {
6068 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6069
6070 AppendVISAInstCommon();
6071
6072 int status = VISA_SUCCESS;
6073
6074 ISA_VA_Sub_Opcode subOp = ERODE_FOPCODE;
6075
6076 if (mode == VA_DILATE)
6077 {
6078 subOp = Dilate_FOPCODE;
6079 }
6080
6081 if (IS_GEN_BOTH_PATH)
6082 {
6083 CreateGenRawDstOperand(dst);
6084 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6085 unsigned int dstSize = ed_exec_mode_byte_size[execMode];
6086 status = m_builder->translateVISASamplerVAGenericInst(surface->g4opnd, sampler->g4opnd, uOffset->g4opnd,
6087 vOffset->g4opnd, NULL, NULL, NULL, 0, execMode, subOp,
6088 dstOpnd, dstOpnd->getType(), dstSize, false);
6089 }
6090 if (IS_VISA_BOTH_PATH)
6091 {
6092 ISA_Opcode opcode = ISA_VA;
6093 VISA_INST_Desc *inst_desc = &CISA_INST_table[opcode];
6094 VISA_opnd *opnd[30];
6095 int num_pred_desc_operands = 0;
6096 int num_operands = 0;
6097
6098 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOp));
6099 ADD_OPND(num_operands, opnd, sampler);
6100 ADD_OPND(num_operands, opnd, surface);
6101 ADD_OPND(num_operands, opnd, uOffset);
6102 ADD_OPND(num_operands, opnd, vOffset);
6103 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
6104 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, execMode, true, subOp));
6105 ADD_OPND(num_operands, opnd, dst);
6106
6107 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6108
6109 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6110
6111 unsigned char size = EXEC_SIZE_1;
6112
6113 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
6114 addInstructionToEnd(inst);
6115 }
6116
6117 return status;
6118 }
6119
AppendVISAVAMinMax(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * mmMode,VISA_RawOpnd * dst)6120 int VISAKernelImpl::AppendVISAVAMinMax(
6121 VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6122 VISA_VectorOpnd *vOffset, VISA_VectorOpnd *mmMode, VISA_RawOpnd *dst)
6123 {
6124 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6125
6126 AppendVISAInstCommon();
6127
6128 int status = VISA_SUCCESS;
6129
6130 ISA_VA_Sub_Opcode subOp = MINMAX_FOPCODE;
6131
6132 if (IS_GEN_BOTH_PATH)
6133 {
6134 CreateGenRawDstOperand(dst);
6135 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6136 status = m_builder->translateVISASamplerVAGenericInst(surface->g4opnd, NULL, uOffset->g4opnd,
6137 vOffset->g4opnd, NULL, NULL, mmMode->g4opnd, 0, 0, subOp,
6138 dstOpnd, dstOpnd->getType(), 32, false);
6139 }
6140 if (IS_VISA_BOTH_PATH)
6141 {
6142 ISA_Opcode opcode = ISA_VA;
6143 VISA_INST_Desc *inst_desc = &CISA_INST_table[opcode];
6144 VISA_opnd *opnd[30];
6145 int num_pred_desc_operands = 0;
6146 int num_operands = 0;
6147
6148 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
6149 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOp));
6150 ADD_OPND(num_operands, opnd, surface);
6151 ADD_OPND(num_operands, opnd, uOffset);
6152 ADD_OPND(num_operands, opnd, vOffset);
6153 ADD_OPND(num_operands, opnd, mmMode);
6154 ADD_OPND(num_operands, opnd, dst);
6155
6156 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6157
6158 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6159
6160 unsigned char size = EXEC_SIZE_1;
6161
6162 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
6163 addInstructionToEnd(inst);
6164 }
6165
6166 return status;
6167 }
6168
AppendVISAVAMinMaxFilter(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,OutputFormatControl cntrl,MMFExecMode execMode,VISA_VectorOpnd * mmfMode,VISA_RawOpnd * dst)6169 int VISAKernelImpl::AppendVISAVAMinMaxFilter(
6170 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface,
6171 VISA_VectorOpnd * uOffset, VISA_VectorOpnd *vOffset,
6172 OutputFormatControl cntrl, MMFExecMode execMode, VISA_VectorOpnd *mmfMode, VISA_RawOpnd *dst)
6173 {
6174 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6175
6176 AppendVISAInstCommon();
6177
6178 int status = VISA_SUCCESS;
6179 ISA_VA_Sub_Opcode subOp = MINMAXFILTER_FOPCODE;
6180
6181 if (cntrl != AVS_16_FULL && cntrl != AVS_8_FULL)
6182 {
6183 assert(0);
6184 return VISA_FAILURE;
6185 }
6186
6187 if (IS_GEN_BOTH_PATH)
6188 {
6189 CreateGenRawDstOperand(dst);
6190 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6191 unsigned dstSize = (VA_MMF_1x1 == execMode) ? 4 : (mmf_exec_mode_size[execMode] * format_control_byteSize2[cntrl]) ;
6192 status = m_builder->translateVISASamplerVAGenericInst(surface->g4opnd, sampler->g4opnd, uOffset->g4opnd,
6193 vOffset->g4opnd, NULL, NULL, mmfMode->g4opnd, cntrl, execMode, subOp,
6194 dstOpnd, dstOpnd->getType(), dstSize);
6195 }
6196 if (IS_VISA_BOTH_PATH)
6197 {
6198 ISA_Opcode opcode = ISA_VA;
6199 VISA_INST_Desc *inst_desc = &CISA_INST_table[opcode];
6200 VISA_opnd *opnd[30];
6201 int num_pred_desc_operands = 0;
6202 int num_operands = 0;
6203
6204 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, subOp));
6205 ADD_OPND(num_operands, opnd, sampler);
6206 ADD_OPND(num_operands, opnd, surface);
6207 ADD_OPND(num_operands, opnd, uOffset);
6208 ADD_OPND(num_operands, opnd, vOffset);
6209 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
6210 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, cntrl, true, subOp));
6211 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, inst_desc, execMode, true, subOp));
6212 ADD_OPND(num_operands, opnd, mmfMode);
6213 ADD_OPND(num_operands, opnd, dst);
6214
6215 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6216
6217 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6218
6219 unsigned char size = EXEC_SIZE_1;
6220
6221 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
6222 addInstructionToEnd(inst);
6223 }
6224
6225 return status;
6226 }
6227
AppendVISAVACorrelationSearch(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * vOrigin,VISA_VectorOpnd * hOrigin,VISA_VectorOpnd * xDirectionSize,VISA_VectorOpnd * yDirectionSize,VISA_VectorOpnd * xDirectionSearchSize,VISA_VectorOpnd * yDirectionSearchSize,VISA_RawOpnd * dst)6228 int VISAKernelImpl::AppendVISAVACorrelationSearch(
6229 VISA_StateOpndHandle *surface,
6230 VISA_VectorOpnd *uOffset, VISA_VectorOpnd *vOffset,
6231 VISA_VectorOpnd *vOrigin, VISA_VectorOpnd *hOrigin,
6232 VISA_VectorOpnd *xDirectionSize, VISA_VectorOpnd *yDirectionSize,
6233 VISA_VectorOpnd *xDirectionSearchSize, VISA_VectorOpnd *yDirectionSearchSize,
6234 VISA_RawOpnd *dst)
6235 {
6236 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6237
6238 AppendVISAInstCommon();
6239
6240 int status = VISA_SUCCESS;
6241 ISA_VA_Sub_Opcode subOp = VA_OP_CODE_CORRELATION_SEARCH;
6242
6243 if (IS_GEN_BOTH_PATH)
6244 {
6245 CreateGenRawDstOperand(dst);
6246 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6247
6248 G4_Declare* dstDcl = dstOpnd->getBase()->asRegVar()->getDeclare();
6249 G4_Type dstType = dstDcl->getElemType();
6250 unsigned int dstSize = dstDcl->getNumElems() * dstDcl->getNumRows() * TypeSize(dstType);
6251
6252 uint8_t execMode = 0;
6253 uint8_t functionality = 0x3; /*reserved*/
6254 status = m_builder->translateVISAVaSklPlusGeneralInst(
6255 subOp, surface->g4opnd, NULL /*sampler*/, execMode, functionality,
6256 //rest
6257 uOffset->g4opnd , vOffset->g4opnd ,
6258
6259 //1pixel convolve
6260 NULL /*offsetOpnd*/,
6261
6262 //FloodFill
6263 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6264 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6265
6266 //LBP Correlation
6267 NULL /*disparityOpnd*/ ,
6268
6269 //correlation search
6270 vOrigin->g4opnd , hOrigin->g4opnd ,
6271 xDirectionSize->g4opnd , yDirectionSize->g4opnd ,
6272 xDirectionSearchSize->g4opnd , yDirectionSearchSize->g4opnd ,
6273
6274 //general
6275 dstOpnd, dstType, dstSize,
6276
6277 //hdc
6278 0 /*pixelSize*/ , NULL /*dstSurfaceOpnd*/,
6279 NULL /*dstXOffOnd*/ , NULL /*dstYOffOpnd*/,
6280 false);
6281 }
6282 if (IS_VISA_BOTH_PATH)
6283 {
6284 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6285 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6286 VISA_opnd *opnd[30];
6287 int num_pred_desc_operands = 0;
6288 int num_operands = 0;
6289
6290 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6291 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6292 ADD_OPND(num_operands, opnd, surface);
6293 ADD_OPND(num_operands, opnd, uOffset);
6294 ADD_OPND(num_operands, opnd, vOffset);
6295 ADD_OPND(num_operands, opnd, vOrigin);
6296 ADD_OPND(num_operands, opnd, hOrigin);
6297 ADD_OPND(num_operands, opnd, xDirectionSize);
6298 ADD_OPND(num_operands, opnd, yDirectionSize);
6299 ADD_OPND(num_operands, opnd, xDirectionSearchSize);
6300 ADD_OPND(num_operands, opnd, yDirectionSearchSize);
6301 ADD_OPND(num_operands, opnd, dst);
6302
6303 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6304
6305 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6306
6307 unsigned char size = EXEC_SIZE_1;
6308
6309 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6310 addInstructionToEnd(inst);
6311 }
6312
6313 return status;
6314 }
6315
AppendVISAVAFloodFill(bool is8Connect,VISA_RawOpnd * pixelMaskHDirection,VISA_VectorOpnd * pixelMaskVDirectionLeft,VISA_VectorOpnd * pixelMaskVDirectionRight,VISA_VectorOpnd * loopCount,VISA_RawOpnd * dst)6316 int VISAKernelImpl::AppendVISAVAFloodFill(
6317 bool is8Connect, VISA_RawOpnd *pixelMaskHDirection,
6318 VISA_VectorOpnd *pixelMaskVDirectionLeft, VISA_VectorOpnd *pixelMaskVDirectionRight,
6319 VISA_VectorOpnd *loopCount, VISA_RawOpnd *dst)
6320 {
6321 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6322
6323 AppendVISAInstCommon();
6324
6325 int status = VISA_SUCCESS;
6326 ISA_VA_Sub_Opcode subOp = VA_OP_CODE_FLOOD_FILL;
6327
6328 if (IS_GEN_BOTH_PATH)
6329 {
6330 CreateGenRawSrcOperand(pixelMaskHDirection);
6331 CreateGenRawDstOperand(dst);
6332 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6333
6334 G4_Declare* dstDcl = dstOpnd->getBase()->asRegVar()->getDeclare();
6335 G4_Type dstType = dstDcl->getElemType();
6336 /*should be UW*/
6337 unsigned int dstSize = 8 * TypeSize(dstType);
6338
6339 uint8_t execMode = is8Connect;
6340 uint8_t functionality = 0x3; /*reserved*/
6341 status = m_builder->translateVISAVaSklPlusGeneralInst(
6342 subOp, NULL /*surface*/, NULL /*sampler*/, execMode, functionality,
6343 //rest
6344 NULL /*uOffset*/ , NULL /*vOffset*/ ,
6345
6346 //1pixel convolve
6347 NULL /*offsetOpnd*/,
6348
6349 //FloodFill
6350 loopCount->g4opnd /*loopCountOpnd*/ , pixelMaskHDirection->g4opnd /*pixelhMasOpnd*/,
6351 pixelMaskVDirectionLeft->g4opnd /*pixelVMaskLeftOpnd*/ , pixelMaskVDirectionRight->g4opnd /*pixelVMaskRightOpnd*/,
6352
6353 //LBP Correlation
6354 NULL /*disparityOpnd*/ ,
6355
6356 //correlation search
6357 NULL , NULL ,
6358 NULL , NULL ,
6359 NULL , NULL ,
6360
6361 //general
6362 dstOpnd, dstType, dstSize,
6363
6364 //hdc
6365 0 /*pixelSize*/ , NULL /*dstSurfaceOpnd*/,
6366 NULL /*dstXOffOnd*/ , NULL /*dstYOffOpnd*/,
6367 false);
6368 }
6369 if (IS_VISA_BOTH_PATH)
6370 {
6371 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6372 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6373 VISA_opnd *opnd[30];
6374 int num_pred_desc_operands = 0;
6375 int num_operands = 0;
6376
6377 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6378 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6379 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, is8Connect, true, subOp));
6380 ADD_OPND(num_operands, opnd, pixelMaskHDirection);
6381 ADD_OPND(num_operands, opnd, pixelMaskVDirectionLeft);
6382 ADD_OPND(num_operands, opnd, pixelMaskVDirectionRight);
6383 ADD_OPND(num_operands, opnd, loopCount);
6384 ADD_OPND(num_operands, opnd, dst);
6385
6386 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6387
6388 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6389
6390 unsigned char size = EXEC_SIZE_1;
6391
6392 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6393 addInstructionToEnd(inst);
6394 }
6395
6396 return status;
6397 }
6398
AppendVISAVALBPCorrelation(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * disparity,VISA_RawOpnd * dst)6399 int VISAKernelImpl::AppendVISAVALBPCorrelation(
6400 VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6401 VISA_VectorOpnd *vOffset, VISA_VectorOpnd *disparity,
6402 VISA_RawOpnd *dst)
6403 {
6404 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6405
6406 AppendVISAInstCommon();
6407
6408 int status = VISA_SUCCESS;
6409 ISA_VA_Sub_Opcode subOp = VA_OP_CODE_LBP_CORRELATION;
6410
6411 if (IS_GEN_BOTH_PATH)
6412 {
6413 uint8_t execMode = 0;
6414 uint8_t functionality = 0x3; /*reserved*/
6415
6416 CreateGenRawDstOperand(dst);
6417 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6418
6419 G4_Declare* dstDcl = dstOpnd->getBase()->asRegVar()->getDeclare();
6420 G4_Type dstType = dstDcl->getElemType();
6421 /*should be UB*/
6422 unsigned int dstSize = lbp_correlation_mode_size[execMode]* TypeSize(dstType);
6423
6424
6425 status = m_builder->translateVISAVaSklPlusGeneralInst(
6426 subOp, surface->g4opnd /*surface*/, NULL /*sampler*/, execMode, functionality,
6427 //rest
6428 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6429
6430 //1pixel convolve
6431 NULL /*offsetOpnd*/,
6432
6433 //FloodFill
6434 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6435 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6436
6437 //LBP Correlation
6438 disparity->g4opnd /*disparityOpnd*/ ,
6439
6440 //correlation search
6441 NULL , NULL ,
6442 NULL , NULL ,
6443 NULL , NULL ,
6444
6445 //general
6446 dstOpnd, dstType, dstSize,
6447
6448 //hdc
6449 0 /*pixelSize*/ , NULL /*dstSurfaceOpnd*/,
6450 NULL /*dstXOffOnd*/ , NULL /*dstYOffOpnd*/,
6451 false);
6452 }
6453 if (IS_VISA_BOTH_PATH)
6454 {
6455 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6456 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6457 VISA_opnd *opnd[30];
6458 int num_pred_desc_operands = 0;
6459 int num_operands = 0;
6460
6461 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6462 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6463 ADD_OPND(num_operands, opnd, surface);
6464 ADD_OPND(num_operands, opnd, uOffset);
6465 ADD_OPND(num_operands, opnd, vOffset);
6466 ADD_OPND(num_operands, opnd, disparity);
6467 ADD_OPND(num_operands, opnd, dst);
6468
6469 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6470
6471 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6472
6473 unsigned char size = EXEC_SIZE_1;
6474
6475 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6476 addInstructionToEnd(inst);
6477 }
6478
6479 return status;
6480 }
6481
AppendVISAVALBPCreation(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,LBPCreationMode mode,VISA_RawOpnd * dst)6482 int VISAKernelImpl::AppendVISAVALBPCreation(
6483 VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6484 VISA_VectorOpnd *vOffset, LBPCreationMode mode,
6485 VISA_RawOpnd *dst)
6486 {
6487 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6488
6489 AppendVISAInstCommon();
6490
6491 int status = VISA_SUCCESS;
6492 ISA_VA_Sub_Opcode subOp = VA_OP_CODE_LBP_CREATION;
6493
6494 if (IS_GEN_BOTH_PATH)
6495 {
6496 uint8_t execMode = 0;
6497 uint8_t functionality = mode; /*reserved*/
6498
6499 CreateGenRawDstOperand(dst);
6500 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6501
6502 G4_Declare* dstDcl = dstOpnd->getBase()->asRegVar()->getDeclare();
6503 G4_Type dstType = dstDcl->getElemType();
6504 /*should be UB*/
6505 unsigned int dstSize = lbp_creation_exec_mode_size[functionality]* TypeSize(dstType);
6506
6507
6508 status = m_builder->translateVISAVaSklPlusGeneralInst(
6509 subOp, surface->g4opnd /*surface*/, NULL /*sampler*/, execMode, functionality,
6510 //rest
6511 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6512
6513 //1pixel convolve
6514 NULL /*offsetOpnd*/,
6515
6516 //FloodFill
6517 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6518 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6519
6520 //LBP Correlation
6521 NULL /*disparityOpnd*/ ,
6522
6523 //correlation search
6524 NULL , NULL ,
6525 NULL , NULL ,
6526 NULL , NULL ,
6527
6528 //general
6529 dstOpnd, dstType, dstSize,
6530
6531 //hdc
6532 0 /*pixelSize*/ , NULL /*dstSurfaceOpnd*/,
6533 NULL /*dstXOffOnd*/ , NULL /*dstYOffOpnd*/,
6534 false);
6535 }
6536 if (IS_VISA_BOTH_PATH)
6537 {
6538 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6539 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6540 VISA_opnd *opnd[30];
6541 int num_pred_desc_operands = 0;
6542 int num_operands = 0;
6543
6544 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6545 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6546 ADD_OPND(num_operands, opnd, surface);
6547 ADD_OPND(num_operands, opnd, uOffset);
6548 ADD_OPND(num_operands, opnd, vOffset);
6549 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, mode, true, subOp));
6550 ADD_OPND(num_operands, opnd, dst);
6551
6552 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6553
6554 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6555
6556 unsigned char size = EXEC_SIZE_1;
6557
6558 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6559 addInstructionToEnd(inst);
6560 }
6561
6562 return status;
6563 }
6564
AppendVISAVAConvolve1D(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,CONVExecMode mode,Convolve1DDirection direction,VISA_RawOpnd * dst)6565 int VISAKernelImpl::AppendVISAVAConvolve1D(
6566 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6567 VISA_VectorOpnd *vOffset, CONVExecMode mode, Convolve1DDirection direction, VISA_RawOpnd *dst)
6568 {
6569 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6570
6571 AppendVISAInstCommon();
6572
6573 int status = VISA_SUCCESS;
6574 ISA_VA_Sub_Opcode subOp = VA_OP_CODE_1D_CONVOLVE_VERTICAL;
6575
6576 if (direction == VA_H_DIRECTION)
6577 subOp = VA_OP_CODE_1D_CONVOLVE_HORIZONTAL;
6578
6579 if (IS_GEN_BOTH_PATH)
6580 {
6581 uint8_t execMode = mode;
6582 uint8_t functionality = 0x3; /*reserved*/
6583
6584 CreateGenRawDstOperand(dst);
6585 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6586
6587 G4_Declare* dstDcl = dstOpnd->getBase()->asRegVar()->getDeclare();
6588 G4_Type dstType = dstDcl->getElemType();
6589 /*should be W*/
6590 unsigned int dstSize = conv_exec_mode_size[execMode]* TypeSize(dstType);
6591
6592
6593 status = m_builder->translateVISAVaSklPlusGeneralInst(
6594 subOp, surface->g4opnd /*surface*/, sampler->g4opnd /*sampler*/, execMode, functionality,
6595 //rest
6596 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6597
6598 //1pixel convolve
6599 NULL /*offsetOpnd*/,
6600
6601 //FloodFill
6602 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6603 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6604
6605 //LBP Correlation
6606 NULL /*disparityOpnd*/ ,
6607
6608 //correlation search
6609 NULL , NULL ,
6610 NULL , NULL ,
6611 NULL , NULL ,
6612
6613 //general
6614 dstOpnd, dstType, dstSize,
6615
6616 //hdc
6617 0 /*pixelSize*/ , NULL /*dstSurfaceOpnd*/,
6618 NULL /*dstXOffOnd*/ , NULL /*dstYOffOpnd*/,
6619 false);
6620 }
6621 if (IS_VISA_BOTH_PATH)
6622 {
6623 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6624 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6625 VISA_opnd *opnd[30];
6626 int num_pred_desc_operands = 0;
6627 int num_operands = 0;
6628
6629 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6630 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6631 ADD_OPND(num_operands, opnd, sampler);
6632 ADD_OPND(num_operands, opnd, surface);
6633 ADD_OPND(num_operands, opnd, uOffset);
6634 ADD_OPND(num_operands, opnd, vOffset);
6635 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, mode, true, subOp));
6636 ADD_OPND(num_operands, opnd, dst);
6637
6638 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6639
6640 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6641
6642 unsigned char size = EXEC_SIZE_1;
6643
6644 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6645 addInstructionToEnd(inst);
6646 }
6647
6648 return status;
6649 }
6650
AppendVISAVAConvolve1Pixel(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,CONV1PixelExecMode mode,VISA_RawOpnd * offsets,VISA_RawOpnd * dst)6651 int VISAKernelImpl::AppendVISAVAConvolve1Pixel(
6652 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6653 VISA_VectorOpnd *vOffset, CONV1PixelExecMode mode, VISA_RawOpnd *offsets, VISA_RawOpnd *dst)
6654 {
6655 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6656
6657 AppendVISAInstCommon();
6658
6659 int status = VISA_SUCCESS;
6660 ISA_VA_Sub_Opcode subOp = VA_OP_CODE_1PIXEL_CONVOLVE;
6661
6662 if (IS_GEN_BOTH_PATH)
6663 {
6664 uint8_t execMode = mode;
6665 uint8_t functionality = 0x3; /*reserved*/
6666
6667 CreateGenRawSrcOperand(offsets);
6668 CreateGenRawDstOperand(dst);
6669 G4_DstRegRegion *dstOpnd = dst->g4opnd->asDstRegRegion();
6670
6671 G4_Declare* dstDcl = dstOpnd->getBase()->asRegVar()->getDeclare();
6672 G4_Type dstType = dstDcl->getElemType();
6673 /*should be W*/
6674 unsigned int dstSize = conv_exec_mode_size[execMode]* TypeSize(dstType);
6675
6676
6677 status = m_builder->translateVISAVaSklPlusGeneralInst(
6678 subOp, surface->g4opnd /*surface*/, sampler->g4opnd /*sampler*/, execMode, functionality,
6679 //rest
6680 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6681
6682 //1pixel convolve
6683 offsets->g4opnd /*offsetOpnd*/,
6684
6685 //FloodFill
6686 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6687 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6688
6689 //LBP Correlation
6690 NULL /*disparityOpnd*/ ,
6691
6692 //correlation search
6693 NULL , NULL ,
6694 NULL , NULL ,
6695 NULL , NULL ,
6696
6697 //general
6698 dstOpnd, dstType, dstSize,
6699
6700 //hdc
6701 0 /*pixelSize*/ , NULL /*dstSurfaceOpnd*/,
6702 NULL /*dstXOffOnd*/ , NULL /*dstYOffOpnd*/,
6703 false);
6704 }
6705 if (IS_VISA_BOTH_PATH)
6706 {
6707 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6708 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6709 VISA_opnd *opnd[30];
6710 int num_pred_desc_operands = 0;
6711 int num_operands = 0;
6712
6713 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6714 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6715 ADD_OPND(num_operands, opnd, sampler);
6716 ADD_OPND(num_operands, opnd, surface);
6717 ADD_OPND(num_operands, opnd, uOffset);
6718 ADD_OPND(num_operands, opnd, vOffset);
6719 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, mode, true, subOp));
6720 ADD_OPND(num_operands, opnd, offsets);
6721 ADD_OPND(num_operands, opnd, dst);
6722
6723 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6724
6725 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6726
6727 unsigned char size = EXEC_SIZE_1;
6728
6729 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6730 addInstructionToEnd(inst);
6731 }
6732
6733 return status;
6734 }
6735
AppendVISAVAHDCConvolve(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,HDCReturnFormat returnFormat,CONVHDCRegionSize regionSize,VISA_StateOpndHandle * dstSurface,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset)6736 int VISAKernelImpl::AppendVISAVAHDCConvolve(
6737 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6738 VISA_VectorOpnd *vOffset, HDCReturnFormat returnFormat, CONVHDCRegionSize regionSize,
6739 VISA_StateOpndHandle *dstSurface, VISA_VectorOpnd *xOffset, VISA_VectorOpnd *yOffset)
6740 {
6741 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6742
6743 AppendVISAInstCommon();
6744
6745 int status = VISA_SUCCESS;
6746 ISA_VA_Sub_Opcode subOp = ISA_HDC_CONV;
6747
6748 if (IS_GEN_BOTH_PATH)
6749 {
6750 uint8_t execMode = VA_CONV_16x4;
6751 uint8_t functionality = regionSize; /*reserved*/
6752 uint8_t pixelSize = returnFormat;
6753
6754 status = m_builder->translateVISAVaSklPlusGeneralInst(
6755 subOp, surface->g4opnd /*surface*/, sampler->g4opnd /*sampler*/, execMode, functionality,
6756 //rest
6757 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6758
6759 //1pixel convolve
6760 NULL /*offsetOpnd*/,
6761
6762 //FloodFill
6763 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6764 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6765
6766 //LBP Correlation
6767 NULL /*disparityOpnd*/ ,
6768
6769 //correlation search
6770 NULL , NULL ,
6771 NULL , NULL ,
6772 NULL , NULL ,
6773
6774 //general
6775 NULL, Type_UNDEF, 0,
6776
6777 //hdc
6778 pixelSize /*pixelSize*/ , dstSurface->g4opnd /*dstSurfaceOpnd*/,
6779 xOffset->g4opnd /*dstXOffOnd*/ , yOffset->g4opnd /*dstYOffOpnd*/,
6780 true);
6781 }
6782 if (IS_VISA_BOTH_PATH)
6783 {
6784 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6785 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6786 VISA_opnd *opnd[30];
6787 int num_pred_desc_operands = 0;
6788 int num_operands = 0;
6789 uint8_t properties = returnFormat;
6790 properties = properties | (regionSize << 4);
6791 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6792 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6793 ADD_OPND(num_operands, opnd, sampler);
6794 ADD_OPND(num_operands, opnd, surface);
6795 ADD_OPND(num_operands, opnd, uOffset);
6796 ADD_OPND(num_operands, opnd, vOffset);
6797 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, properties, true, subOp));
6798 ADD_OPND(num_operands, opnd, dstSurface);
6799 ADD_OPND(num_operands, opnd, xOffset);
6800 ADD_OPND(num_operands, opnd, yOffset);
6801
6802 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6803
6804 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6805
6806 unsigned char size = EXEC_SIZE_1;
6807
6808 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6809 addInstructionToEnd(inst);
6810 }
6811
6812 return status;
6813 }
6814
AppendVISAVAHDCErodeDilate(EDMode subOpED,VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_StateOpndHandle * dstSurface,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset)6815 int VISAKernelImpl::AppendVISAVAHDCErodeDilate(
6816 EDMode subOpED, VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6817 VISA_VectorOpnd *vOffset, VISA_StateOpndHandle *dstSurface, VISA_VectorOpnd *xOffset,
6818 VISA_VectorOpnd *yOffset)
6819 {
6820 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6821
6822 AppendVISAInstCommon();
6823
6824 int status = VISA_SUCCESS;
6825 ISA_VA_Sub_Opcode subOp = ISA_HDC_ERODE;
6826
6827 if (subOpED == VA_DILATE)
6828 subOp = ISA_HDC_DILATE;
6829
6830 if (IS_GEN_BOTH_PATH)
6831 {
6832 uint8_t execMode = VA_ED_64x4;
6833 uint8_t functionality = 0x3; /*reserved*/
6834 uint8_t pixelSize = 1;
6835
6836 status = m_builder->translateVISAVaSklPlusGeneralInst(
6837 subOp, surface->g4opnd /*surface*/, sampler->g4opnd /*sampler*/, execMode, functionality,
6838 //rest
6839 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6840
6841 //1pixel convolve
6842 NULL /*offsetOpnd*/,
6843
6844 //FloodFill
6845 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6846 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6847
6848 //LBP Correlation
6849 NULL /*disparityOpnd*/ ,
6850
6851 //correlation search
6852 NULL , NULL ,
6853 NULL , NULL ,
6854 NULL , NULL ,
6855
6856 //general
6857 NULL, Type_UNDEF, 0,
6858
6859 //hdc
6860 pixelSize /*pixelSize*/ , dstSurface->g4opnd /*dstSurfaceOpnd*/,
6861 xOffset->g4opnd /*dstXOffOnd*/ , yOffset->g4opnd /*dstYOffOpnd*/,
6862 true);
6863 }
6864 if (IS_VISA_BOTH_PATH)
6865 {
6866 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6867 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6868 VISA_opnd *opnd[30];
6869 int num_pred_desc_operands = 0;
6870 int num_operands = 0;
6871
6872 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6873 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6874 ADD_OPND(num_operands, opnd, sampler);
6875 ADD_OPND(num_operands, opnd, surface);
6876 ADD_OPND(num_operands, opnd, uOffset);
6877 ADD_OPND(num_operands, opnd, vOffset);
6878 ADD_OPND(num_operands, opnd, dstSurface);
6879 ADD_OPND(num_operands, opnd, xOffset);
6880 ADD_OPND(num_operands, opnd, yOffset);
6881
6882 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6883
6884 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6885
6886 unsigned char size = EXEC_SIZE_1;
6887
6888 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6889 addInstructionToEnd(inst);
6890 }
6891
6892 return status;
6893 }
6894
AppendVISAVAHDCMinMaxFilter(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,HDCReturnFormat returnFormat,MMFEnableMode mmfMode,VISA_StateOpndHandle * dstSurface,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset)6895 int VISAKernelImpl::AppendVISAVAHDCMinMaxFilter(
6896 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6897 VISA_VectorOpnd *vOffset, HDCReturnFormat returnFormat, MMFEnableMode mmfMode,
6898 VISA_StateOpndHandle *dstSurface, VISA_VectorOpnd *xOffset, VISA_VectorOpnd *yOffset)
6899 {
6900 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6901
6902 AppendVISAInstCommon();
6903
6904 int status = VISA_SUCCESS;
6905 ISA_VA_Sub_Opcode subOp = ISA_HDC_MMF;
6906
6907 if (IS_GEN_BOTH_PATH)
6908 {
6909 uint8_t execMode = VA_CONV_16x4;
6910 uint8_t functionality = mmfMode; /*reserved*/
6911 uint8_t pixelSize = returnFormat;
6912
6913 status = m_builder->translateVISAVaSklPlusGeneralInst(
6914 subOp, surface->g4opnd /*surface*/, sampler->g4opnd /*sampler*/, execMode, functionality,
6915 //rest
6916 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6917
6918 //1pixel convolve
6919 NULL /*offsetOpnd*/,
6920
6921 //FloodFill
6922 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
6923 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
6924
6925 //LBP Correlation
6926 NULL /*disparityOpnd*/ ,
6927
6928 //correlation search
6929 NULL , NULL ,
6930 NULL , NULL ,
6931 NULL , NULL ,
6932
6933 //general
6934 NULL, Type_UNDEF, 0,
6935
6936 //hdc
6937 pixelSize /*pixelSize*/ , dstSurface->g4opnd /*dstSurfaceOpnd*/,
6938 xOffset->g4opnd /*dstXOffOnd*/ , yOffset->g4opnd /*dstYOffOpnd*/,
6939 true);
6940 }
6941 if (IS_VISA_BOTH_PATH)
6942 {
6943 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
6944 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
6945 VISA_opnd *opnd[30];
6946 int num_pred_desc_operands = 0;
6947 int num_operands = 0;
6948
6949 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
6950 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
6951 ADD_OPND(num_operands, opnd, sampler);
6952 ADD_OPND(num_operands, opnd, surface);
6953 ADD_OPND(num_operands, opnd, uOffset);
6954 ADD_OPND(num_operands, opnd, vOffset);
6955 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, returnFormat, true, subOp));
6956 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, mmfMode, true, subOp));
6957 ADD_OPND(num_operands, opnd, dstSurface);
6958 ADD_OPND(num_operands, opnd, xOffset);
6959 ADD_OPND(num_operands, opnd, yOffset);
6960
6961 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
6962
6963 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
6964
6965 unsigned char size = EXEC_SIZE_1;
6966
6967 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
6968 addInstructionToEnd(inst);
6969 }
6970
6971 return status;
6972 }
6973
AppendVISAVAHDCLBPCorrelation(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,VISA_VectorOpnd * disparity,VISA_StateOpndHandle * dstSurface,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset)6974 int VISAKernelImpl::AppendVISAVAHDCLBPCorrelation(
6975 VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
6976 VISA_VectorOpnd *vOffset, VISA_VectorOpnd *disparity,
6977 VISA_StateOpndHandle *dstSurface, VISA_VectorOpnd *xOffset, VISA_VectorOpnd *yOffset)
6978 {
6979 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
6980
6981 AppendVISAInstCommon();
6982
6983 int status = VISA_SUCCESS;
6984 ISA_VA_Sub_Opcode subOp = ISA_HDC_LBPCORRELATION;
6985
6986 if (IS_GEN_BOTH_PATH)
6987 {
6988 uint8_t execMode = VA_CONV_16x4;
6989 uint8_t functionality = 0x3; /*reserved*/
6990 uint8_t pixelSize = 1;
6991
6992 status = m_builder->translateVISAVaSklPlusGeneralInst(
6993 subOp, surface->g4opnd /*surface*/, NULL /*sampler*/, execMode, functionality,
6994 //rest
6995 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
6996
6997 //1pixel convolve
6998 NULL /*offsetOpnd*/,
6999
7000 //FloodFill
7001 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
7002 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
7003
7004 //LBP Correlation
7005 disparity->g4opnd /*disparityOpnd*/ ,
7006
7007 //correlation search
7008 NULL , NULL ,
7009 NULL , NULL ,
7010 NULL , NULL ,
7011
7012 //general
7013 NULL, Type_UNDEF, 0,
7014
7015 //hdc
7016 pixelSize /*pixelSize*/ , dstSurface->g4opnd /*dstSurfaceOpnd*/,
7017 xOffset->g4opnd /*dstXOffOnd*/ , yOffset->g4opnd /*dstYOffOpnd*/,
7018 true);
7019 }
7020 if (IS_VISA_BOTH_PATH)
7021 {
7022 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
7023 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
7024 VISA_opnd *opnd[30];
7025 int num_pred_desc_operands = 0;
7026 int num_operands = 0;
7027
7028 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
7029 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
7030 ADD_OPND(num_operands, opnd, surface);
7031 ADD_OPND(num_operands, opnd, uOffset);
7032 ADD_OPND(num_operands, opnd, vOffset);
7033 ADD_OPND(num_operands, opnd, disparity);
7034 ADD_OPND(num_operands, opnd, dstSurface);
7035 ADD_OPND(num_operands, opnd, xOffset);
7036 ADD_OPND(num_operands, opnd, yOffset);
7037
7038 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
7039
7040 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7041
7042 unsigned char size = EXEC_SIZE_1;
7043
7044 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
7045 addInstructionToEnd(inst);
7046 }
7047
7048 return status;
7049 }
7050
AppendVISAVAHDCLBPCreation(VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,LBPCreationMode mode,VISA_StateOpndHandle * dstSurface,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset)7051 int VISAKernelImpl::AppendVISAVAHDCLBPCreation(
7052 VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
7053 VISA_VectorOpnd *vOffset, LBPCreationMode mode,
7054 VISA_StateOpndHandle *dstSurface, VISA_VectorOpnd *xOffset, VISA_VectorOpnd *yOffset)
7055 {
7056 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7057
7058 AppendVISAInstCommon();
7059
7060 int status = VISA_SUCCESS;
7061 ISA_VA_Sub_Opcode subOp = ISA_HDC_LBPCREATION;
7062
7063 if (mode == VA_3x3_AND_5x5)
7064 {
7065 assert(0);
7066 return VISA_FAILURE;
7067 }
7068
7069 if (IS_GEN_BOTH_PATH)
7070 {
7071 uint8_t execMode = VA_CONV_16x4;
7072 uint8_t functionality = mode; /*reserved*/
7073 uint8_t pixelSize = 1;
7074
7075 status = m_builder->translateVISAVaSklPlusGeneralInst(
7076 subOp, surface->g4opnd /*surface*/, NULL /*sampler*/, execMode, functionality,
7077 //rest
7078 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
7079
7080 //1pixel convolve
7081 NULL /*offsetOpnd*/,
7082
7083 //FloodFill
7084 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
7085 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
7086
7087 //LBP Correlation
7088 NULL /*disparityOpnd*/ ,
7089
7090 //correlation search
7091 NULL , NULL ,
7092 NULL , NULL ,
7093 NULL , NULL ,
7094
7095 //general
7096 NULL, Type_UNDEF, 0,
7097
7098 //hdc
7099 pixelSize /*pixelSize*/ , dstSurface->g4opnd /*dstSurfaceOpnd*/,
7100 xOffset->g4opnd /*dstXOffOnd*/ , yOffset->g4opnd /*dstYOffOpnd*/,
7101 true);
7102 }
7103 if (IS_VISA_BOTH_PATH)
7104 {
7105 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
7106 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
7107 VISA_opnd *opnd[30];
7108 int num_pred_desc_operands = 0;
7109 int num_operands = 0;
7110
7111 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
7112 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
7113 ADD_OPND(num_operands, opnd, surface);
7114 ADD_OPND(num_operands, opnd, uOffset);
7115 ADD_OPND(num_operands, opnd, vOffset);
7116 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, mode, true, subOp));
7117 ADD_OPND(num_operands, opnd, dstSurface);
7118 ADD_OPND(num_operands, opnd, xOffset);
7119 ADD_OPND(num_operands, opnd, yOffset);
7120
7121 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
7122
7123 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7124
7125 unsigned char size = EXEC_SIZE_1;
7126
7127 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
7128 addInstructionToEnd(inst);
7129 }
7130
7131 return status;
7132 }
7133
AppendVISAVAHDCConvolve1D(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,HDCReturnFormat returnFormat,Convolve1DDirection direction,VISA_StateOpndHandle * dstSurface,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset)7134 int VISAKernelImpl::AppendVISAVAHDCConvolve1D(
7135 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
7136 VISA_VectorOpnd *vOffset, HDCReturnFormat returnFormat, Convolve1DDirection direction,
7137 VISA_StateOpndHandle *dstSurface, VISA_VectorOpnd *xOffset, VISA_VectorOpnd *yOffset)
7138 {
7139 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7140
7141 AppendVISAInstCommon();
7142
7143 int status = VISA_SUCCESS;
7144 ISA_VA_Sub_Opcode subOp = ISA_HDC_1DCONV_H;
7145
7146 if (direction == VA_V_DIRECTION)
7147 {
7148 subOp = ISA_HDC_1DCONV_V;
7149 }
7150
7151 if (IS_GEN_BOTH_PATH)
7152 {
7153 uint8_t execMode = VA_CONV_16x4;
7154 uint8_t functionality = 0x3; /*reserved*/
7155 uint8_t pixelSize = returnFormat;
7156
7157 status = m_builder->translateVISAVaSklPlusGeneralInst(
7158 subOp, surface->g4opnd /*surface*/, sampler->g4opnd /*sampler*/, execMode, functionality,
7159 //rest
7160 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
7161
7162 //1pixel convolve
7163 NULL /*offsetOpnd*/,
7164
7165 //FloodFill
7166 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
7167 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
7168
7169 //LBP Correlation
7170 NULL /*disparityOpnd*/ ,
7171
7172 //correlation search
7173 NULL , NULL ,
7174 NULL , NULL ,
7175 NULL , NULL ,
7176
7177 //general
7178 NULL, Type_UNDEF, 0,
7179
7180 //hdc
7181 pixelSize /*pixelSize*/ , dstSurface->g4opnd /*dstSurfaceOpnd*/,
7182 xOffset->g4opnd /*dstXOffOnd*/ , yOffset->g4opnd /*dstYOffOpnd*/,
7183 true);
7184 }
7185 if (IS_VISA_BOTH_PATH)
7186 {
7187 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
7188 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
7189 VISA_opnd *opnd[30];
7190 int num_pred_desc_operands = 0;
7191 int num_operands = 0;
7192
7193 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
7194 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
7195 ADD_OPND(num_operands, opnd, sampler);
7196 ADD_OPND(num_operands, opnd, surface);
7197 ADD_OPND(num_operands, opnd, uOffset);
7198 ADD_OPND(num_operands, opnd, vOffset);
7199 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, returnFormat, true, subOp));
7200 ADD_OPND(num_operands, opnd, dstSurface);
7201 ADD_OPND(num_operands, opnd, xOffset);
7202 ADD_OPND(num_operands, opnd, yOffset);
7203
7204 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
7205
7206 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7207
7208 unsigned char size = EXEC_SIZE_1;
7209
7210 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
7211 addInstructionToEnd(inst);
7212 }
7213
7214 return status;
7215 }
7216
AppendVISAVAHDCConvolve1Pixel(VISA_StateOpndHandle * sampler,VISA_StateOpndHandle * surface,VISA_VectorOpnd * uOffset,VISA_VectorOpnd * vOffset,HDCReturnFormat returnFormat,VISA_RawOpnd * offsets,VISA_StateOpndHandle * dstSurface,VISA_VectorOpnd * xOffset,VISA_VectorOpnd * yOffset)7217 int VISAKernelImpl::AppendVISAVAHDCConvolve1Pixel(
7218 VISA_StateOpndHandle *sampler, VISA_StateOpndHandle *surface, VISA_VectorOpnd * uOffset,
7219 VISA_VectorOpnd *vOffset, HDCReturnFormat returnFormat, VISA_RawOpnd *offsets,
7220 VISA_StateOpndHandle *dstSurface, VISA_VectorOpnd *xOffset, VISA_VectorOpnd *yOffset)
7221 {
7222 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7223
7224 AppendVISAInstCommon();
7225
7226 int status = VISA_SUCCESS;
7227 ISA_VA_Sub_Opcode subOp = ISA_HDC_1PIXELCONV;
7228
7229 if (IS_GEN_BOTH_PATH)
7230 {
7231 CreateGenRawSrcOperand(offsets);
7232 uint8_t execMode = VA_CONV_16x4;
7233 uint8_t functionality = 0x3; /*reserved*/
7234 uint8_t pixelSize = returnFormat;
7235
7236 status = m_builder->translateVISAVaSklPlusGeneralInst(
7237 subOp, surface->g4opnd /*surface*/, sampler->g4opnd /*sampler*/, execMode, functionality,
7238 //rest
7239 uOffset->g4opnd /*uOffset*/ , vOffset->g4opnd /*vOffset*/ ,
7240
7241 //1pixel convolve
7242 offsets->g4opnd /*offsetOpnd*/,
7243
7244 //FloodFill
7245 NULL /*loopCountOpnd*/ , NULL /*pixelhMasOpnd*/,
7246 NULL /*pixelVMaskLeftOpnd*/ , NULL /*pixelVMaskRightOpnd*/,
7247
7248 //LBP Correlation
7249 NULL /*disparityOpnd*/ ,
7250
7251 //correlation search
7252 NULL , NULL ,
7253 NULL , NULL ,
7254 NULL , NULL ,
7255
7256 //general
7257 NULL, Type_UNDEF, 0,
7258
7259 //hdc
7260 pixelSize /*pixelSize*/ , dstSurface->g4opnd /*dstSurfaceOpnd*/,
7261 xOffset->g4opnd /*dstXOffOnd*/ , yOffset->g4opnd /*dstYOffOpnd*/,
7262 true);
7263 }
7264 if (IS_VISA_BOTH_PATH)
7265 {
7266 ISA_Opcode opcode = ISA_VA_SKL_PLUS;
7267 VISA_INST_Desc *instDesc = &CISA_INST_table[opcode];
7268 VISA_opnd *opnd[30];
7269 int num_pred_desc_operands = 0;
7270 int num_operands = 0;
7271
7272 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, instDesc);
7273 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, subOp));
7274 ADD_OPND(num_operands, opnd, sampler);
7275 ADD_OPND(num_operands, opnd, surface);
7276 ADD_OPND(num_operands, opnd, uOffset);
7277 ADD_OPND(num_operands, opnd, vOffset);
7278 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(num_pred_desc_operands, num_operands, instDesc, returnFormat, true, subOp));
7279 ADD_OPND(num_operands, opnd, offsets);
7280 ADD_OPND(num_operands, opnd, dstSurface);
7281 ADD_OPND(num_operands, opnd, xOffset);
7282 ADD_OPND(num_operands, opnd, yOffset);
7283
7284 //CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
7285
7286 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7287
7288 unsigned char size = EXEC_SIZE_1;
7289
7290 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, instDesc);
7291 addInstructionToEnd(inst);
7292 }
7293
7294 return status;
7295 }
7296
AppendVISALifetime(VISAVarLifetime startOrEnd,VISA_VectorOpnd * var)7297 int VISAKernelImpl::AppendVISALifetime(VISAVarLifetime startOrEnd, VISA_VectorOpnd *var)
7298 {
7299 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7300
7301 AppendVISAInstCommon();
7302
7303 int status = VISA_SUCCESS;
7304 unsigned char properties = (unsigned char)startOrEnd;
7305
7306 if (IS_GEN_BOTH_PATH)
7307 {
7308 if (var->g4opnd->isGreg())
7309 {
7310 properties |= (OPERAND_GENERAL << 4);
7311 }
7312 else if (var->g4opnd->isAddress())
7313 {
7314 properties |= (OPERAND_ADDRESS << 4);
7315 }
7316 else if (var->g4opnd->isFlag())
7317 {
7318 properties |= (OPERAND_PREDICATE << 4);
7319 }
7320
7321 status = m_builder->translateVISALifetimeInst(properties, var->g4opnd);
7322 }
7323
7324 if (IS_VISA_BOTH_PATH)
7325 {
7326 VISA_INST_Desc *inst_desc = NULL;
7327 VISA_opnd* opnd[2];
7328 ISA_Opcode opcode = ISA_LIFETIME;
7329 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7330
7331 inst_desc = &CISA_INST_table[opcode];
7332
7333 opnd[0] = (VISA_opnd*)m_mem.alloc(sizeof(VISA_opnd));
7334 opnd[0]->_opnd.other_opnd = properties;
7335 opnd[0]->opnd_type = CISA_OPND_OTHER;
7336 opnd[0]->size = Get_VISA_Type_Size((VISA_Type)inst_desc->opnd_desc[0].data_type);
7337 opnd[0]->tag = (uint8_t) inst_desc->opnd_desc[0].opnd_type;
7338
7339 opnd[1] = (VISA_opnd*)m_mem.alloc(sizeof(VISA_opnd));
7340 if (var->_opnd.v_opnd.tag == OPERAND_GENERAL)
7341 {
7342 opnd[0]->_opnd.other_opnd |= (OPERAND_GENERAL << 4);
7343 opnd[1]->_opnd.other_opnd = var->_opnd.v_opnd.opnd_val.gen_opnd.index;
7344 }
7345 else if (var->_opnd.v_opnd.tag == OPERAND_ADDRESS)
7346 {
7347 opnd[0]->_opnd.other_opnd |= (OPERAND_ADDRESS << 4);
7348 opnd[1]->_opnd.other_opnd = var->_opnd.v_opnd.opnd_val.addr_opnd.index;
7349 }
7350 else if (var->_opnd.v_opnd.tag == OPERAND_PREDICATE)
7351 {
7352 opnd[0]->_opnd.other_opnd |= (OPERAND_PREDICATE << 4);
7353 opnd[1]->_opnd.other_opnd = var->_opnd.v_opnd.opnd_val.pred_opnd.index;
7354 }
7355 opnd[1]->opnd_type = CISA_OPND_OTHER;
7356 opnd[1]->size = Get_VISA_Type_Size((VISA_Type)inst_desc->opnd_desc[1].data_type);
7357 opnd[1]->tag = (uint8_t) inst_desc->opnd_desc[1].opnd_type;
7358
7359 inst->createCisaInstruction(opcode, 1, 0, PredicateOpnd::getNullPred(), opnd, 2, inst_desc);
7360 addInstructionToEnd(inst);
7361
7362 }
7363
7364 return status;
7365 }
7366
AppendVISADpasInstCommon(ISA_Opcode opcode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_RawOpnd * tmpDst,VISA_RawOpnd * src0,VISA_RawOpnd * src1,VISA_VectorOpnd * src2,VISA_VectorOpnd * src3,GenPrecision src2Precision,GenPrecision src1Precision,uint8_t Depth,uint8_t Count)7367 int VISAKernelImpl::AppendVISADpasInstCommon(
7368 ISA_Opcode opcode, VISA_EMask_Ctrl emask,
7369 VISA_Exec_Size executionSize, VISA_RawOpnd* tmpDst, VISA_RawOpnd* src0, VISA_RawOpnd* src1,
7370 VISA_VectorOpnd* src2, VISA_VectorOpnd* src3,
7371 GenPrecision src2Precision, GenPrecision src1Precision,
7372 uint8_t Depth, uint8_t Count)
7373 {
7374 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7375
7376 AppendVISAInstCommon();
7377
7378 int status = VISA_SUCCESS;
7379
7380 auto setAlignIfLarger = [](var_info_t* varinfo, VISA_Align A) {
7381 VISA_Align oldA = varinfo->getAlignment();
7382 if (getAlignInBytes(A) > getAlignInBytes(oldA))
7383 {
7384 varinfo->bit_properties = ((varinfo->bit_properties & ~0xF0) | (A << 4));
7385 }
7386 };
7387
7388 // Make sure alignment is set correctly.
7389 // dst : grf aligned
7390 var_info_t* dcl = &tmpDst->decl->genVar;
7391 uint32_t alignBytes = CISATypeTable[dcl->getType()].typeSize * Get_VISA_Exec_Size(executionSize);
7392 setAlignIfLarger(dcl, getCISAAlign(alignBytes));
7393
7394 // src0 : grf aligned (it could be null)
7395 if (src0->index != 0)
7396 {
7397 dcl = &src0->decl->genVar;
7398 alignBytes = CISATypeTable[dcl->getType()].typeSize * Get_VISA_Exec_Size(executionSize);
7399 setAlignIfLarger(dcl, getCISAAlign(alignBytes));
7400 }
7401
7402 // src1 : grf aligned
7403 dcl = &src1->decl->genVar;
7404 setAlignIfLarger(dcl, getCISAAlign(getGRFSize()));
7405
7406 if (IS_GEN_BOTH_PATH)
7407 {
7408 MUST_BE_TRUE(Get_VISA_Exec_Size(executionSize) == m_builder->getNativeExecSize(),
7409 "execution size of DPAS must be equal to native execution size!");
7410
7411 // src2 : QW/OW/half-grf/GRF-aligned (vectorOpnd, g4opnd has been created)
7412 G4_RegVar* src2RegVar = src2->g4opnd->getTopDcl()->getRegVar();
7413 uint32_t src1Bits = GenPrecisionTable[(int)src1Precision].BitSize;
7414 uint32_t src2Bits = GenPrecisionTable[(int)src2Precision].BitSize;
7415 if (src2Precision == GenPrecision::FP16 || src2Precision == GenPrecision::BF16 ||
7416 src2Precision == GenPrecision::TF32 || src2Precision == GenPrecision::BF8 ||
7417 src2Bits == 8 || (src1Bits <= 4 && src2Bits == 4))
7418 {
7419 G4_SubReg_Align srAlign = GRFALIGN;
7420 if (Count != 8) srAlign = HALFGRFALIGN;
7421 src2RegVar->getDeclare()->setSubRegAlign(srAlign);
7422 }
7423 else if ((src1Bits == 8 && src2Bits == 4) || (src1Bits <= 4 && src2Bits == 2))
7424 {
7425 // OWORD aligned
7426 src2RegVar->getDeclare()->setSubRegAlign(Eight_Word);
7427 }
7428 else
7429 {
7430 // OPS_PER_CHAN=4, U2/S2; QWORD aligned
7431 src2RegVar->getDeclare()->setSubRegAlign(Four_Word);
7432 }
7433
7434
7435 CreateGenRawDstOperand(tmpDst);
7436 CreateGenRawSrcOperand(src0);
7437 CreateGenRawSrcOperand(src1);
7438 status = m_builder->translateVISADpasInst(executionSize, emask, GetGenOpcodeFromVISAOpcode(opcode),
7439 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd->asSrcRegRegion(), src1->g4opnd->asSrcRegRegion(),
7440 src2->g4opnd->asSrcRegRegion(),
7441 src3 ? src3->g4opnd->asSrcRegRegion() : nullptr,
7442 src2Precision, src1Precision, Depth, Count);
7443 }
7444 if (IS_VISA_BOTH_PATH)
7445 {
7446 int num_pred_desc_operands = 2; //accounting for exec_size and pred_id in descriptor
7447 int num_operands = 0;
7448 VISA_INST_Desc *inst_desc = NULL;
7449 VISA_opnd *opnd[6];
7450 VISA_opnd *dst = tmpDst;
7451
7452 // Precision, depth, and count are saved as VISA_opnd
7453 uint32_t info = DpasInfoToUI32(src2Precision, src1Precision, Depth, Count);
7454 VISA_opnd* dpasInfo = CreateOtherOpnd(info, ISA_TYPE_UD);
7455
7456 inst_desc = &CISA_INST_table[opcode];
7457 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
7458
7459 ADD_OPND(num_operands, opnd, dst);
7460
7461 ADD_OPND(num_operands, opnd, src0);
7462
7463 ADD_OPND(num_operands, opnd, src1);
7464
7465 ADD_OPND(num_operands, opnd, src2);
7466
7467
7468 ADD_OPND(num_operands, opnd, dpasInfo);
7469
7470 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
7471
7472 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7473
7474 unsigned char size = executionSize;
7475 size += (emask << 4);
7476 inst->createCisaInstruction(opcode, size, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
7477 addInstructionToEnd(inst);
7478 }
7479
7480 return status;
7481 }
7482
AppendVISADpasInst(ISA_Opcode opcode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_RawOpnd * tmpDst,VISA_RawOpnd * src0,VISA_RawOpnd * src1,VISA_VectorOpnd * src2,GenPrecision src2Precision,GenPrecision src1Precision,uint8_t Depth,uint8_t Count)7483 int VISAKernelImpl::AppendVISADpasInst(
7484 ISA_Opcode opcode, VISA_EMask_Ctrl emask,
7485 VISA_Exec_Size executionSize, VISA_RawOpnd* tmpDst, VISA_RawOpnd* src0, VISA_RawOpnd* src1,
7486 VISA_VectorOpnd* src2, GenPrecision src2Precision, GenPrecision src1Precision,
7487 uint8_t Depth, uint8_t Count)
7488 {
7489 return AppendVISADpasInstCommon(opcode, emask, executionSize, tmpDst, src0, src1,
7490 src2, nullptr, src2Precision, src1Precision, Depth, Count);
7491 }
7492
7493
AppendVISABfnInst(uint8_t booleanFuncCtrl,VISA_PredOpnd * pred,bool satMode,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_VectorOpnd * tmpDst,VISA_VectorOpnd * src0,VISA_VectorOpnd * src1,VISA_VectorOpnd * src2)7494 int VISAKernelImpl::AppendVISABfnInst(
7495 uint8_t booleanFuncCtrl, VISA_PredOpnd *pred, bool satMode,
7496 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
7497 VISA_VectorOpnd *tmpDst, VISA_VectorOpnd *src0, VISA_VectorOpnd *src1, VISA_VectorOpnd *src2)
7498 {
7499 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7500
7501 AppendVISAInstCommon();
7502
7503 int status = VISA_SUCCESS;
7504 if (IS_GEN_BOTH_PATH)
7505 {
7506 G4_Predicate * g4Pred = (pred != NULL) ? pred->g4opnd->asPredicate() : NULL;
7507 status = m_builder->translateVISABfnInst(
7508 booleanFuncCtrl, executionSize, emask, g4Pred,
7509 satMode ? g4::SAT : g4::NOSAT, nullptr,
7510 tmpDst->g4opnd->asDstRegRegion(), src0->g4opnd, GET_G4_OPNG(src1), GET_G4_OPNG(src2));
7511 }
7512 if (IS_VISA_BOTH_PATH)
7513 {
7514 int num_pred_desc_operands = 2; //accounting for exec_size and pred_id in descriptor
7515 int num_operands = 0;
7516 VISA_INST_Desc *inst_desc = NULL;
7517 VISA_opnd *opnd[5]; // dst, src0, src1, src2, BooleanFuncCtrl
7518 VISA_opnd *dst = tmpDst;
7519
7520 inst_desc = &CISA_INST_table[ISA_BFN];
7521 GET_NUM_PRED_DESC_OPNDS(num_pred_desc_operands, inst_desc);
7522 VISA_Modifier mod = MODIFIER_NONE;
7523
7524 if (satMode)
7525 {
7526 #if START_ASSERT_CHECK
7527 if (tmpDst == NULL)
7528 {
7529 ERROR_PRINT("Destination for Arithmetic Instruction is NULL");
7530 assert(0);
7531 return VISA_FAILURE;
7532 }
7533 #endif
7534 mod = MODIFIER_SAT;
7535 dst = (VISA_opnd *)m_mem.alloc(sizeof(VISA_opnd));
7536 *dst = *tmpDst;
7537 dst->_opnd.v_opnd.tag += mod << 3;
7538 }
7539
7540 ADD_OPND(num_operands, opnd, dst);
7541 ADD_OPND(num_operands, opnd, src0);
7542 ADD_OPND(num_operands, opnd, src1);
7543 ADD_OPND(num_operands, opnd, src2);
7544 ADD_OPND(num_operands, opnd, CreateOtherOpnd(booleanFuncCtrl, ISA_TYPE_UB));
7545 CHECK_NUM_OPNDS(inst_desc, num_operands, num_pred_desc_operands);
7546
7547 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
7548
7549 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7550
7551 unsigned char size = executionSize;
7552 size += emask << 4;
7553 inst->createCisaInstruction(ISA_BFN, size, 0, predOpnd, opnd, num_operands, inst_desc);
7554 addInstructionToEnd(inst);
7555 }
7556
7557 return status;
7558 }
7559
AppendVISAQwordGatherInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_SVM_Block_Num numBlocks,VISA_StateOpndHandle * surface,VISA_RawOpnd * address,VISA_RawOpnd * dst)7560 int VISAKernelImpl::AppendVISAQwordGatherInst(
7561 VISA_PredOpnd *pred,
7562 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
7563 VISA_SVM_Block_Num numBlocks, VISA_StateOpndHandle *surface,
7564 VISA_RawOpnd* address, VISA_RawOpnd *dst)
7565 {
7566 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7567
7568 AppendVISAInstCommon();
7569
7570 int status = VISA_SUCCESS;
7571
7572 if (IS_GEN_BOTH_PATH)
7573 {
7574 G4_Predicate * g4Pred = pred ? pred->g4opnd->asPredicate() : nullptr;
7575 CreateGenRawSrcOperand(address);
7576 CreateGenRawDstOperand(dst);
7577 status = m_builder->translateVISAQWGatherInst(executionSize, emask, g4Pred, numBlocks,
7578 surface->g4opnd->asSrcRegRegion(), address->g4opnd->asSrcRegRegion(), dst->g4opnd->asDstRegRegion());
7579 }
7580 if (IS_VISA_BOTH_PATH)
7581 {
7582 VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_QW_GATHER];
7583 VISA_opnd *opnd[10];
7584
7585 int num_operands = 0;
7586 unsigned char size = executionSize;
7587 size += emask << 4;
7588
7589 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
7590
7591
7592 ADD_OPND(num_operands, opnd, CreateOtherOpnd(numBlocks, ISA_TYPE_UB));
7593
7594 ADD_OPND(num_operands, opnd, surface);
7595 ADD_OPND(num_operands, opnd, address);
7596 ADD_OPND(num_operands, opnd, dst);
7597
7598 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7599
7600 inst->createCisaInstruction(ISA_QW_GATHER, size, 0, predOpnd, opnd, num_operands, inst_desc);
7601 addInstructionToEnd(inst);
7602 }
7603
7604 return status;
7605 }
7606
AppendVISAQwordScatterInst(VISA_PredOpnd * pred,VISA_EMask_Ctrl emask,VISA_Exec_Size executionSize,VISA_SVM_Block_Num numBlocks,VISA_StateOpndHandle * surface,VISA_RawOpnd * address,VISA_RawOpnd * src)7607 int VISAKernelImpl::AppendVISAQwordScatterInst(
7608 VISA_PredOpnd *pred,
7609 VISA_EMask_Ctrl emask, VISA_Exec_Size executionSize,
7610 VISA_SVM_Block_Num numBlocks, VISA_StateOpndHandle *surface,
7611 VISA_RawOpnd* address, VISA_RawOpnd *src)
7612 {
7613 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7614
7615 AppendVISAInstCommon();
7616
7617 int status = VISA_SUCCESS;
7618
7619 if (IS_GEN_BOTH_PATH)
7620 {
7621 G4_Predicate * g4Pred = pred ? pred->g4opnd->asPredicate() : nullptr;
7622 CreateGenRawSrcOperand(address);
7623 CreateGenRawSrcOperand(src);
7624 status = m_builder->translateVISAQWScatterInst(executionSize, emask, g4Pred, numBlocks,
7625 surface->g4opnd->asSrcRegRegion(), address->g4opnd->asSrcRegRegion(), src->g4opnd->asSrcRegRegion());
7626 }
7627 if (IS_VISA_BOTH_PATH)
7628 {
7629 VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_QW_SCATTER];
7630 VISA_opnd *opnd[10];
7631
7632 int num_operands = 0;
7633 unsigned char size = executionSize;
7634 size += emask << 4;
7635
7636 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
7637
7638 ADD_OPND(num_operands, opnd, CreateOtherOpnd(numBlocks, ISA_TYPE_UB));
7639
7640 ADD_OPND(num_operands, opnd, surface);
7641 ADD_OPND(num_operands, opnd, address);
7642 ADD_OPND(num_operands, opnd, src);
7643
7644 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
7645
7646 inst->createCisaInstruction(ISA_QW_SCATTER, size, 0, predOpnd, opnd, num_operands, inst_desc);
7647 addInstructionToEnd(inst);
7648 }
7649
7650 return status;
7651 }
7652
AppendVISALscUntypedLoad(LSC_OP subOpcode,LSC_SFID sfid,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR addr,LSC_DATA_SHAPE data,VISA_VectorOpnd * surface,VISA_RawOpnd * dstData,VISA_RawOpnd * src0Addr)7653 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscUntypedLoad(
7654 LSC_OP subOpcode,
7655 LSC_SFID sfid,
7656 VISA_PredOpnd *pred,
7657 VISA_Exec_Size execSize,
7658 VISA_EMask_Ctrl emask,
7659 LSC_CACHE_OPTS cacheOpts,
7660 LSC_ADDR addr,
7661 LSC_DATA_SHAPE data,
7662 VISA_VectorOpnd *surface,
7663 VISA_RawOpnd *dstData,
7664 VISA_RawOpnd *src0Addr)
7665 {
7666 return AppendVISALscUntypedInst(
7667 subOpcode,
7668 sfid,
7669 pred,
7670 execSize,
7671 emask,
7672 cacheOpts,
7673 addr,
7674 data,
7675 surface,
7676 dstData,
7677 src0Addr,
7678 nullptr,
7679 nullptr);
7680 }
AppendVISALscUntypedStore(LSC_OP subOpcode,LSC_SFID sfid,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR addr,LSC_DATA_SHAPE data,VISA_VectorOpnd * surface,VISA_RawOpnd * src0Addr,VISA_RawOpnd * src1Data)7681 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscUntypedStore(
7682 LSC_OP subOpcode,
7683 LSC_SFID sfid,
7684 VISA_PredOpnd *pred,
7685 VISA_Exec_Size execSize,
7686 VISA_EMask_Ctrl emask,
7687 LSC_CACHE_OPTS cacheOpts,
7688 LSC_ADDR addr,
7689 LSC_DATA_SHAPE data,
7690 VISA_VectorOpnd *surface,
7691 VISA_RawOpnd *src0Addr,
7692 VISA_RawOpnd *src1Data)
7693 {
7694 return AppendVISALscUntypedInst(
7695 subOpcode,
7696 sfid,
7697 pred,
7698 execSize,
7699 emask,
7700 cacheOpts,
7701 addr,
7702 data,
7703 surface,
7704 nullptr,
7705 src0Addr,
7706 src1Data,
7707 nullptr);
7708 }
7709
AppendVISALscUntypedAtomic(LSC_OP subOpcode,LSC_SFID sfid,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR addr,LSC_DATA_SHAPE data,VISA_VectorOpnd * surface,VISA_RawOpnd * dstReadBack,VISA_RawOpnd * src0Addr,VISA_RawOpnd * src1AtomOpnd1,VISA_RawOpnd * src2AtomOpnd2)7710 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscUntypedAtomic(
7711 LSC_OP subOpcode,
7712 LSC_SFID sfid,
7713 VISA_PredOpnd *pred,
7714 VISA_Exec_Size execSize,
7715 VISA_EMask_Ctrl emask,
7716 LSC_CACHE_OPTS cacheOpts,
7717 LSC_ADDR addr,
7718 LSC_DATA_SHAPE data,
7719 VISA_VectorOpnd *surface,
7720 VISA_RawOpnd *dstReadBack,
7721 VISA_RawOpnd *src0Addr,
7722 VISA_RawOpnd *src1AtomOpnd1,
7723 VISA_RawOpnd *src2AtomOpnd2)
7724 {
7725 return AppendVISALscUntypedInst(
7726 subOpcode,
7727 sfid,
7728 pred,
7729 execSize,
7730 emask,
7731 cacheOpts,
7732 addr,
7733 data,
7734 surface,
7735 dstReadBack,
7736 src0Addr,
7737 src1AtomOpnd1,
7738 src2AtomOpnd2);
7739 }
7740
7741 static const int LSC_ZERO = 0;
7742
7743 #define LSC_CHECK_NULL_VECTOR_OPERAND(X) \
7744 do {\
7745 if ((X) == nullptr) {\
7746 auto r = CreateVISAImmediate(X, &LSC_ZERO, ISA_TYPE_UD);\
7747 if (r != VISA_SUCCESS)\
7748 return r;\
7749 }\
7750 } while (0)
7751 #define LSC_CHECK_NULL_OPND(X,IS_DST)\
7752 do {\
7753 if ((X) == nullptr) {\
7754 auto r = CreateVISANullRawOperand((X), IS_DST);\
7755 if (r != VISA_SUCCESS)\
7756 return r;\
7757 }\
7758 } while (0)
7759 #define LSC_CHECK_NULL_DST(X) LSC_CHECK_NULL_OPND(X,true)
7760 #define LSC_CHECK_NULL_SRC(X) LSC_CHECK_NULL_OPND(X,false)
7761
AppendVISALscUntypedInst(LSC_OP subOpcode,LSC_SFID lscSfid,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR addr,LSC_DATA_SHAPE dataShape,VISA_VectorOpnd * surface,VISA_RawOpnd * dstData,VISA_RawOpnd * src0Addr,VISA_RawOpnd * src1Data,VISA_RawOpnd * src2Data)7762 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscUntypedInst(
7763 LSC_OP subOpcode,
7764 LSC_SFID lscSfid,
7765 VISA_PredOpnd *pred,
7766 VISA_Exec_Size execSize,
7767 VISA_EMask_Ctrl emask,
7768 LSC_CACHE_OPTS cacheOpts,
7769 LSC_ADDR addr,
7770 LSC_DATA_SHAPE dataShape,
7771 VISA_VectorOpnd *surface,
7772 VISA_RawOpnd *dstData,
7773 VISA_RawOpnd *src0Addr,
7774 VISA_RawOpnd *src1Data,
7775 VISA_RawOpnd *src2Data)
7776 {
7777 if (subOpcode == LSC_LOAD_STRIDED || subOpcode == LSC_STORE_STRIDED) {
7778 return AppendVISALscUntypedStridedInst(
7779 subOpcode, lscSfid, pred, execSize,
7780 emask, cacheOpts, addr, dataShape, surface, dstData, src0Addr,
7781 nullptr, src1Data);
7782 }
7783 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7784
7785 MUST_BE_TRUE(lscSfid != LSC_TGM, "cannot use TGM on an untyped message");
7786
7787 AppendVISAInstCommon();
7788
7789 int status = VISA_SUCCESS;
7790
7791 LSC_CHECK_NULL_VECTOR_OPERAND(surface);
7792 LSC_CHECK_NULL_DST(dstData);
7793 LSC_CHECK_NULL_SRC(src0Addr);
7794 LSC_CHECK_NULL_SRC(src1Data);
7795 LSC_CHECK_NULL_SRC(src2Data);
7796
7797 if (IS_GEN_BOTH_PATH) {
7798 CreateGenRawDstOperand(dstData);
7799 CreateGenRawSrcOperand(src0Addr);
7800 CreateGenRawSrcOperand(src1Data);
7801 CreateGenRawSrcOperand(src2Data);
7802 status = m_builder->translateLscUntypedInst(
7803 subOpcode,
7804 lscSfid,
7805 pred ? pred->g4opnd->asPredicate() : nullptr,
7806 execSize,
7807 emask,
7808 cacheOpts,
7809 addr,
7810 dataShape,
7811 surface->g4opnd,
7812 dstData->g4opnd->asDstRegRegion(),
7813 src0Addr->g4opnd->asSrcRegRegion(),
7814 nullptr,
7815 src1Data->g4opnd->asSrcRegRegion(),
7816 src2Data->g4opnd->asSrcRegRegion());
7817 }
7818
7819 if (IS_VISA_BOTH_PATH) {
7820 const VISA_INST_Desc *instDesc = &CISA_INST_table[ISA_LSC_UNTYPED];
7821 VISA_opnd *opnds[MAX_OPNDS_PER_INST] {};
7822 int numOpnds = 0;
7823
7824 // use same order for load, store, and atomic
7825 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(subOpcode, ISA_TYPE_UB));
7826 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(lscSfid, ISA_TYPE_UB));
7827 //
7828 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l1, ISA_TYPE_UB));
7829 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l3, ISA_TYPE_UB));
7830 //
7831 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addr.type, ISA_TYPE_UB));
7832 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addr.immScale, ISA_TYPE_UW));
7833 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addr.immOffset, ISA_TYPE_D));
7834 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addr.size, ISA_TYPE_UB));
7835 //
7836 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.size, ISA_TYPE_UB));
7837 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.order, ISA_TYPE_UB));
7838 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.elems, ISA_TYPE_UB));
7839 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.chmask, ISA_TYPE_UB));
7840 //
7841 ADD_OPND(numOpnds, opnds, surface);
7842 ADD_OPND(numOpnds, opnds, dstData);
7843 ADD_OPND(numOpnds, opnds, src0Addr);
7844 ADD_OPND(numOpnds, opnds, src1Data);
7845 ADD_OPND(numOpnds, opnds, src2Data);
7846
7847 CisaFramework::CisaInst *inst
7848 = new (m_mem) CisaFramework::CisaInst(m_mem);
7849 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
7850 // Pack execution size & mask
7851 unsigned size = execSize;
7852 PACK_EXEC_SIZE(size, emask);
7853
7854 inst->createCisaInstruction(
7855 ISA_LSC_UNTYPED, (uint8_t)size, 0, predOpnd, opnds, numOpnds, instDesc);
7856 addInstructionToEnd(inst);
7857 }
7858
7859 return status;
7860 }
7861
7862 // for a strided load, this is the "natural" stride to enable a
7863 // block (packed) load.
7864 //
7865 // TODO: move this to IsaDescription.cpp as a helper
lscStridedOpBlockStride(LSC_DATA_SHAPE dataShape)7866 static int lscStridedOpBlockStride(LSC_DATA_SHAPE dataShape)
7867 {
7868 // e.g. given :u32x4, we really want successive lanes to be a 4*32 apart
7869 // (this is like a float4 block load)
7870 // but transposed :u32x4t, we want packed elements and the vector length
7871 // is just the width of the block
7872 int stride = 0;
7873 switch (dataShape.size) {
7874 case LSC_DATA_SIZE_8b: stride = 1; break;
7875 case LSC_DATA_SIZE_16b: stride = 2; break;
7876 // case LSC_DATA_SIZE_32b:
7877 // ... and all the DW conversion cases
7878 default: stride = 4; break;
7879 case LSC_DATA_SIZE_64b: stride = 8; break;
7880 }
7881 if (dataShape.order == LSC_DATA_ORDER_NONTRANSPOSE) {
7882 switch (dataShape.elems) {
7883 case LSC_DATA_ELEMS_1: stride *= 1; break;
7884 case LSC_DATA_ELEMS_2: stride *= 2; break;
7885 case LSC_DATA_ELEMS_3: stride *= 3; break;
7886 case LSC_DATA_ELEMS_4: stride *= 4; break;
7887 case LSC_DATA_ELEMS_8: stride *= 8; break;
7888 case LSC_DATA_ELEMS_16: stride *= 16; break;
7889 case LSC_DATA_ELEMS_32: stride *= 32; break;
7890 case LSC_DATA_ELEMS_64: stride *= 64; break;
7891 default: MUST_BE_TRUE(false,"invalid vector size"); break;
7892 }
7893 }
7894 return stride;
7895 }
7896
AppendVISALscUntypedStridedInst(LSC_OP op,LSC_SFID lscSfid,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR addrInfo,LSC_DATA_SHAPE dataShape,VISA_VectorOpnd * surface,VISA_RawOpnd * dstData,VISA_RawOpnd * src0AddrBase,VISA_VectorOpnd * src0AddrPitch,VISA_RawOpnd * src1Data)7897 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscUntypedStridedInst(
7898 LSC_OP op,
7899 LSC_SFID lscSfid,
7900 VISA_PredOpnd *pred,
7901 VISA_Exec_Size execSize,
7902 VISA_EMask_Ctrl emask,
7903 LSC_CACHE_OPTS cacheOpts,
7904 LSC_ADDR addrInfo,
7905 LSC_DATA_SHAPE dataShape,
7906 VISA_VectorOpnd *surface,
7907 VISA_RawOpnd *dstData,
7908 VISA_RawOpnd *src0AddrBase,
7909 VISA_VectorOpnd *src0AddrPitch,
7910 VISA_RawOpnd *src1Data)
7911 {
7912 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
7913
7914 MUST_BE_TRUE(op == LSC_LOAD_STRIDED || op == LSC_STORE_STRIDED,
7915 "must be a strided op");
7916 MUST_BE_TRUE(lscSfid != LSC_TGM, "cannot use TGM on an untyped message");
7917
7918 AppendVISAInstCommon();
7919
7920 int status = VISA_SUCCESS;
7921
7922 LSC_CHECK_NULL_VECTOR_OPERAND(surface);
7923 LSC_CHECK_NULL_DST(dstData);
7924 if (src0AddrPitch == nullptr) {
7925 int defaultPitch = lscStridedOpBlockStride(dataShape);
7926 status |= CreateVISAImmediate(src0AddrPitch, &defaultPitch, ISA_TYPE_UD);
7927 }
7928 LSC_CHECK_NULL_SRC(src1Data);
7929
7930 if (IS_GEN_BOTH_PATH) {
7931 CreateGenRawDstOperand(dstData);
7932 CreateGenRawSrcOperand(src0AddrBase);
7933 CreateGenRawSrcOperand(src1Data);
7934 status |= m_builder->translateLscUntypedInst(
7935 op,
7936 lscSfid,
7937 pred ? pred->g4opnd->asPredicate() : nullptr,
7938 execSize,
7939 emask,
7940 cacheOpts,
7941 addrInfo,
7942 dataShape,
7943 surface->g4opnd,
7944 dstData->g4opnd->asDstRegRegion(),
7945 src0AddrBase->g4opnd->asSrcRegRegion(),
7946 src0AddrPitch->g4opnd,
7947 src1Data->g4opnd->asSrcRegRegion(),
7948 nullptr);
7949 }
7950
7951 if (IS_VISA_BOTH_PATH) {
7952 const VISA_INST_Desc *instDesc = &CISA_INST_table[ISA_LSC_UNTYPED];
7953 VISA_opnd *opnds[MAX_OPNDS_PER_INST] {};
7954 int numOpnds = 0;
7955
7956 // use same order for load, store, and atomic
7957 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(op, ISA_TYPE_UB));
7958 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(lscSfid, ISA_TYPE_UB));
7959 //
7960 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l1, ISA_TYPE_UB));
7961 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l3, ISA_TYPE_UB));
7962 //
7963 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addrInfo.type, ISA_TYPE_UB));
7964 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addrInfo.immScale, ISA_TYPE_UW));
7965 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addrInfo.immOffset, ISA_TYPE_D));
7966 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addrInfo.size, ISA_TYPE_UB));
7967 //
7968 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.size, ISA_TYPE_UB));
7969 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.order, ISA_TYPE_UB));
7970 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.elems, ISA_TYPE_UB));
7971 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(0, ISA_TYPE_UB)); // chmask
7972 //
7973 ADD_OPND(numOpnds, opnds, surface);
7974 ADD_OPND(numOpnds, opnds, dstData);
7975 ADD_OPND(numOpnds, opnds, src0AddrBase);
7976 ADD_OPND(numOpnds, opnds, src0AddrPitch);
7977 ADD_OPND(numOpnds, opnds, src1Data);
7978
7979 CisaFramework::CisaInst *inst
7980 = new (m_mem) CisaFramework::CisaInst(m_mem);
7981 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
7982 // Pack execution size & mask
7983 unsigned size = execSize;
7984 PACK_EXEC_SIZE(size, emask);
7985
7986 inst->createCisaInstruction(
7987 ISA_LSC_UNTYPED, (uint8_t)size, 0, predOpnd, opnds, numOpnds, instDesc);
7988 addInstructionToEnd(inst);
7989 }
7990
7991 return status;
7992 }
7993
AppendVISALscUntypedBlock2DInst(LSC_OP op,LSC_SFID lscSfid,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_DATA_SHAPE_BLOCK2D dataShape2D,VISA_RawOpnd * dstData,VISA_VectorOpnd * src0Addrs[LSC_BLOCK2D_ADDR_PARAMS],VISA_RawOpnd * src1Data)7994 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscUntypedBlock2DInst(
7995 LSC_OP op,
7996 LSC_SFID lscSfid,
7997 VISA_PredOpnd *pred,
7998 VISA_Exec_Size execSize,
7999 VISA_EMask_Ctrl emask,
8000 LSC_CACHE_OPTS cacheOpts,
8001 LSC_DATA_SHAPE_BLOCK2D dataShape2D,
8002 VISA_RawOpnd *dstData,
8003 VISA_VectorOpnd *src0Addrs[LSC_BLOCK2D_ADDR_PARAMS],
8004 VISA_RawOpnd *src1Data)
8005 {
8006 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
8007
8008 MUST_BE_TRUE(lscSfid != LSC_TGM, "cannot use TGM on an untyped message");
8009
8010 AppendVISAInstCommon();
8011
8012 int status = VISA_SUCCESS;
8013
8014 LSC_CHECK_NULL_DST(dstData);
8015 LSC_CHECK_NULL_SRC(src1Data);
8016
8017 if (IS_GEN_BOTH_PATH) {
8018 CreateGenRawDstOperand(dstData);
8019 // CreateGenRawSrcOperand(src0Addrs*); created in parse
8020 CreateGenRawSrcOperand(src1Data);
8021
8022 G4_Operand *src0AddrSrcRgns[LSC_BLOCK2D_ADDR_PARAMS];
8023 for (size_t i = 0; i < LSC_BLOCK2D_ADDR_PARAMS; i++) {
8024 src0AddrSrcRgns[i] = src0Addrs[i]->g4opnd;
8025 }
8026 status |= m_builder->translateLscUntypedBlock2DInst(
8027 op,
8028 lscSfid,
8029 pred ? pred->g4opnd->asPredicate() : nullptr,
8030 execSize,
8031 emask,
8032 cacheOpts,
8033 dataShape2D,
8034 dstData->g4opnd->asDstRegRegion(),
8035 src0AddrSrcRgns,
8036 src1Data->g4opnd->asSrcRegRegion());
8037 }
8038
8039 if (IS_VISA_BOTH_PATH) {
8040 const VISA_INST_Desc *instDesc = &CISA_INST_table[ISA_LSC_UNTYPED];
8041 VISA_opnd *opnds[MAX_OPNDS_PER_INST] {};
8042 int numOpnds = 0;
8043
8044 // use same order for load, store, and atomic
8045 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(op, ISA_TYPE_UB));
8046 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(lscSfid, ISA_TYPE_UB));
8047 //
8048 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l1, ISA_TYPE_UB));
8049 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l3, ISA_TYPE_UB));
8050 //
8051 ADD_OPND(numOpnds, opnds,
8052 CreateOtherOpnd(dataShape2D.size, ISA_TYPE_UB));
8053 ADD_OPND(numOpnds, opnds,
8054 CreateOtherOpnd(dataShape2D.order, ISA_TYPE_UB));
8055 ADD_OPND(numOpnds, opnds,
8056 CreateOtherOpnd(dataShape2D.blocks, ISA_TYPE_UB));
8057 ADD_OPND(numOpnds, opnds,
8058 CreateOtherOpnd(dataShape2D.width, ISA_TYPE_UW));
8059 ADD_OPND(numOpnds, opnds,
8060 CreateOtherOpnd(dataShape2D.height, ISA_TYPE_UW));
8061 ADD_OPND(numOpnds, opnds,
8062 CreateOtherOpnd(dataShape2D.vnni ? 1 : 0, ISA_TYPE_UB));
8063 //
8064 ADD_OPND(numOpnds, opnds, dstData);
8065 for (size_t i = 0; i < LSC_BLOCK2D_ADDR_PARAMS; i++) {
8066 ADD_OPND(numOpnds, opnds, src0Addrs[i]);
8067 }
8068 ADD_OPND(numOpnds, opnds, src1Data);
8069
8070 CisaFramework::CisaInst *inst
8071 = new (m_mem) CisaFramework::CisaInst(m_mem);
8072 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
8073 // Pack execution size & mask
8074 unsigned size = execSize;
8075 PACK_EXEC_SIZE(size, emask);
8076
8077 inst->createCisaInstruction(
8078 ISA_LSC_UNTYPED, (uint8_t)size, 0, predOpnd, opnds, numOpnds, instDesc);
8079 addInstructionToEnd(inst);
8080 }
8081
8082 return status;
8083 }
8084
AppendVISALscTypedLoad(LSC_OP op,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR_TYPE addrType,LSC_ADDR_SIZE addrSize,LSC_DATA_SHAPE data,VISA_VectorOpnd * surface,VISA_RawOpnd * dstData,VISA_RawOpnd * Us,VISA_RawOpnd * Vs,VISA_RawOpnd * Rs,VISA_RawOpnd * LODs)8085 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscTypedLoad(
8086 LSC_OP op,
8087 VISA_PredOpnd *pred,
8088 VISA_Exec_Size execSize,
8089 VISA_EMask_Ctrl emask,
8090 LSC_CACHE_OPTS cacheOpts,
8091 LSC_ADDR_TYPE addrType,
8092 LSC_ADDR_SIZE addrSize,
8093 LSC_DATA_SHAPE data,
8094 VISA_VectorOpnd *surface,
8095 VISA_RawOpnd *dstData,
8096 VISA_RawOpnd *Us,
8097 VISA_RawOpnd *Vs,
8098 VISA_RawOpnd *Rs,
8099 VISA_RawOpnd *LODs)
8100 {
8101 return AppendVISALscTypedInst(
8102 op,
8103 pred,
8104 execSize,
8105 emask,
8106 cacheOpts,
8107 addrType,
8108 addrSize,
8109 data,
8110 surface,
8111 dstData,
8112 Us,
8113 Vs,
8114 Rs,
8115 LODs,
8116 nullptr,
8117 nullptr);
8118 }
8119
AppendVISALscTypedStore(LSC_OP op,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR_TYPE addrType,LSC_ADDR_SIZE addrSize,LSC_DATA_SHAPE data,VISA_VectorOpnd * surface,VISA_RawOpnd * Us,VISA_RawOpnd * Vs,VISA_RawOpnd * Rs,VISA_RawOpnd * LODs,VISA_RawOpnd * src1Data)8120 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscTypedStore(
8121 LSC_OP op,
8122 VISA_PredOpnd *pred,
8123 VISA_Exec_Size execSize,
8124 VISA_EMask_Ctrl emask,
8125 LSC_CACHE_OPTS cacheOpts,
8126 LSC_ADDR_TYPE addrType,
8127 LSC_ADDR_SIZE addrSize,
8128 LSC_DATA_SHAPE data,
8129 VISA_VectorOpnd *surface,
8130 VISA_RawOpnd *Us,
8131 VISA_RawOpnd *Vs,
8132 VISA_RawOpnd *Rs,
8133 VISA_RawOpnd *LODs,
8134 VISA_RawOpnd *src1Data)
8135 {
8136 return AppendVISALscTypedInst(
8137 op,
8138 pred,
8139 execSize,
8140 emask,
8141 cacheOpts,
8142 addrType,
8143 addrSize,
8144 data,
8145 surface,
8146 nullptr,
8147 Us,
8148 Vs,
8149 Rs,
8150 LODs,
8151 src1Data,
8152 nullptr);
8153 }
8154
AppendVISALscTypedAtomic(LSC_OP op,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR_TYPE addrType,LSC_ADDR_SIZE addrSize,LSC_DATA_SHAPE data,VISA_VectorOpnd * surface,VISA_RawOpnd * dstReadBack,VISA_RawOpnd * Us,VISA_RawOpnd * Vs,VISA_RawOpnd * Rs,VISA_RawOpnd * LODs,VISA_RawOpnd * src1AtomicOpnd1,VISA_RawOpnd * src2AtomicOpnd2)8155 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscTypedAtomic(
8156 LSC_OP op,
8157 VISA_PredOpnd *pred,
8158 VISA_Exec_Size execSize,
8159 VISA_EMask_Ctrl emask,
8160 LSC_CACHE_OPTS cacheOpts,
8161 LSC_ADDR_TYPE addrType,
8162 LSC_ADDR_SIZE addrSize,
8163 LSC_DATA_SHAPE data,
8164 VISA_VectorOpnd *surface,
8165 VISA_RawOpnd *dstReadBack,
8166 VISA_RawOpnd *Us,
8167 VISA_RawOpnd *Vs,
8168 VISA_RawOpnd *Rs,
8169 VISA_RawOpnd *LODs,
8170 VISA_RawOpnd *src1AtomicOpnd1,
8171 VISA_RawOpnd *src2AtomicOpnd2)
8172 {
8173 return AppendVISALscTypedInst(
8174 op,
8175 pred,
8176 execSize,
8177 emask,
8178 cacheOpts,
8179 addrType,
8180 addrSize,
8181 data,
8182 surface,
8183 dstReadBack,
8184 Us,
8185 Vs,
8186 Rs,
8187 LODs,
8188 src1AtomicOpnd1,
8189 src2AtomicOpnd2);
8190 }
8191
8192
AppendVISALscTypedInst(LSC_OP subOpcode,VISA_PredOpnd * pred,VISA_Exec_Size execSize,VISA_EMask_Ctrl emask,LSC_CACHE_OPTS cacheOpts,LSC_ADDR_TYPE addrType,LSC_ADDR_SIZE addrSize,LSC_DATA_SHAPE dataShape,VISA_VectorOpnd * surface,VISA_RawOpnd * dstData,VISA_RawOpnd * src0AddrUs,VISA_RawOpnd * src0AddrVs,VISA_RawOpnd * src0AddrRs,VISA_RawOpnd * src0AddrLODs,VISA_RawOpnd * src1Data,VISA_RawOpnd * src2Data)8193 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscTypedInst(
8194 LSC_OP subOpcode,
8195 VISA_PredOpnd *pred,
8196 VISA_Exec_Size execSize,
8197 VISA_EMask_Ctrl emask,
8198 LSC_CACHE_OPTS cacheOpts,
8199 LSC_ADDR_TYPE addrType,
8200 LSC_ADDR_SIZE addrSize,
8201 LSC_DATA_SHAPE dataShape,
8202 VISA_VectorOpnd *surface,
8203 VISA_RawOpnd *dstData,
8204 VISA_RawOpnd *src0AddrUs,
8205 VISA_RawOpnd *src0AddrVs,
8206 VISA_RawOpnd *src0AddrRs,
8207 VISA_RawOpnd *src0AddrLODs,
8208 VISA_RawOpnd *src1Data,
8209 VISA_RawOpnd *src2Data)
8210 {
8211 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
8212
8213 AppendVISAInstCommon();
8214
8215 int status = VISA_SUCCESS;
8216
8217 LSC_CHECK_NULL_VECTOR_OPERAND(surface);
8218 LSC_CHECK_NULL_DST(dstData);
8219 LSC_CHECK_NULL_SRC(src0AddrUs);
8220 LSC_CHECK_NULL_SRC(src0AddrVs);
8221 LSC_CHECK_NULL_SRC(src0AddrRs);
8222 LSC_CHECK_NULL_SRC(src0AddrLODs);
8223 LSC_CHECK_NULL_SRC(src1Data);
8224 LSC_CHECK_NULL_SRC(src2Data);
8225
8226 if (IS_GEN_BOTH_PATH) {
8227 CreateGenRawDstOperand(dstData);
8228 CreateGenRawSrcOperand(src0AddrUs);
8229 CreateGenRawSrcOperand(src0AddrVs);
8230 CreateGenRawSrcOperand(src0AddrRs);
8231 CreateGenRawSrcOperand(src0AddrLODs);
8232 CreateGenRawSrcOperand(src1Data);
8233 CreateGenRawSrcOperand(src2Data);
8234
8235 status = m_builder->translateLscTypedInst(
8236 subOpcode,
8237 pred ? pred->g4opnd->asPredicate() : nullptr,
8238 execSize,
8239 emask,
8240 cacheOpts,
8241 addrType,
8242 addrSize,
8243 dataShape,
8244 surface->g4opnd,
8245 dstData->g4opnd->asDstRegRegion(),
8246 src0AddrUs->g4opnd->asSrcRegRegion(),
8247 src0AddrVs->g4opnd->asSrcRegRegion(),
8248 src0AddrRs->g4opnd->asSrcRegRegion(),
8249 src0AddrLODs->g4opnd->asSrcRegRegion(),
8250 src1Data->g4opnd->asSrcRegRegion(),
8251 src2Data->g4opnd->asSrcRegRegion()
8252 );
8253 }
8254
8255 if (IS_VISA_BOTH_PATH) {
8256 const VISA_INST_Desc *instDesc = &CISA_INST_table[ISA_LSC_TYPED];
8257 VISA_opnd *opnds[MAX_OPNDS_PER_INST] { };
8258 int numOpnds = 0;
8259
8260 // use same order for load, store, and atomic
8261 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(subOpcode, ISA_TYPE_UB));
8262 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l1, ISA_TYPE_UB));
8263 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(cacheOpts.l3, ISA_TYPE_UB));
8264 //
8265 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addrType, ISA_TYPE_UB));
8266 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(addrSize, ISA_TYPE_UB));
8267 //
8268 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.size, ISA_TYPE_UB));
8269 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.order, ISA_TYPE_UB));
8270 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.elems, ISA_TYPE_UB));
8271 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(dataShape.chmask, ISA_TYPE_UB));
8272 //
8273 ADD_OPND(numOpnds, opnds, surface);
8274 ADD_OPND(numOpnds, opnds, dstData);
8275 ADD_OPND(numOpnds, opnds, src0AddrUs);
8276 ADD_OPND(numOpnds, opnds, src0AddrVs);
8277 ADD_OPND(numOpnds, opnds, src0AddrRs);
8278 ADD_OPND(numOpnds, opnds, src0AddrLODs);
8279 ADD_OPND(numOpnds, opnds, src1Data);
8280 ADD_OPND(numOpnds, opnds, src2Data);
8281
8282 CisaFramework::CisaInst *inst
8283 = new (m_mem) CisaFramework::CisaInst(m_mem);
8284 PredicateOpnd predOpnd = pred ? pred->convertToPred() : PredicateOpnd::getNullPred();
8285 // Pack execution size & mask
8286 unsigned size = execSize;
8287 PACK_EXEC_SIZE(size, emask);
8288
8289 inst->createCisaInstruction(
8290 ISA_LSC_TYPED, (uint8_t)size, 0, predOpnd, opnds, numOpnds, instDesc);
8291 addInstructionToEnd(inst);
8292 }
8293
8294 return status;
8295 }
8296
8297
AppendVISALscFence(LSC_SFID lscSfid,LSC_FENCE_OP fenceOp,LSC_SCOPE scope)8298 VISA_BUILDER_API int VISAKernelImpl::AppendVISALscFence(
8299 LSC_SFID lscSfid,
8300 LSC_FENCE_OP fenceOp,
8301 LSC_SCOPE scope)
8302 {
8303 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
8304
8305 AppendVISAInstCommon();
8306
8307 int status = VISA_SUCCESS;
8308
8309 if (IS_GEN_BOTH_PATH) {
8310 SFID sfid = LSC_SFID_To_SFID(lscSfid);
8311 m_builder->translateLscFence(sfid, fenceOp, scope, status);
8312 }
8313
8314 if (IS_VISA_BOTH_PATH) {
8315 const VISA_INST_Desc *instDesc = &CISA_INST_table[ISA_LSC_FENCE];
8316 VISA_opnd *opnds[MAX_OPNDS_PER_INST];
8317 memset(opnds,0,sizeof(opnds));
8318 int numOpnds = 0;
8319 //
8320 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(lscSfid, ISA_TYPE_UB));
8321 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(fenceOp, ISA_TYPE_UB));
8322 ADD_OPND(numOpnds, opnds, CreateOtherOpnd(scope, ISA_TYPE_UB));
8323
8324 CisaFramework::CisaInst *inst
8325 = new (m_mem) CisaFramework::CisaInst(m_mem);
8326 // Pack execution size & mask
8327 unsigned size = EXEC_SIZE_1;
8328 PACK_EXEC_SIZE(size, vISA_EMASK_M1_NM);
8329
8330 inst->createCisaInstruction(
8331 ISA_LSC_FENCE, (uint8_t)size, 0, PredicateOpnd::getNullPred(), opnds, numOpnds, instDesc);
8332 addInstructionToEnd(inst);
8333 }
8334
8335 return status;
8336 }
8337
AppendVISANamedBarrierWait(VISA_VectorOpnd * barrierId)8338 VISA_BUILDER_API int VISAKernelImpl::AppendVISANamedBarrierWait(
8339 VISA_VectorOpnd* barrierId)
8340 {
8341 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
8342
8343 AppendVISAInstCommon();
8344
8345 int status = VISA_SUCCESS;
8346
8347 if (IS_GEN_BOTH_PATH)
8348 {
8349 status = m_builder->translateVISANamedBarrierWait(barrierId->g4opnd);
8350 }
8351
8352 if (IS_VISA_BOTH_PATH)
8353 {
8354 VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_NBARRIER];
8355 VISA_opnd* opnd[3];
8356 int num_operands = 0;
8357
8358 uint8_t mode = 0; //wait
8359 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(0, num_operands, inst_desc, mode));
8360 ADD_OPND(num_operands, opnd, barrierId);
8361 // pad with dummy operand as NBarrier expects three operands in binary form. It'll be ignored
8362 ADD_OPND(num_operands, opnd, barrierId);
8363
8364 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
8365
8366 inst->createCisaInstruction(ISA_NBARRIER, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
8367 addInstructionToEnd(inst);
8368 }
8369
8370 return status;
8371 }
8372
AppendVISANamedBarrierSignal(VISA_VectorOpnd * barrierId,VISA_VectorOpnd * barrierCount)8373 VISA_BUILDER_API int VISAKernelImpl::AppendVISANamedBarrierSignal(
8374 VISA_VectorOpnd* barrierId,
8375 VISA_VectorOpnd* barrierCount)
8376 {
8377 TIME_SCOPE(VISA_BUILDER_APPEND_INST);
8378
8379 AppendVISAInstCommon();
8380
8381 int status = VISA_SUCCESS;
8382
8383 if (IS_GEN_BOTH_PATH)
8384 {
8385 status = m_builder->translateVISANamedBarrierSignal(barrierId->g4opnd, barrierCount->g4opnd);
8386 }
8387 if (IS_VISA_BOTH_PATH)
8388 {
8389 VISA_INST_Desc *inst_desc = &CISA_INST_table[ISA_NBARRIER];
8390 VISA_opnd* opnd[3];
8391 int num_operands = 0;
8392
8393 uint8_t mode = 1; //signal
8394 ADD_OPND(num_operands, opnd, CreateOtherOpndHelper(0, num_operands, inst_desc, mode));
8395 ADD_OPND(num_operands, opnd, barrierId);
8396 ADD_OPND(num_operands, opnd, barrierCount);
8397
8398 CisaFramework::CisaInst * inst = new(m_mem)CisaFramework::CisaInst(m_mem);
8399
8400 inst->createCisaInstruction(ISA_NBARRIER, EXEC_SIZE_1, 0, PredicateOpnd::getNullPred(), opnd, num_operands, inst_desc);
8401 addInstructionToEnd(inst);
8402 }
8403
8404 return status;
8405 }
8406
addStringPool(std::string str)8407 uint32_t VISAKernelImpl::addStringPool(std::string str)
8408 {
8409 if (str.empty())
8410 {
8411 return 0;
8412 }
8413 m_string_pool_size += (int) str.size()+1; //to account for a null terminating character
8414 m_string_pool.emplace_back(std::move(str));
8415 return (uint32_t)(m_string_pool.size()-1);
8416 }
8417
addInstructionToEnd(CisaInst * inst)8418 void VISAKernelImpl::addInstructionToEnd(CisaInst * inst)
8419 {
8420 m_instruction_list.push_back(inst);
8421 CISA_INST * cisaInst = inst->getCISAInst();
8422 cisaInst->id = getvIsaInstCount();
8423 m_instruction_size += inst->getSize();
8424 DEBUG_PRINT_SIZE_INSTRUCTION("size after instruction added: ", inst->m_inst_desc->opcode, SIZE_VALUE_INST);
8425
8426 if (IsAsmWriterMode())
8427 {
8428 // Print instructions
8429 VISAKernel_format_provider fmt(this);
8430 m_CISABuilder->m_ssIsaAsm << printInstruction(&fmt, inst->getCISAInst(), getOptions()) << "\n";
8431 }
8432 }
8433
addLabel(label_info_t * lbl,char * label_name)8434 int VISAKernelImpl::addLabel(label_info_t * lbl, char * label_name)
8435 {
8436 return m_label_count++;
8437 }
8438
addFunctionDirective(char * func_name)8439 int VISAKernelImpl::addFunctionDirective(char * func_name)
8440 {
8441 return 0;
8442 }
8443
setGenxDebugInfoBuffer(char * buffer,unsigned long size)8444 void VISAKernelImpl::setGenxDebugInfoBuffer(char * buffer, unsigned long size)
8445 {
8446 m_genx_debug_info_buffer = buffer;
8447 m_genx_debug_info_size = size;
8448 }
8449
8450 /**
8451 * finalizeAttributes() sets attributes based on options, etc.
8452 * This is a temporary solution to move some options to attributes.
8453 * Once clients set attributes directily without using options, this
8454 * function shall be removed.
8455 */
finalizeAttributes()8456 void VISAKernelImpl::finalizeAttributes()
8457 {
8458 if (!m_kernelAttrs->isKernelAttrSet(Attributes::ATTR_Target))
8459 {
8460 VISATarget target = m_options->getTarget();
8461 uint8_t val = (uint8_t)target;
8462 AddKernelAttribute("Target", 1, &val);
8463 }
8464 }
8465
8466 /**
8467 * This function is called right before the kernel instructions are outputed in to a buffer.
8468 * It assumes that all the VISA instructions have already been generated.
8469 */
finalizeKernel()8470 void VISAKernelImpl::finalizeKernel()
8471 {
8472 finalizeAttributes();
8473 m_cisa_kernel.string_count = (uint32_t)m_string_pool.size();
8474 m_cisa_kernel.strings = (const char **) m_mem.alloc(m_cisa_kernel.string_count * sizeof(char *));
8475 auto it_string = m_string_pool.begin(), et_string = m_string_pool.end();
8476 int size_check = 0;
8477
8478 for (int i = 0; it_string != et_string; i++, ++it_string)
8479 {
8480 char* string = (char*) m_mem.alloc(it_string->size() + 1);
8481 memcpy_s(string, it_string->size() + 1, it_string->c_str(), it_string->size()+1);
8482 m_cisa_kernel.strings[i] = string;
8483 size_check += (int) it_string->size()+1;
8484 }
8485
8486 m_kernel_data_size = sizeof(m_cisa_kernel.string_count);
8487 m_kernel_data_size += m_string_pool_size;
8488
8489 DEBUG_PRINT_SIZE("\nsize after string_count: ", SIZE_VALUE);
8490
8491 //already set
8492 m_kernel_data_size += sizeof(m_cisa_kernel.name_index);
8493
8494 DEBUG_PRINT_SIZE("size after name_index: ", SIZE_VALUE);
8495
8496 /****VARIABLES*******/
8497 unsigned int adjVarInfoCount = m_var_info_count - m_num_pred_vars;
8498 m_cisa_kernel.variable_count = adjVarInfoCount;
8499 m_cisa_kernel.variables = (var_info_t *) m_mem.alloc(sizeof(var_info_t) * adjVarInfoCount);
8500
8501 uint32_t varInfoSize = 0;
8502 for (unsigned int i = 0; i < adjVarInfoCount; i++)
8503 {
8504 var_info_t * temp = &m_var_info_list.at(i + m_num_pred_vars)->genVar;
8505 m_cisa_kernel.variables[i] = *temp;
8506 varInfoSize += temp->getSizeInBinary();
8507 }
8508 m_kernel_data_size += sizeof(m_cisa_kernel.variable_count);
8509 m_kernel_data_size += varInfoSize;
8510
8511 DEBUG_PRINT_SIZE("size after variables: ", SIZE_VALUE);
8512
8513 /****ADDRESSES**********/
8514
8515 m_cisa_kernel.address_count = (uint16_t)m_addr_info_count;
8516
8517 m_cisa_kernel.addresses = (addr_info_t *) m_mem.alloc(sizeof(addr_info_t) * m_addr_info_count);
8518
8519 std::vector<CISA_GEN_VAR *>::iterator it_addr_info = m_addr_info_list.begin();
8520 for (unsigned int i = 0; i < m_addr_info_count; i++, it_addr_info++)
8521 {
8522 MUST_BE_TRUE(it_addr_info != m_addr_info_list.end(), "Count of addresses does not correspond with number of items.");
8523 m_cisa_kernel.addresses[i] = (*it_addr_info)->addrVar;
8524 }
8525
8526 m_kernel_data_size += sizeof(m_cisa_kernel.address_count);
8527 m_kernel_data_size += m_address_info_size;
8528
8529 DEBUG_PRINT_SIZE("size after addresses: ", SIZE_VALUE);
8530
8531 /****PREDICATES*********/
8532 m_cisa_kernel.predicate_count = (uint16_t)m_pred_info_count;
8533 m_cisa_kernel.predicates = (pred_info_t *) m_mem.alloc(sizeof(pred_info_t) * m_pred_info_count);
8534
8535 std::vector<CISA_GEN_VAR *>::iterator it_pred_info = m_pred_info_list.begin();
8536 for (unsigned int i = 0; i < m_pred_info_count; i++, it_pred_info++)
8537 {
8538 MUST_BE_TRUE(it_pred_info != m_pred_info_list.end(), "Count of predicates does not correspond with number of items.");
8539 pred_info_t * temp = &(*it_pred_info)->predVar;
8540 m_cisa_kernel.predicates[i] = *temp;
8541 }
8542 m_kernel_data_size += sizeof(m_cisa_kernel.predicate_count);
8543 m_kernel_data_size += m_predicate_info_size;
8544
8545 DEBUG_PRINT_SIZE("size after predicates: ", SIZE_VALUE);
8546
8547 /****LABELS**********/
8548 m_cisa_kernel.label_count = (uint16_t)m_label_count;
8549 m_cisa_kernel.labels = (label_info_t *) m_mem.alloc(sizeof(label_info_t) * m_label_count);
8550
8551 std::vector<label_info_t *>::const_iterator it_label_info = m_label_info_list.cbegin();
8552 std::vector<label_info_t *>::const_iterator it_label_info_end = m_label_info_list.cend();
8553 for (unsigned int i = 0; i < m_label_count; i++, it_label_info++)
8554 {
8555 MUST_BE_TRUE(it_label_info != it_label_info_end, "Count of labels does not correspond with number of items.");
8556 label_info_t * temp = *it_label_info;
8557 m_cisa_kernel.labels[i] = *temp;
8558 }
8559 m_kernel_data_size += sizeof(m_cisa_kernel.label_count);
8560 m_kernel_data_size += m_label_info_size;
8561
8562 DEBUG_PRINT_SIZE("size after labels: ", SIZE_VALUE);
8563
8564 /*****SAMPLERS*********/
8565 m_cisa_kernel.sampler_count = (uint8_t)m_sampler_count;
8566 m_cisa_kernel.samplers = (state_info_t *) m_mem.alloc(sizeof(state_info_t) * m_sampler_count);
8567
8568 std::vector<CISA_GEN_VAR*>::iterator it_sampler_info = m_sampler_info_list.begin();
8569 for (unsigned int i = 0; i < m_sampler_count; i++, it_sampler_info++)
8570 {
8571 MUST_BE_TRUE(it_sampler_info != m_sampler_info_list.end(), "Count of sampler declarations does not correspond with number of items.");
8572 state_info_t * temp = &(*it_sampler_info)->stateVar;
8573 m_cisa_kernel.samplers[i] = *temp;
8574 }
8575
8576 m_kernel_data_size += sizeof(m_cisa_kernel.sampler_count);
8577 m_kernel_data_size += m_sampler_info_size;
8578
8579 DEBUG_PRINT_SIZE("size after samplers: ", SIZE_VALUE);
8580
8581 /*****SURFACES******/
8582 unsigned int adjSurfaceCount = m_surface_count - Get_CISA_PreDefined_Surf_Count();
8583 m_cisa_kernel.surface_count = (uint8_t) adjSurfaceCount;
8584 m_cisa_kernel.surfaces = (state_info_t *) m_mem.alloc(sizeof(state_info_t) * adjSurfaceCount);
8585
8586 uint32_t surfaceInfoSize = 0;
8587 for (unsigned int i = 0, j = Get_CISA_PreDefined_Surf_Count(); i < adjSurfaceCount; i++, j++)
8588 {
8589 state_info_t * temp = &m_surface_info_list.at(j)->stateVar;
8590 m_cisa_kernel.surfaces[i] = *temp;
8591 surfaceInfoSize += temp->getSizeInBinary();
8592 }
8593
8594 m_kernel_data_size += sizeof(m_cisa_kernel.surface_count);
8595 m_kernel_data_size += surfaceInfoSize;
8596
8597 DEBUG_PRINT_SIZE("size after surfaces: ", SIZE_VALUE);
8598
8599 /*****VMES********/
8600 // VME variables are removed
8601 m_cisa_kernel.vme_count = 0;
8602 m_kernel_data_size += sizeof(m_cisa_kernel.vme_count);
8603
8604 DEBUG_PRINT_SIZE("size after VMEs: ", SIZE_VALUE);
8605
8606
8607 /*****INPUTS******/
8608
8609 if (getIsKernel())
8610 {
8611 m_input_offset = m_kernel_data_size;
8612 m_cisa_kernel.input_count = (uint8_t)m_input_count;
8613 m_cisa_kernel.inputs = (input_info_t *) m_mem.alloc(sizeof(input_info_t) * m_input_count);
8614
8615 std::vector<input_info_t *>::iterator it_input_info = m_input_info_list.begin();
8616 for (unsigned int i = 0; i < m_input_count; i++, it_input_info++)
8617 {
8618 MUST_BE_TRUE(it_input_info != m_input_info_list.end(), "Count of inputs does not correspond with number of items.");
8619 input_info_t * temp = *it_input_info;
8620 m_cisa_kernel.inputs[i] = *temp;
8621 }
8622 m_kernel_data_size += sizeof(m_cisa_kernel.input_count);
8623 m_kernel_data_size += m_input_info_size;
8624
8625 DEBUG_PRINT_SIZE("size after inputs: ", SIZE_VALUE);
8626 }
8627
8628 /*******INSTRUCTIONS SIZE*****/
8629 m_kernel_data_size += sizeof(m_cisa_kernel.size);
8630 m_cisa_kernel.size = m_instruction_size;
8631
8632 DEBUG_PRINT_SIZE("size after size: ", SIZE_VALUE);
8633
8634 /******OFFSET OF FIRST INSTRUCTION FROM KERNEL START*********/
8635 m_kernel_data_size += sizeof(m_cisa_kernel.entry);
8636
8637 DEBUG_PRINT_SIZE("size after entry: ", SIZE_VALUE);
8638
8639 if (!getIsKernel())
8640 {
8641 m_kernel_data_size += sizeof(m_cisa_kernel.input_size);
8642 DEBUG_PRINT_SIZE("size after input size: ", SIZE_VALUE);
8643
8644 m_kernel_data_size += sizeof(m_cisa_kernel.return_type);
8645 DEBUG_PRINT_SIZE("size after return type: ", SIZE_VALUE);
8646 }
8647
8648 /*******ATTRIBUTES**************/
8649 m_cisa_kernel.attribute_count = (uint16_t)m_attribute_count;
8650 m_cisa_kernel.attributes = (attribute_info_t *) m_mem.alloc(sizeof(attribute_info_t) * m_attribute_count);
8651
8652 std::list<attribute_info_t *>::iterator it_attribute_info = m_attribute_info_list.begin();
8653 for (unsigned int i = 0; i < m_attribute_count; i++, it_attribute_info++)
8654 {
8655 MUST_BE_TRUE(it_attribute_info != m_attribute_info_list.end(), "Count of attributes does not correspond with number of items.");
8656 attribute_info_t * temp = *it_attribute_info;
8657 m_cisa_kernel.attributes[i] = *temp;
8658 }
8659 m_kernel_data_size += sizeof(m_cisa_kernel.attribute_count);
8660 m_kernel_data_size += m_attribute_info_size;
8661
8662 DEBUG_PRINT_SIZE("size after attributes: ", SIZE_VALUE);
8663
8664 /******Setting Entry*********/
8665 m_cisa_kernel.entry = m_kernel_data_size;
8666
8667 m_cisa_binary_size = m_instruction_size + m_kernel_data_size;
8668 m_cisa_binary_buffer = (char *) m_mem.alloc(m_cisa_binary_size);
8669 }
8670
writeInToCisaBinaryBuffer(const void * value,int size)8671 unsigned long VISAKernelImpl::writeInToCisaBinaryBuffer(const void * value, int size)
8672 {
8673 MUST_BE_TRUE(m_bytes_written_cisa_buffer + size <= m_cisa_binary_size,
8674 "Size of VISA instructions binary buffer is exceeded.");
8675
8676 memcpy_s(&m_cisa_binary_buffer[m_bytes_written_cisa_buffer], size, value, size);
8677 m_bytes_written_cisa_buffer += size;
8678
8679 return m_bytes_written_cisa_buffer;
8680 }
8681
getLabelOperandFromFunctionName(const std::string & name)8682 VISA_LabelOpnd* VISAKernelImpl::getLabelOperandFromFunctionName(const std::string &name)
8683 {
8684 auto it = m_funcName_to_labelID_map.find(name);
8685 if (m_funcName_to_labelID_map.end() == it) {
8686 return nullptr;
8687 } else {
8688 return it->second;
8689 }
8690 }
8691
getLabelOpndFromLabelName(const std::string & name)8692 VISA_LabelOpnd* VISAKernelImpl::getLabelOpndFromLabelName(const std::string &name)
8693 {
8694 auto it = m_label_name_to_index_map.find(name);
8695 if (m_label_name_to_index_map.end() == it) {
8696 return nullptr;
8697 } else {
8698 return it->second;
8699 }
8700 }
8701
setLabelOpndNameMap(const std::string & name,VISA_LabelOpnd * lbl,VISA_Label_Kind kind)8702 bool VISAKernelImpl::setLabelOpndNameMap(const std::string &name, VISA_LabelOpnd *lbl, VISA_Label_Kind kind)
8703 {
8704 // TODO: Is it possible to merge the 2 maps? Or a function label and
8705 // a block label are allowed to have the same name?
8706 if (kind == LABEL_BLOCK) {
8707 auto Res = m_label_name_to_index_map.insert({name, lbl});
8708 return Res.second;
8709 } else {
8710 auto Res = m_funcName_to_labelID_map.insert({name, lbl});
8711 return Res.second;
8712 }
8713 }
8714
getDeclFromName(const std::string & name)8715 CISA_GEN_VAR * VISAKernelImpl::getDeclFromName(const std::string &name)
8716 {
8717 // First search in the unique var map
8718 auto it = m_UniqueNamedVarMap.find(name);
8719 if (it != m_UniqueNamedVarMap.end())
8720 {
8721 return it->second;
8722 }
8723
8724 // Search each scope level until var is found, starting from the back
8725 for (auto scope_it = m_GenNamedVarMap.rbegin(); scope_it != m_GenNamedVarMap.rend(); scope_it++)
8726 {
8727 auto it = scope_it->find(name);
8728 if (it != scope_it->end())
8729 {
8730 return it->second;
8731 }
8732 }
8733 return NULL;
8734 }
8735
declExistsInCurrentScope(const std::string & name) const8736 bool VISAKernelImpl::declExistsInCurrentScope(const std::string &name) const
8737 {
8738 // newest scope back and guaranteed to exist since we start with at least
8739 // one scope
8740 const GenDeclNameToVarMap &currScope = m_GenNamedVarMap.back();
8741 bool inCurrScope = currScope.find(name) != currScope.end();
8742 //
8743 // we also must prohibit globally reserved variables that must be
8744 // unique in all scopes (e.g. V0 or V1)
8745 bool reservedVarible =
8746 m_UniqueNamedVarMap.find(name) != m_UniqueNamedVarMap.end();
8747 return inCurrScope || reservedVarible;
8748 }
8749
setNameIndexMap(const std::string & name,CISA_GEN_VAR * genDecl,bool unique)8750 bool VISAKernelImpl::setNameIndexMap(const std::string &name, CISA_GEN_VAR * genDecl, bool unique)
8751 {
8752 MUST_BE_TRUE(!m_GenNamedVarMap.empty(), "decl map is empty!");
8753 if (!unique)
8754 {
8755 // make sure mapping doesn't already exist in the current scope
8756 if (m_GenNamedVarMap.back().find(name) != m_GenNamedVarMap.back().end())
8757 return false;
8758
8759 // also cannot be redefinition of a unique var
8760 if (m_UniqueNamedVarMap.find(name) != m_UniqueNamedVarMap.end())
8761 return false;
8762
8763 // Add var to the current scope
8764 m_GenNamedVarMap.back()[name] = genDecl;
8765 }
8766 else
8767 {
8768 // we cannot create a unique var that redefines any previously created var in any scope
8769 if (getDeclFromName(name) != NULL)
8770 return false;
8771
8772 // unique vars are stored in a separate map
8773 m_UniqueNamedVarMap[name] = genDecl;
8774 }
8775 return true;
8776 }
8777
pushIndexMapScopeLevel()8778 void VISAKernelImpl::pushIndexMapScopeLevel()
8779 {
8780 m_GenNamedVarMap.push_back(GenDeclNameToVarMap());
8781 }
popIndexMapScopeLevel()8782 void VISAKernelImpl::popIndexMapScopeLevel()
8783 {
8784 MUST_BE_TRUE(m_GenNamedVarMap.size() > 1, "Cannot pop base scope level!");
8785 m_GenNamedVarMap.pop_back();
8786 }
8787
get_hash_key(const char * str)8788 unsigned short VISAKernelImpl::get_hash_key(const char* str)
8789 {
8790 const char *str_pt = str;
8791 unsigned short key=0;
8792 unsigned char c;
8793 while ((c = *str_pt++) != '\0') key = (key+c)<<1;
8794
8795 return key % HASH_TABLE_SIZE;
8796 }
new_string_pool()8797 string_pool_entry** VISAKernelImpl::new_string_pool()
8798 {
8799 string_pool_entry ** sp = (string_pool_entry**)m_mem.alloc(sizeof(string_pool_entry *) * HASH_TABLE_SIZE);
8800 //memset(sp, 0, sizeof(string_pool_entry *) * HASH_TABLE_SIZE);
8801
8802 return sp;
8803 }
8804
~VISAKernelImpl()8805 VISAKernelImpl::~VISAKernelImpl()
8806 {
8807 std::list<CisaFramework::CisaInst *>::iterator iter = m_instruction_list.begin();
8808 for (; iter != m_instruction_list.end(); iter++)
8809 {
8810 CisaFramework::CisaInst * inst = *iter;
8811 inst->~CisaInst();
8812 }
8813
8814 m_var_info_list.clear();
8815 m_input_info_list.clear();
8816 m_label_info_list.clear();
8817 m_addr_info_list.clear();
8818
8819 if (IS_GEN_BOTH_PATH)
8820 {
8821 //need to call destructor even thought it is allocated in memory pool.
8822 //so that internal data structures get cleared.
8823 m_kernel->~G4_Kernel();
8824 m_builder->~IR_Builder();
8825 delete m_kernelMem;
8826 }
8827
8828 if (m_kernelInfo != nullptr)
8829 {
8830 delete m_kernelInfo;
8831 }
8832
8833 destroyKernelAttributes();
8834 }
8835
GetGenxBinary(void * & buffer,int & size) const8836 int VISAKernelImpl::GetGenxBinary(void *&buffer, int &size) const
8837 {
8838 buffer = m_genx_binary_buffer;
8839 size = m_genx_binary_size;
8840 return VISA_SUCCESS;
8841 }
8842
GetRelocations(RelocListType & relocs)8843 int VISAKernelImpl::GetRelocations(RelocListType &relocs)
8844 {
8845 G4_Kernel::RelocationTableTy& reloc_table = m_kernel->getRelocationTable();
8846 for (RelocationEntry& reloc : reloc_table)
8847 {
8848 G4_INST* inst = reloc.getInst();
8849 int64_t genOffset = inst->getGenOffset();
8850 uint32_t offset = static_cast<uint32_t>(genOffset + reloc.getTargetOffset(*m_builder));
8851 relocs.emplace_back(reloc.getType(), offset, reloc.getSymbolName());
8852 assert((genOffset != UNDEFINED_GEN_OFFSET) && (offset > genOffset) && (offset < genOffset + BYTES_PER_INST));
8853 }
8854 return VISA_SUCCESS;
8855 }
8856
GetGenRelocEntryBuffer(void * & buffer,unsigned int & byteSize,unsigned int & numEntries)8857 int VISAKernelImpl::GetGenRelocEntryBuffer(void *&buffer, unsigned int &byteSize, unsigned int &numEntries)
8858 {
8859 G4_Kernel::RelocationTableTy& reloc_table = m_kernel->getRelocationTable();
8860 numEntries = reloc_table.size();
8861 byteSize = sizeof(GenRelocEntry) * numEntries;
8862
8863 if (reloc_table.empty())
8864 return VISA_SUCCESS;
8865
8866 // allocate the buffer for relocation table
8867 buffer = allocCodeBlock(byteSize);
8868
8869 if (buffer == nullptr)
8870 return VISA_FAILURE;
8871
8872 GenRelocEntry* buffer_p = (GenRelocEntry*)buffer;
8873 for (auto reloc : reloc_table)
8874 {
8875 auto inst = reloc.getInst();
8876 buffer_p->r_type = reloc.getType();
8877 buffer_p->r_offset = static_cast<uint32_t>(inst->getGenOffset()) + reloc.getTargetOffset(*m_builder);
8878 assert((buffer_p->r_offset > inst->getGenOffset()) && (buffer_p->r_offset < inst->getGenOffset() + BYTES_PER_INST));
8879
8880 assert(reloc.getSymbolName().size() <= MAX_SYMBOL_NAME_LENGTH);
8881 // clean the buffer first
8882 memset(buffer_p->r_symbol, '0', MAX_SYMBOL_NAME_LENGTH);
8883 strcpy_s(buffer_p->r_symbol, MAX_SYMBOL_NAME_LENGTH, reloc.getSymbolName().c_str());
8884 ++buffer_p;
8885 }
8886
8887 return VISA_SUCCESS;
8888 }
8889
GetGenxDebugInfo(void * & buffer,unsigned int & size) const8890 int VISAKernelImpl::GetGenxDebugInfo(void *&buffer, unsigned int &size) const
8891 {
8892 buffer = m_genx_debug_info_buffer;
8893 size = m_genx_debug_info_size;
8894
8895 return VISA_SUCCESS;
8896 }
8897
GetJitInfo(FINALIZER_INFO * & jitInfo) const8898 int VISAKernelImpl::GetJitInfo(FINALIZER_INFO *&jitInfo) const
8899 {
8900 jitInfo = m_jitInfo;
8901 return VISA_SUCCESS;
8902 }
8903
GetKernelInfo(KERNEL_INFO * & kernelInfo) const8904 int VISAKernelImpl::GetKernelInfo(KERNEL_INFO*& kernelInfo) const
8905 {
8906 kernelInfo = m_kernelInfo;
8907 return VISA_SUCCESS;
8908 }
8909
GetCompilerStats(CompilerStats & compilerStats)8910 int VISAKernelImpl::GetCompilerStats(CompilerStats &compilerStats)
8911 {
8912 compilerStats.Link(m_compilerStats);
8913 return VISA_SUCCESS;
8914 }
8915
GetErrorMessage(const char * & errorMsg) const8916 int VISAKernelImpl::GetErrorMessage(const char *&errorMsg) const
8917 {
8918 // do nothing, doesn't seem like this is actually implemented
8919 return VISA_SUCCESS;
8920 }
8921
GetFunctionId(unsigned int & id) const8922 int VISAKernelImpl::GetFunctionId(unsigned int& id) const
8923 {
8924 id = m_functionId;
8925 return VISA_SUCCESS;
8926 }
8927
SetGTPinInit(void * buffer)8928 int VISAKernelImpl::SetGTPinInit(void* buffer)
8929 {
8930 if (!m_kernel)
8931 return VISA_FAILURE;
8932
8933 auto gtpin = m_kernel->getGTPinData();
8934 if (gtpin)
8935 {
8936 if (getOptions()->getOption(vISA_GTPinReRA) || getOptions()->getOption(vISA_GetFreeGRFInfo)
8937 || getOptions()->getuInt32Option(vISA_GTPinScratchAreaSize))
8938 {
8939 // GTPin init set by L0 driver through flags
8940 gtpin->setGTPinInitFromL0(true);
8941 }
8942 if (buffer)
8943 {
8944 gtpin->setGTPinInit(buffer);
8945 }
8946 }
8947
8948 return VISA_SUCCESS;
8949 }
8950
GetGTPinBuffer(void * & buffer,unsigned int & size)8951 int VISAKernelImpl::GetGTPinBuffer(void*& buffer, unsigned int& size)
8952 {
8953 buffer = nullptr;
8954 size = 0;
8955
8956 if (!m_kernel)
8957 return VISA_FAILURE;
8958
8959 auto gtpin = m_kernel->getGTPinData();
8960 if (gtpin)
8961 {
8962 buffer = gtpin->getGTPinInfoBuffer(size);
8963 }
8964
8965 return VISA_SUCCESS;
8966 }
8967
GetFreeGRFInfo(void * & buffer,unsigned int & size)8968 int VISAKernelImpl::GetFreeGRFInfo(void*& buffer, unsigned int& size)
8969 {
8970 buffer = nullptr;
8971 size = 0;
8972
8973 if (getOptions()->getOption(vISA_GetFreeGRFInfo))
8974 {
8975 assert(m_kernel);
8976 auto gtpin = m_kernel->getGTPinData();
8977 if (gtpin)
8978 {
8979 buffer = gtpin->getFreeGRFInfo(size);
8980 }
8981 }
8982 return VISA_SUCCESS;
8983 }
8984
8985 // index
CreateOtherOpnd(unsigned int value,VISA_Type opndType)8986 VISA_opnd* VISAKernelImpl::CreateOtherOpnd(unsigned int value, VISA_Type opndType)
8987 {
8988 VISA_opnd *temp = getOpndFromPool();
8989
8990 temp->_opnd.other_opnd = value;
8991 temp->opnd_type = CISA_OPND_OTHER;
8992 temp->size = (uint16_t) Get_VISA_Type_Size(opndType);
8993 return temp;
8994 }
8995
8996 //FIXME: this needs major rework
CreateOtherOpndHelper(int num_pred_desc_operands,int num_operands,VISA_INST_Desc * inst_desc,unsigned int value,bool hasSubOpcode,uint8_t subOpcode)8997 VISA_opnd* VISAKernelImpl::CreateOtherOpndHelper(int num_pred_desc_operands, int num_operands, VISA_INST_Desc *inst_desc, unsigned int value, bool hasSubOpcode, uint8_t subOpcode)
8998 {
8999 VISA_Type dataType = ISA_TYPE_NUM;
9000 VISA_opnd *temp = getOpndFromPool();
9001
9002 if (!hasSubOpcode)
9003 {
9004 dataType = (VISA_Type)inst_desc->opnd_desc[num_pred_desc_operands + num_operands].data_type;
9005 }
9006 else
9007 {
9008 //Accounts for all the operands added so far to instruction, minus predefined ones: execSize, pred, op
9009 dataType = (VISA_Type)inst_desc->getSubInstDesc(subOpcode).opnd_desc[num_operands - (inst_desc->opnd_num - num_pred_desc_operands) ].data_type;
9010 }
9011 temp->_opnd.other_opnd = value;
9012 temp->opnd_type = CISA_OPND_OTHER;
9013 temp->size = Get_VISA_Type_Size(dataType);
9014 temp->tag = (uint8_t)inst_desc->opnd_desc[num_pred_desc_operands + num_operands].opnd_type;
9015
9016 return temp;
9017 }
9018
getOpndFromPool()9019 VISA_opnd* VISAKernelImpl::getOpndFromPool()
9020 {
9021 VISA_opnd *newOp = nullptr;
9022 if (IS_VISA_BOTH_PATH)
9023 {
9024 newOp = (VISA_opnd *)m_mem.alloc(sizeof(VISA_opnd));
9025 }
9026 else
9027 {
9028 newOp = &m_fastPathOpndPool[(m_opndCounter++) % vISA_NUMBER_OF_OPNDS_IN_POOL];
9029 }
9030 memset(newOp, 0, sizeof(*newOp));
9031 return newOp;
9032 }
9033
CommonISABuildPreDefinedSrc(int index,uint16_t vStride,uint16_t width,uint16_t hStride,uint8_t rowOffset,uint8_t colOffset,VISA_Modifier modifier)9034 G4_Operand* VISAKernelImpl::CommonISABuildPreDefinedSrc(
9035 int index, uint16_t vStride, uint16_t width,
9036 uint16_t hStride, uint8_t rowOffset, uint8_t colOffset, VISA_Modifier modifier)
9037 {
9038 const RegionDesc *rd = m_builder->createRegionDesc(vStride, width, hStride);
9039 G4_Operand* tmpsrc = NULL;
9040 PreDefinedVarsInternal internalIndex = mapExternalToInternalPreDefVar(index);
9041 switch (internalIndex)
9042 {
9043 case PreDefinedVarsInternal::X:
9044 case PreDefinedVarsInternal::Y:
9045 case PreDefinedVarsInternal::LOCAL_ID_X:
9046 case PreDefinedVarsInternal::LOCAL_ID_Y:
9047 case PreDefinedVarsInternal::LOCAL_SIZE_X:
9048 case PreDefinedVarsInternal::LOCAL_SIZE_Y:
9049 case PreDefinedVarsInternal::GROUP_ID_X:
9050 case PreDefinedVarsInternal::GROUP_ID_Y:
9051 case PreDefinedVarsInternal::GROUP_ID_Z:
9052 case PreDefinedVarsInternal::GROUP_COUNT_X:
9053 case PreDefinedVarsInternal::GROUP_COUNT_Y:
9054 {
9055 G4_Type type = GetGenTypeFromVISAType(getPredefinedVarType(internalIndex));
9056 // R0 is already declared
9057 G4_Declare *pre_var_dcl = getGenVar(index)->genVar.dcl;
9058 tmpsrc = m_builder->createSrcRegRegion(
9059 GetGenSrcModFromVISAMod(modifier),
9060 Direct,
9061 pre_var_dcl->getRegVar(),
9062 0,
9063 0,
9064 rd,
9065 type);
9066 break;
9067 }
9068 case PreDefinedVarsInternal::TSC:
9069 case PreDefinedVarsInternal::R0:
9070 case PreDefinedVarsInternal::SR0:
9071 case PreDefinedVarsInternal::CR0:
9072 case PreDefinedVarsInternal::CE0:
9073 case PreDefinedVarsInternal::ARG:
9074 case PreDefinedVarsInternal::RET:
9075 case PreDefinedVarsInternal::FE_SP:
9076 case PreDefinedVarsInternal::FE_FP:
9077 case PreDefinedVarsInternal::HW_TID:
9078 case PreDefinedVarsInternal::DBG:
9079 case PreDefinedVarsInternal::COLOR:
9080 {
9081 G4_Type type = GetGenTypeFromVISAType(getPredefinedVarType(internalIndex));
9082 G4_Declare *preVarDcl = getGenVar(index)->genVar.dcl;
9083 tmpsrc = m_builder->createSrcRegRegion(
9084 GetGenSrcModFromVISAMod(modifier),
9085 Direct,
9086 preVarDcl->getRegVar(),
9087 rowOffset,
9088 colOffset,
9089 rd,
9090 type);
9091 break;
9092 }
9093 default:
9094 ASSERT_USER(false, "unsupported pre-defined variable");
9095 }
9096
9097 m_builder->preDefVars.setHasPredefined(internalIndex, true);
9098 return tmpsrc;
9099 }
9100
setName(const char * n)9101 void VISAKernelImpl::setName(const char* n)
9102 {
9103 if (n[0] == '\0') return;
9104 m_cisa_kernel.name_index = addStringPool(n);
9105 m_name = m_string_pool[m_cisa_kernel.name_index];
9106 if (m_kernel)
9107 {
9108 m_kernel->setName(m_name.c_str());
9109 }
9110 }
9111
setInputSize(uint8_t size)9112 void VISAKernelImpl::setInputSize(uint8_t size)
9113 {
9114 m_cisa_kernel.input_size = size;
9115 }
9116
setReturnSize(unsigned int size)9117 void VISAKernelImpl::setReturnSize(unsigned int size)
9118 {
9119 m_cisa_kernel.return_value_size = (uint8_t)size;
9120 }
9121
SetFunctionInputSize(unsigned int size)9122 int VISAKernelImpl::SetFunctionInputSize(unsigned int size)
9123 {
9124 setInputSize((uint8_t)size);
9125 return VISA_SUCCESS;
9126 }
9127
SetFunctionReturnSize(unsigned int size)9128 int VISAKernelImpl::SetFunctionReturnSize(unsigned int size)
9129 {
9130 setReturnSize(size);
9131 return VISA_SUCCESS;
9132 }
9133
9134 // common tasks for AppendVISAInst* functions
9135 // currently we just increment the VISA offset to make sure it is set correctly
9136 // for each GEN instruction
AppendVISAInstCommon()9137 void VISAKernelImpl::AppendVISAInstCommon()
9138 {
9139 m_vISAInstCount++;
9140 if (IS_GEN_BOTH_PATH)
9141 {
9142 m_builder->curCISAOffset = getvIsaInstCount();
9143 }
9144 }
9145
getVISAOffset() const9146 int VISAKernelImpl::getVISAOffset() const
9147 {
9148 if (IS_GEN_BOTH_PATH)
9149 {
9150 return m_builder->curCISAOffset;
9151 }
9152 // TODO: we should probably move vISA offset in VISKernelImpl so that we
9153 // have it in vISA path too
9154 return -1;
9155 }
9156
computeFCInfo(BinaryEncodingBase * binEncodingInstance)9157 void VISAKernelImpl::computeFCInfo(BinaryEncodingBase* binEncodingInstance)
9158 {
9159 // This function iterates over all instructions in kernel and sets up data
9160 // structures used to emit FC patch file later on after compilation for
9161 // all kernels is complete.
9162 // This function should be invoked only after binary encoding pass.
9163 std::map<BinInst*, std::pair<G4_INST*, bool>> FCInstMap;
9164 G4_Kernel* kernel = getKernel();
9165 IR_Builder* builder = getIRBuilder();
9166
9167 if (isFCCallerKernel() == false && isFCCallableKernel() == false)
9168 {
9169 // No need to do anything since the kernel doesnt
9170 // have any FC calls.
9171 return;
9172 }
9173
9174 // First populate FCInstMap map that holds all pseudo_fc_call/ret
9175 // instructions in the kernel.
9176 BB_LIST_ITER bb_end = kernel->fg.end();
9177 for (BB_LIST_ITER bb_it = kernel->fg.begin();
9178 bb_it != bb_end;
9179 bb_it++)
9180 {
9181 G4_BB* bb = (*bb_it);
9182
9183 INST_LIST_ITER inst_end = bb->end();
9184 for (INST_LIST_ITER inst_it = bb->begin();
9185 inst_it != inst_end;
9186 inst_it++)
9187 {
9188 G4_INST* inst = (*inst_it);
9189 G4_opcode opc = inst->opcode();
9190
9191 if (opc == G4_pseudo_fc_call)
9192 {
9193 FCInstMap.emplace(inst->getBinInst(), std::make_pair(inst, true));
9194 }
9195 else if (opc == G4_pseudo_fc_ret)
9196 {
9197 FCInstMap.emplace(inst->getBinInst(), std::make_pair(inst, false));
9198 }
9199 }
9200 }
9201
9202 BinInstList& binInstList = binEncodingInstance->getBinInstList();
9203 for (unsigned i = 0, size = (unsigned) binInstList.size(); i < size; i++)
9204 {
9205 BinInst* bin = binInstList[i];
9206
9207 std::map<BinInst*, std::pair<G4_INST*, bool>>::iterator fcMapIt = FCInstMap.find(bin);
9208
9209 if (fcMapIt != FCInstMap.end())
9210 {
9211 if (fcMapIt->second.second == true)
9212 {
9213 // pseudo_fc_call
9214 FCCalls* callToPatch = (FCCalls*)builder->mem.alloc(sizeof(FCCalls));
9215 callToPatch->callOffset = i;
9216 unsigned int strLength = (uint32_t) strlen(((G4_Label*)(fcMapIt->second.first->getSrc(0)))->getLabel());
9217 char* labelString = (char*)builder->mem.alloc(strLength + 1);
9218
9219 strcpy_s(labelString, strLength + 1, ((G4_Label*)(fcMapIt->second.first->getSrc(0)))->getLabel());
9220
9221 callToPatch->calleeLabelString = labelString;
9222
9223 builder->getFCPatchInfo()->getFCCallsToPatch().push_back(callToPatch);
9224 }
9225 else
9226 {
9227 // pseduo_fc_ret
9228 builder->getFCPatchInfo()->getFCReturnsToPatch().push_back(i);
9229 }
9230 }
9231 }
9232 }
9233
computeFCInfo()9234 void VISAKernelImpl::computeFCInfo() {
9235 // This function iterates over all instructions in kernel and sets up data
9236 // structures used to emit FC patch file later on after compilation for
9237 // all kernels is complete.
9238 // This function should be invoked only after binary encoding pass.
9239 G4_Kernel* kernel = getKernel();
9240 IR_Builder* builder = getIRBuilder();
9241
9242 if (isFCCallerKernel() == false && isFCCallableKernel() == false) {
9243 // No need to do anything since the kernel doesnt
9244 // have any FC calls.
9245 return;
9246 }
9247
9248 // First populate FCInstMap map that holds all pseudo_fc_call/ret
9249 // instructions in the kernel.
9250 BB_LIST_ITER bb_end = kernel->fg.end();
9251 for (BB_LIST_ITER bb_it = kernel->fg.begin();
9252 bb_it != bb_end;
9253 bb_it++) {
9254 G4_BB* bb = (*bb_it);
9255
9256 INST_LIST_ITER inst_end = bb->end();
9257 for (INST_LIST_ITER inst_it = bb->begin();
9258 inst_it != inst_end;
9259 inst_it++) {
9260 G4_INST* inst = (*inst_it);
9261 G4_opcode opc = inst->opcode();
9262
9263 if (opc == G4_pseudo_fc_call) {
9264 // TODO: Need to create FCCalls and push into calls-to-patch.
9265 // FCInstMap.insert(make_pair(inst->getBinInst(), make_pair(inst, true)));
9266 ASSERT_USER(inst->getGenOffset() % 16 == 0, "Non-128-bit instruction is found!");
9267 unsigned Slot = unsigned(inst->getGenOffset()) / 16;
9268 FCCalls *CallToPatch = (FCCalls *)builder->mem.alloc(sizeof(FCCalls));
9269 CallToPatch->callOffset = Slot;
9270 G4_Label *Label = inst->getSrc(0)->asLabel();
9271 size_t Len = strlen(Label->getLabel());
9272 char *S = (char *)builder->mem.alloc(Len + 1);
9273 strcpy_s(S, Len + 1, Label->getLabel());
9274 CallToPatch->calleeLabelString = S;
9275 builder->getFCPatchInfo()->getFCCallsToPatch().push_back(CallToPatch);
9276 } else if (opc == G4_pseudo_fc_ret) {
9277 ASSERT_USER(inst->getGenOffset() % 16 == 0, "Non-128-bit instruction is found!");
9278 unsigned Slot = unsigned(inst->getGenOffset()) / 16;
9279 builder->getFCPatchInfo()->getFCReturnsToPatch().push_back(Slot);
9280 }
9281 }
9282 }
9283 }
9284
9285
9286 ///Gets declaration id GenVar
getDeclarationID(VISA_GenVar * decl) const9287 int VISAKernelImpl::getDeclarationID(VISA_GenVar *decl) const
9288 {
9289 return decl->index;
9290 }
9291
9292 ///Gets declaration id VISA_AddrVar
getDeclarationID(VISA_AddrVar * decl) const9293 int VISAKernelImpl::getDeclarationID(VISA_AddrVar *decl) const
9294 {
9295 return decl->index;
9296 }
9297
9298 ///Gets declaration id VISA_PredVar
getDeclarationID(VISA_PredVar * decl) const9299 int VISAKernelImpl::getDeclarationID(VISA_PredVar *decl) const
9300 {
9301 return decl->index;
9302 }
9303
9304 ///Gets declaration id VISA_SamplerVar
getDeclarationID(VISA_SamplerVar * decl) const9305 int VISAKernelImpl::getDeclarationID(VISA_SamplerVar *decl) const
9306 {
9307 return decl->index;
9308 }
9309
9310 ///Gets declaration id VISA_SurfaceVar
getDeclarationID(VISA_SurfaceVar * decl) const9311 int VISAKernelImpl::getDeclarationID(VISA_SurfaceVar *decl) const
9312 {
9313 return decl->index;
9314 }
9315
9316 ///Gets declaration id VISA_LabelVar
getDeclarationID(VISA_LabelVar * decl) const9317 int VISAKernelImpl::getDeclarationID(VISA_LabelVar *decl) const
9318 {
9319 return decl->index;
9320 }
9321
getGenOffset() const9322 int64_t VISAKernelImpl::getGenOffset() const
9323 {
9324 assert(false == m_kernel->fg.empty());
9325 auto &entryBB = *(*m_kernel->fg.begin());
9326
9327 // the offset of the first gen inst in this kernel/function
9328 assert(false == entryBB.empty());
9329 auto inst = entryBB.begin();
9330 while ((UNDEFINED_GEN_OFFSET == (*inst)->getGenOffset()) && (entryBB.end() != inst)) {
9331 assert((*inst)->isLabel());
9332 ++inst;
9333 }
9334 assert(inst != entryBB.end());
9335
9336 auto entryPointOffset = (*inst)->getGenOffset();
9337 return entryPointOffset;
9338 }
9339
getGenSize() const9340 int64_t VISAKernelImpl::getGenSize() const
9341 {
9342 assert(false == m_kernel->fg.empty());
9343 auto &lastBB = *(*m_kernel->fg.rbegin());
9344
9345 // the offset of the last gen inst in this kernel/function
9346 assert(false == lastBB.empty());
9347 auto inst = lastBB.rbegin();
9348 assert(UNDEFINED_GEN_OFFSET != (*inst)->getGenOffset()); // expecting terminator
9349
9350 auto size = (*inst)->getGenOffset();
9351 size += (*inst)->isCompactedInst() ? (BYTES_PER_INST / 2) : BYTES_PER_INST;
9352 size -= getGenOffset();
9353 return size;
9354 }
9355
getNumRegTotal() const9356 unsigned VISAKernelImpl::getNumRegTotal() const
9357 {
9358 return m_kernel->getNumRegTotal();
9359 }
9360
getFunctionName() const9361 const char* VISAKernelImpl::getFunctionName() const
9362 {
9363 return m_kernel->getName();
9364 }
9365
getVISAAsm() const9366 std::string VISAKernelImpl::getVISAAsm() const
9367 {
9368 // Return an empty string if the builder option is GEN only.
9369 if (IS_GEN_PATH)
9370 return std::string();
9371
9372 const VISAKernelImpl* fmtKernel =
9373 m_CISABuilder->m_cisaBinary->getFmtKernelForISADump(this, m_CISABuilder->getKernels());
9374 return m_CISABuilder->m_cisaBinary->isaDump(this, fmtKernel);
9375 }
9376
computeAndEmitDebugInfo(VISAKernelImplListTy & functions)9377 void VISAKernelImpl::computeAndEmitDebugInfo(VISAKernelImplListTy& functions)
9378 {
9379 std::list<VISAKernelImpl*> compilationUnitsForDebugInfo;
9380 compilationUnitsForDebugInfo.push_back(this);
9381 auto funcEndIt = functions.end();
9382 for (auto funcIt = functions.begin();
9383 funcIt != funcEndIt;
9384 funcIt++)
9385 {
9386 compilationUnitsForDebugInfo.push_back((*funcIt));
9387 }
9388
9389 std::list<G4_BB*> stackCallEntryBBs;
9390 auto cunitsEnd = compilationUnitsForDebugInfo.end();
9391 for (auto cunitsIt = compilationUnitsForDebugInfo.begin();
9392 cunitsIt != cunitsEnd;
9393 cunitsIt++)
9394 {
9395 VISAKernelImpl* cunit = (*cunitsIt);
9396 if (cunit->getIsKernel() == false)
9397 {
9398 getKernel()->getKernelDebugInfo()->markStackCallFuncDcls(*cunit->m_kernel);
9399 stackCallEntryBBs.push_back(cunit->getKernel()->fg.getEntryBB());
9400 }
9401 }
9402
9403 for (auto cunitsIt = compilationUnitsForDebugInfo.begin();
9404 cunitsIt != cunitsEnd;
9405 cunitsIt++)
9406 {
9407 G4_Kernel& curKernel = *(*cunitsIt)->getKernel();
9408 curKernel.getKernelDebugInfo()->computeDebugInfo(stackCallEntryBBs);
9409 }
9410
9411 #ifndef DLL_MODE
9412 if (getOptions()->getOption(vISA_outputToFile))
9413 {
9414 std::string asmNameStr = getOutputAsmPath();
9415 std::string debugFileNameStr = asmNameStr + ".dbg";
9416 emitDebugInfo(this, functions, debugFileNameStr);
9417 }
9418 #else
9419 void* ptr;
9420 unsigned size;
9421 emitDebugInfoToMem(this, functions, ptr, size);
9422 setGenxDebugInfoBuffer((char*)ptr, size);
9423 #endif
9424 }
9425
9426 extern "C" void freeBlock(void* ptr);
9427
9428 // buf contains instance of gtpin_init_t
enableSrcLine(void * buf)9429 bool enableSrcLine(void* buf)
9430 {
9431 if (!buf)
9432 return false;
9433
9434 auto gtpin_init_data = (gtpin::igc::igc_init_t*)buf;
9435 return gtpin_init_data->srcline_mapping != 0;
9436 }
9437