diff options
author | Abseil Team <absl-team@google.com> | 2021-01-12 07:36:20 -0800 |
---|---|---|
committer | Andy Getz <durandal@google.com> | 2021-01-12 11:57:11 -0500 |
commit | 322ae2420d27fc96d0a8ab1167d7de33671048df (patch) | |
tree | e00368177de976612408e0d995ff352fac200a0d /absl/numeric | |
parent | 62ce712ecc887f669610a93efe18abecf70b47a0 (diff) | |
download | abseil-322ae2420d27fc96d0a8ab1167d7de33671048df.tar.gz abseil-322ae2420d27fc96d0a8ab1167d7de33671048df.tar.bz2 abseil-322ae2420d27fc96d0a8ab1167d7de33671048df.zip |
Export of internal Abseil changes
--
1609589925459c2c0b2a17912c0d65227f709db9 by Abseil Team <absl-team@google.com>:
Clarify the "Potential Mutex deadlock" reason message.
PiperOrigin-RevId: 351367862
--
88bf28863db2c2d2d48767c3e4dfab6a48bdff79 by Abseil Team <absl-team@google.com>:
Print CPU number is fault handler.
This CL adds code to print CPU number inside the fault handler. This is only supported on Linux. The CPU number is also a hint only. There is no guarantee that it is indeed the CPU on which a fault happened.
PiperOrigin-RevId: 351238373
--
66a9c8e44b5744fec1ca0d7b8db7e1d50772d9a2 by Samuel Benzaquen <sbenza@google.com>:
Add better error message for ODR violations of flags.
PiperOrigin-RevId: 351197423
--
6efd1efb341563148dd43255aaa4bf959dfd9554 by Chris Kennelly <ckennelly@google.com>:
Assume bitwise builtins are available on GCC.
These are long-standing builtins but are not consistently detected by
ABSL_HAVE_BUILTIN.
PiperOrigin-RevId: 350814036
GitOrigin-RevId: 1609589925459c2c0b2a17912c0d65227f709db9
Change-Id: Ied3fd2f135187f2c316b403fba45f3bbaea54138
Diffstat (limited to 'absl/numeric')
-rw-r--r-- | absl/numeric/bits_test.cc | 8 | ||||
-rw-r--r-- | absl/numeric/internal/bits.h | 29 |
2 files changed, 27 insertions, 10 deletions
diff --git a/absl/numeric/bits_test.cc b/absl/numeric/bits_test.cc index 8bf7bc9f..7c942aae 100644 --- a/absl/numeric/bits_test.cc +++ b/absl/numeric/bits_test.cc @@ -560,6 +560,14 @@ TEST(IntegralPowersOfTwo, Width) { } } +// On GCC and Clang, anticiapte that implementations will be constexpr +#if defined(__GNUC__) +static_assert(ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT, + "popcount should be constexpr"); +static_assert(ABSL_INTERNAL_HAS_CONSTEXPR_CLZ, "clz should be constexpr"); +static_assert(ABSL_INTERNAL_HAS_CONSTEXPR_CTZ, "ctz should be constexpr"); +#endif + } // namespace ABSL_NAMESPACE_END } // namespace absl diff --git a/absl/numeric/internal/bits.h b/absl/numeric/internal/bits.h index af45700f..e51941d7 100644 --- a/absl/numeric/internal/bits.h +++ b/absl/numeric/internal/bits.h @@ -28,8 +28,15 @@ #include "absl/base/attributes.h" #include "absl/base/config.h" -#if ABSL_HAVE_BUILTIN(__builtin_popcountl) && \ - ABSL_HAVE_BUILTIN(__builtin_popcountll) +#if defined(__GNUC__) && !defined(__clang__) +// GCC +#define ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(x) 1 +#else +#define ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(x) ABSL_HAVE_BUILTIN(x) +#endif + +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcountl) && \ + ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcountll) #define ABSL_INTERNAL_CONSTEXPR_POPCOUNT constexpr #define ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT 1 #else @@ -37,7 +44,8 @@ #define ABSL_INTERNAL_HAS_CONSTEXPR_POPCOUNT 0 #endif -#if ABSL_HAVE_BUILTIN(__builtin_clz) && ABSL_HAVE_BUILTIN(__builtin_clzll) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clz) && \ + ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clzll) #define ABSL_INTERNAL_CONSTEXPR_CLZ constexpr #define ABSL_INTERNAL_HAS_CONSTEXPR_CLZ 1 #else @@ -45,7 +53,8 @@ #define ABSL_INTERNAL_HAS_CONSTEXPR_CLZ 0 #endif -#if ABSL_HAVE_BUILTIN(__builtin_ctz) && ABSL_HAVE_BUILTIN(__builtin_ctzll) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctz) && \ + ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctzll) #define ABSL_INTERNAL_CONSTEXPR_CTZ constexpr #define ABSL_INTERNAL_HAS_CONSTEXPR_CTZ 1 #else @@ -85,7 +94,7 @@ ABSL_MUST_USE_RESULT ABSL_ATTRIBUTE_ALWAYS_INLINE constexpr T RotateLeft( ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_POPCOUNT inline int Popcount32(uint32_t x) noexcept { -#if ABSL_HAVE_BUILTIN(__builtin_popcount) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcount) static_assert(sizeof(unsigned int) == sizeof(x), "__builtin_popcount does not take 32-bit arg"); return __builtin_popcount(x); @@ -98,7 +107,7 @@ Popcount32(uint32_t x) noexcept { ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_POPCOUNT inline int Popcount64(uint64_t x) noexcept { -#if ABSL_HAVE_BUILTIN(__builtin_popcountll) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_popcountll) static_assert(sizeof(unsigned long long) == sizeof(x), // NOLINT(runtime/int) "__builtin_popcount does not take 64-bit arg"); return __builtin_popcountll(x); @@ -122,7 +131,7 @@ Popcount(T x) noexcept { ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline int CountLeadingZeroes32(uint32_t x) { -#if ABSL_HAVE_BUILTIN(__builtin_clz) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clz) // Use __builtin_clz, which uses the following instructions: // x86: bsr, lzcnt // ARM64: clz @@ -169,7 +178,7 @@ CountLeadingZeroes16(uint16_t x) { ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CLZ inline int CountLeadingZeroes64(uint64_t x) { -#if ABSL_HAVE_BUILTIN(__builtin_clzll) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_clzll) // Use __builtin_clzll, which uses the following instructions: // x86: bsr, lzcnt // ARM64: clz @@ -240,7 +249,7 @@ CountLeadingZeroes(T x) { ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CTZ inline int CountTrailingZeroesNonzero32(uint32_t x) { -#if ABSL_HAVE_BUILTIN(__builtin_ctz) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctz) static_assert(sizeof(unsigned int) == sizeof(x), "__builtin_ctz does not take 32-bit arg"); return __builtin_ctz(x); @@ -262,7 +271,7 @@ CountTrailingZeroesNonzero32(uint32_t x) { ABSL_ATTRIBUTE_ALWAYS_INLINE ABSL_INTERNAL_CONSTEXPR_CTZ inline int CountTrailingZeroesNonzero64(uint64_t x) { -#if ABSL_HAVE_BUILTIN(__builtin_ctzll) +#if ABSL_NUMERIC_INTERNAL_HAVE_BUILTIN_OR_GCC(__builtin_ctzll) static_assert(sizeof(unsigned long long) == sizeof(x), // NOLINT(runtime/int) "__builtin_ctzll does not take 64-bit arg"); return __builtin_ctzll(x); |