1;
2; Copyright (c) 2016, Alliance for Open Media. All rights reserved
3;
4; This source code is subject to the terms of the BSD 2 Clause License and
5; the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6; was not distributed with this source code in the LICENSE file, you can
7; obtain it at https://www.aomedia.org/license/software-license. If the Alliance for Open
8; Media Patent License 1.0 was not distributed with this source code in the
9; PATENTS file, you can obtain it at https://www.aomedia.org/license/patent-license.
10;
11
12;
13
14
15;%include "config/aom_config.asm"
16;copy all config down here   %include "aom_config.asm"
17
18ARCH_ARM equ 0
19ARCH_MIPS equ 0
20ARCH_PPC equ 0
21ARCH_X86 equ 0
22%undef ARCH_X86_64
23ARCH_X86_64 equ 1
24CONFIG_ACCOUNTING equ 0
25CONFIG_ANALYZER equ 0
26CONFIG_AV1_DECODER equ 1
27CONFIG_AV1_ENCODER equ 1
28CONFIG_BIG_ENDIAN equ 0
29CONFIG_BITSTREAM_DEBUG equ 0
30CONFIG_COEFFICIENT_RANGE_CHECKING equ 0
31CONFIG_COLLECT_INTER_MODE_RD_STATS equ 1
32CONFIG_COLLECT_RD_STATS equ 0
33CONFIG_DEBUG equ 0
34CONFIG_DIST_8X8 equ 1
35CONFIG_ENTROPY_STATS equ 0
36CONFIG_FILEOPTIONS equ 1
37CONFIG_FP_MB_STATS equ 0
38CONFIG_GCC equ 0
39CONFIG_GCOV equ 0
40CONFIG_GPROF equ 0
41CONFIG_INSPECTION equ 0
42CONFIG_INTERNAL_STATS equ 0
43CONFIG_INTER_STATS_ONLY equ 0
44CONFIG_LIBYUV equ 1
45CONFIG_LOWBITDEPTH equ 0
46CONFIG_MISMATCH_DEBUG equ 0
47CONFIG_MSVS equ 1
48CONFIG_MULTITHREAD equ 1
49CONFIG_OS_SUPPORT equ 1
50CONFIG_PIC equ 0
51CONFIG_RD_DEBUG equ 0
52CONFIG_RUNTIME_CPU_DETECT equ 1
53CONFIG_SHARED equ 0
54CONFIG_SIZE_LIMIT equ 0
55CONFIG_SPATIAL_RESAMPLING equ 1
56CONFIG_STATIC equ 1
57CONFIG_WEBM_IO equ 1
58DECODE_HEIGHT_LIMIT equ 0
59DECODE_WIDTH_LIMIT equ 0
60HAVE_AVX equ 1
61HAVE_AVX2 equ 1
62HAVE_DSPR2 equ 0
63HAVE_FEXCEPT equ 0
64HAVE_MIPS32 equ 0
65HAVE_MIPS64 equ 0
66HAVE_MMX equ 1
67HAVE_MSA equ 0
68HAVE_NEON equ 0
69HAVE_PTHREAD_H equ 0
70HAVE_SSE equ 1
71HAVE_SSE2 equ 1
72HAVE_SSE3 equ 1
73HAVE_SSE4_1 equ 1
74HAVE_SSE4_2 equ 1
75HAVE_SSSE3 equ 1
76HAVE_UNISTD_H equ 0
77HAVE_VSX equ 0
78HAVE_WXWIDGETS equ 0
79
80; 32/64 bit compatibility macros
81;
82; In general, we make the source use 64 bit syntax, then twiddle with it using
83; the preprocessor to get the 32 bit syntax on 32 bit platforms.
84;
85%ifidn __OUTPUT_FORMAT__,elf32
86%define ABI_IS_32BIT 1
87%elifidn __OUTPUT_FORMAT__,macho32
88%define ABI_IS_32BIT 1
89%elifidn __OUTPUT_FORMAT__,win32
90%define ABI_IS_32BIT 1
91%elifidn __OUTPUT_FORMAT__,aout
92%define ABI_IS_32BIT 1
93%else
94%define ABI_IS_32BIT 0
95%endif
96
97%if ABI_IS_32BIT
98%define rax eax
99%define rbx ebx
100%define rcx ecx
101%define rdx edx
102%define rsi esi
103%define rdi edi
104%define rsp esp
105%define rbp ebp
106%define movsxd mov
107%macro movq 2
108  %ifidn %1,eax
109    movd %1,%2
110  %elifidn %2,eax
111    movd %1,%2
112  %elifidn %1,ebx
113    movd %1,%2
114  %elifidn %2,ebx
115    movd %1,%2
116  %elifidn %1,ecx
117    movd %1,%2
118  %elifidn %2,ecx
119    movd %1,%2
120  %elifidn %1,edx
121    movd %1,%2
122  %elifidn %2,edx
123    movd %1,%2
124  %elifidn %1,esi
125    movd %1,%2
126  %elifidn %2,esi
127    movd %1,%2
128  %elifidn %1,edi
129    movd %1,%2
130  %elifidn %2,edi
131    movd %1,%2
132  %elifidn %1,esp
133    movd %1,%2
134  %elifidn %2,esp
135    movd %1,%2
136  %elifidn %1,ebp
137    movd %1,%2
138  %elifidn %2,ebp
139    movd %1,%2
140  %else
141    movq %1,%2
142  %endif
143%endmacro
144%endif
145
146
147; LIBAOM_YASM_WIN64
148; Set LIBAOM_YASM_WIN64 if output is Windows 64bit so the code will work if x64
149; or win64 is defined on the Yasm command line.
150%ifidn __OUTPUT_FORMAT__,win64
151%define LIBAOM_YASM_WIN64 1
152%elifidn __OUTPUT_FORMAT__,x64
153%define LIBAOM_YASM_WIN64 1
154%else
155%define LIBAOM_YASM_WIN64 0
156%endif
157
158; sym()
159; Return the proper symbol name for the target ABI.
160;
161; Certain ABIs, notably MS COFF and Darwin MACH-O, require that symbols
162; with C linkage be prefixed with an underscore.
163;
164%ifidn   __OUTPUT_FORMAT__,elf32
165%define sym(x) x
166%elifidn __OUTPUT_FORMAT__,elf64
167%define sym(x) x
168%elifidn __OUTPUT_FORMAT__,elfx32
169%define sym(x) x
170%elif LIBAOM_YASM_WIN64
171%define sym(x) x
172%else
173%define sym(x) _ %+ x
174%endif
175
176;  PRIVATE
177;  Macro for the attribute to hide a global symbol for the target ABI.
178;  This is only active if CHROMIUM is defined.
179;
180;  Chromium doesn't like exported global symbols due to symbol clashing with
181;  plugins among other things.
182;
183;  Requires Chromium's patched copy of yasm:
184;    http://src.chromium.org/viewvc/chrome?view=rev&revision=73761
185;    http://www.tortall.net/projects/yasm/ticket/236
186;
187%ifdef CHROMIUM
188  %ifidn   __OUTPUT_FORMAT__,elf32
189    %define PRIVATE :hidden
190  %elifidn __OUTPUT_FORMAT__,elf64
191    %define PRIVATE :hidden
192  %elifidn __OUTPUT_FORMAT__,elfx32
193    %define PRIVATE :hidden
194  %elif LIBAOM_YASM_WIN64
195    %define PRIVATE
196  %else
197    %define PRIVATE :private_extern
198  %endif
199%else
200  %define PRIVATE
201%endif
202
203; arg()
204; Return the address specification of the given argument
205;
206%if ABI_IS_32BIT
207  %define arg(x) [ebp+8+4*x]
208%else
209  ; 64 bit ABI passes arguments in registers. This is a workaround to get up
210  ; and running quickly. Relies on SHADOW_ARGS_TO_STACK
211  %if LIBAOM_YASM_WIN64
212    %define arg(x) [rbp+16+8*x]
213  %else
214    %define arg(x) [rbp-8-8*x]
215  %endif
216%endif
217
218; REG_SZ_BYTES, REG_SZ_BITS
219; Size of a register
220%if ABI_IS_32BIT
221%define REG_SZ_BYTES 4
222%define REG_SZ_BITS  32
223%else
224%define REG_SZ_BYTES 8
225%define REG_SZ_BITS  64
226%endif
227
228
229; ALIGN_STACK <alignment> <register>
230; This macro aligns the stack to the given alignment (in bytes). The stack
231; is left such that the previous value of the stack pointer is the first
232; argument on the stack (ie, the inverse of this macro is 'pop rsp.')
233; This macro uses one temporary register, which is not preserved, and thus
234; must be specified as an argument.
235%macro ALIGN_STACK 2
236    mov         %2, rsp
237    and         rsp, -%1
238    lea         rsp, [rsp - (%1 - REG_SZ_BYTES)]
239    push        %2
240%endmacro
241
242
243;
244; The Microsoft assembler tries to impose a certain amount of type safety in
245; its register usage. YASM doesn't recognize these directives, so we just
246; %define them away to maintain as much compatibility as possible with the
247; original inline assembler we're porting from.
248;
249%idefine PTR
250%idefine XMMWORD
251%idefine MMWORD
252
253; PIC macros
254;
255%if ABI_IS_32BIT
256  %if CONFIG_PIC=1
257  %ifidn __OUTPUT_FORMAT__,elf32
258    %define WRT_PLT wrt ..plt
259    %macro GET_GOT 1
260      extern _GLOBAL_OFFSET_TABLE_
261      push %1
262      call %%get_got
263      %%sub_offset:
264      jmp %%exitGG
265      %%get_got:
266      mov %1, [esp]
267      add %1, _GLOBAL_OFFSET_TABLE_ + $$ - %%sub_offset wrt ..gotpc
268      ret
269      %%exitGG:
270      %undef GLOBAL
271      %define GLOBAL(x) x + %1 wrt ..gotoff
272      %undef RESTORE_GOT
273      %define RESTORE_GOT pop %1
274    %endmacro
275  %elifidn __OUTPUT_FORMAT__,macho32
276    %macro GET_GOT 1
277      push %1
278      call %%get_got
279      %%get_got:
280      pop  %1
281      %undef GLOBAL
282      %define GLOBAL(x) x + %1 - %%get_got
283      %undef RESTORE_GOT
284      %define RESTORE_GOT pop %1
285    %endmacro
286  %endif
287  %endif
288
289  %ifdef CHROMIUM
290    %ifidn __OUTPUT_FORMAT__,macho32
291      %define HIDDEN_DATA(x) x:private_extern
292    %else
293      %define HIDDEN_DATA(x) x
294    %endif
295  %else
296    %define HIDDEN_DATA(x) x
297  %endif
298%else
299  %macro GET_GOT 1
300  %endmacro
301  %define GLOBAL(x) rel x
302  %ifidn __OUTPUT_FORMAT__,elf64
303    %define WRT_PLT wrt ..plt
304    %define HIDDEN_DATA(x) x:data hidden
305  %elifidn __OUTPUT_FORMAT__,elfx32
306    %define WRT_PLT wrt ..plt
307    %define HIDDEN_DATA(x) x:data hidden
308  %elifidn __OUTPUT_FORMAT__,macho64
309    %ifdef CHROMIUM
310      %define HIDDEN_DATA(x) x:private_extern
311    %else
312      %define HIDDEN_DATA(x) x
313    %endif
314  %else
315    %define HIDDEN_DATA(x) x
316  %endif
317%endif
318%ifnmacro GET_GOT
319    %macro GET_GOT 1
320    %endmacro
321    %define GLOBAL(x) x
322%endif
323%ifndef RESTORE_GOT
324%define RESTORE_GOT
325%endif
326%ifndef WRT_PLT
327%define WRT_PLT
328%endif
329
330%if ABI_IS_32BIT
331  %macro SHADOW_ARGS_TO_STACK 1
332  %endm
333  %define UNSHADOW_ARGS
334%else
335%if LIBAOM_YASM_WIN64
336  %macro SHADOW_ARGS_TO_STACK 1 ; argc
337    %if %1 > 0
338        mov arg(0),rcx
339    %endif
340    %if %1 > 1
341        mov arg(1),rdx
342    %endif
343    %if %1 > 2
344        mov arg(2),r8
345    %endif
346    %if %1 > 3
347        mov arg(3),r9
348    %endif
349  %endm
350%else
351  %macro SHADOW_ARGS_TO_STACK 1 ; argc
352    %if %1 > 0
353        push rdi
354    %endif
355    %if %1 > 1
356        push rsi
357    %endif
358    %if %1 > 2
359        push rdx
360    %endif
361    %if %1 > 3
362        push rcx
363    %endif
364    %if %1 > 4
365        push r8
366    %endif
367    %if %1 > 5
368        push r9
369    %endif
370    %if %1 > 6
371      %assign i %1-6
372      %assign off 16
373      %rep i
374        mov rax,[rbp+off]
375        push rax
376        %assign off off+8
377      %endrep
378    %endif
379  %endm
380%endif
381  %define UNSHADOW_ARGS mov rsp, rbp
382%endif
383
384; Win64 ABI requires that XMM6:XMM15 are callee saved
385; SAVE_XMM n, [u]
386; store registers 6-n on the stack
387; if u is specified, use unaligned movs.
388; Win64 ABI requires 16 byte stack alignment, but then pushes an 8 byte return
389; value. Typically we follow this up with 'push rbp' - re-aligning the stack -
390; but in some cases this is not done and unaligned movs must be used.
391%if LIBAOM_YASM_WIN64
392%macro SAVE_XMM 1-2 a
393  %if %1 < 6
394    %error Only xmm registers 6-15 must be preserved
395  %else
396    %assign last_xmm %1
397    %define movxmm movdq %+ %2
398    %assign xmm_stack_space ((last_xmm - 5) * 16)
399    sub rsp, xmm_stack_space
400    %assign i 6
401    %rep (last_xmm - 5)
402      movxmm [rsp + ((i - 6) * 16)], xmm %+ i
403      %assign i i+1
404    %endrep
405  %endif
406%endmacro
407%macro RESTORE_XMM 0
408  %ifndef last_xmm
409    %error RESTORE_XMM must be paired with SAVE_XMM n
410  %else
411    %assign i last_xmm
412    %rep (last_xmm - 5)
413      movxmm xmm %+ i, [rsp +((i - 6) * 16)]
414      %assign i i-1
415    %endrep
416    add rsp, xmm_stack_space
417    ; there are a couple functions which return from multiple places.
418    ; otherwise, we could uncomment these:
419    ; %undef last_xmm
420    ; %undef xmm_stack_space
421    ; %undef movxmm
422  %endif
423%endmacro
424%else
425%macro SAVE_XMM 1-2
426%endmacro
427%macro RESTORE_XMM 0
428%endmacro
429%endif
430
431; Name of the rodata section
432;
433; .rodata seems to be an elf-ism, as it doesn't work on OSX.
434;
435%ifidn __OUTPUT_FORMAT__,macho64
436%define SECTION_RODATA section .text
437%elifidn __OUTPUT_FORMAT__,macho32
438%macro SECTION_RODATA 0
439section .text
440%endmacro
441%elifidn __OUTPUT_FORMAT__,aout
442%define SECTION_RODATA section .data
443%else
444%define SECTION_RODATA section .rodata
445%endif
446
447
448; Tell GNU ld that we don't require an executable stack.
449%ifidn __OUTPUT_FORMAT__,elf32
450section .note.GNU-stack noalloc noexec nowrite progbits
451section .text
452%elifidn __OUTPUT_FORMAT__,elf64
453section .note.GNU-stack noalloc noexec nowrite progbits
454section .text
455%elifidn __OUTPUT_FORMAT__,elfx32
456section .note.GNU-stack noalloc noexec nowrite progbits
457section .text
458%endif
459