arm: hpeldsp: prevent overreads in armv6 asm
[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
8ee2b467
MR
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
b3267559 49#elif HAVE_VFP
8ee2b467
MR
50 .fpu vfp
51#endif
52
371266da 53 .syntax unified
8986fddc 54T .thumb
51a15ed7 55ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
543156d7 56ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
c72ab301 57
5dae4872 58.macro function name, export=0, align=2
62634158
MR
59 .set .Lpic_idx, 0
60 .set .Lpic_gp, 0
480cb7ed 61 .macro endfunc
62634158 62 .if .Lpic_idx
cdb7db5a 63 .align 2
62634158
MR
64 .altmacro
65 put_pic %(.Lpic_idx - 1)
66 .noaltmacro
67 .endif
18c31f6f 68ELF .size \name, . - \name
a7e7d40c
MR
69 .endfunc
70 .purgem endfunc
480cb7ed 71 .endm
278caa6a 72 .text
5dae4872 73 .align \align
480cb7ed 74 .if \export
e654b7c2 75 .global EXTERN_ASM\name
e3fec3f0
MS
76ELF .type EXTERN_ASM\name, %function
77 .func EXTERN_ASM\name
e654b7c2 78EXTERN_ASM\name:
e3fec3f0 79 .else
341f394f 80ELF .type \name, %function
c72ab301
MR
81 .func \name
82\name:
e3fec3f0 83 .endif
480cb7ed 84.endm
172a39d1 85
b9a639dd
MR
86.macro const name, align=2
87 .macro endconst
88ELF .size \name, . - \name
89 .purgem endconst
90 .endm
91 .section .rodata
92 .align \align
93\name:
94.endm
95
a7831d50 96#if !HAVE_ARMV6T2_EXTERNAL
dac78fd1
MR
97.macro movw rd, val
98 mov \rd, \val & 255
99 orr \rd, \val & ~255
100.endm
101#endif
102
a4edc5a9 103.macro mov32 rd, val
a7831d50 104#if HAVE_ARMV6T2_EXTERNAL
a4edc5a9
MR
105 movw \rd, #(\val) & 0xffff
106 .if (\val) >> 16
107 movt \rd, #(\val) >> 16
108 .endif
109#else
110 ldr \rd, =\val
111#endif
112.endm
113
62634158
MR
114.macro put_pic num
115 put_pic_\num
116.endm
117
118.macro do_def_pic num, val, label
119 .macro put_pic_\num
120 .if \num
121 .altmacro
122 put_pic %(\num - 1)
123 .noaltmacro
124 .endif
125\label: .word \val
126 .purgem put_pic_\num
127 .endm
128.endm
129
130.macro def_pic val, label
131 .altmacro
132 do_def_pic %.Lpic_idx, \val, \label
133 .noaltmacro
134 .set .Lpic_idx, .Lpic_idx + 1
135.endm
136
137.macro ldpic rd, val, indir=0
138 ldr \rd, .Lpicoff\@
139.Lpic\@:
140 .if \indir
7bda4ed7
MR
141A ldr \rd, [pc, \rd]
142T add \rd, pc
143T ldr \rd, [\rd]
62634158 144 .else
8995d349 145 add \rd, pc
62634158
MR
146 .endif
147 def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
148.endm
149
480cb7ed 150.macro movrel rd, val
62634158
MR
151#if CONFIG_PIC
152 ldpic \rd, \val
a7831d50 153#elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
172a39d1
MR
154 movw \rd, #:lower16:\val
155 movt \rd, #:upper16:\val
156#else
157 ldr \rd, =\val
158#endif
480cb7ed 159.endm
ce742de2 160
62634158
MR
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
7689eea4
MR
189.macro add_sh rd, rn, rm, sh:vararg
190A add \rd, \rn, \rm, \sh
191T mov \rm, \rm, \sh
192T add \rd, \rn, \rm
193.endm
194
8986fddc
MR
195.macro ldr_pre rt, rn, rm:vararg
196A ldr \rt, [\rn, \rm]!
197T add \rn, \rn, \rm
198T ldr \rt, [\rn]
199.endm
200
71ce7602
MR
201.macro ldr_dpre rt, rn, rm:vararg
202A ldr \rt, [\rn, -\rm]!
203T sub \rn, \rn, \rm
204T ldr \rt, [\rn]
205.endm
206
dac78fd1
MR
207.macro ldr_nreg rt, rn, rm:vararg
208A ldr \rt, [\rn, -\rm]
209T sub \rt, \rn, \rm
210T ldr \rt, [\rt]
211.endm
212
8986fddc
MR
213.macro ldr_post rt, rn, rm:vararg
214A ldr \rt, [\rn], \rm
215T ldr \rt, [\rn]
216T add \rn, \rn, \rm
217.endm
218
cbddee1c
JG
219.macro ldrc_pre cc, rt, rn, rm:vararg
220A ldr\cc \rt, [\rn, \rm]!
221T itt \cc
222T add\cc \rn, \rn, \rm
223T ldr\cc \rt, [\rn]
224.endm
225
8986fddc
MR
226.macro ldrd_reg rt, rt2, rn, rm
227A ldrd \rt, \rt2, [\rn, \rm]
228T add \rt, \rn, \rm
229T ldrd \rt, \rt2, [\rt]
230.endm
231
232.macro ldrd_post rt, rt2, rn, rm
233A ldrd \rt, \rt2, [\rn], \rm
234T ldrd \rt, \rt2, [\rn]
235T add \rn, \rn, \rm
236.endm
237
238.macro ldrh_pre rt, rn, rm
239A ldrh \rt, [\rn, \rm]!
240T add \rn, \rn, \rm
241T ldrh \rt, [\rn]
242.endm
243
244.macro ldrh_dpre rt, rn, rm
245A ldrh \rt, [\rn, -\rm]!
246T sub \rn, \rn, \rm
247T ldrh \rt, [\rn]
248.endm
249
250.macro ldrh_post rt, rn, rm
251A ldrh \rt, [\rn], \rm
252T ldrh \rt, [\rn]
253T add \rn, \rn, \rm
254.endm
255
dac78fd1
MR
256.macro ldrb_post rt, rn, rm
257A ldrb \rt, [\rn], \rm
258T ldrb \rt, [\rn]
259T add \rn, \rn, \rm
260.endm
261
8986fddc
MR
262.macro str_post rt, rn, rm:vararg
263A str \rt, [\rn], \rm
264T str \rt, [\rn]
265T add \rn, \rn, \rm
266.endm
267
268.macro strb_post rt, rn, rm:vararg
269A strb \rt, [\rn], \rm
270T strb \rt, [\rn]
271T add \rn, \rn, \rm
272.endm
273
274.macro strd_post rt, rt2, rn, rm
275A strd \rt, \rt2, [\rn], \rm
276T strd \rt, \rt2, [\rn]
277T add \rn, \rn, \rm
278.endm
279
280.macro strh_pre rt, rn, rm
281A strh \rt, [\rn, \rm]!
282T add \rn, \rn, \rm
283T strh \rt, [\rn]
284.endm
285
286.macro strh_dpre rt, rn, rm
287A strh \rt, [\rn, -\rm]!
288T sub \rn, \rn, \rm
289T strh \rt, [\rn]
290.endm
291
292.macro strh_post rt, rn, rm
293A strh \rt, [\rn], \rm
294T strh \rt, [\rn]
295T add \rn, \rn, \rm
296.endm
297
298.macro strh_dpost rt, rn, rm
299A strh \rt, [\rn], -\rm
300T strh \rt, [\rn]
301T sub \rn, \rn, \rm
302.endm
303
ce742de2 304#if HAVE_VFP_ARGS
be7952b5 305ELF .eabi_attribute 28, 1
ce742de2
MR
306# define VFP
307# define NOVFP @
308#else
309# define VFP @
310# define NOVFP
311#endif
e654b7c2
MR
312
313#define GLUE(a, b) a ## b
314#define JOIN(a, b) GLUE(a, b)
315#define X(s) JOIN(EXTERN_ASM, s)