%endif
; Name of the .rodata section.
-; Kludge: Something on OS X fails to align .rodata even given an align attribute,
-; so use a different read-only section.
%macro SECTION_RODATA 0-1 16
- %ifidn __OUTPUT_FORMAT__,macho64
- SECTION .text align=%1
- %elifidn __OUTPUT_FORMAT__,macho
- SECTION .text align=%1
- fakegot:
- %elifidn __OUTPUT_FORMAT__,aout
+ ; Kludge: Something on OS X fails to align .rodata even given an align
+ ; attribute, so use a different read-only section. This has been fixed in
+ ; yasm 0.8.0 and nasm 2.6.
+ %ifdef __YASM_VERSION_ID__
+ %if __YASM_VERSION_ID__ < 00080000h
+ %define NEED_MACHO_RODATA_KLUDGE
+ %endif
+ %elifdef __NASM_VERSION_ID__
+ %if __NASM_VERSION_ID__ < 02060000h
+ %define NEED_MACHO_RODATA_KLUDGE
+ %endif
+ %endif
+
+ %ifidn __OUTPUT_FORMAT__,aout
section .text
%else
- SECTION .rodata align=%1
+ %ifndef NEED_MACHO_RODATA_KLUDGE
+ SECTION .rodata align=%1
+ %else
+ %ifidn __OUTPUT_FORMAT__,macho64
+ SECTION .text align=%1
+ %elifidn __OUTPUT_FORMAT__,macho
+ SECTION .text align=%1
+ fakegot:
+ %else
+ SECTION .rodata align=%1
+ %endif
+ %endif
%endif
+
+ %undef NEED_MACHO_RODATA_KLUDGE
%endmacro
; aout does not support align=
default rel
%endif
+%macro CPUNOP 1
+ %if HAVE_CPUNOP
+ CPU %1
+ %endif
+%endmacro
+
; Always use long nops (reduces 0x90 spam in disassembly on x86_32)
-CPU amdnop
+CPUNOP amdnop
; Macros to eliminate most code duplication between x86_32 and x86_64:
; Currently this works only for leaf functions which load all their arguments
%define r%1mp %2
%elif ARCH_X86_64 ; memory
%define r%1m [rsp + stack_offset + %3]
- %define r%1mp qword r %+ %1m
+ %define r%1mp qword r %+ %1 %+ m
%else
%define r%1m [esp + stack_offset + %3]
- %define r%1mp dword r %+ %1m
+ %define r%1mp dword r %+ %1 %+ m
%endif
%define r%1 %2
%endmacro
%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names...
%assign num_args %1
%assign regs_used %2
+ %if num_args > 7
+ %assign num_args 7
+ %endif
%if regs_used > 7
%assign regs_used 7
%endif
; Applies any symbol mangling needed for C linkage, and sets up a define such that
; subsequent uses of the function name automatically refer to the mangled version.
; Appends cpuflags to the function name if cpuflags has been specified.
-%macro cglobal 1-2+ ; name, [PROLOGUE args]
-%if %0 == 1
- cglobal_internal %1 %+ SUFFIX
-%else
+%macro cglobal 1-2+ "" ; name, [PROLOGUE args]
cglobal_internal %1 %+ SUFFIX, %2
-%endif
%endmacro
%macro cglobal_internal 1-2+
%ifndef cglobaled_%1
%1:
RESET_MM_PERMUTATION ; not really needed, but makes disassembly somewhat nicer
%assign stack_offset 0
- %if %0 > 1
+ %ifnidn %2, ""
PROLOGUE %2
%endif
%endmacro
%assign cpuflags_mmx (1<<0)
%assign cpuflags_mmx2 (1<<1) | cpuflags_mmx
%assign cpuflags_3dnow (1<<2) | cpuflags_mmx
-%assign cpuflags_3dnow2 (1<<3) | cpuflags_3dnow
+%assign cpuflags_3dnowext (1<<3) | cpuflags_3dnow
%assign cpuflags_sse (1<<4) | cpuflags_mmx2
%assign cpuflags_sse2 (1<<5) | cpuflags_sse
%assign cpuflags_sse2slow (1<<6) | cpuflags_sse2
; All subsequent functions (up to the next INIT_CPUFLAGS) is built for the specified cpu.
; You shouldn't need to invoke this macro directly, it's a subroutine for INIT_MMX &co.
%macro INIT_CPUFLAGS 0-2
- CPU amdnop
+ CPUNOP amdnop
%if %0 >= 1
%xdefine cpuname %1
%assign cpuflags cpuflags_%1
%define movu lddqu
%endif
%if notcpuflag(mmx2)
- CPU basicnop
+ CPUNOP basicnop
%endif
%else
%xdefine SUFFIX
; Append cpuflags to the callee's name iff the appended name is known and the plain name isn't
%macro call 1
- call_internal %1, %1 %+ SUFFIX
+ call_internal %1 %+ SUFFIX, %1
%endmacro
%macro call_internal 2
- %xdefine %%i %1
- %ifndef cglobaled_%1
- %ifdef cglobaled_%2
- %xdefine %%i %2
+ %xdefine %%i %2
+ %ifndef cglobaled_%2
+ %ifdef cglobaled_%1
+ %xdefine %%i %1
%endif
%endif
call %%i