[libcxx-commits] [libcxx] 1daf0e2 - [libc++] Add `__libcpp_copysign` conditionally constexpr overloads.
Marek Kurdej via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 21 07:57:49 PDT 2021
Author: Marek Kurdej
Date: 2021-07-21T16:57:43+02:00
New Revision: 1daf0e22562ce50af2203a1d0f0b969a6c54509c
URL: https://github.com/llvm/llvm-project/commit/1daf0e22562ce50af2203a1d0f0b969a6c54509c
DIFF: https://github.com/llvm/llvm-project/commit/1daf0e22562ce50af2203a1d0f0b969a6c54509c.diff
LOG: [libc++] Add `__libcpp_copysign` conditionally constexpr overloads.
This is a spin-off from D79555 review, that with this patch will be able to use `__libcpp_copysign` instead of adhoc `__copysign_constexpr` helper.
Reviewed By: ldionne, #libc
Differential Revision: https://reviews.llvm.org/D106364
Added:
Modified:
libcxx/include/math.h
Removed:
################################################################################
diff --git a/libcxx/include/math.h b/libcxx/include/math.h
index 4ee8aebd920aa..77762d5545124 100644
--- a/libcxx/include/math.h
+++ b/libcxx/include/math.h
@@ -1120,16 +1120,32 @@ cbrt(_A1 __lcpp_x) _NOEXCEPT {return ::cbrt((double)__lcpp_x);}
// copysign
-inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
- float __lcpp_y) _NOEXCEPT {
+#if __has_builtin(__builtin_copysignf)
+_LIBCPP_CONSTEXPR
+#endif
+inline _LIBCPP_INLINE_VISIBILITY float __libcpp_copysign(float __lcpp_x, float __lcpp_y) _NOEXCEPT {
#if __has_builtin(__builtin_copysignf)
return __builtin_copysignf(__lcpp_x, __lcpp_y);
#else
return ::copysignf(__lcpp_x, __lcpp_y);
#endif
}
-inline _LIBCPP_INLINE_VISIBILITY long double
-copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
+
+#if __has_builtin(__builtin_copysign)
+_LIBCPP_CONSTEXPR
+#endif
+inline _LIBCPP_INLINE_VISIBILITY double __libcpp_copysign(double __lcpp_x, double __lcpp_y) _NOEXCEPT {
+#if __has_builtin(__builtin_copysign)
+ return __builtin_copysign(__lcpp_x, __lcpp_y);
+#else
+ return ::copysign(__lcpp_x, __lcpp_y);
+#endif
+}
+
+#if __has_builtin(__builtin_copysignl)
+_LIBCPP_CONSTEXPR
+#endif
+inline _LIBCPP_INLINE_VISIBILITY long double __libcpp_copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
#if __has_builtin(__builtin_copysignl)
return __builtin_copysignl(__lcpp_x, __lcpp_y);
#else
@@ -1138,6 +1154,9 @@ copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
}
template <class _A1, class _A2>
+#if __has_builtin(__builtin_copysign)
+_LIBCPP_CONSTEXPR
+#endif
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf
<
@@ -1145,8 +1164,7 @@ typename std::_EnableIf
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2>
>::type
-copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
-{
+__libcpp_copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)), "");
@@ -1157,6 +1175,26 @@ copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT
#endif
}
+inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x, float __lcpp_y) _NOEXCEPT {
+ return ::__libcpp_copysign(__lcpp_x, __lcpp_y);
+}
+
+inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
+ return ::__libcpp_copysign(__lcpp_x, __lcpp_y);
+}
+
+template <class _A1, class _A2>
+inline _LIBCPP_INLINE_VISIBILITY
+typename std::_EnableIf
+<
+ std::is_arithmetic<_A1>::value &&
+ std::is_arithmetic<_A2>::value,
+ std::__promote<_A1, _A2>
+>::type
+ copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
+ return ::__libcpp_copysign(__lcpp_x, __lcpp_y);
+}
+
// erf
inline _LIBCPP_INLINE_VISIBILITY float erf(float __lcpp_x) _NOEXCEPT {return ::erff(__lcpp_x);}
More information about the libcxx-commits
mailing list