blob: 0b56aed5f4cb7b4c9086e13a9ec78b091629d84c [file] [log] [blame]
Craig Topperc334dd62011-12-26 02:31:10 +00001/*===---- bmi2intrin.h - BMI2 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
Craig Topperc334dd62011-12-26 02:31:10 +00006 *
7 *===-----------------------------------------------------------------------===
8 */
9
10#if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
11#error "Never use <bmi2intrin.h> directly; include <x86intrin.h> instead."
12#endif
13
Craig Topperc334dd62011-12-26 02:31:10 +000014#ifndef __BMI2INTRIN_H
15#define __BMI2INTRIN_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__("bmi2")))
Eric Christopher4d1851682015-06-17 07:09:20 +000019
Michael Kupersteine45af542015-06-30 13:36:19 +000020static __inline__ unsigned int __DEFAULT_FN_ATTRS
Craig Topperc334dd62011-12-26 02:31:10 +000021_bzhi_u32(unsigned int __X, unsigned int __Y)
22{
23 return __builtin_ia32_bzhi_si(__X, __Y);
24}
25
Michael Kupersteine45af542015-06-30 13:36:19 +000026static __inline__ unsigned int __DEFAULT_FN_ATTRS
Craig Topperc334dd62011-12-26 02:31:10 +000027_pdep_u32(unsigned int __X, unsigned int __Y)
28{
29 return __builtin_ia32_pdep_si(__X, __Y);
30}
31
Michael Kupersteine45af542015-06-30 13:36:19 +000032static __inline__ unsigned int __DEFAULT_FN_ATTRS
Craig Topperc334dd62011-12-26 02:31:10 +000033_pext_u32(unsigned int __X, unsigned int __Y)
34{
35 return __builtin_ia32_pext_si(__X, __Y);
36}
37
38#ifdef __x86_64__
39
Michael Kupersteine45af542015-06-30 13:36:19 +000040static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperc334dd62011-12-26 02:31:10 +000041_bzhi_u64(unsigned long long __X, unsigned long long __Y)
42{
43 return __builtin_ia32_bzhi_di(__X, __Y);
44}
45
Michael Kupersteine45af542015-06-30 13:36:19 +000046static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperc334dd62011-12-26 02:31:10 +000047_pdep_u64(unsigned long long __X, unsigned long long __Y)
48{
49 return __builtin_ia32_pdep_di(__X, __Y);
50}
51
Michael Kupersteine45af542015-06-30 13:36:19 +000052static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Craig Topperc334dd62011-12-26 02:31:10 +000053_pext_u64(unsigned long long __X, unsigned long long __Y)
54{
55 return __builtin_ia32_pext_di(__X, __Y);
56}
57
Michael Kupersteine45af542015-06-30 13:36:19 +000058static __inline__ unsigned long long __DEFAULT_FN_ATTRS
Michael Liao4a7f8c22012-10-05 18:50:09 +000059_mulx_u64 (unsigned long long __X, unsigned long long __Y,
60 unsigned long long *__P)
61{
62 unsigned __int128 __res = (unsigned __int128) __X * __Y;
63 *__P = (unsigned long long) (__res >> 64);
64 return (unsigned long long) __res;
65}
66
67#else /* !__x86_64__ */
68
Michael Kupersteine45af542015-06-30 13:36:19 +000069static __inline__ unsigned int __DEFAULT_FN_ATTRS
Michael Liao4a7f8c22012-10-05 18:50:09 +000070_mulx_u32 (unsigned int __X, unsigned int __Y, unsigned int *__P)
71{
72 unsigned long long __res = (unsigned long long) __X * __Y;
73 *__P = (unsigned int) (__res >> 32);
74 return (unsigned int) __res;
75}
76
Craig Topperc334dd62011-12-26 02:31:10 +000077#endif /* !__x86_64__ */
78
Michael Kupersteine45af542015-06-30 13:36:19 +000079#undef __DEFAULT_FN_ATTRS
Eric Christopher4d1851682015-06-17 07:09:20 +000080
Craig Topperc334dd62011-12-26 02:31:10 +000081#endif /* __BMI2INTRIN_H */