Skip to content

Commit 7dc49cd

Browse files
ashwinikardileigcbot
authored andcommitted
Create a GenISA intrinsic for native Mad instructions
Create a GenISA intrinsic for native Mad instructions
1 parent d17b45a commit 7dc49cd

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ namespace IGC
338338
// src0 * src1 + src2
339339
inline void Madw(CVariable* dst, CVariable* src0, CVariable* src1, CVariable* src2);
340340
inline void Mad(CVariable* dst, CVariable* src0, CVariable* src1, CVariable* src2);
341+
inline void NativeMad(CVariable* dst, CVariable* src0, CVariable* src1, CVariable* src2);
341342
inline void Lrp(CVariable* dst, CVariable* src0, CVariable* src1, CVariable* src2);
342343
inline void Xor(CVariable* dst, CVariable* src0, CVariable* src1);
343344
inline void Or(CVariable* dst, CVariable* src0, CVariable* src1);
@@ -933,6 +934,12 @@ namespace IGC
933934
Arithmetic(ISA_MAD, dst, src0, src1, src2);
934935
}
935936

937+
// src0 * src1 + src2
938+
inline void CEncoder::NativeMad(CVariable* dst, CVariable* src0, CVariable* src1, CVariable* src2)
939+
{
940+
Arithmetic(ISA_MAD, dst, src0, src1, src2);
941+
}
942+
936943
inline void CEncoder::Lrp(CVariable* dst, CVariable* src0, CVariable* src1, CVariable* src2)
937944
{
938945
Arithmetic(ISA_LRP, dst, src0, src1, src2);

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9115,6 +9115,9 @@ void EmitPass::EmitGenIntrinsicMessage(llvm::GenIntrinsicInst* inst)
91159115
case GenISAIntrinsic::GenISA_frc:
91169116
emitFrc(inst);
91179117
break;
9118+
case GenISAIntrinsic::GenISA_nativeMad:
9119+
emitNativeMad(inst);
9120+
break;
91189121
case GenISAIntrinsic::GenISA_RenderTargetRead:
91199122
case GenISAIntrinsic::GenISA_RenderTargetReadSampleFreq:
91209123
emitRenderTargetRead(inst);
@@ -16212,6 +16215,18 @@ void EmitPass::emitFMArtn(llvm::GenIntrinsicInst *inst) {
1621216215
ResetRoundingMode(inst);
1621316216
}
1621416217

16218+
void EmitPass::emitNativeMad(llvm::GenIntrinsicInst* inst) {
16219+
IGC_ASSERT_MESSAGE(inst->getNumArgOperands() == 3, "ICE: incorrect gen intrinsic");
16220+
16221+
CVariable* src0 = GetSymbol(inst->getOperand(0));
16222+
CVariable* src1 = GetSymbol(inst->getOperand(1));
16223+
CVariable* src2 = GetSymbol(inst->getOperand(2));
16224+
CVariable* dst = m_destination;
16225+
16226+
m_encoder->NativeMad(dst, src0, src1, src2);
16227+
m_encoder->Push();
16228+
}
16229+
1621516230
void EmitPass::emitftoi(llvm::GenIntrinsicInst* inst)
1621616231
{
1621716232
IGC_ASSERT_MESSAGE(inst->getOperand(0)->getType()->isFloatingPointTy(), "Unsupported type");

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ class EmitPass : public llvm::FunctionPass
449449
void emitLLVMStackSave(llvm::IntrinsicInst* inst);
450450
void emitLLVMStackRestore(llvm::IntrinsicInst* inst);
451451

452+
void emitNativeMad(llvm::GenIntrinsicInst* inst);
453+
452454
void emitUnmaskedRegionBoundary(bool start);
453455
void emitDpas(llvm::GenIntrinsicInst *GII,
454456
const SSource* source,

IGC/GenISAIntrinsics/Intrinsic_definitions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,5 +2374,12 @@
23742374
[("float4", ""),
23752375
[("int", "usage"),
23762376
("int", "owordOffset")],
2377-
"ReadMem"]]
2377+
"ReadMem"]],
2378+
####################################################################################################
2379+
"GenISA_nativeMad": ["Native Mad instruction intrinsic",
2380+
[("anyfloat", "dest"),
2381+
[(0, "src0"),
2382+
(0, "src1"),
2383+
(0, "src2")],
2384+
"NoMem"]]
23782385
}

IGC/LLVM3DBuilder/BuiltinsFrontend.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ class LLVM3DBuilder : public llvm::IGCIRBuilder<T, InserterTyDef()>
218218
llvm::Value* float_src1,
219219
llvm::Value* float_src2);
220220

221+
llvm::Value* Create_MAD(
222+
llvm::Value* float_src0,
223+
llvm::Value* float_src1,
224+
llvm::Value* float_src2);
225+
221226
llvm::Value* Create_resinfo(
222227
llvm::Value* int32_src_s_mip,
223228
llvm::Value* int32_textureIdx);

IGC/LLVM3DBuilder/BuiltinsFrontendDefinitions.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,19 @@ llvm::Value* LLVM3DBuilder<preserveNames, T, Inserter>::CreateDeriveRTY_Fine(llv
34053405
return this->CreateCall(floor, V);
34063406
}
34073407

3408+
template<bool preserveNames, typename T, typename Inserter>
3409+
llvm::Value* LLVM3DBuilder<preserveNames, T, Inserter>::Create_MAD(llvm::Value* float_src0, llvm::Value* float_src1, llvm::Value* float_src2)
3410+
{
3411+
llvm::Module* const module = this->GetInsertBlock()->getParent()->getParent();
3412+
IGC_ASSERT(nullptr != float_src0);
3413+
3414+
llvm::Function* madFunc = llvm::GenISAIntrinsic::getDeclaration(module, llvm::GenISAIntrinsic::GenISA_nativeMad, float_src0->getType());
3415+
llvm::Value* args[] = { float_src0, float_src1, float_src2 };
3416+
llvm::Value* float_madres_s = this->CreateCall(madFunc, args);
3417+
3418+
return float_madres_s;
3419+
}
3420+
34083421
template<bool preserveNames, typename T, typename Inserter>
34093422
llvm::Value* LLVM3DBuilder<preserveNames, T, Inserter>::Create_MAD_Scalar(llvm::Value* float_src0, llvm::Value* float_src1, llvm::Value* float_src2)
34103423
{

0 commit comments

Comments
 (0)