OSDN Git Service

Backported from mainline
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / bmiintrin.h
1 /* Copyright (C) 2010, 2011 Free Software Foundation, Inc.
2
3    This file is part of GCC.
4
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.
9
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.
14
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.
18
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/>.  */
23
24 #if !defined _X86INTRIN_H_INCLUDED && !defined _IMMINTRIN_H_INCLUDED
25 # error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead."
26 #endif
27
28 #ifndef __BMI__
29 # error "BMI instruction set not enabled"
30 #endif /* __BMI__ */
31
32 #ifndef _BMIINTRIN_H_INCLUDED
33 #define _BMIINTRIN_H_INCLUDED
34
35 extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__))
36 __tzcnt_u16 (unsigned short __X)
37 {
38   return __builtin_ctzs (__X);
39 }
40
41
42 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
43 __andn_u32 (unsigned int __X, unsigned int __Y)
44 {
45   return ~__X & __Y;
46 }
47
48 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
49 __bextr_u32 (unsigned int __X, unsigned int __Y)
50 {
51   return __builtin_ia32_bextr_u32 (__X, __Y);
52 }
53
54 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
55 __blsi_u32 (unsigned int __X)
56 {
57   return __X & -__X;
58 }
59
60 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
61 __blsmsk_u32 (unsigned int __X)
62 {
63   return __X ^ (__X - 1);
64 }
65
66 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
67 __blsr_u32 (unsigned int __X)
68 {
69   return __X & (__X - 1);
70 }
71
72
73 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
74 __tzcnt_u32 (unsigned int __X)
75 {
76   return __builtin_ctz (__X);
77 }
78
79
80 #ifdef  __x86_64__
81 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
82 __andn_u64 (unsigned long long __X, unsigned long long __Y)
83 {
84   return ~__X & __Y;
85 }
86
87 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
88 __bextr_u64 (unsigned long long __X, unsigned long long __Y)
89 {
90   return __builtin_ia32_bextr_u64 (__X, __Y);
91 }
92
93 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
94 __blsi_u64 (unsigned long long __X)
95 {
96   return __X & -__X;
97 }
98
99 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
100 __blsmsk_u64 (unsigned long long __X)
101 {
102   return __X ^ (__X - 1);
103 }
104
105 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
106 __blsr_u64 (unsigned long long __X)
107 {
108   return __X & (__X - 1);
109 }
110
111 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
112 __tzcnt_u64 (unsigned long long __X)
113 {
114   return __builtin_ctzll (__X);
115 }
116
117 #endif /* __x86_64__  */
118
119 #endif /* _BMIINTRIN_H_INCLUDED */