tree-optimization/115388 - wrong DSE in irreductible regions
[official-gcc.git] / gcc / config / i386 / ia32intrin.h
blob47d561ef3f354a8952fc1cd65158df865008ed79
1 /* Copyright (C) 2009-2024 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 _X86GPRINTRIN_H_INCLUDED
25 # error "Never use <ia32intrin.h> directly; include <x86gprintrin.h> instead."
26 #endif
28 /* 32bit bsf */
29 extern __inline int
30 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
31 __bsfd (int __X)
33 return __builtin_ctz (__X);
36 /* 32bit bsr */
37 extern __inline int
38 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
39 __bsrd (int __X)
41 return __builtin_ia32_bsrsi (__X);
44 /* 32bit bswap */
45 extern __inline int
46 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
47 __bswapd (int __X)
49 return __builtin_bswap32 (__X);
52 #ifndef __iamcu__
54 #ifndef __CRC32__
55 #pragma GCC push_options
56 #pragma GCC target("crc32")
57 #define __DISABLE_CRC32__
58 #endif /* __CRC32__ */
60 /* 32bit accumulate CRC32 (polynomial 0x11EDC6F41) value. */
61 extern __inline unsigned int
62 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
63 __crc32b (unsigned int __C, unsigned char __V)
65 return __builtin_ia32_crc32qi (__C, __V);
68 extern __inline unsigned int
69 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
70 __crc32w (unsigned int __C, unsigned short __V)
72 return __builtin_ia32_crc32hi (__C, __V);
75 extern __inline unsigned int
76 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
77 __crc32d (unsigned int __C, unsigned int __V)
79 return __builtin_ia32_crc32si (__C, __V);
82 #ifdef __DISABLE_CRC32__
83 #undef __DISABLE_CRC32__
84 #pragma GCC pop_options
85 #endif /* __DISABLE_CRC32__ */
87 #endif /* __iamcu__ */
89 /* 32bit popcnt */
90 extern __inline int
91 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
92 __popcntd (unsigned int __X)
94 return __builtin_popcount (__X);
97 #ifndef __iamcu__
99 /* rdpmc */
100 extern __inline unsigned long long
101 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
102 __rdpmc (int __S)
104 return __builtin_ia32_rdpmc (__S);
107 #endif /* __iamcu__ */
109 /* rdtsc */
110 extern __inline unsigned long long
111 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
112 __rdtsc (void)
114 return __builtin_ia32_rdtsc ();
117 #ifndef __iamcu__
119 /* rdtscp */
120 extern __inline unsigned long long
121 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
122 __rdtscp (unsigned int *__A)
124 return __builtin_ia32_rdtscp (__A);
127 #endif /* __iamcu__ */
129 /* 8bit rol */
130 extern __inline unsigned char
131 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
132 __rolb (unsigned char __X, int __C)
134 return __builtin_ia32_rolqi (__X, __C);
137 /* 16bit rol */
138 extern __inline unsigned short
139 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
140 __rolw (unsigned short __X, int __C)
142 return __builtin_ia32_rolhi (__X, __C);
145 /* 32bit rol */
146 extern __inline unsigned int
147 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
148 __rold (unsigned int __X, int __C)
150 __C &= 31;
151 return (__X << __C) | (__X >> (-__C & 31));
154 /* 8bit ror */
155 extern __inline unsigned char
156 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
157 __rorb (unsigned char __X, int __C)
159 return __builtin_ia32_rorqi (__X, __C);
162 /* 16bit ror */
163 extern __inline unsigned short
164 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
165 __rorw (unsigned short __X, int __C)
167 return __builtin_ia32_rorhi (__X, __C);
170 /* 32bit ror */
171 extern __inline unsigned int
172 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
173 __rord (unsigned int __X, int __C)
175 __C &= 31;
176 return (__X >> __C) | (__X << (-__C & 31));
179 /* Pause */
180 extern __inline void
181 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
182 __pause (void)
184 __builtin_ia32_pause ();
187 #ifdef __x86_64__
188 /* 64bit bsf */
189 extern __inline int
190 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
191 __bsfq (long long __X)
193 return __builtin_ctzll (__X);
196 /* 64bit bsr */
197 extern __inline int
198 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
199 __bsrq (long long __X)
201 return __builtin_ia32_bsrdi (__X);
204 /* 64bit bswap */
205 extern __inline long long
206 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
207 __bswapq (long long __X)
209 return __builtin_bswap64 (__X);
212 #ifndef __CRC32__
213 #pragma GCC push_options
214 #pragma GCC target("crc32")
215 #define __DISABLE_CRC32__
216 #endif /* __CRC32__ */
218 /* 64bit accumulate CRC32 (polynomial 0x11EDC6F41) value. */
219 extern __inline unsigned long long
220 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
221 __crc32q (unsigned long long __C, unsigned long long __V)
223 return __builtin_ia32_crc32di (__C, __V);
226 #ifdef __DISABLE_CRC32__
227 #undef __DISABLE_CRC32__
228 #pragma GCC pop_options
229 #endif /* __DISABLE_CRC32__ */
231 /* 64bit popcnt */
232 extern __inline long long
233 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
234 __popcntq (unsigned long long __X)
236 return __builtin_popcountll (__X);
239 /* 64bit rol */
240 extern __inline unsigned long long
241 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
242 __rolq (unsigned long long __X, int __C)
244 __C &= 63;
245 return (__X << __C) | (__X >> (-__C & 63));
248 /* 64bit ror */
249 extern __inline unsigned long long
250 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
251 __rorq (unsigned long long __X, int __C)
253 __C &= 63;
254 return (__X >> __C) | (__X << (-__C & 63));
257 /* Read flags register */
258 extern __inline unsigned long long
259 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
260 __readeflags (void)
262 return __builtin_ia32_readeflags_u64 ();
265 /* Write flags register */
266 extern __inline void
267 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
268 __writeeflags (unsigned long long __X)
270 __builtin_ia32_writeeflags_u64 (__X);
273 #define _bswap64(a) __bswapq(a)
274 #define _popcnt64(a) __popcntq(a)
275 #else
277 /* Read flags register */
278 extern __inline unsigned int
279 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
280 __readeflags (void)
282 return __builtin_ia32_readeflags_u32 ();
285 /* Write flags register */
286 extern __inline void
287 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
288 __writeeflags (unsigned int __X)
290 __builtin_ia32_writeeflags_u32 (__X);
293 #endif
295 /* On LP64 systems, longs are 64-bit. Use the appropriate rotate
296 * function. */
297 #ifdef __LP64__
298 #define _lrotl(a,b) __rolq((a), (b))
299 #define _lrotr(a,b) __rorq((a), (b))
300 #else
301 #define _lrotl(a,b) __rold((a), (b))
302 #define _lrotr(a,b) __rord((a), (b))
303 #endif
305 #define _bit_scan_forward(a) __bsfd(a)
306 #define _bit_scan_reverse(a) __bsrd(a)
307 #define _bswap(a) __bswapd(a)
308 #define _popcnt32(a) __popcntd(a)
309 #ifndef __iamcu__
310 #define _rdpmc(a) __rdpmc(a)
311 #define _rdtscp(a) __rdtscp(a)
312 #endif /* __iamcu__ */
313 #define _rdtsc() __rdtsc()
314 #define _rotwl(a,b) __rolw((a), (b))
315 #define _rotwr(a,b) __rorw((a), (b))
316 #define _rotl(a,b) __rold((a), (b))
317 #define _rotr(a,b) __rord((a), (b))