1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef _LIBCPP___ALGORITHM_HALF_POSITIVE_H 10 #define _LIBCPP___ALGORITHM_HALF_POSITIVE_H 11 12 #include <__config> 13 #include <type_traits> 14 15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 16 # pragma GCC system_header 17 # pragma clang include_instead(<algorithm>) 18 #endif 19 20 _LIBCPP_BEGIN_NAMESPACE_STD 21 22 // Perform division by two quickly for positive integers (llvm.org/PR39129) 23 24 template <typename _Integral> 25 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 26 typename enable_if 27 < 28 is_integral<_Integral>::value, 29 _Integral 30 >::type 31 __half_positive(_Integral __value) 32 { 33 return static_cast<_Integral>(static_cast<typename make_unsigned<_Integral>::type>(__value) / 2); 34 } 35 36 template <typename _Tp> 37 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 38 typename enable_if 39 < 40 !is_integral<_Tp>::value, 41 _Tp 42 >::type 43 __half_positive(_Tp __value) 44 { 45 return __value / 2; 46 } 47 48 _LIBCPP_END_NAMESPACE_STD 49 50 #endif // _LIBCPP___ALGORITHM_HALF_POSITIVE_H 51