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