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 static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
00036 __tzcnt16(unsigned short __X)
00037 {
00038   return __builtin_ctzs(__X);
00039 }
00040 
00041 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00042 __andn_u32(unsigned int __X, unsigned int __Y)
00043 {
00044   return ~__X & __Y;
00045 }
00046 
00047 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00048 __bextr_u32(unsigned int __X, unsigned int __Y)
00049 {
00050   return __builtin_ia32_bextr_u32(__X, __Y);
00051 }
00052 
00053 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00054 __blsi_u32(unsigned int __X)
00055 {
00056   return __X & -__X;
00057 }
00058 
00059 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00060 __blsmsk_u32(unsigned int __X)
00061 {
00062   return __X ^ (__X - 1);
00063 }
00064 
00065 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00066 __blsr_u32(unsigned int __X)
00067 {
00068   return __X & (__X - 1);
00069 }
00070 
00071 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
00072 __tzcnt32(unsigned int __X)
00073 {
00074   return __builtin_ctz(__X);
00075 }
00076 
00077 #ifdef __x86_64__
00078 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00079 __andn_u64 (unsigned long long __X, unsigned long long __Y)
00080 {
00081   return ~__X & __Y;
00082 }
00083 
00084 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00085 __bextr_u64(unsigned long long __X, unsigned long long __Y)
00086 {
00087   return __builtin_ia32_bextr_u64(__X, __Y);
00088 }
00089 
00090 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00091 __blsi_u64(unsigned long long __X)
00092 {
00093   return __X & -__X;
00094 }
00095 
00096 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00097 __blsmsk_u64(unsigned long long __X)
00098 {
00099   return __X ^ (__X - 1);
00100 }
00101 
00102 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00103 __blsr_u64(unsigned long long __X)
00104 {
00105   return __X & (__X - 1);
00106 }
00107 
00108 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
00109 __tzcnt64(unsigned long long __X)
00110 {
00111   return __builtin_ctzll(__X);
00112 }
00113 #endif
00114 
00115 #endif /* __BMIINTRIN_H */