]> git.sesse.net Git - x264/blob - common/x86/x86inc-32.asm
force unroll macroblock_load_pic_pointers
[x264] / common / x86 / x86inc-32.asm
1 ;*****************************************************************************
2 ;* x86inc-32.asm: h264 encoder library
3 ;*****************************************************************************
4 ;* Copyright (C) 2006-2008 x264 project
5 ;*
6 ;* Author: Sam Hocevar <sam@zoy.org>
7 ;*
8 ;* This program is free software; you can redistribute it and/or modify
9 ;* it under the terms of the GNU General Public License as published by
10 ;* the Free Software Foundation; either version 2 of the License, or
11 ;* (at your option) any later version.
12 ;*
13 ;* This program is distributed in the hope that it will be useful,
14 ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;* GNU General Public License for more details.
17 ;*
18 ;* You should have received a copy of the GNU General Public License
19 ;* along with this program; if not, write to the Free Software
20 ;* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21 ;*****************************************************************************
22
23 BITS 32
24
25 ; Name of the .rodata section. On OS X we cannot use .rodata because NASM
26 ; is unable to compute address offsets outside of .text so we use the .text
27 ; section instead until NASM is fixed.
28 %macro SECTION_RODATA 0
29     %ifidn __OUTPUT_FORMAT__,macho
30         SECTION .text align=16
31         fakegot:
32     %else
33         SECTION .rodata align=16
34     %endif
35 %endmacro
36
37 ; PIC support macros. All these macros are totally harmless when __PIC__ is
38 ; not defined but can ruin everything if misused in PIC mode. On x86, shared
39 ; objects cannot directly access global variables by address, they need to
40 ; go through the GOT (global offset table). Most OSes do not care about it
41 ; and let you load non-shared .so objects (Linux, Win32...). However, OS X
42 ; requires PIC code in its .dylib objects.
43 ;
44 ; - GLOBAL should be used as a suffix for global addressing, eg.
45 ;     picgetgot ebx
46 ;     mov eax, [foo GLOBAL]
47 ;   instead of
48 ;     mov eax, [foo]
49 ;
50 ; - picgetgot computes the GOT address into the given register in PIC
51 ;   mode, otherwise does nothing. You need to do this before using GLOBAL.
52 ;   Before in both execution order and compiled code order (so GLOBAL knows
53 ;   which register the GOT is in).
54 ;
55 ; - picpush and picpop respectively push and pop the given register
56 ;   in PIC mode, otherwise do nothing. You should always use them around
57 ;   picgetgot except when sure that the register is no longer used and is
58 ;   being restored later by other means.
59 ;
60 ; - picesp is defined to compensate the changing of esp when pushing
61 ;   a register into the stack, eg.
62 ;     mov eax, [esp + 8]
63 ;     pushpic  ebx
64 ;     mov eax, [picesp + 12]
65 ;   instead of
66 ;     mov eax, [esp + 8]
67 ;     pushpic  ebx
68 ;     mov eax, [esp + 12]
69 ;
70 %ifdef __PIC__
71     %define PIC32
72     %ifidn __OUTPUT_FORMAT__,macho
73         ; There is no real global offset table on OS X, but we still
74         ; need to reference our variables by offset.
75         %define GOT_reg(x) - fakegot + x
76         %macro picgetgot 1
77             call %%getgot 
78           %%getgot: 
79             pop %1 
80             add %1, $$ - %%getgot
81             %undef GLOBAL
82             %define GLOBAL GOT_reg(%1)
83         %endmacro
84     %else
85         %ifidn __OUTPUT_FORMAT__,elf
86             %define GOT _GLOBAL_OFFSET_TABLE_
87         %else ; for a.out
88             %define GOT __GLOBAL_OFFSET_TABLE_
89         %endif
90         extern GOT
91         %define GOT_reg(x) + x wrt ..gotoff
92         %macro picgetgot 1
93             call %%getgot 
94           %%getgot: 
95             pop %1 
96             add %1, GOT + $$ - %%getgot wrt ..gotpc 
97             %undef GLOBAL
98             %define GLOBAL GOT_reg(%1)
99         %endmacro
100     %endif
101     %macro picpush 1
102         push %1
103     %endmacro
104     %macro picpop 1
105         pop %1
106     %endmacro
107     %define picesp esp+4
108 %else
109     %define GLOBAL
110     %macro picgetgot 1
111     %endmacro
112     %macro picpush 1
113     %endmacro
114     %macro picpop 1
115     %endmacro
116     %define picesp esp
117 %endif
118