ARM: use 2-operand syntax for ADD Rd, PC in Apple PIC code
[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_ARMVFP
50 .fpu vfp
51 #endif
52
53 .syntax unified
54 T .thumb
55
56 .macro require8 val=1
57 ELF .eabi_attribute 24, \val
58 .endm
59
60 .macro preserve8 val=1
61 ELF .eabi_attribute 25, \val
62 .endm
63
64 .macro function name, export=0
65 .set .Lpic_idx, 0
66 .set .Lpic_gp, 0
67 .macro endfunc
68 .if .Lpic_idx
69 .align 2
70 .altmacro
71 put_pic %(.Lpic_idx - 1)
72 .noaltmacro
73 .endif
74 ELF .size \name, . - \name
75 .endfunc
76 .purgem endfunc
77 .endm
78 .text
79 .align 2
80 .if \export
81 .global EXTERN_ASM\name
82 EXTERN_ASM\name:
83 .endif
84 ELF .type \name, %function
85 .func \name
86 \name:
87 .endm
88
89 .macro const name, align=2
90 .macro endconst
91 ELF .size \name, . - \name
92 .purgem endconst
93 .endm
94 .section .rodata
95 .align \align
96 \name:
97 .endm
98
99 #if !HAVE_ARMV6T2
100 .macro movw rd, val
101 mov \rd, \val & 255
102 orr \rd, \val & ~255
103 .endm
104 #endif
105
106 .macro mov32 rd, val
107 #if HAVE_ARMV6T2
108 movw \rd, #(\val) & 0xffff
109 .if (\val) >> 16
110 movt \rd, #(\val) >> 16
111 .endif
112 #else
113 ldr \rd, =\val
114 #endif
115 .endm
116
117 .macro put_pic num
118 put_pic_\num
119 .endm
120
121 .macro do_def_pic num, val, label
122 .macro put_pic_\num
123 .if \num
124 .altmacro
125 put_pic %(\num - 1)
126 .noaltmacro
127 .endif
128 \label: .word \val
129 .purgem put_pic_\num
130 .endm
131 .endm
132
133 .macro def_pic val, label
134 .altmacro
135 do_def_pic %.Lpic_idx, \val, \label
136 .noaltmacro
137 .set .Lpic_idx, .Lpic_idx + 1
138 .endm
139
140 .macro ldpic rd, val, indir=0
141 ldr \rd, .Lpicoff\@
142 .Lpic\@:
143 .if \indir
144 ldr \rd, [pc, \rd]
145 .else
146 add \rd, pc
147 .endif
148 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
149 .endm
150
151 .macro movrel rd, val
152 #if CONFIG_PIC
153 ldpic \rd, \val
154 #elif HAVE_ARMV6T2 && !defined(__APPLE__)
155 movw \rd, #:lower16:\val
156 movt \rd, #:upper16:\val
157 #else
158 ldr \rd, =\val
159 #endif
160 .endm
161
162 .macro movrelx rd, val, gp
163 #if CONFIG_PIC && defined(__ELF__)
164 .ifnb \gp
165 .if .Lpic_gp
166 .unreq gp
167 .endif
168 gp .req \gp
169 ldpic gp, _GLOBAL_OFFSET_TABLE_
170 .elseif !.Lpic_gp
171 gp .req r12
172 ldpic gp, _GLOBAL_OFFSET_TABLE_
173 .endif
174 .set .Lpic_gp, 1
175 ldr \rd, .Lpicoff\@
176 ldr \rd, [gp, \rd]
177 def_pic \val(GOT), .Lpicoff\@
178 #elif CONFIG_PIC && defined(__APPLE__)
179 ldpic \rd, .Lpic\@, indir=1
180 .non_lazy_symbol_pointer
181 .Lpic\@:
182 .indirect_symbol \val
183 .word 0
184 .text
185 #else
186 movrel \rd, \val
187 #endif
188 .endm
189
190 .macro add_sh rd, rn, rm, sh:vararg
191 A add \rd, \rn, \rm, \sh
192 T mov \rm, \rm, \sh
193 T add \rd, \rn, \rm
194 .endm
195
196 .macro ldr_pre rt, rn, rm:vararg
197 A ldr \rt, [\rn, \rm]!
198 T add \rn, \rn, \rm
199 T ldr \rt, [\rn]
200 .endm
201
202 .macro ldr_dpre rt, rn, rm:vararg
203 A ldr \rt, [\rn, -\rm]!
204 T sub \rn, \rn, \rm
205 T ldr \rt, [\rn]
206 .endm
207
208 .macro ldr_nreg rt, rn, rm:vararg
209 A ldr \rt, [\rn, -\rm]
210 T sub \rt, \rn, \rm
211 T ldr \rt, [\rt]
212 .endm
213
214 .macro ldr_post rt, rn, rm:vararg
215 A ldr \rt, [\rn], \rm
216 T ldr \rt, [\rn]
217 T add \rn, \rn, \rm
218 .endm
219
220 .macro ldrd_reg rt, rt2, rn, rm
221 A ldrd \rt, \rt2, [\rn, \rm]
222 T add \rt, \rn, \rm
223 T ldrd \rt, \rt2, [\rt]
224 .endm
225
226 .macro ldrd_post rt, rt2, rn, rm
227 A ldrd \rt, \rt2, [\rn], \rm
228 T ldrd \rt, \rt2, [\rn]
229 T add \rn, \rn, \rm
230 .endm
231
232 .macro ldrh_pre rt, rn, rm
233 A ldrh \rt, [\rn, \rm]!
234 T add \rn, \rn, \rm
235 T ldrh \rt, [\rn]
236 .endm
237
238 .macro ldrh_dpre rt, rn, rm
239 A ldrh \rt, [\rn, -\rm]!
240 T sub \rn, \rn, \rm
241 T ldrh \rt, [\rn]
242 .endm
243
244 .macro ldrh_post rt, rn, rm
245 A ldrh \rt, [\rn], \rm
246 T ldrh \rt, [\rn]
247 T add \rn, \rn, \rm
248 .endm
249
250 .macro ldrb_post rt, rn, rm
251 A ldrb \rt, [\rn], \rm
252 T ldrb \rt, [\rn]
253 T add \rn, \rn, \rm
254 .endm
255
256 .macro str_post rt, rn, rm:vararg
257 A str \rt, [\rn], \rm
258 T str \rt, [\rn]
259 T add \rn, \rn, \rm
260 .endm
261
262 .macro strb_post rt, rn, rm:vararg
263 A strb \rt, [\rn], \rm
264 T strb \rt, [\rn]
265 T add \rn, \rn, \rm
266 .endm
267
268 .macro strd_post rt, rt2, rn, rm
269 A strd \rt, \rt2, [\rn], \rm
270 T strd \rt, \rt2, [\rn]
271 T add \rn, \rn, \rm
272 .endm
273
274 .macro strh_pre rt, rn, rm
275 A strh \rt, [\rn, \rm]!
276 T add \rn, \rn, \rm
277 T strh \rt, [\rn]
278 .endm
279
280 .macro strh_dpre rt, rn, rm
281 A strh \rt, [\rn, -\rm]!
282 T sub \rn, \rn, \rm
283 T strh \rt, [\rn]
284 .endm
285
286 .macro strh_post rt, rn, rm
287 A strh \rt, [\rn], \rm
288 T strh \rt, [\rn]
289 T add \rn, \rn, \rm
290 .endm
291
292 .macro strh_dpost rt, rn, rm
293 A strh \rt, [\rn], -\rm
294 T strh \rt, [\rn]
295 T sub \rn, \rn, \rm
296 .endm
297
298 #if HAVE_VFP_ARGS
299 .eabi_attribute 28, 1
300 # define VFP
301 # define NOVFP @
302 #else
303 # define VFP @
304 # define NOVFP
305 #endif
306
307 #define GLUE(a, b) a ## b
308 #define JOIN(a, b) GLUE(a, b)
309 #define X(s) JOIN(EXTERN_ASM, s)