Skip to content

Commit

Permalink
Use C++20 bit manipulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
shin1m committed Jul 8, 2023
1 parent c8b2578 commit c543f71
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions include/xemmai/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "portable/define.h"
#include <atomic>
#include <bit>
#include <map>
#include <mutex>
#include <new>
Expand All @@ -16,10 +17,6 @@ namespace xemmai
template<typename T>
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__
Expand Down Expand Up @@ -139,10 +136,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));

Expand Down

0 comments on commit c543f71

Please sign in to comment.