Debian Codegraph @

src/libmpg123/mangle.h

raw
1 /*
2 mangle: support defines for preprocessed assembler
3
4 copyright 1995-2023 by the mpg123 project - free software under the terms of the LGPL 2.1
5 see COPYING and AUTHORS files in distribution or http://mpg123.org
6
7 This once started out as mangle.h from MPlayer, but you can't really call it derived work... the small part that in principle stems from MPlayer also being not very special (once you decided to use such a header at all, it's quite obvious material).
8 */
9
10 #ifndef __MANGLE_H
11 #define __MANGLE_H
12
13 #include "config.h"
14
15 #if (defined OPT_I486) || (defined OPT_I586) || (defined OPT_I586_DITHER) \
16 || (defined OPT_MMX) || (defined OPT_SSE) || (defined OPT_3DNOW) || (defined OPT_3DNOWEXT) \
17 || (defined OPT_3DNOW_VINTAGE) || (defined OPT_3DNOWEXT_VINTAGE) \
18 || (defined OPT_SSE_VINTAGE)
19 #define OPT_X86
20 #endif
21
22 #ifdef CCALIGN
23 #define MOVUAPS movaps
24 #else
25 #define MOVUAPS movups
26 #endif
27
28 /*
29 ALIGNX: align to X bytes
30 This differs per compiler/platform in taking the byte count or an exponent for base 2.
31 A way out is balign, if the assembler supports it (gas extension).
32 */
33
34 #ifdef ASMALIGN_BALIGN
35
36 #define ALIGN4 .balign 4
37 #define ALIGN8 .balign 8
38 #define ALIGN16 .balign 16
39 #define ALIGN32 .balign 32
40 #define ALIGN64 .balign 64
41
42 #else
43
44 #ifdef ASMALIGN_EXP
45 #define ALIGN4 .align 2
46 #define ALIGN8 .align 3
47 #define ALIGN16 .align 4
48 #define ALIGN32 .align 5
49 #define ALIGN64 .align 6
50 #else
51 #ifdef ASMALIGN_BYTE
52 #define ALIGN4 .align 4
53 #define ALIGN8 .align 8
54 #define ALIGN16 .align 16
55 #define ALIGN32 .align 32
56 #define ALIGN64 .align 64
57 #else
58 #ifdef ASMALIGN_ARMASM
59 #define ALIGN4 ALIGN 4
60 #define ALIGN8 ALIGN 8
61 #define ALIGN16 ALIGN 16
62 #define ALIGN32 ALIGN 32
63 #define ALIGN64 ALIGN 64
64 #else
65 #error "Dunno how assembler alignment works. Please specify."
66 #endif
67 #endif
68 #endif
69
70 #endif
71
72 #define MANGLE_MACROCAT_REALLY(a, b) a ## b
73 #define MANGLE_MACROCAT(a, b) MANGLE_MACROCAT_REALLY(a, b)
74 /* Feel free to add more to the list, eg. a.out IMO */
75 #if defined(__USER_LABEL_PREFIX__)
76 #define ASM_NAME(a) MANGLE_MACROCAT(__USER_LABEL_PREFIX__,a)
77 #define ASM_VALUE(a) MANGLE_MACROCAT($,ASM_NAME(a))
78 #elif defined(__CYGWIN__) || defined(_WIN32) && !defined (_WIN64) && !defined (_M_ARM) || defined(__OS2__) || \
79 (defined(__OpenBSD__) && !defined(__ELF__)) || defined(__APPLE__)
80 #define ASM_NAME(a) MANGLE_MACROCAT(_,a)
81 #define ASM_VALUE(a) MANGLE_MACROCAT($_,a)
82 #else
83 #define ASM_NAME(a) a
84 #define ASM_VALUE(a) MANGLE_MACROCAT($,a)
85 #endif
86
87 #if !defined(__APPLE__) && !defined (__OS2__)
88 #define RODATA .section .rodata
89 #else
90 #define RODATA .data
91 #endif
92
93 /* Enable position-independent code for certain platforms. */
94
95 #if defined(OPT_X86)
96
97 #define _EBX_ %ebx
98
99 #if defined(PIC) && defined(__ELF__)
100
101 /* ELF binaries (Unix/Linux) */
102 #define LOCAL_VAR(a) MANGLE_MACROCAT(a, @GOTOFF(_EBX_))
103 #define GLOBAL_VAR(a) MANGLE_MACROCAT(ASM_NAME(a), @GOTOFF(_EBX_))
104 #define GLOBAL_VAR_PTR(a) MANGLE_MACROCAT(ASM_NAME(a), @GOT(_EBX_))
105 #define FUNC(a) ASM_NAME(a)
106 #define EXTERNAL_FUNC(a) MANGLE_MACROCAT(ASM_NAME(a), @PLT)
107 #undef ASM_VALUE
108 #define ASM_VALUE(a) MANGLE_MACROCAT(MANGLE_MACROCAT($,a), @GOTOFF)
109 #define GET_GOT \
110 call 1f; \
111 1: \
112 pop _EBX_; \
113 2: \
114 addl $_GLOBAL_OFFSET_TABLE_ + (2b-1b), _EBX_
115 #define PREPARE_GOT pushl _EBX_
116 #define RESTORE_GOT popl _EBX_
117
118 #elif defined(PIC) && defined(__APPLE__)
119
120 /* Mach-O binaries (OSX/iOS) */
121 #define LOCAL_VAR(a) MANGLE_MACROCAT(a, - Lpic_base(_EBX_))
122 #define GLOBAL_VAR(a) .err This ABI cannot access non-local symbols directly.
123 #define GLOBAL_VAR_PTR(a) MANGLE_MACROCAT(MANGLE_MACROCAT(L_, a), - Lpic_base(_EBX_))
124 #define FUNC(a) MANGLE_MACROCAT(L_, a)
125 #define EXTERNAL_FUNC(a) MANGLE_MACROCAT(L_, a)
126 #define GET_GOT \
127 call Lpic_base; \
128 Lpic_base: \
129 pop _EBX_
130 #define PREPARE_GOT pushl _EBX_
131 #define RESTORE_GOT popl _EBX_
132
133 #else
134
135 /* Dummies for everyone else. */
136 #define LOCAL_VAR(a) a
137 #define GLOBAL_VAR ASM_NAME
138 #define GLOBAL_VAR_PTR(a) .err Cannot use indirect addressing in non-PIC object.
139 #define FUNC ASM_NAME
140 #define EXTERNAL_FUNC ASM_NAME
141 #define GET_GOT
142 #define PREPARE_GOT
143 #define RESTORE_GOT
144
145 #endif /* PIC variants */
146
147 // Apple and Android NDK seem both not to like direct global access.
148 #if defined(PIC) && (defined(__APPLE__) || defined(__ANDROID__))
149 #define PIC_GLOBAL_PTR
150 #endif
151
152 #endif /* OPT_X86 */
153
154 #if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__APPLE__)
155 #define COMM(a,b,c) .comm a,b
156 #else
157 #define COMM(a,b,c) .comm a,b,c
158 #endif
159 /* more hacks for macosx; no .bss ... */
160 #ifdef __APPLE__
161 #define BSS .data
162 #else
163 #define BSS .bss
164 #endif
165
166 /* armasm for WIN32 UWP */
167 #ifdef _M_ARM
168 #define GLOBAL_SYMBOL EXPORT
169 #else
170 #define GLOBAL_SYMBOL .globl
171 #endif
172
173 /* Mark non-executable stack.
174 It's mainly for GNU on Linux... who else does (not) like this? */
175 #if !defined(__SUNPRO_C) && defined(__linux__) && defined(__ELF__)
176 #if defined(__arm__)
177 #define NONEXEC_STACK .section .note.GNU-stack,"",%progbits
178 #else
179 #define NONEXEC_STACK .section .note.GNU-stack,"",@progbits
180 #endif
181 #else
182 #define NONEXEC_STACK
183 #endif
184
185 #if (defined(__x86_64__) || defined(_M_X64)) && (defined(_WIN64) || defined (__CYGWIN__))
186 #define IS_MSABI 1 /* Not using SYSV */
187 #endif
188
189 /* Macros for +-4GiB PC-relative addressing on AArch64 */
190 #ifdef __APPLE__
191 #define AARCH64_PCREL_HI(label) label@PAGE
192 #define AARCH64_PCREL_LO(label) label@PAGEOFF
193 #else
194 #define AARCH64_PCREL_HI(label) label
195 #define AARCH64_PCREL_LO(label) :lo12:label
196 #endif
197
198 #ifdef __APPLE__
199 #define AARCH64_DUP_4S(dst, src, elem) dup.4s dst, src[elem]
200 #define AARCH64_DUP_2D(dst, src, elem) dup.2d dst, src[elem]
201 #define AARCH64_SQXTN2_8H(dst, src) sqxtn2.8h dst, src
202 #else
203 #define AARCH64_DUP_4S(dst, src, elem) dup dst.4s, src.s[elem]
204 #define AARCH64_DUP_2D(dst, src, elem) dup dst.2d, src.d[elem]
205 #define AARCH64_SQXTN2_8H(dst, src) sqxtn2 dst.8h, src.4s
206 #endif
207
208 #endif /* !__MANGLE_H */
209