Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 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 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 37 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 38 | __blcfill_u32(unsigned int a) |
| 39 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 40 | return a & (a + 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 43 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 44 | __blci_u32(unsigned int a) |
| 45 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 46 | return a | ~(a + 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 49 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 50 | __blcic_u32(unsigned int a) |
| 51 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 52 | return ~a & (a + 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 55 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 56 | __blcmsk_u32(unsigned int a) |
| 57 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 58 | return a ^ (a + 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 61 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 62 | __blcs_u32(unsigned int a) |
| 63 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 64 | return a | (a + 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 67 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 68 | __blsfill_u32(unsigned int a) |
| 69 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 70 | return a | (a - 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 71 | } |
| 72 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 73 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 74 | __blsic_u32(unsigned int a) |
| 75 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 76 | return ~a | (a - 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 79 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 80 | __t1mskc_u32(unsigned int a) |
| 81 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 82 | return ~a | (a + 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 85 | static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__)) |
| 86 | __tzmsk_u32(unsigned int a) |
| 87 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 88 | return ~a & (a - 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | #ifdef __x86_64__ |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 92 | #define __bextri_u64(a, b) (__builtin_ia32_bextri_u64((a), (int)(b))) |
| 93 | |
| 94 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 95 | __nodebug__)) |
| 96 | __blcfill_u64(unsigned long long a) |
| 97 | { |
| 98 | return a & (a + 1); |
| 99 | } |
| 100 | |
| 101 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 102 | __nodebug__)) |
| 103 | __blci_u64(unsigned long long a) |
| 104 | { |
| 105 | return a | ~(a + 1); |
| 106 | } |
| 107 | |
| 108 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 109 | __nodebug__)) |
| 110 | __blcic_u64(unsigned long long a) |
| 111 | { |
| 112 | return ~a & (a + 1); |
| 113 | } |
| 114 | |
| 115 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 116 | __nodebug__)) |
| 117 | __blcmsk_u64(unsigned long long a) |
| 118 | { |
| 119 | return a ^ (a + 1); |
| 120 | } |
| 121 | |
| 122 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 123 | __nodebug__)) |
| 124 | __blcs_u64(unsigned long long a) |
| 125 | { |
| 126 | return a | (a + 1); |
| 127 | } |
| 128 | |
| 129 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 130 | __nodebug__)) |
| 131 | __blsfill_u64(unsigned long long a) |
| 132 | { |
| 133 | return a | (a - 1); |
| 134 | } |
| 135 | |
| 136 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 137 | __nodebug__)) |
| 138 | __blsic_u64(unsigned long long a) |
| 139 | { |
| 140 | return ~a | (a - 1); |
| 141 | } |
| 142 | |
| 143 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 144 | __nodebug__)) |
| 145 | __t1mskc_u64(unsigned long long a) |
| 146 | { |
| 147 | return ~a | (a + 1); |
| 148 | } |
| 149 | |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 150 | static __inline__ unsigned long long __attribute__((__always_inline__, |
| 151 | __nodebug__)) |
| 152 | __tzmsk_u64(unsigned long long a) |
| 153 | { |
Craig Topper | d5276cc | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 154 | return ~a & (a - 1); |
Yunzhong Gao | 8c8bbad | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 155 | } |
| 156 | #endif |
| 157 | |
| 158 | #endif /* __TBMINTRIN_H */ |