• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Test the __XXXX routines in the <bit> header.
10 // These are not supposed to be exhaustive tests, just sanity checks.
11 
12 #include <bit>
13 #include <cassert>
14 
15 #include "test_macros.h"
16 
test()17 TEST_CONSTEXPR_CXX14 bool test() {
18   const unsigned v = 0x12345678;
19 
20   ASSERT_SAME_TYPE(unsigned, decltype(std::__rotr(v, 3)));
21   ASSERT_SAME_TYPE(int, decltype(std::__countl_zero(v)));
22 
23   assert(std::__rotr(v, 3) == 0x02468acfU);
24   assert(std::__countl_zero(v) == 3);
25 
26 #if TEST_STD_VER > 17
27   ASSERT_SAME_TYPE(unsigned, decltype(std::__bit_log2(v)));
28   assert(std::__bit_log2(v) == 28);
29 #endif
30 
31   return true;
32 }
33 
main(int,char **)34 int main(int, char**) {
35   test();
36 #if TEST_STD_VER > 11
37   static_assert(test(), "");
38 #endif
39 
40   return 0;
41 }
42