From 7c9e871eb66de64e7a1861fd1faebcd5524fed96 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 12 Dec 2024 00:17:02 +0100 Subject: Add reserve_capacity to buffer --- asl/utility.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'asl/utility.hpp') diff --git a/asl/utility.hpp b/asl/utility.hpp index 7740eff..451a1e3 100644 --- a/asl/utility.hpp +++ b/asl/utility.hpp @@ -2,6 +2,7 @@ #include "asl/meta.hpp" #include "asl/layout.hpp" +#include "asl/assert.hpp" #define ASL_MOVE(expr_) (static_cast<::asl::un_ref_t&&>(expr_)) @@ -30,6 +31,22 @@ T min(T a, T b) return (a <= b) ? a : b; } +constexpr uint64_t round_up_pow2(uint64_t v) +{ + ASL_ASSERT(v <= 0x8000'0000'0000'0000); + + v -= 1; + + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + + return v + 1; +} + #define ASL_DELETE_COPY(T) \ T(const T&) = delete; \ T& operator=(const T&) = delete; -- cgit