Bring in all split-stack work done over on gccgo branch.
[official-gcc.git] / gcc / config / i386 / immintrin.h
blob3e69060700abbd2db7f9bdcf6e17aaa86b9281e0
1 /* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
8 any later version.
10 GCC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
24 #ifndef _IMMINTRIN_H_INCLUDED
25 #define _IMMINTRIN_H_INCLUDED
27 #ifdef __MMX__
28 #include <mmintrin.h>
29 #endif
31 #ifdef __SSE__
32 #include <xmmintrin.h>
33 #endif
35 #ifdef __SSE2__
36 #include <emmintrin.h>
37 #endif
39 #ifdef __SSE3__
40 #include <pmmintrin.h>
41 #endif
43 #ifdef __SSSE3__
44 #include <tmmintrin.h>
45 #endif
47 #if defined (__SSE4_2__) || defined (__SSE4_1__)
48 #include <smmintrin.h>
49 #endif
51 #if defined (__AES__) || defined (__PCLMUL__)
52 #include <wmmintrin.h>
53 #endif
55 #ifdef __AVX__
56 #include <avxintrin.h>
57 #endif
59 #ifdef __RDRND__
60 extern __inline unsigned short
61 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
62 _rdrand_u16 (void)
64 return __builtin_ia32_rdrand16 ();
67 extern __inline unsigned int
68 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
69 _rdrand_u32 (void)
71 return __builtin_ia32_rdrand32 ();
73 #endif /* __RDRND__ */
75 #ifdef __x86_64__
76 #ifdef __FSGSBASE__
77 extern __inline unsigned int
78 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
79 _readfsbase_u32 (void)
81 return __builtin_ia32_rdfsbase32 ();
84 extern __inline unsigned long long
85 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
86 _readfsbase_u64 (void)
88 return __builtin_ia32_rdfsbase64 ();
91 extern __inline unsigned int
92 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
93 _readgsbase_u32 (void)
95 return __builtin_ia32_rdgsbase32 ();
98 extern __inline unsigned long long
99 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
100 _readgsbase_u64 (void)
102 return __builtin_ia32_rdgsbase64 ();
105 extern __inline void
106 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
107 _writefsbase_u32 (unsigned int __B)
109 __builtin_ia32_wrfsbase32 (__B);
112 extern __inline void
113 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
114 _writefsbase_u64 (unsigned long long __B)
116 __builtin_ia32_wrfsbase64 (__B);
119 extern __inline void
120 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
121 _writegsbase_u32 (unsigned int __B)
123 __builtin_ia32_wrgsbase32 (__B);
126 extern __inline void
127 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
128 _writegsbase_u64 (unsigned long long __B)
130 __builtin_ia32_wrgsbase64 (__B);
132 #endif /* __FSGSBASE__ */
134 #ifdef __RDRND__
135 extern __inline unsigned long long
136 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
137 _rdrand_u64 (void)
139 return __builtin_ia32_rdrand64 ();
141 #endif /* __RDRND__ */
142 #endif /* __x86_64__ */
144 #ifdef __F16C__
145 extern __inline float __attribute__((__gnu_inline__, __always_inline__, __artificial__))
146 _cvtsh_ss (unsigned short __S)
148 __v8hi __H = __extension__ (__v8hi){ __S, 0, 0, 0, 0, 0, 0, 0 };
149 __v4sf __A = __builtin_ia32_vcvtph2ps (__H);
150 return __builtin_ia32_vec_ext_v4sf (__A, 0);
153 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
154 _mm_cvtph_ps (__m128i __A)
156 return (__m128) __builtin_ia32_vcvtph2ps ((__v8hi) __A);
159 extern __inline __m256 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
160 _mm256_cvtph_ps (__m128i __A)
162 return (__m256) __builtin_ia32_vcvtph2ps256 ((__v8hi) __A);
165 #ifdef __OPTIMIZE__
166 extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__))
167 _cvtss_sh (float __F, const int __I)
169 __v4sf __A = __extension__ (__v4sf){ __F, 0, 0, 0 };
170 __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I);
171 return (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0);
174 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
175 _mm_cvtps_ph (__m128 __A, const int __I)
177 return (__m128i) __builtin_ia32_vcvtps2ph ((__v4sf) __A, __I);
180 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
181 _mm256_cvtps_ph (__m256 __A, const int __I)
183 return (__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf) __A, __I);
185 #else
186 #define _cvtss_sh(__F, __I) \
187 (__extension__ \
188 ({ \
189 __v4sf __A = __extension__ (__v4sf){ __F, 0, 0, 0 }; \
190 __v8hi __H = __builtin_ia32_vcvtps2ph (__A, __I); \
191 (unsigned short) __builtin_ia32_vec_ext_v8hi (__H, 0); \
194 #define _mm_cvtps_ph(A, I) \
195 ((__m128i) __builtin_ia32_vcvtps2ph ((__v4sf)(__m128) A, (int) (I)))
197 #define _mm256_cvtps_ph(A, I) \
198 ((__m128i) __builtin_ia32_vcvtps2ph256 ((__v8sf)(__m256) A, (int) (I)))
199 #endif
201 #endif /* __F16C__ */
203 #endif /* _IMMINTRIN_H_INCLUDED */