arm: Add EXTERN_ASM to the .func and .type declarations for exported symbols
[libav.git] / libavutil / arm / asm.S
1 /*
2 * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
3 *
4 * This file is part of Libav.
5 *
6 * Libav is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * Libav is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "config.h"
22
23 #ifdef __ELF__
24 # define ELF
25 #else
26 # define ELF @
27 #endif
28
29 #if CONFIG_THUMB
30 # define A @
31 # define T
32 #else
33 # define A
34 # define T @
35 #endif
36
37 #if HAVE_NEON
38 .arch armv7-a
39 #elif HAVE_ARMV6T2
40 .arch armv6t2
41 #elif HAVE_ARMV6
42 .arch armv6
43 #elif HAVE_ARMV5TE
44 .arch armv5te
45 #endif
46
47 #if HAVE_NEON
48 .fpu neon
49 #elif HAVE_VFP
50 .fpu vfp
51 #endif
52
53 .syntax unified
54 T .thumb
55 ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
56
57 .macro function name, export=0, align=2
58 .set .Lpic_idx, 0
59 .set .Lpic_gp, 0
60 .macro endfunc
61 .if .Lpic_idx
62 .align 2
63 .altmacro
64 put_pic %(.Lpic_idx - 1)
65 .noaltmacro
66 .endif
67 ELF .size \name, . - \name
68 .endfunc
69 .purgem endfunc
70 .endm
71 .text
72 .align \align
73 .if \export
74 .global EXTERN_ASM\name
75 ELF .type EXTERN_ASM\name, %function
76 .func EXTERN_ASM\name
77 EXTERN_ASM\name:
78 .else
79 ELF .type \name, %function
80 .func \name
81 \name:
82 .endif
83 .endm
84
85 .macro const name, align=2
86 .macro endconst
87 ELF .size \name, . - \name
88 .purgem endconst
89 .endm
90 .section .rodata
91 .align \align
92 \name:
93 .endm
94
95 #if !HAVE_ARMV6T2_EXTERNAL
96 .macro movw rd, val
97 mov \rd, \val & 255
98 orr \rd, \val & ~255
99 .endm
100 #endif
101
102 .macro mov32 rd, val
103 #if HAVE_ARMV6T2_EXTERNAL
104 movw \rd, #(\val) & 0xffff
105 .if (\val) >> 16
106 movt \rd, #(\val) >> 16
107 .endif
108 #else
109 ldr \rd, =\val
110 #endif
111 .endm
112
113 .macro put_pic num
114 put_pic_\num
115 .endm
116
117 .macro do_def_pic num, val, label
118 .macro put_pic_\num
119 .if \num
120 .altmacro
121 put_pic %(\num - 1)
122 .noaltmacro
123 .endif
124 \label: .word \val
125 .purgem put_pic_\num
126 .endm
127 .endm
128
129 .macro def_pic val, label
130 .altmacro
131 do_def_pic %.Lpic_idx, \val, \label
132 .noaltmacro
133 .set .Lpic_idx, .Lpic_idx + 1
134 .endm
135
136 .macro ldpic rd, val, indir=0
137 ldr \rd, .Lpicoff\@
138 .Lpic\@:
139 .if \indir
140 A ldr \rd, [pc, \rd]
141 T add \rd, pc
142 T ldr \rd, [\rd]
143 .else
144 add \rd, pc
145 .endif
146 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
147 .endm
148
149 .macro movrel rd, val
150 #if CONFIG_PIC
151 ldpic \rd, \val
152 #elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
153 movw \rd, #:lower16:\val
154 movt \rd, #:upper16:\val
155 #else
156 ldr \rd, =\val
157 #endif
158 .endm
159
160 .macro movrelx rd, val, gp
161 #if CONFIG_PIC && defined(__ELF__)
162 .ifnb \gp
163 .if .Lpic_gp
164 .unreq gp
165 .endif
166 gp .req \gp
167 ldpic gp, _GLOBAL_OFFSET_TABLE_
168 .elseif !.Lpic_gp
169 gp .req r12
170 ldpic gp, _GLOBAL_OFFSET_TABLE_
171 .endif
172 .set .Lpic_gp, 1
173 ldr \rd, .Lpicoff\@
174 ldr \rd, [gp, \rd]
175 def_pic \val(GOT), .Lpicoff\@
176 #elif CONFIG_PIC && defined(__APPLE__)
177 ldpic \rd, .Lpic\@, indir=1
178 .non_lazy_symbol_pointer
179 .Lpic\@:
180 .indirect_symbol \val
181 .word 0
182 .text
183 #else
184 movrel \rd, \val
185 #endif
186 .endm
187
188 .macro add_sh rd, rn, rm, sh:vararg
189 A add \rd, \rn, \rm, \sh
190 T mov \rm, \rm, \sh
191 T add \rd, \rn, \rm
192 .endm
193
194 .macro ldr_pre rt, rn, rm:vararg
195 A ldr \rt, [\rn, \rm]!
196 T add \rn, \rn, \rm
197 T ldr \rt, [\rn]
198 .endm
199
200 .macro ldr_dpre rt, rn, rm:vararg
201 A ldr \rt, [\rn, -\rm]!
202 T sub \rn, \rn, \rm
203 T ldr \rt, [\rn]
204 .endm
205
206 .macro ldr_nreg rt, rn, rm:vararg
207 A ldr \rt, [\rn, -\rm]
208 T sub \rt, \rn, \rm
209 T ldr \rt, [\rt]
210 .endm
211
212 .macro ldr_post rt, rn, rm:vararg
213 A ldr \rt, [\rn], \rm
214 T ldr \rt, [\rn]
215 T add \rn, \rn, \rm
216 .endm
217
218 .macro ldrd_reg rt, rt2, rn, rm
219 A ldrd \rt, \rt2, [\rn, \rm]
220 T add \rt, \rn, \rm
221 T ldrd \rt, \rt2, [\rt]
222 .endm
223
224 .macro ldrd_post rt, rt2, rn, rm
225 A ldrd \rt, \rt2, [\rn], \rm
226 T ldrd \rt, \rt2, [\rn]
227 T add \rn, \rn, \rm
228 .endm
229
230 .macro ldrh_pre rt, rn, rm
231 A ldrh \rt, [\rn, \rm]!
232 T add \rn, \rn, \rm
233 T ldrh \rt, [\rn]
234 .endm
235
236 .macro ldrh_dpre rt, rn, rm
237 A ldrh \rt, [\rn, -\rm]!
238 T sub \rn, \rn, \rm
239 T ldrh \rt, [\rn]
240 .endm
241
242 .macro ldrh_post rt, rn, rm
243 A ldrh \rt, [\rn], \rm
244 T ldrh \rt, [\rn]
245 T add \rn, \rn, \rm
246 .endm
247
248 .macro ldrb_post rt, rn, rm
249 A ldrb \rt, [\rn], \rm
250 T ldrb \rt, [\rn]
251 T add \rn, \rn, \rm
252 .endm
253
254 .macro str_post rt, rn, rm:vararg
255 A str \rt, [\rn], \rm
256 T str \rt, [\rn]
257 T add \rn, \rn, \rm
258 .endm
259
260 .macro strb_post rt, rn, rm:vararg
261 A strb \rt, [\rn], \rm
262 T strb \rt, [\rn]
263 T add \rn, \rn, \rm
264 .endm
265
266 .macro strd_post rt, rt2, rn, rm
267 A strd \rt, \rt2, [\rn], \rm
268 T strd \rt, \rt2, [\rn]
269 T add \rn, \rn, \rm
270 .endm
271
272 .macro strh_pre rt, rn, rm
273 A strh \rt, [\rn, \rm]!
274 T add \rn, \rn, \rm
275 T strh \rt, [\rn]
276 .endm
277
278 .macro strh_dpre rt, rn, rm
279 A strh \rt, [\rn, -\rm]!
280 T sub \rn, \rn, \rm
281 T strh \rt, [\rn]
282 .endm
283
284 .macro strh_post rt, rn, rm
285 A strh \rt, [\rn], \rm
286 T strh \rt, [\rn]
287 T add \rn, \rn, \rm
288 .endm
289
290 .macro strh_dpost rt, rn, rm
291 A strh \rt, [\rn], -\rm
292 T strh \rt, [\rn]
293 T sub \rn, \rn, \rm
294 .endm
295
296 #if HAVE_VFP_ARGS
297 ELF .eabi_attribute 28, 1
298 # define VFP
299 # define NOVFP @
300 #else
301 # define VFP @
302 # define NOVFP
303 #endif
304
305 #define GLUE(a, b) a ## b
306 #define JOIN(a, b) GLUE(a, b)
307 #define X(s) JOIN(EXTERN_ASM, s)