From 152656f8d3c34a1a5efef6d512439fc686690ecf Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Thu, 25 Sep 2008 02:31:50 -0700 Subject: [PATCH] Actually make non-power-of-2 alignments work We can't use ($$-$) % (%1) since the wraparound will be wrong except for powers of 2. Signed-off-by: H. Peter Anvin --- macros/smartalign.mac | 6 +++--- standard.mac | 6 +++--- test/align13.asm | 16 ++++++++++++++++ test/align13s.asm | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 test/align13.asm create mode 100644 test/align13s.asm diff --git a/macros/smartalign.mac b/macros/smartalign.mac index b79a8549..2c45d284 100644 --- a/macros/smartalign.mac +++ b/macros/smartalign.mac @@ -161,14 +161,14 @@ USE: smartalign %unimacro align 1-2+.nolist %imacro align 1-2+.nolist %ifnempty %2 - times ($$-$) % (%1) %2 + times ((%1) - (($-$$) % (%1))) %2 %else %push - %assign %$pad ($$-$) % %1 + %assign %$pad (%1) - (($-$$) % (%1)) %if %$pad > __ALIGN_JMP_THRESHOLD__ jmp %$end ; We can't re-use %$pad here as $ will have changed! - times ($$-$) % %1 db 90h + times ((%1) - (($-$$) % (%1))) nop %$end: %else %if __BITS__ == 16 diff --git a/standard.mac b/standard.mac index 4e356d96..b3e4ae3a 100644 --- a/standard.mac +++ b/standard.mac @@ -66,13 +66,13 @@ __SECT__ %endmacro %imacro align 1-2+.nolist nop - times ($$-$) % (%1) %2 + times ((%1) - (($-$$) % (%1))) %2 %endmacro %imacro alignb 1-2+.nolist %ifempty %2 - resb ($$-$) % (%1) + resb ((%1) - (($-$$) % (%1))) %else - times ($$-$) % (%1) %2 + times ((%1) - (($-$$) % (%1))) %2 %endif %endmacro diff --git a/test/align13.asm b/test/align13.asm new file mode 100644 index 00000000..7f5b70fb --- /dev/null +++ b/test/align13.asm @@ -0,0 +1,16 @@ +; Test of non-power-of-2 alignment + + bits 32 + + inc eax + inc eax + align 13 + inc eax + inc eax + align 13 + inc eax + inc eax + align 13 + inc eax + inc eax + \ No newline at end of file diff --git a/test/align13s.asm b/test/align13s.asm new file mode 100644 index 00000000..f0d4b3a3 --- /dev/null +++ b/test/align13s.asm @@ -0,0 +1,17 @@ +; Test of non-power-of-2 alignment +%use smartalign + + bits 32 + + inc eax + inc eax + align 13 + inc eax + inc eax + align 13 + inc eax + inc eax + align 13 + inc eax + inc eax + \ No newline at end of file -- 2.11.4.GIT