bf5c1b7ee17939ffc47e78d52ea16f9610b0dfbc
[libav.git] / libavutil / aarch64 / 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 HAVE_AS_FUNC
30 # define FUNC
31 #else
32 # define FUNC #
33 #endif
34
35 .macro function name, export=0, align=2
36 .macro endfunc
37 ELF .size \name, . - \name
38 FUNC .endfunc
39 .purgem endfunc
40 .endm
41 .text
42 .align \align
43 .if \export
44 .global EXTERN_ASM\name
45 ELF .type EXTERN_ASM\name, %function
46 FUNC .func EXTERN_ASM\name
47 EXTERN_ASM\name:
48 .else
49 ELF .type \name, %function
50 FUNC .func \name
51 \name:
52 .endif
53 .endm
54
55 .macro const name, align=2, relocate=0
56 .macro endconst
57 ELF .size \name, . - \name
58 .purgem endconst
59 .endm
60 #if HAVE_SECTION_DATA_REL_RO
61 .if \relocate
62 .section .data.rel.ro
63 .else
64 .section .rodata
65 .endif
66 #elif defined(_WIN32)
67 .section .rdata
68 #elif !defined(__MACH__)
69 .section .rodata
70 #else
71 .const_data
72 #endif
73 .align \align
74 \name:
75 .endm
76
77 .macro movrel rd, val, offset=0
78 #if CONFIG_PIC && defined(__APPLE__)
79 .if \offset < 0
80 adrp \rd, \val@PAGE
81 add \rd, \rd, \val@PAGEOFF
82 sub \rd, \rd, -(\offset)
83 .else
84 adrp \rd, \val+(\offset)@PAGE
85 add \rd, \rd, \val+(\offset)@PAGEOFF
86 .endif
87 #elif CONFIG_PIC && defined(_WIN32)
88 .if \offset < 0
89 adrp \rd, \val
90 add \rd, \rd, :lo12:\val
91 sub \rd, \rd, -(\offset)
92 .else
93 adrp \rd, \val+(\offset)
94 add \rd, \rd, :lo12:\val+(\offset)
95 .endif
96 #elif CONFIG_PIC
97 adrp \rd, \val+(\offset)
98 add \rd, \rd, :lo12:\val+(\offset)
99 #else
100 ldr \rd, =\val+\offset
101 #endif
102 .endm
103
104 #define GLUE(a, b) a ## b
105 #define JOIN(a, b) GLUE(a, b)
106 #define X(s) JOIN(EXTERN_ASM, s)