From 90fc44ecfa4741a055ec3d35722e2624c2231f98 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 4 Jul 2018 09:07:23 +0100 Subject: Optimize std::rotl and std::rotr, add test for std::popcount * include/std/bit (__rotl, __rotr): Avoid branch. (_If_is_unsigned_integer): Use remove_cv_t. * testsuite/26_numerics/bit/bitops.count/popcount.cc: New. From-SVN: r262378 --- libstdc++-v3/include/std/bit | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'libstdc++-v3/include/std/bit') diff --git a/libstdc++-v3/include/std/bit b/libstdc++-v3/include/std/bit index 76aa095..ace8895 100644 --- a/libstdc++-v3/include/std/bit +++ b/libstdc++-v3/include/std/bit @@ -46,9 +46,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { constexpr auto _Nd = numeric_limits<_Tp>::digits; const unsigned __sN = __s % _Nd; - if (__sN) - return (__x << __sN) | (__x >> (_Nd - __sN)); - return __x; + return (__x << __sN) | (__x >> ((-__sN) % _Nd)); } template @@ -57,9 +55,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { constexpr auto _Nd = numeric_limits<_Tp>::digits; const unsigned __sN = __s % _Nd; - if (__sN) - return (__x >> __sN) | (__x << (_Nd - __sN)); - return __x; + return (__x >> __sN) | (__x << ((-__sN) % _Nd)); } template @@ -237,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using _If_is_unsigned_integer - = typename _If_is_unsigned_integer_type<_Tp, _Up>::type; + = typename _If_is_unsigned_integer_type, _Up>::type; #if ! __STRICT_ANSI__ // [bitops.rot], rotating -- cgit v1.1