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 <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2008-09-25 02:31:50 -07:00
parent 6e79efc26b
commit 152656f8d3
4 changed files with 39 additions and 6 deletions

View file

@ -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

View file

@ -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

16
test/align13.asm Normal file
View file

@ -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

17
test/align13s.asm Normal file
View file

@ -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