Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 1 | /*===---- bmi2intrin.h - BMI2 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 |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 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 | |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 14 | #ifndef __BMI2INTRIN_H |
| 15 | #define __BMI2INTRIN_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__("bmi2"))) |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 19 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 20 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 21 | _bzhi_u32(unsigned int __X, unsigned int __Y) |
| 22 | { |
| 23 | return __builtin_ia32_bzhi_si(__X, __Y); |
| 24 | } |
| 25 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 26 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 27 | _pdep_u32(unsigned int __X, unsigned int __Y) |
| 28 | { |
| 29 | return __builtin_ia32_pdep_si(__X, __Y); |
| 30 | } |
| 31 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 32 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 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 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 40 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 41 | _bzhi_u64(unsigned long long __X, unsigned long long __Y) |
| 42 | { |
| 43 | return __builtin_ia32_bzhi_di(__X, __Y); |
| 44 | } |
| 45 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 46 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 47 | _pdep_u64(unsigned long long __X, unsigned long long __Y) |
| 48 | { |
| 49 | return __builtin_ia32_pdep_di(__X, __Y); |
| 50 | } |
| 51 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 52 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 53 | _pext_u64(unsigned long long __X, unsigned long long __Y) |
| 54 | { |
| 55 | return __builtin_ia32_pext_di(__X, __Y); |
| 56 | } |
| 57 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 58 | static __inline__ unsigned long long __DEFAULT_FN_ATTRS |
Michael Liao | 4a7f8c2 | 2012-10-05 18:50:09 +0000 | [diff] [blame] | 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 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 69 | static __inline__ unsigned int __DEFAULT_FN_ATTRS |
Michael Liao | 4a7f8c2 | 2012-10-05 18:50:09 +0000 | [diff] [blame] | 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 | |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 77 | #endif /* !__x86_64__ */ |
| 78 | |
Michael Kuperstein | e45af54 | 2015-06-30 13:36:19 +0000 | [diff] [blame] | 79 | #undef __DEFAULT_FN_ATTRS |
Eric Christopher | 4d185168 | 2015-06-17 07:09:20 +0000 | [diff] [blame] | 80 | |
Craig Topper | c334dd6 | 2011-12-26 02:31:10 +0000 | [diff] [blame] | 81 | #endif /* __BMI2INTRIN_H */ |