ARM: Move asm.S from libavcodec to libavutil
[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 .macro endfunc
66 ELF .size \name, . - \name
67 .endfunc
68 .purgem endfunc
69 .endm
70 .text
71 .align 2
72 .if \export
73 .global EXTERN_ASM\name
74 EXTERN_ASM\name:
75 .endif
76 ELF .type \name, %function
77 .func \name
78 \name:
79 .endm
80
81 .macro const name, align=2
82 .macro endconst
83 ELF .size \name, . - \name
84 .purgem endconst
85 .endm
86 .section .rodata
87 .align \align
88 \name:
89 .endm
90
91 #if !HAVE_ARMV6T2
92 .macro movw rd, val
93 mov \rd, \val & 255
94 orr \rd, \val & ~255
95 .endm
96 #endif
97
98 .macro mov32 rd, val
99 #if HAVE_ARMV6T2
100 movw \rd, #(\val) & 0xffff
101 .if (\val) >> 16
102 movt \rd, #(\val) >> 16
103 .endif
104 #else
105 ldr \rd, =\val
106 #endif
107 .endm
108
109 .macro movrel rd, val
110 #if HAVE_ARMV6T2 && !CONFIG_PIC && !defined(__APPLE__)
111 movw \rd, #:lower16:\val
112 movt \rd, #:upper16:\val
113 #else
114 ldr \rd, =\val
115 #endif
116 .endm
117
118 .macro ldr_pre rt, rn, rm:vararg
119 A ldr \rt, [\rn, \rm]!
120 T add \rn, \rn, \rm
121 T ldr \rt, [\rn]
122 .endm
123
124 .macro ldr_dpre rt, rn, rm:vararg
125 A ldr \rt, [\rn, -\rm]!
126 T sub \rn, \rn, \rm
127 T ldr \rt, [\rn]
128 .endm
129
130 .macro ldr_nreg rt, rn, rm:vararg
131 A ldr \rt, [\rn, -\rm]
132 T sub \rt, \rn, \rm
133 T ldr \rt, [\rt]
134 .endm
135
136 .macro ldr_post rt, rn, rm:vararg
137 A ldr \rt, [\rn], \rm
138 T ldr \rt, [\rn]
139 T add \rn, \rn, \rm
140 .endm
141
142 .macro ldrd_reg rt, rt2, rn, rm
143 A ldrd \rt, \rt2, [\rn, \rm]
144 T add \rt, \rn, \rm
145 T ldrd \rt, \rt2, [\rt]
146 .endm
147
148 .macro ldrd_post rt, rt2, rn, rm
149 A ldrd \rt, \rt2, [\rn], \rm
150 T ldrd \rt, \rt2, [\rn]
151 T add \rn, \rn, \rm
152 .endm
153
154 .macro ldrh_pre rt, rn, rm
155 A ldrh \rt, [\rn, \rm]!
156 T add \rn, \rn, \rm
157 T ldrh \rt, [\rn]
158 .endm
159
160 .macro ldrh_dpre rt, rn, rm
161 A ldrh \rt, [\rn, -\rm]!
162 T sub \rn, \rn, \rm
163 T ldrh \rt, [\rn]
164 .endm
165
166 .macro ldrh_post rt, rn, rm
167 A ldrh \rt, [\rn], \rm
168 T ldrh \rt, [\rn]
169 T add \rn, \rn, \rm
170 .endm
171
172 .macro ldrb_post rt, rn, rm
173 A ldrb \rt, [\rn], \rm
174 T ldrb \rt, [\rn]
175 T add \rn, \rn, \rm
176 .endm
177
178 .macro str_post rt, rn, rm:vararg
179 A str \rt, [\rn], \rm
180 T str \rt, [\rn]
181 T add \rn, \rn, \rm
182 .endm
183
184 .macro strb_post rt, rn, rm:vararg
185 A strb \rt, [\rn], \rm
186 T strb \rt, [\rn]
187 T add \rn, \rn, \rm
188 .endm
189
190 .macro strd_post rt, rt2, rn, rm
191 A strd \rt, \rt2, [\rn], \rm
192 T strd \rt, \rt2, [\rn]
193 T add \rn, \rn, \rm
194 .endm
195
196 .macro strh_pre rt, rn, rm
197 A strh \rt, [\rn, \rm]!
198 T add \rn, \rn, \rm
199 T strh \rt, [\rn]
200 .endm
201
202 .macro strh_dpre rt, rn, rm
203 A strh \rt, [\rn, -\rm]!
204 T sub \rn, \rn, \rm
205 T strh \rt, [\rn]
206 .endm
207
208 .macro strh_post rt, rn, rm
209 A strh \rt, [\rn], \rm
210 T strh \rt, [\rn]
211 T add \rn, \rn, \rm
212 .endm
213
214 .macro strh_dpost rt, rn, rm
215 A strh \rt, [\rn], -\rm
216 T strh \rt, [\rn]
217 T sub \rn, \rn, \rm
218 .endm
219
220 #if HAVE_VFP_ARGS
221 .eabi_attribute 28, 1
222 # define VFP
223 # define NOVFP @
224 #else
225 # define VFP @
226 # define NOVFP
227 #endif
228
229 #define GLUE(a, b) a ## b
230 #define JOIN(a, b) GLUE(a, b)
231 #define X(s) JOIN(EXTERN_ASM, s)