From cb089681cfba813c1c2d6255e7598b9e75963679 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Fri, 5 Sep 2025 09:12:26 -0400 Subject: [PATCH] make arena_align_up use 16-bit values --- include/util/arena_alloc.nasm | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/include/util/arena_alloc.nasm b/include/util/arena_alloc.nasm index 1b0a1dd..52910ef 100644 --- a/include/util/arena_alloc.nasm +++ b/include/util/arena_alloc.nasm @@ -38,28 +38,26 @@ arena_init: ret ; size_t align_up(size_t x, size_t a) -; eax, ebx. ecx are all clobbered +; ax, bx. cx are all clobbered +; align x up to the nearest specified alignment (a), a should be a power of 2 +; (x + (a-1)) & ~(a-1) +; return value in ax arena_align_up: __CDECL16_ENTRY .func: - ; align x up to the nearest specified alignment (a) - ; (x + (a-1)) & ~(a-1) - mov eax, [bp + 4] ; x + + mov ax, [bp + 4] ; x - mov ebx, [bp + 6] ; a - 1 - sub ebx, 1 + mov bx, [bp + 6] + sub bx, 1 ; a - 1 - mov ecx, eax - add ecx, ebx ; x + (a+1) + mov cx, ax + add cx, bx ; x + (a+1) + not bx ; ~(a-1) - not ebx - and ecx, ebx ; ecx contains the result - - xor eax, eax - xor ebx, ebx - mov eax, ecx ; return result in eax - xor ecx, ecx + and cx, bx ; and with the inverse + mov ax, cx ; move to ax and return .endp: __CDECL16_EXIT ret