arm: hpeldsp: prevent overreads in armv6 asm
[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 ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
57
58 .macro function name, export=0, align=2
59 .set .Lpic_idx, 0
60 .set .Lpic_gp, 0
61 .macro endfunc
62 .if .Lpic_idx
63 .align 2
64 .altmacro
65 put_pic %(.Lpic_idx - 1)
66 .noaltmacro
67 .endif
68 ELF .size \name, . - \name
69 .endfunc
70 .purgem endfunc
71 .endm
72 .text
73 .align \align
74 .if \export
75 .global EXTERN_ASM\name
76 ELF .type EXTERN_ASM\name, %function
77 .func EXTERN_ASM\name
78 EXTERN_ASM\name:
79 .else
80 ELF .type \name, %function
81 .func \name
82 \name:
83 .endif
84 .endm
85
86 .macro const name, align=2
87 .macro endconst
88 ELF .size \name, . - \name
89 .purgem endconst
90 .endm
91 .section .rodata
92 .align \align
93 \name:
94 .endm
95
96 #if !HAVE_ARMV6T2_EXTERNAL
97 .macro movw rd, val
98 mov \rd, \val & 255
99 orr \rd, \val & ~255
100 .endm
101 #endif
102
103 .macro mov32 rd, val
104 #if HAVE_ARMV6T2_EXTERNAL
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
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
141 A ldr \rd, [pc, \rd]
142 T add \rd, pc
143 T ldr \rd, [\rd]
144 .else
145 add \rd, pc
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_EXTERNAL && !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 ldrc_pre cc, rt, rn, rm:vararg
220 A ldr\cc \rt, [\rn, \rm]!
221 T itt \cc
222 T add\cc \rn, \rn, \rm
223 T ldr\cc \rt, [\rn]
224 .endm
225
226 .macro ldrd_reg rt, rt2, rn, rm
227 A ldrd \rt, \rt2, [\rn, \rm]
228 T add \rt, \rn, \rm
229 T ldrd \rt, \rt2, [\rt]
230 .endm
231
232 .macro ldrd_post rt, rt2, rn, rm
233 A ldrd \rt, \rt2, [\rn], \rm
234 T ldrd \rt, \rt2, [\rn]
235 T add \rn, \rn, \rm
236 .endm
237
238 .macro ldrh_pre rt, rn, rm
239 A ldrh \rt, [\rn, \rm]!
240 T add \rn, \rn, \rm
241 T ldrh \rt, [\rn]
242 .endm
243
244 .macro ldrh_dpre rt, rn, rm
245 A ldrh \rt, [\rn, -\rm]!
246 T sub \rn, \rn, \rm
247 T ldrh \rt, [\rn]
248 .endm
249
250 .macro ldrh_post rt, rn, rm
251 A ldrh \rt, [\rn], \rm
252 T ldrh \rt, [\rn]
253 T add \rn, \rn, \rm
254 .endm
255
256 .macro ldrb_post rt, rn, rm
257 A ldrb \rt, [\rn], \rm
258 T ldrb \rt, [\rn]
259 T add \rn, \rn, \rm
260 .endm
261
262 .macro str_post rt, rn, rm:vararg
263 A str \rt, [\rn], \rm
264 T str \rt, [\rn]
265 T add \rn, \rn, \rm
266 .endm
267
268 .macro strb_post rt, rn, rm:vararg
269 A strb \rt, [\rn], \rm
270 T strb \rt, [\rn]
271 T add \rn, \rn, \rm
272 .endm
273
274 .macro strd_post rt, rt2, rn, rm
275 A strd \rt, \rt2, [\rn], \rm
276 T strd \rt, \rt2, [\rn]
277 T add \rn, \rn, \rm
278 .endm
279
280 .macro strh_pre rt, rn, rm
281 A strh \rt, [\rn, \rm]!
282 T add \rn, \rn, \rm
283 T strh \rt, [\rn]
284 .endm
285
286 .macro strh_dpre rt, rn, rm
287 A strh \rt, [\rn, -\rm]!
288 T sub \rn, \rn, \rm
289 T strh \rt, [\rn]
290 .endm
291
292 .macro strh_post rt, rn, rm
293 A strh \rt, [\rn], \rm
294 T strh \rt, [\rn]
295 T add \rn, \rn, \rm
296 .endm
297
298 .macro strh_dpost rt, rn, rm
299 A strh \rt, [\rn], -\rm
300 T strh \rt, [\rn]
301 T sub \rn, \rn, \rm
302 .endm
303
304 #if HAVE_VFP_ARGS
305 ELF .eabi_attribute 28, 1
306 # define VFP
307 # define NOVFP @
308 #else
309 # define VFP @
310 # define NOVFP
311 #endif
312
313 #define GLUE(a, b) a ## b
314 #define JOIN(a, b) GLUE(a, b)
315 #define X(s) JOIN(EXTERN_ASM, s)