• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Test the __XXXX routines in the <bit> header.
10 // These are not supposed to be exhaustive tests, just sanity checks.
11 
12 #include <__bit/bit_log2.h>
13 #include <__bit/countl.h>
14 #include <__bit/rotate.h>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
test()19 TEST_CONSTEXPR_CXX14 bool test() {
20   const unsigned v = 0x12345678;
21 
22   ASSERT_SAME_TYPE(unsigned, decltype(std::__rotr(v, 3)));
23   ASSERT_SAME_TYPE(int, decltype(std::__countl_zero(v)));
24 
25   assert(std::__rotr(v, 3) == 0x02468acfU);
26   assert(std::__countl_zero(v) == 3);
27 
28 #if TEST_STD_VER > 17
29   ASSERT_SAME_TYPE(unsigned, decltype(std::__bit_log2(v)));
30   assert(std::__bit_log2(v) == 28);
31 #endif
32 
33   return true;
34 }
35 
main(int,char **)36 int main(int, char**) {
37   test();
38 #if TEST_STD_VER > 11
39   static_assert(test(), "");
40 #endif
41 
42   return 0;
43 }
44