[libcxx-commits] [PATCH] D96121: [libcxx] Use builtin in isinf/isnormal/fpclassify/isfinite
Qiu Chaofan via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Feb 5 04:49:28 PST 2021
qiucf created this revision.
qiucf added reviewers: EricWF, TokarIP.
qiucf requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
In bootstrap testing on Power9 target with libcxx enabled, build would fail because glibc uses `__builtin_types_compatible_p` in definition of these macros but the builtin is not available in C++ mode. And glibc assumes:
/* Since __builtin_isinf_sign is broken for float128 before GCC 7.0,
use the helper function, __isinff128, with older compilers. This is
only provided for C mode, because in C++ mode, GCC has no support
for __builtin_types_compatible_p (and when in C++ mode, this macro is
not used anyway, because libstdc++ headers undefine it). */
So we need another way to do the implementation, just like rG767eadd78 <https://reviews.llvm.org/rG767eadd782291026b9b87be871de6bcd347c7d14>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96121
Files:
libcxx/include/math.h
Index: libcxx/include/math.h
===================================================================
--- libcxx/include/math.h
+++ libcxx/include/math.h
@@ -380,7 +380,12 @@
int
__libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT
{
+#if __has_builtin(__builtin_fpclassify)
+ return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,
+ FP_ZERO, __lcpp_x);
+#else
return fpclassify(__lcpp_x);
+#endif
}
#undef fpclassify
@@ -426,7 +431,11 @@
bool
__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT
{
+#if __has_builtin(__builtin_isfinite)
+ return __builtin_isfinite(__lcpp_x);
+#else
return isfinite(__lcpp_x);
+#endif
}
#undef isfinite
@@ -460,7 +469,11 @@
bool
__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT
{
+#if __has_builtin(__builtin_isinf)
+ return __builtin_isinf(__lcpp_x);
+#else
return isinf(__lcpp_x);
+#endif
}
#undef isinf
@@ -556,7 +569,11 @@
bool
__libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT
{
+#if __has_builtin(__builtin_isnormal)
+ return __builtin_isnormal(__lcpp_x);
+#else
return isnormal(__lcpp_x);
+#endif
}
#undef isnormal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96121.321711.patch
Type: text/x-patch
Size: 1123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210205/a15c9d2c/attachment.bin>
More information about the libcxx-commits
mailing list