Skip to content

Commit

Permalink
Merge pull request #391 from jserv/improve-align-down
Browse files Browse the repository at this point in the history
Rewrite align_down with bitwise operations
  • Loading branch information
daanx authored Apr 28, 2021
2 parents aca4624 + 5294391 commit 6d16581
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ static void* mi_align_up_ptr(void* p, size_t alignment) {
return (void*)_mi_align_up((uintptr_t)p, alignment);
}

static uintptr_t _mi_align_down(uintptr_t sz, size_t alignment) {
static inline uintptr_t _mi_align_down(uintptr_t sz, size_t alignment) {
mi_assert_internal(alignment != 0);
uintptr_t mask = alignment - 1;
if ((alignment & mask) == 0) // power of two?
return sz & ~mask;
return (sz / alignment) * alignment;
}

Expand Down

0 comments on commit 6d16581

Please sign in to comment.