blob: f4e848a1c0019c1ed5ce827d86fbe1054b203e60 [file] [log] [blame]
Yunzhong Gaof4e0b102013-09-30 17:25:14 +00001/*===---- tbmintrin.h - TBM intrinsics -------------------------------------===
2 *
Chandler Carruth4cf57432019-04-08 20:51:30 +00003 * 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 Gaof4e0b102013-09-30 17:25:14 +00006 *
7 *===-----------------------------------------------------------------------===
8 */
9
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000010#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 Christopher4d1851682015-06-17 07:09:20 +000017/* Define the default attributes for the functions in this file. */
Michael Kupersteine45af542015-06-30 13:36:19 +000018#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("tbm")))
Eric Christopher4d1851682015-06-17 07:09:20 +000019
Craig Topperd619eaaa2015-11-11 03:47:10 +000020#define __bextri_u32(a, b) \
21 ((unsigned int)__builtin_ia32_bextri_u32((unsigned int)(a), \
22 (unsigned int)(b)))
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000023
Michael Kupersteine45af542015-06-30 13:36:19 +000024static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000025__blcfill_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000026{
Eric Christopher39a84d02016-02-12 02:22:53 +000027 return __a & (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000028}
29
Michael Kupersteine45af542015-06-30 13:36:19 +000030static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000031__blci_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000032{
Eric Christopher39a84d02016-02-12 02:22:53 +000033 return __a | ~(__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000034}
35
Michael Kupersteine45af542015-06-30 13:36:19 +000036static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000037__blcic_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000038{
Eric Christopher39a84d02016-02-12 02:22:53 +000039 return ~__a & (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000040}
41
Michael Kupersteine45af542015-06-30 13:36:19 +000042static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000043__blcmsk_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000044{
Eric Christopher39a84d02016-02-12 02:22:53 +000045 return __a ^ (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000046}
47
Michael Kupersteine45af542015-06-30 13:36:19 +000048static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000049__blcs_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000050{
Eric Christopher39a84d02016-02-12 02:22:53 +000051 return __a | (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000052}
53
Michael Kupersteine45af542015-06-30 13:36:19 +000054static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000055__blsfill_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000056{
Eric Christopher39a84d02016-02-12 02:22:53 +000057 return __a | (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000058}
59
Michael Kupersteine45af542015-06-30 13:36:19 +000060static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000061__blsic_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000062{
Eric Christopher39a84d02016-02-12 02:22:53 +000063 return ~__a | (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000064}
65
Michael Kupersteine45af542015-06-30 13:36:19 +000066static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000067__t1mskc_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000068{
Eric Christopher39a84d02016-02-12 02:22:53 +000069 return ~__a | (__a + 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000070}
71
Michael Kupersteine45af542015-06-30 13:36:19 +000072static __inline__ unsigned int __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000073__tzmsk_u32(unsigned int __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000074{
Eric Christopher39a84d02016-02-12 02:22:53 +000075 return ~__a & (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +000076}
77
78#ifdef __x86_64__
Craig Topperd619eaaa2015-11-11 03:47:10 +000079#define __bextri_u64(a, b) \
80 ((unsigned long long)__builtin_ia32_bextri_u64((unsigned long long)(a), \
81 (unsigned long long)(b)))
Craig Topperd335c9d2013-10-05 17:08:42 +000082
Michael Kupersteine45af542015-06-30 13:36:19 +000083static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000084__blcfill_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +000085{
Eric Christopher39a84d02016-02-12 02:22:53 +000086 return __a & (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +000087}
88
Michael Kupersteine45af542015-06-30 13:36:19 +000089static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000090__blci_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +000091{
Eric Christopher39a84d02016-02-12 02:22:53 +000092 return __a | ~(__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +000093}
94
Michael Kupersteine45af542015-06-30 13:36:19 +000095static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +000096__blcic_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +000097{
Eric Christopher39a84d02016-02-12 02:22:53 +000098 return ~__a & (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +000099}
100
Michael Kupersteine45af542015-06-30 13:36:19 +0000101static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000102__blcmsk_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000103{
Eric Christopher39a84d02016-02-12 02:22:53 +0000104 return __a ^ (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000105}
106
Michael Kupersteine45af542015-06-30 13:36:19 +0000107static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000108__blcs_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000109{
Eric Christopher39a84d02016-02-12 02:22:53 +0000110 return __a | (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000111}
112
Michael Kupersteine45af542015-06-30 13:36:19 +0000113static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000114__blsfill_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000115{
Eric Christopher39a84d02016-02-12 02:22:53 +0000116 return __a | (__a - 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000117}
118
Michael Kupersteine45af542015-06-30 13:36:19 +0000119static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000120__blsic_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000121{
Eric Christopher39a84d02016-02-12 02:22:53 +0000122 return ~__a | (__a - 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000123}
124
Michael Kupersteine45af542015-06-30 13:36:19 +0000125static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000126__t1mskc_u64(unsigned long long __a)
Craig Topperd335c9d2013-10-05 17:08:42 +0000127{
Eric Christopher39a84d02016-02-12 02:22:53 +0000128 return ~__a | (__a + 1);
Craig Topperd335c9d2013-10-05 17:08:42 +0000129}
130
Michael Kupersteine45af542015-06-30 13:36:19 +0000131static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Eric Christopher39a84d02016-02-12 02:22:53 +0000132__tzmsk_u64(unsigned long long __a)
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000133{
Eric Christopher39a84d02016-02-12 02:22:53 +0000134 return ~__a & (__a - 1);
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000135}
136#endif
137
Michael Kupersteine45af542015-06-30 13:36:19 +0000138#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +0000139
Yunzhong Gaof4e0b102013-09-30 17:25:14 +0000140#endif /* __TBMINTRIN_H */