OSDN Git Service

Add support for BMI.
[pf3gnuchains/gcc-fork.git] / gcc / config / i386 / bmiintrin.h
1 /* Copyright (C) 2010 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 #ifndef _X86INTRIN_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 __lzcnt_u16 (unsigned short __X)
37 {
38   return __builtin_ia32_lzcnt_u16 (__X);
39 }
40
41 extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__))
42 __tzcnt_u16 (unsigned short __X)
43 {
44   return __builtin_ctzs(__X);
45 }
46
47
48 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
49 __andn_u32 (unsigned int __X, unsigned int __Y)
50 {
51   unsigned int tmp = ~(__X) & (__Y);
52   return tmp;
53 }
54
55 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
56 __bextr_u32 (unsigned int __X, unsigned int __Y)
57 {
58   return __builtin_ia32_bextr_u32 (__X, __Y);
59 }
60
61 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
62 __blsi_u32 (unsigned int __X)
63 {
64   unsigned int tmp = (__X) & (-(__X));
65   return tmp;
66 }
67
68 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
69 __blsmsk_u32 (unsigned int __X)
70 {
71   unsigned int tmp = (__X) ^ (__X - 1);
72   return tmp;
73 }
74
75 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
76 __blsr_u32 (unsigned int __X)
77 {
78   unsigned int tmp = (__X) & (__X - 1);
79   return tmp;
80 }
81
82 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
83 __lzcnt_u32 (unsigned int __X)
84 {
85   return __builtin_ia32_lzcnt_u32 (__X);
86 }
87
88
89 extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
90 __tzcnt_u32 (unsigned int __X)
91 {
92   return __builtin_ctz(__X);
93 }
94
95
96 #ifdef  __x86_64__
97 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
98 __andn_u64 (unsigned long long __X, unsigned long long __Y)
99 {
100   unsigned long long tmp = ~(__X) & (__Y);
101   return tmp;
102 }
103
104 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
105 __bextr_u64 (unsigned long long __X, unsigned long long __Y)
106 {
107   return __builtin_ia32_bextr_u64 (__X, __Y);
108 }
109
110 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
111 __blsi_u64 (unsigned long long __X)
112 {
113   unsigned long long tmp = (__X) & (-(__X));
114   return tmp;
115 }
116
117 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
118 __blsmsk_u64 (unsigned long long __X)
119 {
120   unsigned long long tmp = (__X) ^ (__X - 1);
121   return tmp;
122 }
123
124 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
125 __blsr_u64 (unsigned long long __X)
126 {
127   unsigned long long tmp = (__X) & (__X - 1);
128   return tmp;
129 }
130
131 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
132 __lzcnt_u64 (unsigned long long __X)
133 {
134   return __builtin_ia32_lzcnt_u64 (__X);
135 }
136
137 extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
138 __tzcnt_u64 (unsigned long long __X)
139 {
140   return __builtin_ctzll(__X);
141 }
142
143 #endif /* __x86_64__  */
144
145 #endif /* _BMIINTRIN_H_INCLUDED */