From 52a6cd1b41fc4d58e3b0b918a830e4078dcf1b56 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 5 Apr 2026 16:08:54 -0500 Subject: [PATCH] Implement memalignment (C23). Note that this returns the actual alignment of the address, which can be greater than what can be used with alignas. In IIGS-specific code, it could be used to test for page or bank alignment. --- stdlib.asm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/stdlib.asm b/stdlib.asm index 6548bc6..f37045b 100644 --- a/stdlib.asm +++ b/stdlib.asm @@ -778,6 +778,40 @@ ret stx n creturn 2:n end +**************************************************************** +* +* size_t memalignment(const void *p) +* +* Inputs: +* p - a pointer +* +* Outputs: +* The maximum alignment satisfied by p. +* +**************************************************************** +* +memalignment start + + csubroutine (4:p) + + lda p compute alignment = p & -p + beq lb1 + eor #$ffff + inc a + and p + sta p + stz p+2 + bra ret + +lb1 lda p+2 + eor #$ffff + inc a + and p+2 + sta p+2 + +ret creturn 4:p + end + **************************************************************** * * void qsort(base, count, size, compar)