PR debug/83917
[official-gcc.git] / libgcc / config / i386 / i386-asm.h
blobdbf99564b0c00c3397afba6387ba6b5ea6ce1313
1 /* Defines common perprocessor and assembly macros for use by various stubs.
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 Contributed by Daniel Santos <daniel.santos@pobox.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef I386_ASM_H
27 #define I386_ASM_H
29 #include "auto-target.h"
30 #undef PACKAGE_VERSION
31 #undef PACKAGE_NAME
32 #undef PACKAGE_STRING
33 #undef PACKAGE_TARNAME
34 #undef PACKAGE_URL
35 #include "auto-host.h"
37 #ifndef USE_GAS_CFI_DIRECTIVES
38 # ifdef __GCC_HAVE_DWARF2_CFI_ASM
39 # define USE_GAS_CFI_DIRECTIVES 1
40 # else
41 # define USE_GAS_CFI_DIRECTIVES 0
42 # endif
43 #endif
44 #if USE_GAS_CFI_DIRECTIVES
45 # define cfi_startproc() .cfi_startproc
46 # define cfi_endproc() .cfi_endproc
47 # define cfi_adjust_cfa_offset(X) .cfi_adjust_cfa_offset X
48 # define cfi_def_cfa_register(X) .cfi_def_cfa_register X
49 # define cfi_def_cfa(R,O) .cfi_def_cfa R, O
50 # define cfi_register(D,S) .cfi_register D, S
51 # define cfi_offset(R,O) .cfi_offset R, O
52 # ifdef __x86_64__
53 # define cfi_push(X) .cfi_adjust_cfa_offset 8; .cfi_rel_offset X, 0
54 # define cfi_pop(X) .cfi_adjust_cfa_offset -8; .cfi_restore X
55 # else
56 # define cfi_push(X) .cfi_adjust_cfa_offset 4; .cfi_rel_offset X, 0
57 # define cfi_pop(X) .cfi_adjust_cfa_offset -4; .cfi_restore X
58 # endif
59 #else
60 # define cfi_startproc()
61 # define cfi_endproc()
62 # define cfi_adjust_cfa_offset(X)
63 # define cfi_def_cfa_register(X)
64 # define cfi_def_cfa(R,O)
65 # define cfi_register(D,S)
66 # define cfi_offset(R,O)
67 # define cfi_push(X)
68 # define cfi_pop(X)
69 #endif
71 #define PASTE2(a, b) PASTE2a(a, b)
72 #define PASTE2a(a, b) a ## b
74 /* These macros currently support GNU/Linux, Solaris and Darwin. */
76 #ifdef __ELF__
77 # define FN_TYPE(fn) .type fn,@function
78 # define FN_SIZE(fn) .size fn,.-fn
79 # ifdef HAVE_GAS_HIDDEN
80 # define FN_HIDDEN(fn) .hidden fn
81 # endif
82 #else
83 # define FN_TYPE(fn)
84 # define FN_SIZE(fn)
85 #endif
87 #ifndef FN_HIDDEN
88 # define FN_HIDDEN(fn)
89 #endif
91 #ifdef __USER_LABEL_PREFIX__
92 # define ASMNAME(name) PASTE2(__USER_LABEL_PREFIX__, name)
93 #else
94 # define ASMNAME(name) name
95 #endif
97 #define FUNC_BEGIN(fn) \
98 .globl ASMNAME(fn); \
99 FN_TYPE (ASMNAME(fn)); \
100 ASMNAME(fn):
102 #define HIDDEN_FUNC(fn) \
103 .globl ASMNAME(fn); \
104 FN_TYPE(ASMNAME(fn)); \
105 FN_HIDDEN(ASMNAME(fn)); \
106 ASMNAME(fn):
108 #define FUNC_END(fn) FN_SIZE(ASMNAME(fn))
110 #ifdef MS2SYSV_STUB_AVX
111 # define MS2SYSV_STUB_PREFIX __avx_
112 # ifdef HAVE_AS_AVX
113 # define MOVAPS vmovaps
114 # endif
115 #elif defined(MS2SYSV_STUB_SSE)
116 # define MS2SYSV_STUB_PREFIX __sse_
117 # define MOVAPS movaps
118 #endif
120 #ifdef MS2SYSV_STUB_PREFIX
122 # define MS2SYSV_STUB_BEGIN(base_name) \
123 HIDDEN_FUNC(PASTE2(MS2SYSV_STUB_PREFIX, base_name))
125 # define MS2SYSV_STUB_END(base_name) \
126 FUNC_END(PASTE2(MS2SYSV_STUB_PREFIX, base_name))
128 /* If expanding for sse or avx and we have assembler support. */
129 # ifdef MOVAPS
130 /* Save SSE registers 6-15 using rax as the base address. */
131 # define SSE_SAVE \
132 MOVAPS %xmm15,-0x30(%rax); \
133 MOVAPS %xmm14,-0x20(%rax); \
134 MOVAPS %xmm13,-0x10(%rax); \
135 MOVAPS %xmm12, (%rax); \
136 MOVAPS %xmm11, 0x10(%rax); \
137 MOVAPS %xmm10, 0x20(%rax); \
138 MOVAPS %xmm9, 0x30(%rax); \
139 MOVAPS %xmm8, 0x40(%rax); \
140 MOVAPS %xmm7, 0x50(%rax); \
141 MOVAPS %xmm6, 0x60(%rax)
143 /* Restore SSE registers 6-15 using rsi as the base address. */
144 # define SSE_RESTORE \
145 MOVAPS -0x30(%rsi), %xmm15; \
146 MOVAPS -0x20(%rsi), %xmm14; \
147 MOVAPS -0x10(%rsi), %xmm13; \
148 MOVAPS (%rsi), %xmm12; \
149 MOVAPS 0x10(%rsi), %xmm11; \
150 MOVAPS 0x20(%rsi), %xmm10; \
151 MOVAPS 0x30(%rsi), %xmm9 ; \
152 MOVAPS 0x40(%rsi), %xmm8 ; \
153 MOVAPS 0x50(%rsi), %xmm7 ; \
154 MOVAPS 0x60(%rsi), %xmm6
155 # else /* MOVAPS */
156 /* If the assembler doesn't support AVX then directly emit machine code
157 for the instructions above. */
158 # define SSE_SAVE \
159 .byte 0xc5, 0x78, 0x29, 0x78, 0xd0; /* vmovaps %xmm15,-0x30(%rax) */ \
160 .byte 0xc5, 0x78, 0x29, 0x70, 0xe0; /* vmovaps %xmm14,-0x20(%rax) */ \
161 .byte 0xc5, 0x78, 0x29, 0x68, 0xf0; /* vmovaps %xmm13,-0x10(%rax) */ \
162 .byte 0xc5, 0x78, 0x29, 0x20; /* vmovaps %xmm12, (%rax) */ \
163 .byte 0xc5, 0x78, 0x29, 0x58, 0x10; /* vmovaps %xmm11, 0x10(%rax) */ \
164 .byte 0xc5, 0x78, 0x29, 0x50, 0x20; /* vmovaps %xmm10, 0x20(%rax) */ \
165 .byte 0xc5, 0x78, 0x29, 0x48, 0x30; /* vmovaps %xmm9, 0x30(%rax) */ \
166 .byte 0xc5, 0x78, 0x29, 0x40, 0x40; /* vmovaps %xmm8, 0x40(%rax) */ \
167 .byte 0xc5, 0xf8, 0x29, 0x78, 0x50; /* vmovaps %xmm7, 0x50(%rax) */ \
168 .byte 0xc5, 0xf8, 0x29, 0x70, 0x60; /* vmovaps %xmm6, 0x60(%rax) */
169 # define SSE_RESTORE \
170 .byte 0xc5, 0x78, 0x28, 0x7e, 0xd0; /* vmovaps -0x30(%rsi),%xmm15 */ \
171 .byte 0xc5, 0x78, 0x28, 0x76, 0xe0; /* vmovaps -0x20(%rsi),%xmm14 */ \
172 .byte 0xc5, 0x78, 0x28, 0x6e, 0xf0; /* vmovaps -0x10(%rsi),%xmm13 */ \
173 .byte 0xc5, 0x78, 0x28, 0x26; /* vmovaps (%rsi),%xmm12 */ \
174 .byte 0xc5, 0x78, 0x28, 0x5e, 0x10; /* vmovaps 0x10(%rsi),%xmm11 */ \
175 .byte 0xc5, 0x78, 0x28, 0x56, 0x20; /* vmovaps 0x20(%rsi),%xmm10 */ \
176 .byte 0xc5, 0x78, 0x28, 0x4e, 0x30; /* vmovaps 0x30(%rsi),%xmm9 */ \
177 .byte 0xc5, 0x78, 0x28, 0x46, 0x40; /* vmovaps 0x40(%rsi),%xmm8 */ \
178 .byte 0xc5, 0xf8, 0x28, 0x7e, 0x50; /* vmovaps 0x50(%rsi),%xmm7 */ \
179 .byte 0xc5, 0xf8, 0x28, 0x76, 0x60; /* vmovaps 0x60(%rsi),%xmm6 */
180 # endif /* MOVAPS */
181 #endif /* MS2SYSV_STUB_PREFIX */
182 #endif /* I386_ASM_H */