[clang] 57ca62d - [clang][Interp] Implement __builtin_copysign
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 28 01:55:54 PDT 2023
Author: Timm Bäder
Date: 2023-07-28T10:55:34+02:00
New Revision: 57ca62d5d35a424722059f42da4a6c75fbba2eb0
URL: https://github.com/llvm/llvm-project/commit/57ca62d5d35a424722059f42da4a6c75fbba2eb0
DIFF: https://github.com/llvm/llvm-project/commit/57ca62d5d35a424722059f42da4a6c75fbba2eb0.diff
LOG: [clang][Interp] Implement __builtin_copysign
Differential Revision: https://reviews.llvm.org/D155368
Added:
Modified:
clang/lib/AST/Interp/InterpBuiltin.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 7d8ca716cc8025..e4c0091452e399 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -130,6 +130,19 @@ static bool interp__builtin_inf(InterpState &S, CodePtr OpPC,
return true;
}
+static bool interp__builtin_copysign(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *F) {
+ const Floating &Arg1 = getParam<Floating>(Frame, 0);
+ const Floating &Arg2 = getParam<Floating>(Frame, 1);
+
+ APFloat Copy = Arg1.getAPFloat();
+ Copy.copySign(Arg2.getAPFloat());
+ S.Stk.push<Floating>(Floating(Copy));
+
+ return true;
+}
+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
InterpFrame *Frame = S.Current;
APValue Dummy;
@@ -174,6 +187,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
if (interp__builtin_inf(S, OpPC, Frame, F))
return Ret<PT_Float>(S, OpPC, Dummy);
break;
+ case Builtin::BI__builtin_copysign:
+ case Builtin::BI__builtin_copysignf:
+ case Builtin::BI__builtin_copysignl:
+ case Builtin::BI__builtin_copysignf128:
+ if (interp__builtin_copysign(S, OpPC, Frame, F))
+ return Ret<PT_Float>(S, OpPC, Dummy);
+ break;
default:
return false;
More information about the cfe-commits
mailing list