1#include "flang/Common/leading-zero-bit-count.h"
2#include "testing.h"
3
4using Fortran::common::LeadingZeroBitCount;
5
6int main() {
7 MATCH(64, LeadingZeroBitCount(std::uint64_t{0}));
8 for (int j{0}; j < 64; ++j) {
9 for (int k{0}; k < j; ++k) {
10 std::uint64_t x = (std::uint64_t{1} << j) | (std::uint64_t{1} << k);
11 MATCH(63 - j, LeadingZeroBitCount(x))("j=%d, k=%d", j, k);
12 }
13 }
14 MATCH(32, LeadingZeroBitCount(std::uint32_t{0}));
15 for (int j{0}; j < 32; ++j) {
16 for (int k{0}; k < j; ++k) {
17 std::uint32_t x = (std::uint32_t{1} << j) | (std::uint32_t{1} << k);
18 MATCH(31 - j, LeadingZeroBitCount(x))("j=%d, k=%d", j, k);
19 }
20 }
21 MATCH(16, LeadingZeroBitCount(std::uint16_t{0}));
22 for (int j{0}; j < 16; ++j) {
23 for (int k{0}; k < j; ++k) {
24 std::uint16_t x = (std::uint16_t{1} << j) | (std::uint16_t{1} << k);
25 MATCH(15 - j, LeadingZeroBitCount(x))("j=%d, k=%d", j, k);
26 }
27 }
28 MATCH(8, LeadingZeroBitCount(std::uint8_t{0}));
29 for (int j{0}; j < 8; ++j) {
30 for (int k{0}; k < j; ++k) {
31 std::uint8_t x = (std::uint8_t{1} << j) | (std::uint8_t{1} << k);
32 MATCH(7 - j, LeadingZeroBitCount(x))("j=%d, k=%d", j, k);
33 }
34 }
35 return testing::Complete();
36}
37

source code of flang/unittests/Evaluate/leading-zero-bit-count.cpp