1 #include "flang/Common/bit-population-count.h"
4 using Fortran::common::BitPopulationCount
;
5 using Fortran::common::Parity
;
8 MATCH(0, BitPopulationCount(std::uint64_t{0}));
9 MATCH(false, Parity(std::uint64_t{0}));
10 MATCH(64, BitPopulationCount(~std::uint64_t{0}));
11 MATCH(false, Parity(~std::uint64_t{0}));
12 for (int j
{0}; j
< 64; ++j
) {
13 std::uint64_t x
= std::uint64_t{1} << j
;
14 MATCH(1, BitPopulationCount(x
));
15 MATCH(true, Parity(x
));
16 MATCH(63, BitPopulationCount(~x
));
17 MATCH(true, Parity(~x
));
18 for (int k
{0}; k
< j
; ++k
) {
19 std::uint64_t y
= x
| (std::uint64_t{1} << k
);
20 MATCH(2, BitPopulationCount(y
));
21 MATCH(false, Parity(y
));
22 MATCH(62, BitPopulationCount(~y
));
23 MATCH(false, Parity(~y
));
26 MATCH(0, BitPopulationCount(std::uint32_t{0}));
27 MATCH(false, Parity(std::uint32_t{0}));
28 MATCH(32, BitPopulationCount(~std::uint32_t{0}));
29 MATCH(false, Parity(~std::uint32_t{0}));
30 for (int j
{0}; j
< 32; ++j
) {
31 std::uint32_t x
= std::uint32_t{1} << j
;
32 MATCH(1, BitPopulationCount(x
));
33 MATCH(true, Parity(x
));
34 MATCH(31, BitPopulationCount(~x
));
35 MATCH(true, Parity(~x
));
36 for (int k
{0}; k
< j
; ++k
) {
37 std::uint32_t y
= x
| (std::uint32_t{1} << k
);
38 MATCH(2, BitPopulationCount(y
));
39 MATCH(false, Parity(y
));
40 MATCH(30, BitPopulationCount(~y
));
41 MATCH(false, Parity(~y
));
44 MATCH(0, BitPopulationCount(std::uint16_t{0}));
45 MATCH(false, Parity(std::uint16_t{0}));
46 MATCH(16, BitPopulationCount(static_cast<std::uint16_t>(~0)));
47 MATCH(false, Parity(static_cast<std::uint16_t>(~0)));
48 for (int j
{0}; j
< 16; ++j
) {
49 std::uint16_t x
= std::uint16_t{1} << j
;
50 MATCH(1, BitPopulationCount(x
));
51 MATCH(true, Parity(x
));
52 MATCH(15, BitPopulationCount(static_cast<std::uint16_t>(~x
)));
53 MATCH(true, Parity(static_cast<std::uint16_t>(~x
)));
54 for (int k
{0}; k
< j
; ++k
) {
55 std::uint16_t y
= x
| (std::uint16_t{1} << k
);
56 MATCH(2, BitPopulationCount(y
));
57 MATCH(false, Parity(y
));
58 MATCH(14, BitPopulationCount(static_cast<std::uint16_t>(~y
)));
59 MATCH(false, Parity(static_cast<std::uint16_t>(~y
)));
62 MATCH(0, BitPopulationCount(std::uint8_t{0}));
63 MATCH(false, Parity(std::uint8_t{0}));
64 MATCH(8, BitPopulationCount(static_cast<std::uint8_t>(~0)));
65 MATCH(false, Parity(static_cast<std::uint8_t>(~0)));
66 for (int j
{0}; j
< 8; ++j
) {
67 std::uint8_t x
= std::uint8_t{1} << j
;
68 MATCH(1, BitPopulationCount(x
));
69 MATCH(true, Parity(x
));
70 MATCH(7, BitPopulationCount(static_cast<std::uint8_t>(~x
)));
71 MATCH(true, Parity(static_cast<std::uint8_t>(~x
)));
72 for (int k
{0}; k
< j
; ++k
) {
73 std::uint8_t y
= x
| (std::uint8_t{1} << k
);
74 MATCH(2, BitPopulationCount(y
));
75 MATCH(false, Parity(y
));
76 MATCH(6, BitPopulationCount(static_cast<std::uint8_t>(~y
)));
77 MATCH(false, Parity(static_cast<std::uint8_t>(~y
)));
80 return testing::Complete();