clang API Documentation

bmiintrin.h
Go to the documentation of this file.
00001 /*===---- bmiintrin.h - BMI intrinsics -------------------------------------===
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy
00004  * of this software and associated documentation files (the "Software"), to deal
00005  * in the Software without restriction, including without limitation the rights
00006  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00007  * copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in
00011  * all copies or substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00019  * THE SOFTWARE.
00020  *
00021  *===-----------------------------------------------------------------------===
00022  */
00023 
00024 #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
00025 #error "Never use <bmiintrin.h> directly; include <x86intrin.h> instead."
00026 #endif
00027 
00028 #ifndef __BMI__
00029 # error "BMI instruction set not enabled"
00030 #endif /* __BMI__ */
00031 
00032 #ifndef __BMIINTRIN_H
00033 #define __BMIINTRIN_H
00034 
00035 #define _tzcnt_u16(a)     (__tzcnt_u16((a)))
00036 #define _andn_u32(a, b)   (__andn_u32((a), (b)))
00037 /* _bextr_u32 != __bextr_u32 */
00038 #define _blsi_u32(a)      (__blsi_u32((a)))
00039 #define _blsmsk_u32(a)    (__blsmsk_u32((a)))
00040 #define _blsr_u32(a)      (__blsr_u32((a)))
00041 #define _tzcnt_u32(a)     (__tzcnt_u32((a)))
00042 
00043 static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
00044 __tzcnt_u16(unsigned short __X)
00045 {
00046   return __X ? __builtin_ctzs(__X) : 16;
00047 }
00048 
00049 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00050 __andn_u32(unsigned int __X, unsigned int __Y)
00051 {
00052   return ~__X & __Y;
00053 }
00054 
00055 /* AMD-specified, double-leading-underscore version of BEXTR */
00056 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00057 __bextr_u32(unsigned int __X, unsigned int __Y)
00058 {
00059   return __builtin_ia32_bextr_u32(__X, __Y);
00060 }
00061 
00062 /* Intel-specified, single-leading-underscore version of BEXTR */
00063 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00064 _bextr_u32(unsigned int __X, unsigned int __Y, unsigned int __Z)
00065 {
00066   return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
00067 }
00068 
00069 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00070 __blsi_u32(unsigned int __X)
00071 {
00072   return __X & -__X;
00073 }
00074 
00075 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00076 __blsmsk_u32(unsigned int __X)
00077 {
00078   return __X ^ (__X - 1);
00079 }
00080 
00081 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00082 __blsr_u32(unsigned int __X)
00083 {
00084   return __X & (__X - 1);
00085 }
00086 
00087 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00088 __tzcnt_u32(unsigned int __X)
00089 {
00090   return __X ? __builtin_ctz(__X) : 32;
00091 }
00092 
00093 #ifdef __x86_64__
00094 
00095 #define _andn_u64(a, b)   (__andn_u64((a), (b)))
00096 /* _bextr_u64 != __bextr_u64 */
00097 #define _blsi_u64(a)      (__blsi_u64((a)))
00098 #define _blsmsk_u64(a)    (__blsmsk_u64((a)))
00099 #define _blsr_u64(a)      (__blsr_u64((a)))
00100 #define _tzcnt_u64(a)     (__tzcnt_u64((a)))
00101 
00102 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00103 __andn_u64 (unsigned long long __X, unsigned long long __Y)
00104 {
00105   return ~__X & __Y;
00106 }
00107 
00108 /* AMD-specified, double-leading-underscore version of BEXTR */
00109 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00110 __bextr_u64(unsigned long long __X, unsigned long long __Y)
00111 {
00112   return __builtin_ia32_bextr_u64(__X, __Y);
00113 }
00114 
00115 /* Intel-specified, single-leading-underscore version of BEXTR */
00116 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00117 _bextr_u64(unsigned long long __X, unsigned int __Y, unsigned int __Z)
00118 {
00119   return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8)));
00120 }
00121 
00122 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00123 __blsi_u64(unsigned long long __X)
00124 {
00125   return __X & -__X;
00126 }
00127 
00128 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00129 __blsmsk_u64(unsigned long long __X)
00130 {
00131   return __X ^ (__X - 1);
00132 }
00133 
00134 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00135 __blsr_u64(unsigned long long __X)
00136 {
00137   return __X & (__X - 1);
00138 }
00139 
00140 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00141 __tzcnt_u64(unsigned long long __X)
00142 {
00143   return __X ? __builtin_ctzll(__X) : 64;
00144 }
00145 
00146 #endif /* __x86_64__ */
00147 
00148 #endif /* __BMIINTRIN_H */