Skip to content

Commit

Permalink
[clang][Interp] Implement __builtin_copysign
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D155368
  • Loading branch information
tbaederr committed Jul 28, 2023
1 parent 3c0604b commit 57ca62d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions clang/lib/AST/Interp/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 57ca62d

Please sign in to comment.