comctl32/tests: Remove some workarounds from ListView tests.
[wine.git] / include / wine / asm.h
blob788e26126cb008e750d6c2b439eae9ffd2ed9390
1 /*
2 * Inline assembly support
4 * Copyright 2019 Alexandre Julliard
6 * This library 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.
11 * This library 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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_WINE_ASM_H
22 #define __WINE_WINE_ASM_H
24 #if defined(__APPLE__) || (defined(_WIN32) && defined(__i386__))
25 # define __ASM_NAME(name) "_" name
26 #else
27 # define __ASM_NAME(name) name
28 #endif
30 #if defined(_WIN32) && defined(__i386__)
31 # define __ASM_STDCALL(name,args) __ASM_NAME(name) "@" #args
32 #else
33 # define __ASM_STDCALL(name,args) __ASM_NAME(name)
34 #endif
36 #if defined(__GCC_HAVE_DWARF2_CFI_ASM) || (defined(__clang__) && defined(__GNUC__) && !defined(__SEH__))
37 # define __ASM_CFI(str) str
38 #else
39 # define __ASM_CFI(str)
40 #endif
42 #ifdef __SEH__
43 # if defined(__aarch64__) && defined(__clang_major__) && (__clang_major__ < 12 || defined(__apple_build_version__))
44 /* Clang got support for aarch64 SEH assembly directives in Clang 12,
45 * before that, only .seh_startproc/.seh_endproc but nothing else was
46 * supported. Support for it doesn't exist in any Apple branded version
47 * of Clang yet. */
48 # define __ASM_SEH(str)
49 # else
50 # define __ASM_SEH(str) str
51 # endif
52 #else
53 # define __ASM_SEH(str)
54 #endif
56 #ifdef _WIN32
57 # define __ASM_FUNC_TYPE(name) ".def " name "; .scl 2; .type 32; .endef"
58 #elif defined(__APPLE__)
59 # define __ASM_FUNC_TYPE(name) ""
60 #elif defined(__arm__) || defined(__arm64__)
61 # define __ASM_FUNC_TYPE(name) ".type " name ",%function"
62 #else
63 # define __ASM_FUNC_TYPE(name) ".type " name ",@function"
64 #endif
66 #if !defined(__GNUC__) && !defined(__clang__)
67 # define __ASM_BLOCK_BEGIN(name) void __asm_dummy_##name(void) {
68 # define __ASM_BLOCK_END }
69 #else
70 # define __ASM_BLOCK_BEGIN(name)
71 # define __ASM_BLOCK_END
72 #endif
74 #define __ASM_DEFINE_FUNC(name,code) \
75 __ASM_BLOCK_BEGIN(__LINE__) \
76 asm(".text\n\t.align 4\n\t.globl " name "\n\t" __ASM_FUNC_TYPE(name) __ASM_SEH("\n\t.seh_proc " name) "\n" name ":\n\t" \
77 __ASM_CFI(".cfi_startproc\n\t") code __ASM_CFI("\n\t.cfi_endproc") __ASM_SEH("\n\t.seh_endproc") ); \
78 __ASM_BLOCK_END
80 #define __ASM_GLOBAL_FUNC(name,code) __ASM_DEFINE_FUNC(__ASM_NAME(#name),code)
82 #define __ASM_STDCALL_FUNC(name,args,code) __ASM_DEFINE_FUNC(__ASM_STDCALL(#name,args),code)
84 /* fastcall support */
86 #if defined(__i386__) && !defined(_WIN32)
88 # define DEFINE_FASTCALL1_WRAPPER(func) \
89 __ASM_STDCALL_FUNC( __fastcall_ ## func, 4, \
90 "popl %eax\n\t" \
91 "pushl %ecx\n\t" \
92 "pushl %eax\n\t" \
93 "jmp " __ASM_STDCALL(#func,4) )
94 # define DEFINE_FASTCALL_WRAPPER(func,args) \
95 __ASM_STDCALL_FUNC( __fastcall_ ## func, args, \
96 "popl %eax\n\t" \
97 "pushl %edx\n\t" \
98 "pushl %ecx\n\t" \
99 "pushl %eax\n\t" \
100 "jmp " __ASM_STDCALL(#func,args) )
102 #else /* __i386__ */
104 # define DEFINE_FASTCALL1_WRAPPER(func) /* nothing */
105 # define DEFINE_FASTCALL_WRAPPER(func,args) /* nothing */
107 #endif /* __i386__ */
109 /* thiscall support */
111 #if defined(__i386__) && !defined(__MINGW32__) && (!defined(_MSC_VER) || !defined(__clang__))
113 #define __ASM_USE_THISCALL_WRAPPER
114 # ifdef _MSC_VER
115 # define DEFINE_THISCALL_WRAPPER(func,args) \
116 __declspec(naked) void __thiscall_##func(void) \
117 { __asm { \
118 pop eax \
119 push ecx \
120 push eax \
121 jmp func \
123 # else /* _MSC_VER */
124 # define DEFINE_THISCALL_WRAPPER(func,args) \
125 extern void __thiscall_ ## func(void); \
126 __ASM_STDCALL_FUNC( __thiscall_ ## func, args, \
127 "popl %eax\n\t" \
128 "pushl %ecx\n\t" \
129 "pushl %eax\n\t" \
130 "jmp " __ASM_STDCALL(#func,args) )
131 # endif /* _MSC_VER */
133 # define THISCALL(func) (void *)__thiscall_ ## func
134 # define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
136 #else /* __i386__ */
138 # define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
139 # define THISCALL(func) func
140 # define THISCALL_NAME(func) __ASM_NAME(#func)
142 #endif /* __i386__ */
144 #if defined(__GNUC__) && !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
145 #define __ASM_OBSOLETE(func) __asm__( ".symver " #func "_obsolete," #func "@WINE_1.0" )
146 #else
147 #undef __ASM_OBSOLETE
148 #endif
150 #endif /* __WINE_WINE_ASM_H */