From 91a8f73a72c237065a4d4394f7372dc508c258d2 Mon Sep 17 00:00:00 2001 From: talha Date: Wed, 13 Mar 2024 23:31:17 +0500 Subject: Refactored memory files a bit --- memory/memory.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'memory/memory.c') diff --git a/memory/memory.c b/memory/memory.c index 0c998c7..7fb0fc2 100644 --- a/memory/memory.c +++ b/memory/memory.c @@ -1,17 +1,12 @@ #include "memory.h" -size_t clamp_top(size_t size, size_t top) -{ - return size > top ? top : size; +b8 is_power_of_two(uintptr_t x) { + return (x & (x-1)) == 0; } -uintptr_t mem_clamp_top(uintptr_t mem, uintptr_t top) +uintptr_t fast_modulo(uintptr_t p, uintptr_t a) { - return mem > top ? top : mem; -} - -b8 is_power_of_two(uintptr_t x) { - return (x & (x-1)) == 0; + return (p & (a-1)); } uintptr_t align_forward(uintptr_t ptr, size_t alignment) { @@ -21,7 +16,7 @@ uintptr_t align_forward(uintptr_t ptr, size_t alignment) { p = ptr; a = (uintptr_t)alignment; - modulo = p & (a-1); + modulo = fast_modulo(p, a); if (modulo != 0) { p += (a - modulo); @@ -133,10 +128,6 @@ void stack_init(struct stack* s, void *backing_store, size_t capacity) s->capacity = capacity; } -uintptr_t fast_modulo(uintptr_t p, uintptr_t a) -{ - return (p & (a-1)); -} size_t calc_padding_with_header(uintptr_t ptr, uintptr_t alignment, size_t hdr_sz) { -- cgit v1.2.3