| 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 | // XFAIL: FROZEN-CXX03-HEADERS-FIXME |
| 13 | |
| 14 | #include <__bit/bit_log2.h> |
| 15 | #include <__bit/countl.h> |
| 16 | #include <__bit/rotate.h> |
| 17 | #include <cassert> |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | |
| 21 | TEST_CONSTEXPR_CXX14 bool test() { |
| 22 | const unsigned v = 0x12345678; |
| 23 | |
| 24 | ASSERT_SAME_TYPE(unsigned, decltype(std::__rotr(v, 3))); |
| 25 | ASSERT_SAME_TYPE(int, decltype(std::__countl_zero(v))); |
| 26 | |
| 27 | assert(std::__rotr(v, 3) == 0x02468acfU); |
| 28 | assert(std::__countl_zero(v) == 3); |
| 29 | |
| 30 | #if TEST_STD_VER > 17 |
| 31 | ASSERT_SAME_TYPE(unsigned, decltype(std::__bit_log2(v))); |
| 32 | assert(std::__bit_log2(v) == 28); |
| 33 | #endif |
| 34 | |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | int main(int, char**) { |
| 39 | test(); |
| 40 | #if TEST_STD_VER > 11 |
| 41 | static_assert(test(), "" ); |
| 42 | #endif |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |