[clang] d37f1e9 - [clang][Interp] Implement __builtin_isnormal
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 31 00:20:00 PDT 2023
Author: Timm Bäder
Date: 2023-07-31T09:14:16+02:00
New Revision: d37f1e9965bd07bb8e05388aec0140addaf15e40
URL: https://github.com/llvm/llvm-project/commit/d37f1e9965bd07bb8e05388aec0140addaf15e40
DIFF: https://github.com/llvm/llvm-project/commit/d37f1e9965bd07bb8e05388aec0140addaf15e40.diff
LOG: [clang][Interp] Implement __builtin_isnormal
Differential Revision: https://reviews.llvm.org/D155374
Added:
Modified:
clang/lib/AST/Interp/Floating.h
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Floating.h b/clang/lib/AST/Interp/Floating.h
index f98f49a7afb70e..c997323837c1c1 100644
--- a/clang/lib/AST/Interp/Floating.h
+++ b/clang/lib/AST/Interp/Floating.h
@@ -89,6 +89,7 @@ class Floating final {
bool isNan() const { return F.isNaN(); }
bool isInf() const { return F.isInfinity(); }
bool isFinite() const { return F.isFinite(); }
+ bool isNormal() const { return F.isNormal(); }
ComparisonCategoryResult compare(const Floating &RHS) const {
llvm::APFloatBase::cmpResult CmpRes = F.compare(RHS.F);
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 6fe9bc7628efef..8c71f2f016252a 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -196,6 +196,15 @@ static bool interp__builtin_isfinite(InterpState &S, CodePtr OpPC,
return true;
}
+static bool interp__builtin_isnormal(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *F) {
+ const Floating &Arg = S.Stk.peek<Floating>();
+
+ S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Arg.isNormal()));
+ return true;
+}
+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
InterpFrame *Frame = S.Current;
APValue Dummy;
@@ -276,6 +285,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
if (interp__builtin_isfinite(S, OpPC, Frame, F))
return Ret<PT_Sint32>(S, OpPC, Dummy);
break;
+ case Builtin::BI__builtin_isnormal:
+ if (interp__builtin_isnormal(S, OpPC, Frame, F))
+ return Ret<PT_Sint32>(S, OpPC, Dummy);
+ break;
default:
return false;
diff --git a/clang/test/AST/Interp/builtin-functions.cpp b/clang/test/AST/Interp/builtin-functions.cpp
index 9457100a15f528..924914f9f942bd 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -79,4 +79,7 @@ namespace inf {
static_assert(__builtin_isfinite(1.0), "");
static_assert(!__builtin_isfinite(__builtin_inf()), "");
+
+ static_assert(__builtin_isnormal(1.0), "");
+ static_assert(!__builtin_isnormal(__builtin_inf()), "");
}
More information about the cfe-commits
mailing list