arm: Clear the gp register alias at the end of functions
[libav.git] / libavutil / arm / asm.S
CommitLineData
c72ab301
MR
1/*
2 * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
3 *
2912e87a 4 * This file is part of Libav.
c72ab301 5 *
2912e87a 6 * Libav is free software; you can redistribute it and/or
c72ab301
MR
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 *
2912e87a 11 * Libav is distributed in the hope that it will be useful,
c72ab301
MR
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
2912e87a 17 * License along with Libav; if not, write to the Free Software
c72ab301
MR
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
172a39d1
MR
21#include "config.h"
22
e21a8921 23#ifdef __ELF__
341f394f
MR
24# define ELF
25#else
26# define ELF @
e21a8921 27#endif
341f394f 28
8986fddc
MR
29#if CONFIG_THUMB
30# define A @
31# define T
32#else
33# define A
34# define T @
35#endif
36
d5a55981
JG
37#if HAVE_AS_FUNC
38# define FUNC
39#else
40# define FUNC @
41#endif
42
6f9e34ba
MS
43#if HAVE_AS_FPU_DIRECTIVE
44# define FPU
45#else
46# define FPU @
47#endif
48
8ee2b467
MR
49#if HAVE_NEON
50 .arch armv7-a
51#elif HAVE_ARMV6T2
52 .arch armv6t2
53#elif HAVE_ARMV6
54 .arch armv6
55#elif HAVE_ARMV5TE
56 .arch armv5te
57#endif
dcae2e32
MS
58#if HAVE_AS_OBJECT_ARCH
59ELF .object_arch armv4
60#endif
8ee2b467
MR
61
62#if HAVE_NEON
6f9e34ba 63FPU .fpu neon
dcae2e32
MS
64ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
65ELF .eabi_attribute 12, 0 @ suppress Tag_Advanced_SIMD_arch
b3267559 66#elif HAVE_VFP
6f9e34ba 67FPU .fpu vfp
dcae2e32 68ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
8ee2b467
MR
69#endif
70
371266da 71 .syntax unified
8986fddc 72T .thumb
51a15ed7 73ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
543156d7 74ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
c72ab301 75
5dae4872 76.macro function name, export=0, align=2
62634158
MR
77 .set .Lpic_idx, 0
78 .set .Lpic_gp, 0
480cb7ed 79 .macro endfunc
62634158 80 .if .Lpic_idx
cdb7db5a 81 .align 2
62634158
MR
82 .altmacro
83 put_pic %(.Lpic_idx - 1)
84 .noaltmacro
85 .endif
824e8c28
MS
86 .if .Lpic_gp
87 .unreq gp
88 .endif
18c31f6f 89ELF .size \name, . - \name
d5a55981 90FUNC .endfunc
a7e7d40c 91 .purgem endfunc
480cb7ed 92 .endm
278caa6a 93 .text
5dae4872 94 .align \align
480cb7ed 95 .if \export
e654b7c2 96 .global EXTERN_ASM\name
e3fec3f0 97ELF .type EXTERN_ASM\name, %function
d5a55981 98FUNC .func EXTERN_ASM\name
e654b7c2 99EXTERN_ASM\name:
e3fec3f0 100 .else
341f394f 101ELF .type \name, %function
d5a55981 102FUNC .func \name
c72ab301 103\name:
e3fec3f0 104 .endif
480cb7ed 105.endm
172a39d1 106
f963f803 107.macro const name, align=2, relocate=0
b9a639dd
MR
108 .macro endconst
109ELF .size \name, . - \name
110 .purgem endconst
111 .endm
f963f803
MS
112.if HAVE_SECTION_DATA_REL_RO && \relocate
113 .section .data.rel.ro
114.else
b9a639dd 115 .section .rodata
f963f803 116.endif
b9a639dd
MR
117 .align \align
118\name:
119.endm
120
a7831d50 121#if !HAVE_ARMV6T2_EXTERNAL
dac78fd1
MR
122.macro movw rd, val
123 mov \rd, \val & 255
124 orr \rd, \val & ~255
125.endm
126#endif
127
a4edc5a9 128.macro mov32 rd, val
a7831d50 129#if HAVE_ARMV6T2_EXTERNAL
a4edc5a9
MR
130 movw \rd, #(\val) & 0xffff
131 .if (\val) >> 16
132 movt \rd, #(\val) >> 16
133 .endif
134#else
135 ldr \rd, =\val
136#endif
137.endm
138
62634158
MR
139.macro put_pic num
140 put_pic_\num
141.endm
142
143.macro do_def_pic num, val, label
144 .macro put_pic_\num
145 .if \num
146 .altmacro
147 put_pic %(\num - 1)
148 .noaltmacro
149 .endif
150\label: .word \val
151 .purgem put_pic_\num
152 .endm
153.endm
154
155.macro def_pic val, label
156 .altmacro
157 do_def_pic %.Lpic_idx, \val, \label
158 .noaltmacro
159 .set .Lpic_idx, .Lpic_idx + 1
160.endm
161
162.macro ldpic rd, val, indir=0
163 ldr \rd, .Lpicoff\@
164.Lpic\@:
165 .if \indir
7bda4ed7
MR
166A ldr \rd, [pc, \rd]
167T add \rd, pc
168T ldr \rd, [\rd]
62634158 169 .else
8995d349 170 add \rd, pc
62634158
MR
171 .endif
172 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
173.endm
174
480cb7ed 175.macro movrel rd, val
62634158
MR
176#if CONFIG_PIC
177 ldpic \rd, \val
a7831d50 178#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
172a39d1
MR
179 movw \rd, #:lower16:\val
180 movt \rd, #:upper16:\val
181#else
182 ldr \rd, =\val
183#endif
480cb7ed 184.endm
ce742de2 185
62634158
MR
186.macro movrelx rd, val, gp
187#if CONFIG_PIC && defined(__ELF__)
188 .ifnb \gp
189 .if .Lpic_gp
190 .unreq gp
191 .endif
192 gp .req \gp
193 ldpic gp, _GLOBAL_OFFSET_TABLE_
194 .elseif !.Lpic_gp
195 gp .req r12
196 ldpic gp, _GLOBAL_OFFSET_TABLE_
197 .endif
198 .set .Lpic_gp, 1
199 ldr \rd, .Lpicoff\@
200 ldr \rd, [gp, \rd]
201 def_pic \val(GOT), .Lpicoff\@
202#elif CONFIG_PIC && defined(__APPLE__)
203 ldpic \rd, .Lpic\@, indir=1
204 .non_lazy_symbol_pointer
205.Lpic\@:
206 .indirect_symbol \val
207 .word 0
208 .text
209#else
210 movrel \rd, \val
211#endif
212.endm
213
7689eea4
MR
214.macro add_sh rd, rn, rm, sh:vararg
215A add \rd, \rn, \rm, \sh
216T mov \rm, \rm, \sh
217T add \rd, \rn, \rm
218.endm
219
8986fddc
MR
220.macro ldr_pre rt, rn, rm:vararg
221A ldr \rt, [\rn, \rm]!
222T add \rn, \rn, \rm
223T ldr \rt, [\rn]
224.endm
225
71ce7602
MR
226.macro ldr_dpre rt, rn, rm:vararg
227A ldr \rt, [\rn, -\rm]!
228T sub \rn, \rn, \rm
229T ldr \rt, [\rn]
230.endm
231
dac78fd1
MR
232.macro ldr_nreg rt, rn, rm:vararg
233A ldr \rt, [\rn, -\rm]
234T sub \rt, \rn, \rm
235T ldr \rt, [\rt]
236.endm
237
8986fddc
MR
238.macro ldr_post rt, rn, rm:vararg
239A ldr \rt, [\rn], \rm
240T ldr \rt, [\rn]
241T add \rn, \rn, \rm
242.endm
243
cbddee1c
JG
244.macro ldrc_pre cc, rt, rn, rm:vararg
245A ldr\cc \rt, [\rn, \rm]!
246T itt \cc
247T add\cc \rn, \rn, \rm
248T ldr\cc \rt, [\rn]
249.endm
250
8986fddc
MR
251.macro ldrd_reg rt, rt2, rn, rm
252A ldrd \rt, \rt2, [\rn, \rm]
253T add \rt, \rn, \rm
254T ldrd \rt, \rt2, [\rt]
255.endm
256
257.macro ldrd_post rt, rt2, rn, rm
258A ldrd \rt, \rt2, [\rn], \rm
259T ldrd \rt, \rt2, [\rn]
260T add \rn, \rn, \rm
261.endm
262
263.macro ldrh_pre rt, rn, rm
264A ldrh \rt, [\rn, \rm]!
265T add \rn, \rn, \rm
266T ldrh \rt, [\rn]
267.endm
268
269.macro ldrh_dpre rt, rn, rm
270A ldrh \rt, [\rn, -\rm]!
271T sub \rn, \rn, \rm
272T ldrh \rt, [\rn]
273.endm
274
275.macro ldrh_post rt, rn, rm
276A ldrh \rt, [\rn], \rm
277T ldrh \rt, [\rn]
278T add \rn, \rn, \rm
279.endm
280
dac78fd1
MR
281.macro ldrb_post rt, rn, rm
282A ldrb \rt, [\rn], \rm
283T ldrb \rt, [\rn]
284T add \rn, \rn, \rm
285.endm
286
8986fddc
MR
287.macro str_post rt, rn, rm:vararg
288A str \rt, [\rn], \rm
289T str \rt, [\rn]
290T add \rn, \rn, \rm
291.endm
292
293.macro strb_post rt, rn, rm:vararg
294A strb \rt, [\rn], \rm
295T strb \rt, [\rn]
296T add \rn, \rn, \rm
297.endm
298
299.macro strd_post rt, rt2, rn, rm
300A strd \rt, \rt2, [\rn], \rm
301T strd \rt, \rt2, [\rn]
302T add \rn, \rn, \rm
303.endm
304
305.macro strh_pre rt, rn, rm
306A strh \rt, [\rn, \rm]!
307T add \rn, \rn, \rm
308T strh \rt, [\rn]
309.endm
310
311.macro strh_dpre rt, rn, rm
312A strh \rt, [\rn, -\rm]!
313T sub \rn, \rn, \rm
314T strh \rt, [\rn]
315.endm
316
317.macro strh_post rt, rn, rm
318A strh \rt, [\rn], \rm
319T strh \rt, [\rn]
320T add \rn, \rn, \rm
321.endm
322
323.macro strh_dpost rt, rn, rm
324A strh \rt, [\rn], -\rm
325T strh \rt, [\rn]
326T sub \rn, \rn, \rm
327.endm
328
ce742de2 329#if HAVE_VFP_ARGS
be7952b5 330ELF .eabi_attribute 28, 1
ce742de2
MR
331# define VFP
332# define NOVFP @
333#else
334# define VFP @
335# define NOVFP
336#endif
e654b7c2
MR
337
338#define GLUE(a, b) a ## b
339#define JOIN(a, b) GLUE(a, b)
340#define X(s) JOIN(EXTERN_ASM, s)