1 /* Copyright (C) 2009-2015 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)
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 _X86INTRIN_H_INCLUDED
25 # error "Never use <ia32intrin.h> directly; include <x86intrin.h> instead."
30 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
33 return __builtin_ctz (__X
);
38 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
41 return __builtin_ia32_bsrsi (__X
);
46 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
49 return __builtin_bswap32 (__X
);
53 #pragma GCC push_options
54 #pragma GCC target("sse4.2")
55 #define __DISABLE_SSE4_2__
56 #endif /* __SSE4_2__ */
58 /* 32bit accumulate CRC32 (polynomial 0x11EDC6F41) value. */
59 extern __inline
unsigned int
60 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
61 __crc32b (unsigned int __C
, unsigned char __V
)
63 return __builtin_ia32_crc32qi (__C
, __V
);
66 extern __inline
unsigned int
67 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
68 __crc32w (unsigned int __C
, unsigned short __V
)
70 return __builtin_ia32_crc32hi (__C
, __V
);
73 extern __inline
unsigned int
74 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
75 __crc32d (unsigned int __C
, unsigned int __V
)
77 return __builtin_ia32_crc32si (__C
, __V
);
80 #ifdef __DISABLE_SSE4_2__
81 #undef __DISABLE_SSE4_2__
82 #pragma GCC pop_options
83 #endif /* __DISABLE_SSE4_2__ */
87 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
88 __popcntd (unsigned int __X
)
90 return __builtin_popcount (__X
);
94 extern __inline
unsigned long long
95 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
98 return __builtin_ia32_rdpmc (__S
);
102 extern __inline
unsigned long long
103 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
106 return __builtin_ia32_rdtsc ();
110 extern __inline
unsigned long long
111 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
112 __rdtscp (unsigned int *__A
)
114 return __builtin_ia32_rdtscp (__A
);
118 extern __inline
unsigned char
119 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
120 __rolb (unsigned char __X
, int __C
)
122 return __builtin_ia32_rolqi (__X
, __C
);
126 extern __inline
unsigned short
127 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
128 __rolw (unsigned short __X
, int __C
)
130 return __builtin_ia32_rolhi (__X
, __C
);
134 extern __inline
unsigned int
135 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
136 __rold (unsigned int __X
, int __C
)
138 return (__X
<< __C
) | (__X
>> (32 - __C
));
142 extern __inline
unsigned char
143 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
144 __rorb (unsigned char __X
, int __C
)
146 return __builtin_ia32_rorqi (__X
, __C
);
150 extern __inline
unsigned short
151 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
152 __rorw (unsigned short __X
, int __C
)
154 return __builtin_ia32_rorhi (__X
, __C
);
158 extern __inline
unsigned int
159 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
160 __rord (unsigned int __X
, int __C
)
162 return (__X
>> __C
) | (__X
<< (32 - __C
));
167 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
170 __builtin_ia32_pause ();
176 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
177 __bsfq (long long __X
)
179 return __builtin_ctzll (__X
);
184 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
185 __bsrq (long long __X
)
187 return __builtin_ia32_bsrdi (__X
);
191 extern __inline
long long
192 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
193 __bswapq (long long __X
)
195 return __builtin_bswap64 (__X
);
199 #pragma GCC push_options
200 #pragma GCC target("sse4.2")
201 #define __DISABLE_SSE4_2__
202 #endif /* __SSE4_2__ */
204 /* 64bit accumulate CRC32 (polynomial 0x11EDC6F41) value. */
205 extern __inline
unsigned long long
206 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
207 __crc32q (unsigned long long __C
, unsigned long long __V
)
209 return __builtin_ia32_crc32di (__C
, __V
);
212 #ifdef __DISABLE_SSE4_2__
213 #undef __DISABLE_SSE4_2__
214 #pragma GCC pop_options
215 #endif /* __DISABLE_SSE4_2__ */
218 extern __inline
long long
219 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
220 __popcntq (unsigned long long __X
)
222 return __builtin_popcountll (__X
);
226 extern __inline
unsigned long long
227 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
228 __rolq (unsigned long long __X
, int __C
)
230 return (__X
<< __C
) | (__X
>> (64 - __C
));
234 extern __inline
unsigned long long
235 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
236 __rorq (unsigned long long __X
, int __C
)
238 return (__X
>> __C
) | (__X
<< (64 - __C
));
241 /* Read flags register */
242 extern __inline
unsigned long long
243 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
246 return __builtin_ia32_readeflags_u64 ();
249 /* Write flags register */
251 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
252 __writeeflags (unsigned long long X
)
254 __builtin_ia32_writeeflags_u64 (X
);
257 #define _bswap64(a) __bswapq(a)
258 #define _popcnt64(a) __popcntq(a)
261 /* Read flags register */
262 extern __inline
unsigned int
263 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
266 return __builtin_ia32_readeflags_u32 ();
269 /* Write flags register */
271 __attribute__((__gnu_inline__
, __always_inline__
, __artificial__
))
272 __writeeflags (unsigned int X
)
274 __builtin_ia32_writeeflags_u32 (X
);
279 /* On LP64 systems, longs are 64-bit. Use the appropriate rotate
282 #define _lrotl(a,b) __rolq((a), (b))
283 #define _lrotr(a,b) __rorq((a), (b))
285 #define _lrotl(a,b) __rold((a), (b))
286 #define _lrotr(a,b) __rord((a), (b))
289 #define _bit_scan_forward(a) __bsfd(a)
290 #define _bit_scan_reverse(a) __bsrd(a)
291 #define _bswap(a) __bswapd(a)
292 #define _popcnt32(a) __popcntd(a)
293 #define _rdpmc(a) __rdpmc(a)
294 #define _rdtsc() __rdtsc()
295 #define _rdtscp(a) __rdtscp(a)
296 #define _rotwl(a,b) __rolw((a), (b))
297 #define _rotwr(a,b) __rorw((a), (b))
298 #define _rotl(a,b) __rold((a), (b))
299 #define _rotr(a,b) __rord((a), (b))