Skip to content

Commit af8adfa

Browse files
Enable __builtin_bit_cast for CUDA (#3066)
1 parent d503c92 commit af8adfa

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

stl/inc/complex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ namespace _Float_multi_prec {
133133
// multiplication
134134

135135
// round to 26 significant bits, ties toward zero
136-
_NODISCARD _CONSTEXPR_BIT_CAST double _High_half(const double _Val) noexcept {
136+
_NODISCARD constexpr double _High_half(const double _Val) noexcept {
137137
const auto _Bits = _Bit_cast<unsigned long long>(_Val);
138138
const auto _High_half_bits = (_Bits + 0x3ff'ffffULL) & 0xffff'ffff'f800'0000ULL;
139139
return _Bit_cast<double>(_High_half_bits);
@@ -144,7 +144,7 @@ namespace _Float_multi_prec {
144144
// 1) _Prod0 is _Xval^2 faithfully rounded
145145
// 2) no internal overflow or underflow occurs
146146
// violation of condition 1 could lead to relative error on the order of epsilon
147-
_NODISCARD _CONSTEXPR_BIT_CAST double _Sqr_error_fallback(const double _Xval, const double _Prod0) noexcept {
147+
_NODISCARD constexpr double _Sqr_error_fallback(const double _Xval, const double _Prod0) noexcept {
148148
const double _Xhigh = _High_half(_Xval);
149149
const double _Xlow = _Xval - _Xhigh;
150150
return ((_Xhigh * _Xhigh - _Prod0) + 2.0 * _Xhigh * _Xlow) + _Xlow * _Xlow;

stl/inc/xutility

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ _STL_DISABLE_CLANG_WARNINGS
4343
#endif // _USE_STD_VECTOR_ALGORITHMS
4444
#endif // ^^^ no support for vector algorithms ^^^
4545

46-
#ifdef __CUDACC__
47-
#define _CONSTEXPR_BIT_CAST inline
48-
#else // ^^^ workaround ^^^ / vvv no workaround vvv
49-
#define _CONSTEXPR_BIT_CAST constexpr
50-
#endif // ^^^ no workaround ^^^
51-
5246
#if _USE_STD_VECTOR_ALGORITHMS
5347
_EXTERN_C
5448
// The "noalias" attribute tells the compiler optimizer that pointers going into these hand-vectorized algorithms
@@ -152,14 +146,8 @@ template <class _To, class _From,
152146
enable_if_t<conjunction_v<bool_constant<sizeof(_To) == sizeof(_From)>, is_trivially_copyable<_To>,
153147
is_trivially_copyable<_From>>,
154148
int> = 0>
155-
_NODISCARD _CONSTEXPR_BIT_CAST _To _Bit_cast(const _From& _Val) noexcept {
156-
#ifdef __CUDACC__
157-
_To _To_obj; // assumes default-init
158-
_CSTD memcpy(_STD addressof(_To_obj), _STD addressof(_Val), sizeof(_To));
159-
return _To_obj;
160-
#else // ^^^ workaround ^^^ / vvv no workaround vvv
149+
_NODISCARD constexpr _To _Bit_cast(const _From& _Val) noexcept {
161150
return __builtin_bit_cast(_To, _Val);
162-
#endif // ^^^ no workaround ^^^
163151
}
164152

165153
template <class _Ty>
@@ -5114,7 +5102,7 @@ _NODISCARD _CONSTEXPR20 _InIt _Find_unchecked(_InIt _First, const _InIt _Last, c
51145102
#else // ^^^ _USE_STD_VECTOR_ALGORITHMS ^^^ / vvv not _USE_STD_VECTOR_ALGORITHMS vvv
51155103
if constexpr (sizeof(_Iter_value_t<_InIt>) == 1) {
51165104
const auto _First_ptr = _To_address(_First);
5117-
const auto _Result = static_cast<remove_reference_t<_Iter_ref_t<_InIt>>*>(
5105+
const auto _Result = static_cast<remove_reference_t<_Iter_ref_t<_InIt>>*>(
51185106
_CSTD memchr(_First_ptr, static_cast<unsigned char>(_Val), static_cast<size_t>(_Last - _First)));
51195107
if constexpr (is_pointer_v<_InIt>) {
51205108
return _Result ? _Result : _Last;
@@ -6100,28 +6088,28 @@ struct _CXX17_DEPRECATE_ITERATOR_BASE_CLASS iterator { // base type for iterator
61006088
};
61016089

61026090
template <class _Ty, enable_if_t<is_floating_point_v<_Ty>, int> = 0>
6103-
_NODISCARD _CONSTEXPR_BIT_CAST auto _Float_abs_bits(const _Ty& _Xx) {
6091+
_NODISCARD constexpr auto _Float_abs_bits(const _Ty& _Xx) {
61046092
using _Traits = _Floating_type_traits<_Ty>;
61056093
using _Uint_type = typename _Traits::_Uint_type;
61066094
const auto _Bits = _Bit_cast<_Uint_type>(_Xx);
61076095
return _Bits & ~_Traits::_Shifted_sign_mask;
61086096
}
61096097

61106098
template <class _Ty, enable_if_t<is_floating_point_v<_Ty>, int> = 0>
6111-
_NODISCARD _CONSTEXPR_BIT_CAST _Ty _Float_abs(const _Ty _Xx) { // constexpr floating-point abs()
6099+
_NODISCARD constexpr _Ty _Float_abs(const _Ty _Xx) { // constexpr floating-point abs()
61126100
return _Bit_cast<_Ty>(_Float_abs_bits(_Xx));
61136101
}
61146102

61156103
template <class _Ty, enable_if_t<is_floating_point_v<_Ty>, int> = 0>
6116-
_NODISCARD _CONSTEXPR_BIT_CAST _Ty _Float_copysign(const _Ty _Magnitude, const _Ty _Sign) { // constexpr copysign()
6104+
_NODISCARD constexpr _Ty _Float_copysign(const _Ty _Magnitude, const _Ty _Sign) { // constexpr copysign()
61176105
using _Traits = _Floating_type_traits<_Ty>;
61186106
using _Uint_type = typename _Traits::_Uint_type;
61196107
const auto _Signbit = _Bit_cast<_Uint_type>(_Sign) & _Traits::_Shifted_sign_mask;
61206108
return _Bit_cast<_Ty>(_Float_abs_bits(_Magnitude) | _Signbit);
61216109
}
61226110

61236111
template <class _Ty, enable_if_t<is_floating_point_v<_Ty>, int> = 0>
6124-
_NODISCARD _CONSTEXPR_BIT_CAST bool _Is_nan(const _Ty _Xx) { // constexpr isnan()
6112+
_NODISCARD constexpr bool _Is_nan(const _Ty _Xx) { // constexpr isnan()
61256113
using _Traits = _Floating_type_traits<_Ty>;
61266114
return _Float_abs_bits(_Xx) > _Traits::_Shifted_exponent_mask;
61276115
}
@@ -6131,20 +6119,20 @@ _NODISCARD _CONSTEXPR_BIT_CAST bool _Is_nan(const _Ty _Xx) { // constexpr isnan(
61316119
// When the value is a 32-bit or 64-bit signaling NaN, the conversion to/from 80-bit raises FE_INVALID
61326120
// and turns it into a quiet NaN. This behavior is undesirable if we want to test for signaling NaNs.
61336121
template <class _Ty, enable_if_t<is_floating_point_v<_Ty>, int> = 0>
6134-
_NODISCARD _CONSTEXPR_BIT_CAST bool _Is_signaling_nan(const _Ty& _Xx) { // returns true if input is a signaling NaN
6122+
_NODISCARD constexpr bool _Is_signaling_nan(const _Ty& _Xx) { // returns true if input is a signaling NaN
61356123
using _Traits = _Floating_type_traits<_Ty>;
61366124
const auto _Abs_bits = _Float_abs_bits(_Xx);
61376125
return _Abs_bits > _Traits::_Shifted_exponent_mask && ((_Abs_bits & _Traits::_Special_nan_mantissa_mask) == 0);
61386126
}
61396127

61406128
template <class _Ty, enable_if_t<is_floating_point_v<_Ty>, int> = 0>
6141-
_NODISCARD _CONSTEXPR_BIT_CAST bool _Is_inf(const _Ty _Xx) { // constexpr isinf()
6129+
_NODISCARD constexpr bool _Is_inf(const _Ty _Xx) { // constexpr isinf()
61426130
using _Traits = _Floating_type_traits<_Ty>;
61436131
return _Float_abs_bits(_Xx) == _Traits::_Shifted_exponent_mask;
61446132
}
61456133

61466134
template <class _Ty, enable_if_t<is_floating_point_v<_Ty>, int> = 0>
6147-
_NODISCARD _CONSTEXPR_BIT_CAST bool _Is_finite(const _Ty _Xx) { // constexpr isfinite()
6135+
_NODISCARD constexpr bool _Is_finite(const _Ty _Xx) { // constexpr isfinite()
61486136
using _Traits = _Floating_type_traits<_Ty>;
61496137
return _Float_abs_bits(_Xx) < _Traits::_Shifted_exponent_mask;
61506138
}

0 commit comments

Comments
 (0)