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)
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/>. */
29 #include "auto-target.h"
30 #include "auto-host.h"
32 #define PASTE2(a, b) PASTE2a(a, b)
33 #define PASTE2a(a, b) a ## b
35 /* These macros currently support GNU/Linux, Solaris and Darwin. */
38 # define FN_TYPE(fn) .type fn,@function
39 # define FN_SIZE(fn) .size fn,.-fn
40 # ifdef HAVE_GAS_HIDDEN
41 # define FN_HIDDEN(fn) .hidden fn
49 # define FN_HIDDEN(fn)
52 #ifdef __USER_LABEL_PREFIX__
53 # define ASMNAME(name) PASTE2(__USER_LABEL_PREFIX__, name)
55 # define ASMNAME(name) name
58 #define FUNC_BEGIN(fn) \
60 FN_TYPE (ASMNAME(fn)); \
63 #define HIDDEN_FUNC(fn) \
65 FN_TYPE(ASMNAME(fn)); \
66 FN_HIDDEN(ASMNAME(fn)); \
69 #define FUNC_END(fn) FN_SIZE(ASMNAME(fn))
71 #ifdef MS2SYSV_STUB_AVX
72 # define MS2SYSV_STUB_PREFIX __avx_
74 # define MOVAPS vmovaps
76 #elif defined(MS2SYSV_STUB_SSE)
77 # define MS2SYSV_STUB_PREFIX __sse_
78 # define MOVAPS movaps
81 #ifdef MS2SYSV_STUB_PREFIX
83 # define MS2SYSV_STUB_BEGIN(base_name) \
84 HIDDEN_FUNC(PASTE2(MS2SYSV_STUB_PREFIX, base_name))
86 # define MS2SYSV_STUB_END(base_name) \
87 FUNC_END(PASTE2(MS2SYSV_STUB_PREFIX, base_name))
89 /* If expanding for sse or avx and we have assembler support. */
91 /* Save SSE registers 6-15 using rax as the base address. */
93 MOVAPS %xmm15,-0x30(%rax); \
94 MOVAPS %xmm14,-0x20(%rax); \
95 MOVAPS %xmm13,-0x10(%rax); \
96 MOVAPS %xmm12, (%rax); \
97 MOVAPS %xmm11, 0x10(%rax); \
98 MOVAPS %xmm10, 0x20(%rax); \
99 MOVAPS %xmm9, 0x30(%rax); \
100 MOVAPS %xmm8, 0x40(%rax); \
101 MOVAPS %xmm7, 0x50(%rax); \
102 MOVAPS %xmm6, 0x60(%rax)
104 /* Restore SSE registers 6-15 using rsi as the base address. */
105 # define SSE_RESTORE \
106 MOVAPS -0x30(%rsi), %xmm15; \
107 MOVAPS -0x20(%rsi), %xmm14; \
108 MOVAPS -0x10(%rsi), %xmm13; \
109 MOVAPS (%rsi), %xmm12; \
110 MOVAPS 0x10(%rsi), %xmm11; \
111 MOVAPS 0x20(%rsi), %xmm10; \
112 MOVAPS 0x30(%rsi), %xmm9 ; \
113 MOVAPS 0x40(%rsi), %xmm8 ; \
114 MOVAPS 0x50(%rsi), %xmm7 ; \
115 MOVAPS 0x60(%rsi), %xmm6
117 /* If the assembler doesn't support AVX then directly emit machine code
118 for the instructions above. */
120 .byte 0xc5, 0x78, 0x29, 0x78, 0xd0; /* vmovaps %xmm15,-0x30(%rax) */ \
121 .byte 0xc5, 0x78, 0x29, 0x70, 0xe0; /* vmovaps %xmm14,-0x20(%rax) */ \
122 .byte 0xc5, 0x78, 0x29, 0x68, 0xf0; /* vmovaps %xmm13,-0x10(%rax) */ \
123 .byte 0xc5, 0x78, 0x29, 0x20; /* vmovaps %xmm12, (%rax) */ \
124 .byte 0xc5, 0x78, 0x29, 0x58, 0x10; /* vmovaps %xmm11, 0x10(%rax) */ \
125 .byte 0xc5, 0x78, 0x29, 0x50, 0x20; /* vmovaps %xmm10, 0x20(%rax) */ \
126 .byte 0xc5, 0x78, 0x29, 0x48, 0x30; /* vmovaps %xmm9, 0x30(%rax) */ \
127 .byte 0xc5, 0x78, 0x29, 0x40, 0x40; /* vmovaps %xmm8, 0x40(%rax) */ \
128 .byte 0xc5, 0xf8, 0x29, 0x78, 0x50; /* vmovaps %xmm7, 0x50(%rax) */ \
129 .byte 0xc5, 0xf8, 0x29, 0x70, 0x60; /* vmovaps %xmm6, 0x60(%rax) */
130 # define SSE_RESTORE \
131 .byte 0xc5, 0x78, 0x28, 0x7e, 0xd0; /* vmovaps -0x30(%rsi),%xmm15 */ \
132 .byte 0xc5, 0x78, 0x28, 0x76, 0xe0; /* vmovaps -0x20(%rsi),%xmm14 */ \
133 .byte 0xc5, 0x78, 0x28, 0x6e, 0xf0; /* vmovaps -0x10(%rsi),%xmm13 */ \
134 .byte 0xc5, 0x78, 0x28, 0x26; /* vmovaps (%rsi),%xmm12 */ \
135 .byte 0xc5, 0x78, 0x28, 0x5e, 0x10; /* vmovaps 0x10(%rsi),%xmm11 */ \
136 .byte 0xc5, 0x78, 0x28, 0x56, 0x20; /* vmovaps 0x20(%rsi),%xmm10 */ \
137 .byte 0xc5, 0x78, 0x28, 0x4e, 0x30; /* vmovaps 0x30(%rsi),%xmm9 */ \
138 .byte 0xc5, 0x78, 0x28, 0x46, 0x40; /* vmovaps 0x40(%rsi),%xmm8 */ \
139 .byte 0xc5, 0xf8, 0x28, 0x7e, 0x50; /* vmovaps 0x50(%rsi),%xmm7 */ \
140 .byte 0xc5, 0xf8, 0x28, 0x76, 0x60; /* vmovaps 0x60(%rsi),%xmm6 */
142 #endif /* MS2SYSV_STUB_PREFIX */
143 #endif /* I386_ASM_H */