merge from trunk
[official-gcc.git] / gcc / config / i386 / ia32intrin.h
blob540bc3f09ee90e9a29fe135bca054a8fa964daa6
1 /* Copyright (C) 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 _X86INTRIN_H_INCLUDED
25 # error "Never use <ia32intrin.h> directly; include <x86intrin.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 #ifdef __SSE4_2__
53 /* 32bit accumulate CRC32 (polynomial 0x11EDC6F41) value. */
54 extern __inline unsigned int
55 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
56 __crc32b (unsigned int __C, unsigned char __V)
58 return __builtin_ia32_crc32qi (__C, __V);
61 extern __inline unsigned int
62 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
63 __crc32w (unsigned int __C, unsigned short __V)
65 return __builtin_ia32_crc32hi (__C, __V);
68 extern __inline unsigned int
69 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
70 __crc32d (unsigned int __C, unsigned int __V)
72 return __builtin_ia32_crc32si (__C, __V);
74 #endif /* SSE4.2 */
76 /* 32bit popcnt */
77 extern __inline int
78 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
79 __popcntd (unsigned int __X)
81 return __builtin_popcount (__X);
84 /* rdpmc */
85 extern __inline unsigned long long
86 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
87 __rdpmc (int __S)
89 return __builtin_ia32_rdpmc (__S);
92 /* rdtsc */
93 extern __inline unsigned long long
94 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
95 __rdtsc (void)
97 return __builtin_ia32_rdtsc ();
100 /* rdtscp */
101 extern __inline unsigned long long
102 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
103 __rdtscp (unsigned int *__A)
105 return __builtin_ia32_rdtscp (__A);
108 /* 8bit rol */
109 extern __inline unsigned char
110 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
111 __rolb (unsigned char __X, int __C)
113 return __builtin_ia32_rolqi (__X, __C);
116 /* 16bit rol */
117 extern __inline unsigned short
118 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
119 __rolw (unsigned short __X, int __C)
121 return __builtin_ia32_rolhi (__X, __C);
124 /* 32bit rol */
125 extern __inline unsigned int
126 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
127 __rold (unsigned int __X, int __C)
129 return (__X << __C) | (__X >> (32 - __C));
132 /* 8bit ror */
133 extern __inline unsigned char
134 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
135 __rorb (unsigned char __X, int __C)
137 return __builtin_ia32_rorqi (__X, __C);
140 /* 16bit ror */
141 extern __inline unsigned short
142 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
143 __rorw (unsigned short __X, int __C)
145 return __builtin_ia32_rorhi (__X, __C);
148 /* 32bit ror */
149 extern __inline unsigned int
150 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
151 __rord (unsigned int __X, int __C)
153 return (__X >> __C) | (__X << (32 - __C));
156 #ifdef __x86_64__
157 /* 64bit bsf */
158 extern __inline int
159 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
160 __bsfq (long long __X)
162 return __builtin_ctzll (__X);
165 /* 64bit bsr */
166 extern __inline int
167 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
168 __bsrq (long long __X)
170 return __builtin_ia32_bsrdi (__X);
173 /* 64bit bswap */
174 extern __inline long long
175 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
176 __bswapq (long long __X)
178 return __builtin_bswap64 (__X);
181 /* 64bit accumulate CRC32 (polynomial 0x11EDC6F41) value. */
182 extern __inline unsigned long long
183 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
184 __crc32q (unsigned long long __C, unsigned long long __V)
186 return __builtin_ia32_crc32di (__C, __V);
189 /* 64bit popcnt */
190 extern __inline long long
191 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
192 __popcntq (unsigned long long __X)
194 return __builtin_popcountll (__X);
197 /* 64bit rol */
198 extern __inline unsigned long long
199 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
200 __rolq (unsigned long long __X, int __C)
202 return (__X << __C) | (__X >> (64 - __C));
205 /* 64bit ror */
206 extern __inline unsigned long long
207 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
208 __rorq (unsigned long long __X, int __C)
210 return (__X >> __C) | (__X << (64 - __C));
213 #define _bswap64(a) __bswapq(a)
214 #define _popcnt64(a) __popcntq(a)
215 #define _lrotl(a,b) __rolq((a), (b))
216 #define _lrotr(a,b) __rorq((a), (b))
217 #else
218 #define _lrotl(a,b) __rold((a), (b))
219 #define _lrotr(a,b) __rord((a), (b))
220 #endif
222 #define _bit_scan_forward(a) __bsfd(a)
223 #define _bit_scan_reverse(a) __bsrd(a)
224 #define _bswap(a) __bswapd(a)
225 #define _popcnt32(a) __popcntd(a)
226 #define _rdpmc(a) __rdpmc(a)
227 #define _rdtsc() __rdtsc()
228 #define _rdtscp(a) __rdtscp(a)
229 #define _rotwl(a,b) __rolw((a), (b))
230 #define _rotwr(a,b) __rorw((a), (b))
231 #define _rotl(a,b) __rold((a), (b))
232 #define _rotr(a,b) __rord((a), (b))