From 78c9bd1c2fbd55889e62a2032e9bc96684ced3b5 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:50:44 -0600 Subject: Bit extract (#5847) * promoting bitfield extraction and insertion to become intrinsics for internal compiler use * removing duplicate intrinsics from glsl.meta.slang * refactor: update function signatures of bitfield extraction and insertion to use uint as the parameter type for offset and bits. --------- Co-authored-by: Nate Morrical Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index d1c16a3a1..5e5d94b14 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -1950,6 +1950,20 @@ static T* createInst( return createInstImpl(builder, op, type, 3, &args[0]); } +template +static T* createInst( + IRBuilder* builder, + IROp op, + IRType* type, + IRInst* arg1, + IRInst* arg2, + IRInst* arg3, + IRInst* arg4) +{ + IRInst* args[] = {arg1, arg2, arg3, arg4}; + return createInstImpl(builder, op, type, 4, &args[0]); +} + template static T* createInstWithTrailingArgs( IRBuilder* builder, @@ -3625,7 +3639,25 @@ IRInst* IRBuilder::emitLookupInterfaceMethodInst( IRInst* IRBuilder::emitGetSequentialIDInst(IRInst* rttiObj) { auto inst = createInst(this, kIROp_GetSequentialID, getUIntType(), rttiObj); + addInst(inst); + return inst; +} +IRInst* IRBuilder::emitBitfieldExtract(IRType* type, IRInst* value, IRInst* offset, IRInst* bits) +{ + auto inst = createInst(this, kIROp_BitfieldExtract, type, value, offset, bits); + addInst(inst); + return inst; +} + +IRInst* IRBuilder::emitBitfieldInsert( + IRType* type, + IRInst* base, + IRInst* insert, + IRInst* offset, + IRInst* bits) +{ + auto inst = createInst(this, kIROp_BitfieldInsert, type, base, insert, offset, bits); addInst(inst); return inst; } @@ -8188,6 +8220,8 @@ bool IRInst::mightHaveSideEffects(SideEffectAnalysisOptions options) case kIROp_PtrCast: case kIROp_CastDynamicResource: case kIROp_AllocObj: + case kIROp_BitfieldExtract: + case kIROp_BitfieldInsert: case kIROp_PackAnyValue: case kIROp_UnpackAnyValue: case kIROp_Reinterpret: -- cgit v1.2.3