Merge pull request #391 from jserv/improve-align-down

Rewrite align_down with bitwise operations
This commit is contained in:
Daan 2021-04-28 13:07:13 -07:00 committed by GitHub
commit 6d1658123c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}