Go to the documentation of this file.
15 #include "absl/numeric/bits.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "absl/random/random.h"
108 constexpr
int kTrials = 100;
110 for (
int i = 0;
i < kTrials; ++
i) {
113 int shift =
absl::Uniform(rng, -2 * std::numeric_limits<uint8_t>::digits,
114 2 * std::numeric_limits<uint8_t>::digits);
119 for (
int i = 0;
i < kTrials; ++
i) {
122 int shift =
absl::Uniform(rng, -2 * std::numeric_limits<uint16_t>::digits,
123 2 * std::numeric_limits<uint16_t>::digits);
128 for (
int i = 0;
i < kTrials; ++
i) {
131 int shift =
absl::Uniform(rng, -2 * std::numeric_limits<uint32_t>::digits,
132 2 * std::numeric_limits<uint32_t>::digits);
137 for (
int i = 0;
i < kTrials; ++
i) {
140 int shift =
absl::Uniform(rng, -2 * std::numeric_limits<uint64_t>::digits,
141 2 * std::numeric_limits<uint64_t>::digits);
147 TEST(Counting, LeadingZeroes) {
148 #if ABSL_INTERNAL_HAS_CONSTEXPR_CLZ
168 for (
int i = 0;
i < 8;
i++) {
172 for (
int i = 0;
i < 16;
i++) {
176 for (
int i = 0;
i < 32;
i++) {
180 for (
int i = 0;
i < 64;
i++) {
186 #if ABSL_INTERNAL_HAS_CONSTEXPR_CLZ
207 TEST(Counting, TrailingZeroes) {
208 #if ABSL_INTERNAL_HAS_CONSTEXPR_CTZ
230 #if ABSL_INTERNAL_HAS_CONSTEXPR_CTZ
252 #if ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT
265 #endif // ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT
280 for (
int i = 0;
i < 8;
i++) {
287 for (
int i = 0;
i < 16;
i++) {
294 for (
int i = 0;
i < 32;
i++) {
299 for (
int i = 0;
i < 64;
i++) {
305 template <
typename T>
311 template <
typename T>
314 for (
int i = 0; i < std::numeric_limits<T>::digits;
i++) {
317 ret.value |=
T{1} <<
i;
326 constexpr
int kTrials = 100;
328 for (
int i = 0;
i < kTrials; ++
i) {
329 auto input = GeneratePopcountInput<uint8_t>(rng);
333 for (
int i = 0;
i < kTrials; ++
i) {
334 auto input = GeneratePopcountInput<uint16_t>(rng);
338 for (
int i = 0;
i < kTrials; ++
i) {
339 auto input = GeneratePopcountInput<uint32_t>(rng);
343 for (
int i = 0;
i < kTrials; ++
i) {
344 auto input = GeneratePopcountInput<uint64_t>(rng);
349 TEST(IntegralPowersOfTwo, SingleBit) {
389 template <
typename T, T arg, T = bit_ceil(arg)>
393 template <
typename T, T arg>
398 TEST(IntegralPowersOfTwo, Ceiling) {
399 #if ABSL_INTERNAL_HAS_CONSTEXPR_CLZ
405 static_assert(
bit_ceil(1337
u) == 2048,
"");
406 static_assert(
bit_ceil(65536
u) == 65536,
"");
407 static_assert(
bit_ceil(65536
u - 1337
u) == 65536,
"");
453 #if ABSL_INTERNAL_HAS_CONSTEXPR_CLZ
460 static_assert(
bit_floor(65536
u) == 65536,
"");
461 static_assert(
bit_floor(65536
u - 1337
u) == 32768,
"");
476 for (
int i = 0;
i < 8;
i++) {
484 for (
int i = 0;
i < 16;
i++) {
492 for (
int i = 0;
i < 32;
i++) {
500 for (
int i = 0;
i < 64;
i++) {
509 TEST(IntegralPowersOfTwo, Width) {
510 #if ABSL_INTERNAL_HAS_CONSTEXPR_CLZ
546 for (
int i = 0;
i < 8;
i++) {
550 for (
int i = 0;
i < 16;
i++) {
554 for (
int i = 0;
i < 32;
i++) {
558 for (
int i = 0;
i < 64;
i++) {
564 #if defined(__GNUC__)
566 "popcount should be constexpr");
#define EXPECT_FALSE(condition)
PopcountInput< T > GeneratePopcountInput(absl::BitGen &gen)
OPENSSL_EXPORT pem_password_cb void * u
ABSL_INTERNAL_CONSTEXPR_CTZ std::enable_if< std::is_unsigned< T >::value, int >::type countr_one(T x) noexcept
TEST(NotificationTest, SanityTest)
ABSL_NAMESPACE_BEGIN constexpr ABSL_MUST_USE_RESULT std::enable_if< std::is_unsigned< T >::value, T >::type rotl(T x, int s) noexcept
#define ABSL_NAMESPACE_END
#define T(upbtypeconst, upbtype, ctype, default_value)
Duration Floor(const Duration d, const Duration unit)
#define ABSL_NAMESPACE_BEGIN
unsigned __int64 uint64_t
#define ABSL_INTERNAL_HAS_CONSTEXPR_CLZ
ABSL_INTERNAL_CONSTEXPR_CTZ std::enable_if< std::is_unsigned< T >::value, int >::type countr_zero(T x) noexcept
bool IsBitCeilConstantExpression(char)
constexpr std::enable_if< std::is_unsigned< T >::value, bool >::type has_single_bit(T x) noexcept
ABSL_INTERNAL_CONSTEXPR_CLZ std::enable_if< std::is_unsigned< T >::value, int >::type countl_one(T x) noexcept
OPENSSL_EXPORT GENERAL_NAME * gen
ABSL_INTERNAL_CONSTEXPR_CLZ std::enable_if< std::is_unsigned< T >::value, T >::type bit_width(T x) noexcept
ABSL_INTERNAL_CONSTEXPR_CLZ std::enable_if< std::is_unsigned< T >::value, int >::type countl_zero(T x) noexcept
ABSL_INTERNAL_CONSTEXPR_POPCOUNT std::enable_if< std::is_unsigned< T >::value, int >::type popcount(T x) noexcept
UniquePtr< SSL_SESSION > ret
static uint64_t Rotate(uint64_t val, int shift)
ABSL_INTERNAL_CONSTEXPR_CLZ std::enable_if< std::is_unsigned< T >::value, T >::type bit_floor(T x) noexcept
#define ABSL_INTERNAL_HAS_CONSTEXPR_CTZ
#define EXPECT_TRUE(condition)
#define ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT
constexpr ABSL_MUST_USE_RESULT std::enable_if< std::is_unsigned< T >::value, T >::type rotr(T x, int s) noexcept
ABSL_INTERNAL_CONSTEXPR_CLZ std::enable_if< std::is_unsigned< T >::value, T >::type bit_ceil(T x)
bool Bernoulli(URBG &&urbg, double p)
ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_POPCOUNT int Popcount(T x) noexcept
absl::enable_if_t<!std::is_same< R, void >::value, R > Uniform(TagType tag, URBG &&urbg, R lo, R hi)
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:48