| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 1 | /*===---- tbmintrin.h - TBM intrinsics -------------------------------------=== |
| 2 | * | ||||
| Chandler Carruth | 4cf5743 | 2019-04-08 20:51:30 +0000 | [diff] [blame] | 3 | * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | * See https://llvm.org/LICENSE.txt for license information. | ||||
| 5 | * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 6 | * |
| 7 | *===-----------------------------------------------------------------------=== | ||||
| 8 | */ | ||||
| 9 | |||||
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 10 | #ifndef __X86INTRIN_H |
| 11 | #error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead." | ||||
| 12 | #endif | ||||
| 13 | |||||
| 14 | #ifndef __TBMINTRIN_H | ||||
| 15 | #define __TBMINTRIN_H | ||||
| 16 | |||||
| Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 17 | /* Define the default attributes for the functions in this file. */ |
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 18 | #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("tbm"))) |
| Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 19 | |
| Craig Topper | d619eaaa | 2015-11-11 03:47:10 +0000 | [diff] [blame] | 20 | #define __bextri_u32(a, b) \ |
| 21 | ((unsigned int)__builtin_ia32_bextri_u32((unsigned int)(a), \ | ||||
| 22 | (unsigned int)(b))) | ||||
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 23 | |
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 24 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 25 | __blcfill_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 26 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 27 | return __a & (__a + 1); |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 28 | } |
| 29 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 30 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 31 | __blci_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 32 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 33 | return __a | ~(__a + 1); |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 34 | } |
| 35 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 36 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 37 | __blcic_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 38 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +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 |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 43 | __blcmsk_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 44 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +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 |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 49 | __blcs_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 50 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +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 |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 55 | __blsfill_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 56 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +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 |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 61 | __blsic_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 62 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +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 |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 67 | __t1mskc_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 68 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +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 |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 73 | __tzmsk_u32(unsigned int __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 74 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 75 | return ~__a & (__a - 1); |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 76 | } |
| 77 | |||||
| 78 | #ifdef __x86_64__ | ||||
| Craig Topper | d619eaaa | 2015-11-11 03:47:10 +0000 | [diff] [blame] | 79 | #define __bextri_u64(a, b) \ |
| 80 | ((unsigned long long)__builtin_ia32_bextri_u64((unsigned long long)(a), \ | ||||
| 81 | (unsigned long long)(b))) | ||||
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 82 | |
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 83 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 84 | __blcfill_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 85 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 86 | return __a & (__a + 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 87 | } |
| 88 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 89 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 90 | __blci_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 91 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 92 | return __a | ~(__a + 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 93 | } |
| 94 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 95 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 96 | __blcic_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 97 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 98 | return ~__a & (__a + 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 99 | } |
| 100 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 101 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 102 | __blcmsk_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 103 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 104 | return __a ^ (__a + 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 105 | } |
| 106 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 107 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 108 | __blcs_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 109 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 110 | return __a | (__a + 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 111 | } |
| 112 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 113 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 114 | __blsfill_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 115 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 116 | return __a | (__a - 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 117 | } |
| 118 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 119 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 120 | __blsic_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 121 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 122 | return ~__a | (__a - 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 123 | } |
| 124 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 125 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 126 | __t1mskc_u64(unsigned long long __a) |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 127 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 128 | return ~__a | (__a + 1); |
| Craig Topper | d335c9d | 2013-10-05 17:08:42 +0000 | [diff] [blame] | 129 | } |
| 130 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 131 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 132 | __tzmsk_u64(unsigned long long __a) |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 133 | { |
| Eric Christopher | 39a84d0 | 2016-02-12 02:22:53 +0000 | [diff] [blame] | 134 | return ~__a & (__a - 1); |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 135 | } |
| 136 | #endif | ||||
| 137 | |||||
| Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 138 | #undef __DEFAULT_FN_ATTRS |
| Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 139 | |
| Yunzhong Gao | f4e0b10 | 2013-09-30 17:25:14 +0000 | [diff] [blame] | 140 | #endif /* __TBMINTRIN_H */ |