From 13793dd42fe3bee48eaf90fe2f4faa2bee11d1e9 Mon Sep 17 00:00:00 2001 From: Shin-ichi MORITA Date: Sun, 9 Jul 2023 06:53:34 +0900 Subject: [PATCH] Use C++20 bit manipulation. --- include/xemmai/heap.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/include/xemmai/heap.h b/include/xemmai/heap.h index c0a90443..9e84c464 100644 --- a/include/xemmai/heap.h +++ b/include/xemmai/heap.h @@ -16,10 +16,6 @@ namespace xemmai template class t_heap { - static constexpr size_t f_log(size_t a_x) - { - return a_x > 1 ? f_log(a_x >> 1) + 1 : 0; - } static void* f_map(size_t a_n) { #ifdef __unix__ @@ -139,10 +135,10 @@ class t_heap constexpr T* f_allocate_medium(size_t a_size); public: - static constexpr size_t V_UNIT = 2 << f_log(sizeof(T) - 1); + static constexpr size_t V_UNIT = std::bit_ceil(sizeof(T)); static_assert(V_UNIT >> 1 < sizeof(T)); static_assert(V_UNIT >= sizeof(T)); - static constexpr size_t V_RANKX = sizeof(void*) * 8 - f_log(V_UNIT); + static constexpr size_t V_RANKX = std::countl_zero(V_UNIT - 1); static_assert((V_UNIT << (V_RANKX - 1)) - 1 == ~size_t(0) >> 1); static_assert((V_UNIT << V_RANKX) - 1 == ~size_t(0));