arm: Produce .const_data instead of .section .rodata for Mach-O
[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
59cee42d 49#if HAVE_AS_ARCH_DIRECTIVE
8ee2b467
MR
50#if HAVE_NEON
51 .arch armv7-a
52#elif HAVE_ARMV6T2
53 .arch armv6t2
54#elif HAVE_ARMV6
55 .arch armv6
56#elif HAVE_ARMV5TE
57 .arch armv5te
58#endif
59cee42d 59#endif
dcae2e32
MS
60#if HAVE_AS_OBJECT_ARCH
61ELF .object_arch armv4
62#endif
8ee2b467
MR
63
64#if HAVE_NEON
6f9e34ba 65FPU .fpu neon
dcae2e32
MS
66ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
67ELF .eabi_attribute 12, 0 @ suppress Tag_Advanced_SIMD_arch
b3267559 68#elif HAVE_VFP
6f9e34ba 69FPU .fpu vfp
dcae2e32 70ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
8ee2b467
MR
71#endif
72
371266da 73 .syntax unified
8986fddc 74T .thumb
51a15ed7 75ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
543156d7 76ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
c72ab301 77
5dae4872 78.macro function name, export=0, align=2
62634158
MR
79 .set .Lpic_idx, 0
80 .set .Lpic_gp, 0
480cb7ed 81 .macro endfunc
62634158 82 .if .Lpic_idx
cdb7db5a 83 .align 2
62634158
MR
84 .altmacro
85 put_pic %(.Lpic_idx - 1)
86 .noaltmacro
87 .endif
824e8c28
MS
88 .if .Lpic_gp
89 .unreq gp
90 .endif
18c31f6f 91ELF .size \name, . - \name
d5a55981 92FUNC .endfunc
a7e7d40c 93 .purgem endfunc
480cb7ed 94 .endm
278caa6a 95 .text
5dae4872 96 .align \align
480cb7ed 97 .if \export
e654b7c2 98 .global EXTERN_ASM\name
e3fec3f0 99ELF .type EXTERN_ASM\name, %function
d5a55981 100FUNC .func EXTERN_ASM\name
e654b7c2 101EXTERN_ASM\name:
e3fec3f0 102 .else
341f394f 103ELF .type \name, %function
d5a55981 104FUNC .func \name
c72ab301 105\name:
e3fec3f0 106 .endif
480cb7ed 107.endm
172a39d1 108
f963f803 109.macro const name, align=2, relocate=0
b9a639dd
MR
110 .macro endconst
111ELF .size \name, . - \name
112 .purgem endconst
113 .endm
3a7b4ae6
MS
114#if HAVE_SECTION_DATA_REL_RO
115.if \relocate
f963f803
MS
116 .section .data.rel.ro
117.else
b9a639dd 118 .section .rodata
f963f803 119.endif
3a7b4ae6
MS
120#elif !defined(__MACH__)
121 .section .rodata
122#else
123 .const_data
124#endif
b9a639dd
MR
125 .align \align
126\name:
127.endm
128
a7831d50 129#if !HAVE_ARMV6T2_EXTERNAL
dac78fd1
MR
130.macro movw rd, val
131 mov \rd, \val & 255
132 orr \rd, \val & ~255
133.endm
134#endif
135
a4edc5a9 136.macro mov32 rd, val
a7831d50 137#if HAVE_ARMV6T2_EXTERNAL
a4edc5a9
MR
138 movw \rd, #(\val) & 0xffff
139 .if (\val) >> 16
140 movt \rd, #(\val) >> 16
141 .endif
142#else
143 ldr \rd, =\val
144#endif
145.endm
146
62634158
MR
147.macro put_pic num
148 put_pic_\num
149.endm
150
151.macro do_def_pic num, val, label
152 .macro put_pic_\num
153 .if \num
154 .altmacro
155 put_pic %(\num - 1)
156 .noaltmacro
157 .endif
158\label: .word \val
159 .purgem put_pic_\num
160 .endm
161.endm
162
163.macro def_pic val, label
164 .altmacro
165 do_def_pic %.Lpic_idx, \val, \label
166 .noaltmacro
167 .set .Lpic_idx, .Lpic_idx + 1
168.endm
169
170.macro ldpic rd, val, indir=0
171 ldr \rd, .Lpicoff\@
172.Lpic\@:
173 .if \indir
7bda4ed7
MR
174A ldr \rd, [pc, \rd]
175T add \rd, pc
176T ldr \rd, [\rd]
62634158 177 .else
8995d349 178 add \rd, pc
62634158
MR
179 .endif
180 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
181.endm
182
480cb7ed 183.macro movrel rd, val
62634158
MR
184#if CONFIG_PIC
185 ldpic \rd, \val
a7831d50 186#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
172a39d1
MR
187 movw \rd, #:lower16:\val
188 movt \rd, #:upper16:\val
189#else
190 ldr \rd, =\val
191#endif
480cb7ed 192.endm
ce742de2 193
62634158 194.macro movrelx rd, val, gp
6a1ea4ec
JG
195 .ifc \rd,\gp
196 .error "movrelx needs two distinct registers"
197 .endif
198 .ifc \rd\()_\gp,r12_
199 .warning "movrelx rd=\rd without explicit set gp"
200 .endif
201 .ifc \rd\()_\gp,ip_
202 .warning "movrelx rd=\rd without explicit set gp"
203 .endif
62634158
MR
204#if CONFIG_PIC && defined(__ELF__)
205 .ifnb \gp
206 .if .Lpic_gp
207 .unreq gp
208 .endif
209 gp .req \gp
210 ldpic gp, _GLOBAL_OFFSET_TABLE_
211 .elseif !.Lpic_gp
212 gp .req r12
213 ldpic gp, _GLOBAL_OFFSET_TABLE_
214 .endif
215 .set .Lpic_gp, 1
216 ldr \rd, .Lpicoff\@
217 ldr \rd, [gp, \rd]
218 def_pic \val(GOT), .Lpicoff\@
219#elif CONFIG_PIC && defined(__APPLE__)
220 ldpic \rd, .Lpic\@, indir=1
221 .non_lazy_symbol_pointer
222.Lpic\@:
223 .indirect_symbol \val
224 .word 0
225 .text
226#else
227 movrel \rd, \val
228#endif
229.endm
230
7689eea4
MR
231.macro add_sh rd, rn, rm, sh:vararg
232A add \rd, \rn, \rm, \sh
233T mov \rm, \rm, \sh
234T add \rd, \rn, \rm
235.endm
236
8986fddc
MR
237.macro ldr_pre rt, rn, rm:vararg
238A ldr \rt, [\rn, \rm]!
239T add \rn, \rn, \rm
240T ldr \rt, [\rn]
241.endm
242
71ce7602
MR
243.macro ldr_dpre rt, rn, rm:vararg
244A ldr \rt, [\rn, -\rm]!
245T sub \rn, \rn, \rm
246T ldr \rt, [\rn]
247.endm
248
dac78fd1
MR
249.macro ldr_nreg rt, rn, rm:vararg
250A ldr \rt, [\rn, -\rm]
251T sub \rt, \rn, \rm
252T ldr \rt, [\rt]
253.endm
254
8986fddc
MR
255.macro ldr_post rt, rn, rm:vararg
256A ldr \rt, [\rn], \rm
257T ldr \rt, [\rn]
258T add \rn, \rn, \rm
259.endm
260
cbddee1c
JG
261.macro ldrc_pre cc, rt, rn, rm:vararg
262A ldr\cc \rt, [\rn, \rm]!
263T itt \cc
264T add\cc \rn, \rn, \rm
265T ldr\cc \rt, [\rn]
266.endm
267
8986fddc
MR
268.macro ldrd_reg rt, rt2, rn, rm
269A ldrd \rt, \rt2, [\rn, \rm]
270T add \rt, \rn, \rm
271T ldrd \rt, \rt2, [\rt]
272.endm
273
274.macro ldrd_post rt, rt2, rn, rm
275A ldrd \rt, \rt2, [\rn], \rm
276T ldrd \rt, \rt2, [\rn]
277T add \rn, \rn, \rm
278.endm
279
280.macro ldrh_pre rt, rn, rm
281A ldrh \rt, [\rn, \rm]!
282T add \rn, \rn, \rm
283T ldrh \rt, [\rn]
284.endm
285
286.macro ldrh_dpre rt, rn, rm
287A ldrh \rt, [\rn, -\rm]!
288T sub \rn, \rn, \rm
289T ldrh \rt, [\rn]
290.endm
291
292.macro ldrh_post rt, rn, rm
293A ldrh \rt, [\rn], \rm
294T ldrh \rt, [\rn]
295T add \rn, \rn, \rm
296.endm
297
dac78fd1
MR
298.macro ldrb_post rt, rn, rm
299A ldrb \rt, [\rn], \rm
300T ldrb \rt, [\rn]
301T add \rn, \rn, \rm
302.endm
303
8986fddc
MR
304.macro str_post rt, rn, rm:vararg
305A str \rt, [\rn], \rm
306T str \rt, [\rn]
307T add \rn, \rn, \rm
308.endm
309
310.macro strb_post rt, rn, rm:vararg
311A strb \rt, [\rn], \rm
312T strb \rt, [\rn]
313T add \rn, \rn, \rm
314.endm
315
316.macro strd_post rt, rt2, rn, rm
317A strd \rt, \rt2, [\rn], \rm
318T strd \rt, \rt2, [\rn]
319T add \rn, \rn, \rm
320.endm
321
322.macro strh_pre rt, rn, rm
323A strh \rt, [\rn, \rm]!
324T add \rn, \rn, \rm
325T strh \rt, [\rn]
326.endm
327
328.macro strh_dpre rt, rn, rm
329A strh \rt, [\rn, -\rm]!
330T sub \rn, \rn, \rm
331T strh \rt, [\rn]
332.endm
333
334.macro strh_post rt, rn, rm
335A strh \rt, [\rn], \rm
336T strh \rt, [\rn]
337T add \rn, \rn, \rm
338.endm
339
340.macro strh_dpost rt, rn, rm
341A strh \rt, [\rn], -\rm
342T strh \rt, [\rn]
343T sub \rn, \rn, \rm
344.endm
345
ce742de2 346#if HAVE_VFP_ARGS
be7952b5 347ELF .eabi_attribute 28, 1
ce742de2
MR
348# define VFP
349# define NOVFP @
350#else
351# define VFP @
352# define NOVFP
353#endif
e654b7c2
MR
354
355#define GLUE(a, b) a ## b
356#define JOIN(a, b) GLUE(a, b)
357#define X(s) JOIN(EXTERN_ASM, s)