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>
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