diff options
author | Luis Hector Chavez <lhchavez@google.com> | 2017-07-26 20:29:06 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-26 20:29:06 +0000 |
commit | 38bc769bac923a216e9381d720ba730bd7b2f5ef (patch) | |
tree | 0987cb51d27d74f7ff76c75683d6b504bac0e6d4 /base/bits.h | |
parent | a29e6994243913703862fdbe17c059150c9ae149 (diff) | |
parent | 54cfa4a2bacc9c43b06c1582d929da42bb165100 (diff) | |
download | libchrome-38bc769bac923a216e9381d720ba730bd7b2f5ef.tar.gz |
Revert "libchrome: Uprev the library to r456626 from Chromium" am: e5b2c6fa6f
am: 54cfa4a2ba
Change-Id: I651f5f9421f53c4c10798749155641b3e8bde687
Diffstat (limited to 'base/bits.h')
-rw-r--r-- | base/bits.h | 59 |
1 files changed, 1 insertions, 58 deletions
diff --git a/base/bits.h b/base/bits.h index d101cb731a..a3a59d1dfa 100644 --- a/base/bits.h +++ b/base/bits.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,13 +10,8 @@ #include <stddef.h> #include <stdint.h> -#include "base/compiler_specific.h" #include "base/logging.h" -#if defined(COMPILER_MSVC) -#include <intrin.h> -#endif - namespace base { namespace bits { @@ -54,58 +49,6 @@ inline size_t Align(size_t size, size_t alignment) { return (size + alignment - 1) & ~(alignment - 1); } -// These functions count the number of leading zeros in a binary value, starting -// with the most significant bit. C does not have an operator to do this, but -// fortunately the various compilers have built-ins that map to fast underlying -// processor instructions. -#if defined(COMPILER_MSVC) - -ALWAYS_INLINE uint32_t CountLeadingZeroBits32(uint32_t x) { - unsigned long index; - return LIKELY(_BitScanReverse(&index, x)) ? (31 - index) : 32; -} - -#if defined(ARCH_CPU_64_BITS) - -// MSVC only supplies _BitScanForward64 when building for a 64-bit target. -ALWAYS_INLINE uint64_t CountLeadingZeroBits64(uint64_t x) { - unsigned long index; - return LIKELY(_BitScanReverse64(&index, x)) ? (63 - index) : 64; -} - -#endif - -#elif defined(COMPILER_GCC) - -// This is very annoying. __builtin_clz has undefined behaviour for an input of -// 0, even though there's clearly a return value that makes sense, and even -// though some processor clz instructions have defined behaviour for 0. We could -// drop to raw __asm__ to do better, but we'll avoid doing that unless we see -// proof that we need to. -ALWAYS_INLINE uint32_t CountLeadingZeroBits32(uint32_t x) { - return LIKELY(x) ? __builtin_clz(x) : 32; -} - -ALWAYS_INLINE uint64_t CountLeadingZeroBits64(uint64_t x) { - return LIKELY(x) ? __builtin_clzll(x) : 64; -} - -#endif - -#if defined(ARCH_CPU_64_BITS) - -ALWAYS_INLINE size_t CountLeadingZeroBitsSizeT(size_t x) { - return CountLeadingZeroBits64(x); -} - -#else - -ALWAYS_INLINE size_t CountLeadingZeroBitsSizeT(size_t x) { - return CountLeadingZeroBits32(x); -} - -#endif - } // namespace bits } // namespace base |