2 ; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 ; Use of this source code is governed by a BSD-style license
5 ; that can be found in the LICENSE file in the root of the source
6 ; tree. An additional intellectual property rights grant can be found
7 ; in the file PATENTS. All contributing project authors may
8 ; be found in the AUTHORS file in the root of the source tree.
12 %include "vpx_config.asm"
14 ; 32/64 bit compatibility macros
16 ; In general, we make the source use 64 bit syntax, then twiddle with it using
17 ; the preprocessor to get the 32 bit syntax on 32 bit platforms.
19 %ifidn __OUTPUT_FORMAT__,elf32
20 %define ABI_IS_32BIT 1
21 %elifidn __OUTPUT_FORMAT__,macho32
22 %define ABI_IS_32BIT 1
23 %elifidn __OUTPUT_FORMAT__,win32
24 %define ABI_IS_32BIT 1
25 %elifidn __OUTPUT_FORMAT__,aout
26 %define ABI_IS_32BIT 1
28 %define ABI_IS_32BIT 0
82 ; Set LIBVPX_YASM_WIN64 if output is Windows 64bit so the code will work if x64
83 ; or win64 is defined on the Yasm command line.
84 %ifidn __OUTPUT_FORMAT__,win64
85 %define LIBVPX_YASM_WIN64 1
86 %elifidn __OUTPUT_FORMAT__,x64
87 %define LIBVPX_YASM_WIN64 1
89 %define LIBVPX_YASM_WIN64 0
92 ; Declare groups of platforms
93 %ifidn __OUTPUT_FORMAT__,elf32
95 %elifidn __OUTPUT_FORMAT__,elfx32
97 %elifidn __OUTPUT_FORMAT__,elf64
103 %ifidn __OUTPUT_FORMAT__,macho32
104 %define LIBVPX_MACHO 1
105 %elifidn __OUTPUT_FORMAT__,macho64
106 %define LIBVPX_MACHO 1
108 %define LIBVPX_MACHO 0
112 ; Return the proper symbol name for the target ABI.
114 ; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
115 ; with C linkage be prefixed with an underscore.
117 %if LIBVPX_ELF || LIBVPX_YASM_WIN64
121 %define sym(x) _ %+ x
125 ; Return a global declaration with the proper decoration for the target ABI.
127 ; When CHROMIUM is defined, include attributes to hide the symbol from the
130 ; Chromium doesn't like exported global symbols due to symbol clashing with
131 ; plugins among other things.
133 ; Requires Chromium's patched copy of yasm:
134 ; http://src.chromium.org/viewvc/chrome?view=rev&revision=73761
135 ; http://www.tortall.net/projects/yasm/ticket/236
140 %if __NASM_VERSION_ID__ < 0x020e0000 ; 2.14
141 ; nasm < 2.14 does not support :private_extern directive
142 %fatal Must use nasm 2.14 or newer
147 %define globalsym(x) global sym(x) %+ :function hidden
149 %define globalsym(x) global sym(x) %+ :private_extern
152 %define globalsym(x) global sym(x)
155 %define globalsym(x) global sym(x)
159 ; Return the address specification of the given argument
162 %define arg(x) [ebp+8+4*x]
164 ; 64 bit ABI passes arguments in registers. This is a workaround to get up
165 ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
166 %if LIBVPX_YASM_WIN64
167 %define arg(x) [rbp+16+8*x]
169 %define arg(x) [rbp-8-8*x]
173 ; REG_SZ_BYTES, REG_SZ_BITS
176 %define REG_SZ_BYTES 4
177 %define REG_SZ_BITS 32
179 %define REG_SZ_BYTES 8
180 %define REG_SZ_BITS 64
184 ; ALIGN_STACK <alignment> <register>
185 ; This macro aligns the stack to the given alignment (in bytes). The stack
186 ; is left such that the previous value of the stack pointer is the first
187 ; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
188 ; This macro uses one temporary register, which is not preserved, and thus
189 ; must be specified as an argument.
193 lea rsp, [rsp - (%1 - REG_SZ_BYTES)]
199 ; The Microsoft assembler tries to impose a certain amount of type safety in
200 ; its register usage. YASM doesn't recognize these directives, so we just
201 ; %define them away to maintain as much compatibility as possible with the
202 ; original inline assembler we're porting from.
212 %ifidn __OUTPUT_FORMAT__,elf32
213 %define WRT_PLT wrt ..plt
215 extern _GLOBAL_OFFSET_TABLE_
222 add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%sub_offset wrt ..gotpc
226 %define GLOBAL(x) x + %1 wrt ..gotoff
228 %define RESTORE_GOT pop %1
230 %elifidn __OUTPUT_FORMAT__,macho32
237 %define GLOBAL(x) x + %1 - %%get_got
239 %define RESTORE_GOT pop %1
245 %ifidn __OUTPUT_FORMAT__,macho32
246 %define HIDDEN_DATA(x) x:private_extern
248 %define HIDDEN_DATA(x) x
251 %define HIDDEN_DATA(x) x
256 %define GLOBAL(x) rel x
257 %ifidn __OUTPUT_FORMAT__,elf64
258 %define WRT_PLT wrt ..plt
259 %define HIDDEN_DATA(x) x:data hidden
260 %elifidn __OUTPUT_FORMAT__,elfx32
261 %define WRT_PLT wrt ..plt
262 %define HIDDEN_DATA(x) x:data hidden
263 %elifidn __OUTPUT_FORMAT__,macho64
265 %define HIDDEN_DATA(x) x:private_extern
267 %define HIDDEN_DATA(x) x
270 %define HIDDEN_DATA(x) x
286 %macro SHADOW_ARGS_TO_STACK 1
288 %define UNSHADOW_ARGS
290 %if LIBVPX_YASM_WIN64
291 %macro SHADOW_ARGS_TO_STACK 1 ; argc
306 %macro SHADOW_ARGS_TO_STACK 1 ; argc
336 %define UNSHADOW_ARGS mov rsp, rbp
339 ; Win64 ABI requires that XMM6:XMM15 are callee saved
341 ; store registers 6-n on the stack
342 ; if u is specified, use unaligned movs.
343 ; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
344 ; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
345 ; but in some cases this is not done and unaligned movs must be used.
346 %if LIBVPX_YASM_WIN64
347 %macro SAVE_XMM 1-2 a
349 %error Only xmm registers 6-15 must be preserved
352 %define movxmm movdq %+ %2
353 %assign xmm_stack_space ((last_xmm - 5) * 16)
354 sub rsp, xmm_stack_space
357 movxmm [rsp + ((i - 6) * 16)], xmm %+ i
364 %error RESTORE_XMM must be paired with SAVE_XMM n
368 movxmm xmm %+ i, [rsp +((i - 6) * 16)]
371 add rsp, xmm_stack_space
372 ; there are a couple functions which return from multiple places.
373 ; otherwise, we could uncomment these:
375 ; %undef xmm_stack_space
386 ; Name of the rodata section
388 ; .rodata seems to be an elf-ism, as it doesn't work on OSX.
390 %ifidn __OUTPUT_FORMAT__,macho64
391 %define SECTION_RODATA section .text
392 %elifidn __OUTPUT_FORMAT__,macho32
393 %macro SECTION_RODATA 0
396 %elifidn __OUTPUT_FORMAT__,aout
397 %define SECTION_RODATA section .data
399 %define SECTION_RODATA section .rodata
403 ; Tell GNU ld that we don't require an executable stack.
404 %ifidn __OUTPUT_FORMAT__,elf32
405 section .note.GNU-stack noalloc noexec nowrite progbits
407 %elifidn __OUTPUT_FORMAT__,elf64
408 section .note.GNU-stack noalloc noexec nowrite progbits
410 %elifidn __OUTPUT_FORMAT__,elfx32
411 section .note.GNU-stack noalloc noexec nowrite progbits
415 ; On Android platforms use lrand48 when building postproc routines. Prior to L
416 ; rand() was not available.
417 %if CONFIG_POSTPROC=1 || CONFIG_VP9_POSTPROC=1
420 %define LIBVPX_RAND lrand48
423 %define LIBVPX_RAND rand
425 %endif ; CONFIG_POSTPROC || CONFIG_VP9_POSTPROC