tbaeder created this revision. tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin. Herald added a project: All. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Split out from https://reviews.llvm.org/D155368 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155546 Files: clang/lib/AST/Interp/InterpBuiltin.cpp Index: clang/lib/AST/Interp/InterpBuiltin.cpp =================================================================== --- clang/lib/AST/Interp/InterpBuiltin.cpp +++ clang/lib/AST/Interp/InterpBuiltin.cpp @@ -139,6 +139,25 @@ return true; } +static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC, + const InterpFrame *Frame, const Function *F) { + const Floating &LHS = getParam<Floating>(Frame, 0); + const Floating &RHS = getParam<Floating>(Frame, 1); + + Floating Result; + + // When comparing zeroes, return -0.0 if one of the zeroes is negative. + if (LHS.isZero() && RHS.isZero() && RHS.isNegative()) + Result = RHS; + else if (LHS.isNan() || RHS < LHS) + Result = RHS; + else + Result = LHS; + + S.Stk.push<Floating>(Result); + return true; +} + bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) { InterpFrame *Frame = S.Current; APValue Dummy; @@ -191,6 +210,14 @@ return Ret<PT_Float>(S, OpPC, Dummy); break; + case Builtin::BI__builtin_fmin: + case Builtin::BI__builtin_fminf: + case Builtin::BI__builtin_fminl: + case Builtin::BI__builtin_fminf16: + case Builtin::BI__builtin_fminf128: + if (interp__builtin_fmin(S, OpPC, Frame, F)) + return Ret<PT_Float>(S, OpPC, Dummy); + break; default: return false;
Index: clang/lib/AST/Interp/InterpBuiltin.cpp =================================================================== --- clang/lib/AST/Interp/InterpBuiltin.cpp +++ clang/lib/AST/Interp/InterpBuiltin.cpp @@ -139,6 +139,25 @@ return true; } +static bool interp__builtin_fmin(InterpState &S, CodePtr OpPC, + const InterpFrame *Frame, const Function *F) { + const Floating &LHS = getParam<Floating>(Frame, 0); + const Floating &RHS = getParam<Floating>(Frame, 1); + + Floating Result; + + // When comparing zeroes, return -0.0 if one of the zeroes is negative. + if (LHS.isZero() && RHS.isZero() && RHS.isNegative()) + Result = RHS; + else if (LHS.isNan() || RHS < LHS) + Result = RHS; + else + Result = LHS; + + S.Stk.push<Floating>(Result); + return true; +} + bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) { InterpFrame *Frame = S.Current; APValue Dummy; @@ -191,6 +210,14 @@ return Ret<PT_Float>(S, OpPC, Dummy); break; + case Builtin::BI__builtin_fmin: + case Builtin::BI__builtin_fminf: + case Builtin::BI__builtin_fminl: + case Builtin::BI__builtin_fminf16: + case Builtin::BI__builtin_fminf128: + if (interp__builtin_fmin(S, OpPC, Frame, F)) + return Ret<PT_Float>(S, OpPC, Dummy); + break; default: return false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits