https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/110675
None >From e57f67c73af56e510943612e4eff651838706b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Tue, 1 Oct 2024 15:41:43 +0200 Subject: [PATCH] [clang][bytecode] Implement ia32_{pdep,pext} builtins --- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 54 ++++++++++++++++++++++++ 1 file changed, 54 insertions(+) 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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits