1/*===---- bmi2intrin.h - BMI2 intrinsics -----------------------------------===
2 *
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
6 *
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
14#ifndef __BMI2INTRIN_H
15#define __BMI2INTRIN_H
16
17/* Define the default attributes for the functions in this file. */
18#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("bmi2")))
19
20static __inline__ unsigned int __DEFAULT_FN_ATTRS
21_bzhi_u32(unsigned int __X, unsigned int __Y)
22{
23  return __builtin_ia32_bzhi_si(__X, __Y);
24}
25
26static __inline__ unsigned int __DEFAULT_FN_ATTRS
27_pdep_u32(unsigned int __X, unsigned int __Y)
28{
29  return __builtin_ia32_pdep_si(__X, __Y);
30}
31
32static __inline__ unsigned int __DEFAULT_FN_ATTRS
33_pext_u32(unsigned int __X, unsigned int __Y)
34{
35  return __builtin_ia32_pext_si(__X, __Y);
36}
37
38#ifdef  __x86_64__
39
40static __inline__ unsigned long long __DEFAULT_FN_ATTRS
41_bzhi_u64(unsigned long long __X, unsigned long long __Y)
42{
43  return __builtin_ia32_bzhi_di(__X, __Y);
44}
45
46static __inline__ unsigned long long __DEFAULT_FN_ATTRS
47_pdep_u64(unsigned long long __X, unsigned long long __Y)
48{
49  return __builtin_ia32_pdep_di(__X, __Y);
50}
51
52static __inline__ unsigned long long __DEFAULT_FN_ATTRS
53_pext_u64(unsigned long long __X, unsigned long long __Y)
54{
55  return __builtin_ia32_pext_di(__X, __Y);
56}
57
58static __inline__ unsigned long long __DEFAULT_FN_ATTRS
59_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
69static __inline__ unsigned int __DEFAULT_FN_ATTRS
70_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
77#endif /* !__x86_64__  */
78
79#undef __DEFAULT_FN_ATTRS
80
81#endif /* __BMI2INTRIN_H */
82