summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/26_numerics/bit
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2018-07-03 22:04:45 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2018-07-03 22:04:45 +0100
commitf3e91052bd7e5af791ca720cd14e9ac9227e3801 (patch)
tree93c8036d608b1b66477816d43343955cc80e6940 /libstdc++-v3/testsuite/26_numerics/bit
parentcf3e6e9f15e11273083517ebfd7d0a94213d70f5 (diff)
P0556R3 Integral power-of-2 operations, P0553R2 Bit operations
P0553R2 is not in the C++2a working draft yet, but is likely to be approved soon. Neither proposal supports std::byte but this adds overloads of each function for std::byte, assuming that will also get added. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/precompiled/stdc++.h: Include new header. * include/std/bit: New header. (__rotl, __rotr, __countl_zero, __countl_one, __countr_zero) (__countr_one, __popcount, __ispow2, __ceil2, __floor2, __log2p1): Define for C++14. [!__STRICT_ANSI__] (rotl, rotr, countl_zero, countl_one, countr_zero) (countr_one, popcount): Define for C++2a. Also overload for std::byte. (ispow2, ceil2, floor2, log2p1): Define for C++2a. [!__STRICT_ANSI__] (ispow2, ceil2, floor2, log2p1): Overload for std::byte. * testsuite/26_numerics/bit/bit.pow.two/ceil2.cc: New. * testsuite/26_numerics/bit/bit.pow.two/floor2.cc: New. * testsuite/26_numerics/bit/bit.pow.two/ispow2.cc: New. * testsuite/26_numerics/bit/bit.pow.two/log2p1.cc: New. * testsuite/26_numerics/bit/bitops.rot/rotl.cc: New. * testsuite/26_numerics/bit/bitops.rot/rotr.cc: New. * testsuite/26_numerics/bit/bitops.count/countl_one.cc: New. * testsuite/26_numerics/bit/bitops.count/countl_zero.cc: New. * testsuite/26_numerics/bit/bitops.count/countr_one.cc: New. * testsuite/26_numerics/bit/bitops.count/countr_zero.cc: New. From-SVN: r262360
Diffstat (limited to 'libstdc++-v3/testsuite/26_numerics/bit')
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ceil2.cc108
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/floor2.cc109
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ispow2.cc157
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/log2p1.cc109
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_one.cc103
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_zero.cc104
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_one.cc106
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_zero.cc105
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotl.cc119
-rw-r--r--libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotr.cc119
10 files changed, 1139 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ceil2.cc b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ceil2.cc
new file mode 100644
index 00000000000..65e1569c277
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ceil2.cc
@@ -0,0 +1,108 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::ceil2(x))
+{
+ static_assert( noexcept(std::ceil2(x)) );
+
+ static_assert( std::ceil2(UInt(0)) == 1 );
+ static_assert( std::ceil2(UInt(1)) == 1 );
+ static_assert( std::ceil2(UInt(2)) == 2 );
+ static_assert( std::ceil2(UInt(3)) == 4 );
+ static_assert( std::ceil2(UInt(4)) == 4 );
+ static_assert( std::ceil2(UInt(0x11)) == 0x20 );
+ static_assert( std::ceil2(UInt(0x20)) == 0x20 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::ceil2(UInt(0x201)) == 0x400 );
+ static_assert( std::ceil2(UInt(0x8ff)) == 0x1000 );
+ static_assert( std::ceil2(UInt(0x1000)) == 0x1000 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 32)
+ {
+ static_assert( std::ceil2(UInt(0xabcdef)) == 0x1000000 );
+ static_assert( std::ceil2(UInt(0x1000000)) == 0x1000000 );
+ static_assert( std::ceil2(UInt(0x1000001)) == 0x2000000 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 64)
+ {
+ static_assert( std::ceil2(UInt(1) << 64) == (UInt(1) << 64) );
+ static_assert( std::ceil2(UInt(3) << 64) == (UInt(4) << 64) );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::ceil2(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+static_assert( std::ceil2(std::byte{0}) == std::byte{1} );
+static_assert( std::ceil2(std::byte{1}) == std::byte{1} );
+static_assert( std::ceil2(std::byte{2}) == std::byte{2} );
+static_assert( std::ceil2(std::byte{3}) == std::byte{4} );
+static_assert( std::ceil2(std::byte{100}) == std::byte{128} );
+static_assert( std::ceil2(std::byte{128}) == std::byte{128} );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/floor2.cc b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/floor2.cc
new file mode 100644
index 00000000000..0206110ec2f
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/floor2.cc
@@ -0,0 +1,109 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::floor2(x))
+{
+ static_assert( noexcept(std::floor2(x)) );
+
+ static_assert( std::floor2(UInt(0)) == 0 );
+ static_assert( std::floor2(UInt(1)) == 1 );
+ static_assert( std::floor2(UInt(2)) == 2 );
+ static_assert( std::floor2(UInt(3)) == 2 );
+ static_assert( std::floor2(UInt(4)) == 4 );
+ static_assert( std::floor2(UInt(0x11)) == 0x10 );
+ static_assert( std::floor2(UInt(0x20)) == 0x20 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::floor2(UInt(0x201)) == 0x200 );
+ static_assert( std::floor2(UInt(0x8ff)) == 0x800 );
+ static_assert( std::floor2(UInt(0x1000)) == 0x1000 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 32)
+ {
+ static_assert( std::floor2(UInt(0xabcdef)) == 0x800000 );
+ static_assert( std::floor2(UInt(0x1000000)) == 0x1000000 );
+ static_assert( std::floor2(UInt(0x1000001)) == 0x1000000 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 64)
+ {
+ static_assert( std::floor2(UInt(1) << 64) == (UInt(1) << 64) );
+ static_assert( std::floor2(UInt(3) << 64) == (UInt(2) << 64) );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::floor2(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+static_assert( std::floor2(std::byte{0}) == std::byte{0} );
+static_assert( std::floor2(std::byte{1}) == std::byte{1} );
+static_assert( std::floor2(std::byte{2}) == std::byte{2} );
+static_assert( std::floor2(std::byte{3}) == std::byte{2} );
+static_assert( std::floor2(std::byte{100}) == std::byte{64} );
+static_assert( std::floor2(std::byte{128}) == std::byte{128} );
+static_assert( std::floor2(std::byte{255}) == std::byte{128} );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ispow2.cc b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ispow2.cc
new file mode 100644
index 00000000000..ba8cfa8da7c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/ispow2.cc
@@ -0,0 +1,157 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::ispow2(x))
+{
+ static_assert( noexcept(std::ispow2(x)) );
+
+ static_assert( ! std::ispow2( (UInt)0 ) );
+ static_assert( ! std::ispow2( (UInt)-1 ) );
+ static_assert( ! std::ispow2( (UInt)3 ) );
+ static_assert( ! std::ispow2( (UInt)0x0f ) );
+ static_assert( ! std::ispow2( (UInt)0xff ) );
+ static_assert( ! std::ispow2( (UInt)0x0a ) );
+ static_assert( ! std::ispow2( (UInt)0xa0 ) );
+
+ constexpr UInt one = 1;
+ static_assert( std::ispow2( (UInt)(one << 0) ) );
+
+ static_assert( std::ispow2( (UInt)(one << 1) ) );
+ static_assert( std::ispow2( (UInt)(one << 2) ) );
+ static_assert( std::ispow2( (UInt)(one << 3) ) );
+ static_assert( std::ispow2( (UInt)(one << 4) ) );
+ static_assert( std::ispow2( (UInt)(one << 5) ) );
+ static_assert( std::ispow2( (UInt)(one << 6) ) );
+ static_assert( std::ispow2( (UInt)(one << 7) ) );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::ispow2( (UInt)(one << 8) ) );
+ static_assert( std::ispow2( (UInt)(one << 9) ) );
+ static_assert( std::ispow2( (UInt)(one << 10) ) );
+ static_assert( std::ispow2( (UInt)(one << 11) ) );
+ static_assert( std::ispow2( (UInt)(one << 12) ) );
+ static_assert( std::ispow2( (UInt)(one << 13) ) );
+ static_assert( std::ispow2( (UInt)(one << 14) ) );
+ static_assert( std::ispow2( (UInt)(one << 15) ) );
+
+ static_assert( ! std::ispow2( (UInt)0xf000 ) );
+ static_assert( ! std::ispow2( (UInt)0xff00 ) );
+ static_assert( ! std::ispow2( (UInt)0xf0f0 ) );
+ static_assert( ! std::ispow2( (UInt)0xf00f ) );
+ static_assert( ! std::ispow2( (UInt)0x0f0f ) );
+ static_assert( ! std::ispow2( (UInt)0x00ff ) );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 16)
+ {
+ static_assert( std::ispow2( (UInt)(one << 16) ) );
+ static_assert( std::ispow2( (UInt)(one << 17) ) );
+ static_assert( ! std::ispow2( (UInt)((one << 16) + 1) ) );
+ static_assert( ! std::ispow2( (UInt)((one << 16) + 0x10) ) );
+ }
+
+ // msp340 target has 20-bit __GLIBCXX_TYPE_INT_N_0 type
+ if constexpr (std::numeric_limits<UInt>::digits > 20)
+ {
+ static_assert( std::ispow2( (UInt)(one << 20) ) );
+ static_assert( std::ispow2( (UInt)(one << 21) ) );
+ static_assert( std::ispow2( (UInt)(one << 24) ) );
+ static_assert( std::ispow2( (UInt)(one << 28) ) );
+ static_assert( std::ispow2( (UInt)(one << 31) ) );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 32)
+ {
+ static_assert( std::ispow2( (UInt)(one << 32) ) );
+ static_assert( std::ispow2( (UInt)(one << 33) ) );
+ static_assert( std::ispow2( (UInt)(one << 41) ) );
+
+ static_assert( ! std::ispow2( (UInt)((one << 32) + 1) ) );
+ static_assert( ! std::ispow2( (UInt)((one << 32) + (one << 31)) ) );
+ static_assert( ! std::ispow2( (UInt)((one << 33) + 1) ) );
+ static_assert( ! std::ispow2( (UInt)((one << 33) + (one << 32)) ) );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits == 64)
+ {
+ static_assert( std::ispow2( (UInt)(one << 63) ) );
+
+ static_assert( ! std::ispow2( (UInt)((one << 63) + 1) ) );
+ static_assert( ! std::ispow2( (UInt)((one << 63) + (one << 8)) ) );
+ static_assert( ! std::ispow2( (UInt)((one << 63) + (one << 32)) ) );
+ }
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::ispow2(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+static_assert( std::ispow2(std::byte{0}) == false );
+static_assert( std::ispow2(std::byte{1}) == true );
+static_assert( std::ispow2(std::byte{2}) == true );
+static_assert( std::ispow2(std::byte{3}) == false );
+static_assert( std::ispow2(std::byte{100}) == false );
+static_assert( std::ispow2(std::byte{128}) == true );
+static_assert( std::ispow2(std::byte{255}) == false );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/log2p1.cc b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/log2p1.cc
new file mode 100644
index 00000000000..142f6ee857d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bit.pow.two/log2p1.cc
@@ -0,0 +1,109 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::log2p1(x))
+{
+ static_assert( noexcept(std::log2p1(x)) );
+
+ static_assert( std::log2p1(UInt(0)) == 0 );
+ static_assert( std::log2p1(UInt(1)) == 1 );
+ static_assert( std::log2p1(UInt(2)) == 2 );
+ static_assert( std::log2p1(UInt(3)) == 2 );
+ static_assert( std::log2p1(UInt(4)) == 3 );
+ static_assert( std::log2p1(UInt(0x11)) == 5 );
+ static_assert( std::log2p1(UInt(0x20)) == 6 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::log2p1(UInt(0x201)) == 10 );
+ static_assert( std::log2p1(UInt(0x8ff)) == 12 );
+ static_assert( std::log2p1(UInt(0x1000)) == 13 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 32)
+ {
+ static_assert( std::log2p1(UInt(0xabcdef)) == 24 );
+ static_assert( std::log2p1(UInt(0x1000000)) == 25 );
+ static_assert( std::log2p1(UInt(0x1000001)) == 25 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 64)
+ {
+ static_assert( std::log2p1(UInt(1) << 64) == 65 );
+ static_assert( std::log2p1(UInt(3) << 64) == 66 );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::log2p1(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+static_assert( std::log2p1(std::byte{0}) == std::byte{0} );
+static_assert( std::log2p1(std::byte{1}) == std::byte{1} );
+static_assert( std::log2p1(std::byte{2}) == std::byte{2} );
+static_assert( std::log2p1(std::byte{3}) == std::byte{2} );
+static_assert( std::log2p1(std::byte{100}) == std::byte{7} );
+static_assert( std::log2p1(std::byte{128}) == std::byte{8} );
+static_assert( std::log2p1(std::byte{255}) == std::byte{8} );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_one.cc b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_one.cc
new file mode 100644
index 00000000000..c9ef5538538
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_one.cc
@@ -0,0 +1,103 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::countl_one(x))
+{
+ static_assert( noexcept(std::countl_one(x)) );
+
+ constexpr unsigned digits = std::numeric_limits<UInt>::digits;
+
+ static_assert( std::countl_one((UInt)0) == 0 );
+ static_assert( std::countl_one((UInt)-1) == digits );
+
+ static_assert( std::countl_one((UInt)3) == 0 );
+ static_assert( std::countl_one((UInt)((UInt)1 << digits - 1)) == 1 );
+ static_assert( std::countl_one((UInt)((UInt)3 << digits - 2)) == 2 );
+ static_assert( std::countl_one((UInt)((UInt)7 << digits - 3)) == 3 );
+ static_assert( std::countl_one((UInt)((UInt)255 << digits - 8)) == 8 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::countl_one((UInt)((UInt)-1 ^ 0x100)) == digits - 9 );
+ static_assert( std::countl_one((UInt)((UInt)-1 ^ 0x101)) == digits - 9 );
+ static_assert( std::countl_one((UInt)((UInt)-1 ^ 0x201)) == digits - 10 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 64)
+ {
+ static_assert( std::countl_one((UInt)-1 ^ ((UInt)1 << 70)) == digits - 71 );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::countl_one(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+constexpr int bits = std::numeric_limits<unsigned char>::digits;
+static_assert( std::countl_one(std::byte{0}) == 0 );
+static_assert( std::countl_one(~std::byte{0}) == bits );
+static_assert( std::countl_one(~std::byte{0} ^ std::byte{7}) == bits - 3 );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_zero.cc b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_zero.cc
new file mode 100644
index 00000000000..7d619a7d697
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countl_zero.cc
@@ -0,0 +1,104 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::countl_zero(x))
+{
+ static_assert( noexcept(std::countl_zero(x)) );
+
+ constexpr unsigned digits = std::numeric_limits<UInt>::digits;
+
+ static_assert( std::countl_zero((UInt)0) == digits );
+ static_assert( std::countl_zero((UInt)-1) == 0 );
+
+ static_assert( std::countl_zero((UInt)1) == digits - 1 );
+ static_assert( std::countl_zero((UInt)3) == digits - 2 );
+ static_assert( std::countl_zero((UInt)0b0101'1010) == digits - 7 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::countl_zero((UInt)(1u << 8)) == digits - 9 );
+ static_assert( std::countl_zero((UInt)(3u << 9)) == digits - 11 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 64)
+ {
+ static_assert( std::countl_zero((UInt)3 << 70) == digits - 72 );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::countl_zero(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+constexpr int bits = std::numeric_limits<unsigned char>::digits;
+static_assert( std::countl_zero(std::byte{0}) == bits );
+static_assert( std::countl_zero(std::byte{0x01}) == bits - 1 );
+static_assert( std::countl_zero(std::byte{0x02}) == bits - 2 );
+static_assert( std::countl_zero(std::byte{0x03}) == bits - 2 );
+static_assert( std::countl_zero(std::byte{0x30}) == 2 );
+static_assert( std::countl_zero(std::byte{0x40}) == 1 );
+static_assert( std::countl_zero(std::byte{0x41}) == 1 );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_one.cc b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_one.cc
new file mode 100644
index 00000000000..bb1ddd6234d
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_one.cc
@@ -0,0 +1,106 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::countr_one(x))
+{
+ static_assert( noexcept(std::countr_one(x)) );
+
+ constexpr unsigned digits = std::numeric_limits<UInt>::digits;
+
+ static_assert( std::countr_one((UInt)0) == 0 );
+ static_assert( std::countr_one((UInt)-1) == digits );
+ static_assert( std::countr_one((UInt)127) == 7 );
+
+ static_assert( std::countr_one((UInt)1) == 1 );
+ static_assert( std::countr_one((UInt)3) == 2 );
+ static_assert( std::countr_one((UInt)0x1f) == 5 );
+ static_assert( std::countr_one((UInt)((UInt)-1 ^ 0x10)) == 4 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::countr_one((UInt)((UInt)-1 ^ 0x100)) == 8 );
+ static_assert( std::countr_one((UInt)((UInt)-1 ^ 0x101)) == 0 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 64)
+ {
+ static_assert( std::countr_one((UInt)-1 ^ ((UInt)1 << 70)) == 70 );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::countr_one(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+constexpr int bits = std::numeric_limits<unsigned char>::digits;
+static_assert( std::countr_one(std::byte{0}) == 0 );
+static_assert( std::countr_one(std::byte{0x01}) == 1 );
+static_assert( std::countr_one(std::byte{0x02}) == 0 );
+static_assert( std::countr_one(std::byte{0x03}) == 2 );
+static_assert( std::countr_one(std::byte{0x30}) == 0 );
+static_assert( std::countr_one(std::byte{0x0f}) == 4 );
+static_assert( std::countr_one(std::byte{0xff}) == 8 );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_zero.cc b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_zero.cc
new file mode 100644
index 00000000000..d3b63aa4984
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bitops.count/countr_zero.cc
@@ -0,0 +1,105 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::countr_zero(x))
+{
+ static_assert( noexcept(std::countr_zero(x)) );
+
+ constexpr unsigned digits = std::numeric_limits<UInt>::digits;
+
+ static_assert( std::countr_zero((UInt)0) == digits );
+ static_assert( std::countr_zero((UInt)-1) == 0 );
+ static_assert( std::countr_zero((UInt)127) == 0 );
+
+ static_assert( std::countr_zero((UInt)1) == 0 );
+ static_assert( std::countr_zero((UInt)2) == 1 );
+ static_assert( std::countr_zero((UInt)0x70) == 4 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::countr_zero((UInt)(1u << 8)) == 8 );
+ static_assert( std::countr_zero((UInt)(4u << 9)) == 11 );
+ }
+
+ if constexpr (std::numeric_limits<UInt>::digits > 64)
+ {
+ static_assert( std::countr_zero((UInt)2 << 70) == 71 );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::countr_zero(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+constexpr int bits = std::numeric_limits<unsigned char>::digits;
+static_assert( std::countr_zero(std::byte{0}) == bits );
+static_assert( std::countr_zero(std::byte{0x01}) == 0 );
+static_assert( std::countr_zero(std::byte{0x02}) == 1 );
+static_assert( std::countr_zero(std::byte{0x03}) == 0 );
+static_assert( std::countr_zero(std::byte{0x30}) == 4 );
+static_assert( std::countr_zero(std::byte{0x40}) == 6 );
+static_assert( std::countr_zero(std::byte{0x41}) == 0 );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotl.cc b/libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotl.cc
new file mode 100644
index 00000000000..a44da00040c
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotl.cc
@@ -0,0 +1,119 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::rotl(x, 0u))
+{
+ static_assert( noexcept(std::rotl(x, 0u)) );
+
+ constexpr unsigned digits = std::numeric_limits<UInt>::digits;
+
+ static_assert( std::rotl((UInt)0, 0) == 0 );
+ static_assert( std::rotl((UInt)0, 1) == 0 );
+ static_assert( std::rotl((UInt)0, 4) == 0 );
+ static_assert( std::rotl((UInt)0, 8) == 0 );
+ static_assert( std::rotl((UInt)-1, 0) == (UInt)-1 );
+ static_assert( std::rotl((UInt)-1, 1) == (UInt)-1 );
+ static_assert( std::rotl((UInt)-1, 4) == (UInt)-1 );
+ static_assert( std::rotl((UInt)-1, 8) == (UInt)-1 );
+
+ static_assert( std::rotl((UInt)1, 0) == (UInt)1 << 0 );
+ static_assert( std::rotl((UInt)1, 1) == (UInt)1 << 1 );
+ static_assert( std::rotl((UInt)1, 4) == (UInt)1 << 4 );
+ static_assert( std::rotl((UInt)1, digits) == (UInt)1 );
+ static_assert( std::rotl((UInt)7, digits) == (UInt)7 );
+ static_assert( std::rotl((UInt)6, digits - 1) == (UInt)3 );
+ static_assert( std::rotl((UInt)3, 6) == (UInt)3 << 6 );
+
+ static_assert( std::rotl((UInt)0b0110'1100, 1) == 0b1101'1000 );
+ static_assert( std::rotl((UInt)0b0110'1100, digits - 1) == 0b0011'0110 );
+
+ static_assert( std::rotl((UInt)0x01, 0 ) == 0x01 );
+ static_assert( std::rotl((UInt)0x10, 0 ) == 0x10 );
+ static_assert( std::rotl((UInt)0x10, 1 ) == 0x20 );
+ static_assert( std::rotl((UInt)0x10, 2 ) == 0x40 );
+ static_assert( std::rotl((UInt)0x10, 3 ) == 0x80 );
+ static_assert( std::rotl((UInt)0x11, 1 ) == 0x22 );
+ static_assert( std::rotl((UInt)0x11, 2 ) == 0x44 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::rotl((UInt)0b0011'0111, 3) == 0b1'1011'1000 );
+ static_assert( std::rotl((UInt)0b1010'0101, 4) == 0b1010'0101'0000 );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::rotl(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+static_assert( std::rotl(std::byte{0}, 4) == std::byte{0} );
+static_assert( std::rotl(std::byte{0x01}, 4) == std::byte{0x10} );
+static_assert( std::rotl(std::byte{0x02}, 3) == std::byte{0x10} );
+static_assert( std::rotl(std::byte{0x03}, 2) == std::byte{0x0c} );
+static_assert( std::rotl(std::byte{0x30}, 2) == std::byte{0xc0} );
+static_assert( std::rotl(std::byte{0x40}, 1) == std::byte{0x80} );
+static_assert( std::rotl(std::byte{0x41}, 9) == std::byte{0x82} );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif
diff --git a/libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotr.cc b/libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotr.cc
new file mode 100644
index 00000000000..c4a17689f79
--- /dev/null
+++ b/libstdc++-v3/testsuite/26_numerics/bit/bitops.rot/rotr.cc
@@ -0,0 +1,119 @@
+// Copyright (C) 2018 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <bit>
+
+template<typename UInt>
+constexpr auto
+test(UInt x)
+-> decltype(std::rotr(x, 0u))
+{
+ static_assert( noexcept(std::rotr(x, 0u)) );
+
+ constexpr unsigned digits = std::numeric_limits<UInt>::digits;
+
+ static_assert( std::rotr((UInt)0, 0) == 0 );
+ static_assert( std::rotr((UInt)0, 1) == 0 );
+ static_assert( std::rotr((UInt)0, 4) == 0 );
+ static_assert( std::rotr((UInt)0, 8) == 0 );
+ static_assert( std::rotr((UInt)-1, 0) == (UInt)-1 );
+ static_assert( std::rotr((UInt)-1, 1) == (UInt)-1 );
+ static_assert( std::rotr((UInt)-1, 4) == (UInt)-1 );
+ static_assert( std::rotr((UInt)-1, 8) == (UInt)-1 );
+
+ static_assert( std::rotr((UInt)128, 0) == (UInt)128 >> 0 );
+ static_assert( std::rotr((UInt)128, 1) == (UInt)128 >> 1 );
+ static_assert( std::rotr((UInt)128, 4) == (UInt)128 >> 4 );
+ static_assert( std::rotr((UInt)1, digits) == (UInt)1 );
+ static_assert( std::rotr((UInt)7, digits) == (UInt)7 );
+ static_assert( std::rotr((UInt)6, digits - 1) == (UInt)12 );
+ static_assert( std::rotr((UInt)36, digits - 2) == (UInt)144 );
+
+ static_assert( std::rotr((UInt)0b0110'1100, 1) == 0b0011'0110 );
+ static_assert( std::rotr((UInt)0b0110'1100, digits - 1) == 0b1101'1000 );
+
+ static_assert( std::rotr((UInt)0x01, 0 ) == 0x01 );
+ static_assert( std::rotr((UInt)0x10, 0 ) == 0x10 );
+ static_assert( std::rotr((UInt)0x10, 1 ) == 0x08 );
+ static_assert( std::rotr((UInt)0x10, 2 ) == 0x04 );
+ static_assert( std::rotr((UInt)0x10, 3 ) == 0x02 );
+ static_assert( std::rotr((UInt)0x11, digits - 1 ) == 0x22 );
+ static_assert( std::rotr((UInt)0x11, digits - 2 ) == 0x44 );
+
+ if constexpr (std::numeric_limits<UInt>::digits > 8)
+ {
+ static_assert( std::rotr((UInt)0b0011'0111, 3)
+ == (0b0110 | ((UInt)0b0111 << digits - 3)) );
+ static_assert( std::rotr((UInt)0b1010'0101, 4)
+ == (0b1010 | ((UInt)0b0101 << digits - 4)) );
+ }
+
+ return true;
+}
+
+static_assert( test( (unsigned char)0 ) );
+static_assert( test( (unsigned short)0 ) );
+static_assert( test( (unsigned int)0 ) );
+static_assert( test( (unsigned long)0 ) );
+static_assert( test( (unsigned long long)0 ) );
+
+// std::rotr(T) shall not participate in overload resolution
+// unless T is an unsigned integer type.
+struct X { constexpr bool did_not_match() { return true; } };
+constexpr X test(...) { return X{}; }
+static_assert( test( (bool)0 ).did_not_match() );
+static_assert( test( (char)0 ).did_not_match() );
+static_assert( test( (int)0 ).did_not_match() );
+static_assert( test( (char16_t)0 ).did_not_match() );
+static_assert( test( (float)0 ).did_not_match() );
+static_assert( test( (void*)0 ).did_not_match() );
+static_assert( test( X{} ).did_not_match() );
+enum E : unsigned { e };
+static_assert( test( e ).did_not_match() );
+
+#ifndef __STRICT_ANSI__
+#include <cstddef>
+static_assert( std::rotr(std::byte{0}, 4) == std::byte{0} );
+static_assert( std::rotr(std::byte{0x01}, 4) == std::byte{0x10} );
+static_assert( std::rotr(std::byte{0x02}, 3) == std::byte{0x40} );
+static_assert( std::rotr(std::byte{0x03}, 2) == std::byte{0xc0} );
+static_assert( std::rotr(std::byte{0x30}, 2) == std::byte{0x0c} );
+static_assert( std::rotr(std::byte{0x40}, 1) == std::byte{0x20} );
+static_assert( std::rotr(std::byte{0x41}, 9) == std::byte{0xa0} );
+#else
+static_assert( test( (std::byte)0 ).did_not_match() );
+#endif
+
+#if !defined(__STRICT_ANSI__) && defined _GLIBCXX_USE_INT128
+static_assert( test( (unsigned __int128)0 ) );
+static_assert( test( (__int128)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_0)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_0)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_0)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_1)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_1)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_1)0 ).did_not_match() );
+#endif
+#if defined(__GLIBCXX_TYPE_INT_N_2)
+static_assert( test( (unsigned __GLIBCXX_TYPE_INT_N_2)0 ) );
+static_assert( test( (__GLIBCXX_TYPE_INT_N_2)0 ).did_not_match() );
+#endif