1/*===---- tbmintrin.h - TBM intrinsics -------------------------------------=== 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * of this software and associated documentation files (the "Software"), to deal 5 * in the Software without restriction, including without limitation the rights 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 * copies of the Software, and to permit persons to whom the Software is 8 * furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 * THE SOFTWARE. 20 * 21 *===-----------------------------------------------------------------------=== 22 */ 23 24#ifndef __TBM__ 25#error "TBM instruction set is not enabled" 26#endif 27 28#ifndef __X86INTRIN_H 29#error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead." 30#endif 31 32#ifndef __TBMINTRIN_H 33#define __TBMINTRIN_H 34 35#define __bextri_u32(a, b) (__builtin_ia32_bextri_u32((a), (b))) 36 37static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 38__blcfill_u32(unsigned int a) 39{ 40 return a & (a + 1); 41} 42 43static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 44__blci_u32(unsigned int a) 45{ 46 return a | ~(a + 1); 47} 48 49static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 50__blcic_u32(unsigned int a) 51{ 52 return ~a & (a + 1); 53} 54 55static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 56__blcmsk_u32(unsigned int a) 57{ 58 return a ^ (a + 1); 59} 60 61static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 62__blcs_u32(unsigned int a) 63{ 64 return a | (a + 1); 65} 66 67static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 68__blsfill_u32(unsigned int a) 69{ 70 return a | (a - 1); 71} 72 73static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 74__blsic_u32(unsigned int a) 75{ 76 return ~a | (a - 1); 77} 78 79static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 80__t1mskc_u32(unsigned int a) 81{ 82 return ~a | (a + 1); 83} 84 85static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) 86__tzmsk_u32(unsigned int a) 87{ 88 return ~a & (a - 1); 89} 90 91#ifdef __x86_64__ 92#define __bextri_u64(a, b) (__builtin_ia32_bextri_u64((a), (int)(b))) 93 94static __inline__ unsigned long long __attribute__((__always_inline__, 95 __nodebug__)) 96__blcfill_u64(unsigned long long a) 97{ 98 return a & (a + 1); 99} 100 101static __inline__ unsigned long long __attribute__((__always_inline__, 102 __nodebug__)) 103__blci_u64(unsigned long long a) 104{ 105 return a | ~(a + 1); 106} 107 108static __inline__ unsigned long long __attribute__((__always_inline__, 109 __nodebug__)) 110__blcic_u64(unsigned long long a) 111{ 112 return ~a & (a + 1); 113} 114 115static __inline__ unsigned long long __attribute__((__always_inline__, 116 __nodebug__)) 117__blcmsk_u64(unsigned long long a) 118{ 119 return a ^ (a + 1); 120} 121 122static __inline__ unsigned long long __attribute__((__always_inline__, 123 __nodebug__)) 124__blcs_u64(unsigned long long a) 125{ 126 return a | (a + 1); 127} 128 129static __inline__ unsigned long long __attribute__((__always_inline__, 130 __nodebug__)) 131__blsfill_u64(unsigned long long a) 132{ 133 return a | (a - 1); 134} 135 136static __inline__ unsigned long long __attribute__((__always_inline__, 137 __nodebug__)) 138__blsic_u64(unsigned long long a) 139{ 140 return ~a | (a - 1); 141} 142 143static __inline__ unsigned long long __attribute__((__always_inline__, 144 __nodebug__)) 145__t1mskc_u64(unsigned long long a) 146{ 147 return ~a | (a + 1); 148} 149 150static __inline__ unsigned long long __attribute__((__always_inline__, 151 __nodebug__)) 152__tzmsk_u64(unsigned long long a) 153{ 154 return ~a & (a - 1); 155} 156#endif 157 158#endif /* __TBMINTRIN_H */ 159