Skip to content

Commit

Permalink
Add constexpr annotation to align_up/down.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjp41 committed Sep 11, 2020
1 parent 17d5a3e commit d3ecd66
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ds/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,19 @@ namespace snmalloc
return BITS - clz_const(x - 1);
}

static SNMALLOC_FAST_PATH size_t align_down(size_t value, size_t alignment)
constexpr SNMALLOC_FAST_PATH size_t
align_down(size_t value, size_t alignment)
{
SNMALLOC_ASSERT(next_pow2(alignment) == alignment);
SNMALLOC_ASSERT(next_pow2_const(alignment) == alignment);

size_t align_1 = alignment - 1;
value &= ~align_1;
return value;
}

static inline size_t align_up(size_t value, size_t alignment)
constexpr SNMALLOC_FAST_PATH size_t align_up(size_t value, size_t alignment)
{
SNMALLOC_ASSERT(next_pow2(alignment) == alignment);
SNMALLOC_ASSERT(next_pow2_const(alignment) == alignment);

size_t align_1 = alignment - 1;
value += align_1;
Expand Down

0 comments on commit d3ecd66

Please sign in to comment.