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