diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-07-04 09:07:23 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-07-04 09:07:23 +0100 |
commit | 90fc44ecfa4741a055ec3d35722e2624c2231f98 (patch) | |
tree | fd397e0cb3a87ce87d0e8d28b2e2e5a46427262d /libstdc++-v3/include | |
parent | 6e38deee4659d87d57e54a869d546dc01cf733cc (diff) | |
download | gcc-90fc44ecfa4741a055ec3d35722e2624c2231f98.zip gcc-90fc44ecfa4741a055ec3d35722e2624c2231f98.tar.gz gcc-90fc44ecfa4741a055ec3d35722e2624c2231f98.tar.bz2 |
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
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/std/bit | 10 |
1 files changed, 3 insertions, 7 deletions
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<typename _Tp> @@ -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<typename _Tp> @@ -237,7 +233,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Tp, typename _Up = _Tp> using _If_is_unsigned_integer - = typename _If_is_unsigned_integer_type<_Tp, _Up>::type; + = typename _If_is_unsigned_integer_type<remove_cv_t<_Tp>, _Up>::type; #if ! __STRICT_ANSI__ // [bitops.rot], rotating |