Reorganise the code

This commit is contained in:
2024-04-29 21:42:33 +01:00
parent 7164156c35
commit 05e56d67ea
10 changed files with 2 additions and 7 deletions

28
src/mem/util/mem_utils.c Normal file
View File

@@ -0,0 +1,28 @@
#include "mem_utils.h"
#include "aliases.h"
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
internal bool is_power_of_two(u64 num) { return (num & (num - 1)) == 0; }
void *wapp_mem_util_align_forward(void *ptr, u64 alignment) {
if (!ptr) {
return NULL;
}
assert(is_power_of_two(alignment));
uptr p = (uptr)ptr;
uptr align = (uptr)alignment;
// Similar to p % align, but it's a faster implementation that works fine
// because align is guaranteed to be a power of 2
uptr modulo = p & (align - 1);
if (modulo != 0) {
p += align - modulo;
}
return (void *)p;
}