From a1db1cd9e22e77041d5f1360f1d1ccdc52b86306 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Mon, 26 May 2025 00:47:54 +0200 Subject: Implement chunked_buffer --- asl/base/numeric.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'asl/base/numeric.hpp') diff --git a/asl/base/numeric.hpp b/asl/base/numeric.hpp index bbd229d..8d3b8ef 100644 --- a/asl/base/numeric.hpp +++ b/asl/base/numeric.hpp @@ -7,6 +7,7 @@ #include "asl/base/integers.hpp" #include "asl/base/bit.hpp" #include "asl/base/meta.hpp" +#include "asl/base/assert.hpp" namespace asl { @@ -14,10 +15,24 @@ namespace asl template constexpr bool is_pow2(T x) { - using unsigned_type = select_t, T, as_unsigned_integer>; + using unsigned_type = as_unsigned_integer; return x > 0 && has_single_bit(static_cast(x)); } +template +constexpr T round_down_pow2(T x, T div) +{ + ASL_ASSERT(is_pow2(div)); + return x & (-div); +} + +template +constexpr T round_up_pow2(T x, T div) +{ + ASL_ASSERT(is_pow2(div)); + return (x + (div - 1)) & (-div); +} + template concept is_numeric = is_integer || is_floating_point; -- cgit