diff options
author | Victor Khimenko <khim@google.com> | 2023-12-14 02:10:24 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-12-14 02:10:24 +0000 |
commit | 87ada30fbde026edeb4a9300daad285f188e6b69 (patch) | |
tree | a91a3b3bcfd79f16aaad77c86a21d799c005d1d0 | |
parent | e8923d6c9caaa4a9eb38cb4df060aee7c64c97b2 (diff) | |
parent | 0af29d6b2649821d52a0f126e7b411b4c4d47ea6 (diff) | |
download | binary_translation-87ada30fbde026edeb4a9300daad285f188e6b69.tar.gz |
Merge "Implement BitUtilLog2 efficiently" into main am: 9ecae22fcf am: e9ab9928e0 am: 0af29d6b26
Original change: https://android-review.googlesource.com/c/platform/frameworks/libs/binary_translation/+/2874095
Change-Id: Ib4fae718714cfd07ab8463e054185f1be5972e6c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | base/include/berberis/base/bit_util.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/base/include/berberis/base/bit_util.h b/base/include/berberis/base/bit_util.h index e3610dde..4fb08470 100644 --- a/base/include/berberis/base/bit_util.h +++ b/base/include/berberis/base/bit_util.h @@ -70,8 +70,9 @@ constexpr bool IsAligned(T* p, size_t align) { template <typename T> constexpr T BitUtilLog2(T x) { static_assert(std::is_integral_v<T>, "Log2: T must be integral"); - DCHECK(IsPowerOf2(x)); - return x == 1 ? 0 : BitUtilLog2(x >> 1) + 1; + CHECK(IsPowerOf2(x)); + // TODO(b/260725458): Use std::countr_zero after C++20 becomes available + return __builtin_ctz(x); } // Verify that argument value fits into a target. |