Yunzhong Gao | f4e0b10 | 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 | |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 24 | #ifndef __X86INTRIN_H |
| 25 | #error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead." |
| 26 | #endif |
| 27 | |
| 28 | #ifndef __TBMINTRIN_H |
| 29 | #define __TBMINTRIN_H |
| 30 | |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 31 | /* Define the default attributes for the functions in this file. */ |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 32 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("tbm"))) |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 33 | |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 34 | #define __bextri_u32(a, b) (__builtin_ia32_bextri_u32((a), (b))) |
| 35 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 36 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 37 | __blcfill_u32(unsigned int a) |
| 38 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 39 | return a & (a + 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 42 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 43 | __blci_u32(unsigned int a) |
| 44 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 45 | return a | ~(a + 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 48 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 49 | __blcic_u32(unsigned int a) |
| 50 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 51 | return ~a & (a + 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 54 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 55 | __blcmsk_u32(unsigned int a) |
| 56 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 57 | return a ^ (a + 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 60 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 61 | __blcs_u32(unsigned int a) |
| 62 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 63 | return a | (a + 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 66 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 67 | __blsfill_u32(unsigned int a) |
| 68 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 69 | return a | (a - 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 72 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 73 | __blsic_u32(unsigned int a) |
| 74 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 75 | return ~a | (a - 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 78 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 79 | __t1mskc_u32(unsigned int a) |
| 80 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 81 | return ~a | (a + 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 84 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 85 | __tzmsk_u32(unsigned int a) |
| 86 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 87 | return ~a & (a - 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | #ifdef __x86_64__ |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 91 | #define __bextri_u64(a, b) (__builtin_ia32_bextri_u64((a), (int)(b))) |
| 92 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 93 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 94 | __blcfill_u64(unsigned long long a) |
| 95 | { |
| 96 | return a & (a + 1); |
| 97 | } |
| 98 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 99 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 100 | __blci_u64(unsigned long long a) |
| 101 | { |
| 102 | return a | ~(a + 1); |
| 103 | } |
| 104 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 105 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 106 | __blcic_u64(unsigned long long a) |
| 107 | { |
| 108 | return ~a & (a + 1); |
| 109 | } |
| 110 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 111 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 112 | __blcmsk_u64(unsigned long long a) |
| 113 | { |
| 114 | return a ^ (a + 1); |
| 115 | } |
| 116 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 117 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 118 | __blcs_u64(unsigned long long a) |
| 119 | { |
| 120 | return a | (a + 1); |
| 121 | } |
| 122 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 123 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 124 | __blsfill_u64(unsigned long long a) |
| 125 | { |
| 126 | return a | (a - 1); |
| 127 | } |
| 128 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 129 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 130 | __blsic_u64(unsigned long long a) |
| 131 | { |
| 132 | return ~a | (a - 1); |
| 133 | } |
| 134 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 135 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 136 | __t1mskc_u64(unsigned long long a) |
| 137 | { |
| 138 | return ~a | (a + 1); |
| 139 | } |
| 140 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 141 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 142 | __tzmsk_u64(unsigned long long a) |
| 143 | { |
Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 144 | return ~a & (a - 1); |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 145 | } |
| 146 | #endif |
| 147 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame^] | 148 | #undef __DEFAULT_FN_ATTRS |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 149 | |
Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 150 | #endif /* __TBMINTRIN_H */ |