[clang] f3baa73 - [clang][bytecode] Implement ia32_{pdep,pext} builtins (#110675)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 1 08:17:41 PDT 2024
Author: Timm Baeder
Date: 2024-10-01T17:17:37+02:00
New Revision: f3baa73c8b212cc039abf1bc3bb2024df8acae02
URL: https://github.com/llvm/llvm-project/commit/f3baa73c8b212cc039abf1bc3bb2024df8acae02
DIFF: https://github.com/llvm/llvm-project/commit/f3baa73c8b212cc039abf1bc3bb2024df8acae02.diff
LOG: [clang][bytecode] Implement ia32_{pdep,pext} builtins (#110675)
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 347b23d7b89c46..ebc800623f0d48 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -1219,6 +1219,48 @@ static bool interp__builtin_ia32_tzcnt(InterpState &S, CodePtr OpPC,
return true;
}
+static bool interp__builtin_ia32_pdep(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func,
+ const CallExpr *Call) {
+ PrimType ValT = *S.Ctx.classify(Call->getArg(0));
+ PrimType MaskT = *S.Ctx.classify(Call->getArg(1));
+
+ APSInt Val =
+ peekToAPSInt(S.Stk, ValT, align(primSize(ValT)) + align(primSize(MaskT)));
+ APSInt Mask = peekToAPSInt(S.Stk, MaskT);
+
+ unsigned BitWidth = Val.getBitWidth();
+ APInt Result = APInt::getZero(BitWidth);
+ for (unsigned I = 0, P = 0; I != BitWidth; ++I) {
+ if (Mask[I])
+ Result.setBitVal(I, Val[P++]);
+ }
+ pushInteger(S, Result, Call->getType());
+ return true;
+}
+
+static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func,
+ const CallExpr *Call) {
+ PrimType ValT = *S.Ctx.classify(Call->getArg(0));
+ PrimType MaskT = *S.Ctx.classify(Call->getArg(1));
+
+ APSInt Val =
+ peekToAPSInt(S.Stk, ValT, align(primSize(ValT)) + align(primSize(MaskT)));
+ APSInt Mask = peekToAPSInt(S.Stk, MaskT);
+
+ unsigned BitWidth = Val.getBitWidth();
+ APInt Result = APInt::getZero(BitWidth);
+ for (unsigned I = 0, P = 0; I != BitWidth; ++I) {
+ if (Mask[I])
+ Result.setBitVal(P++, Val[I]);
+ }
+ pushInteger(S, Result, Call->getType());
+ return true;
+}
+
static bool interp__builtin_os_log_format_buffer_size(InterpState &S,
CodePtr OpPC,
const InterpFrame *Frame,
@@ -1832,6 +1874,18 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
return false;
break;
+ case clang::X86::BI__builtin_ia32_pdep_si:
+ case clang::X86::BI__builtin_ia32_pdep_di:
+ if (!interp__builtin_ia32_pdep(S, OpPC, Frame, F, Call))
+ return false;
+ break;
+
+ case clang::X86::BI__builtin_ia32_pext_si:
+ case clang::X86::BI__builtin_ia32_pext_di:
+ if (!interp__builtin_ia32_pext(S, OpPC, Frame, F, Call))
+ return false;
+ break;
+
case Builtin::BI__builtin_os_log_format_buffer_size:
if (!interp__builtin_os_log_format_buffer_size(S, OpPC, Frame, F, Call))
return false;
More information about the cfe-commits
mailing list