1/* Copyright (C) 2010-2022 Free Software Foundation, Inc. 2 3 This file is part of GCC. 4 5 GCC is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3, or (at your option) 8 any later version. 9 10 GCC is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 Under Section 7 of GPL version 3, you are granted additional 16 permissions described in the GCC Runtime Library Exception, version 17 3.1, as published by the Free Software Foundation. 18 19 You should have received a copy of the GNU General Public License and 20 a copy of the GCC Runtime Library Exception along with this program; 21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 22 <http://www.gnu.org/licenses/>. */ 23 24#ifndef _X86GPRINTRIN_H_INCLUDED 25# error "Never use <bmiintrin.h> directly; include <x86gprintrin.h> instead." 26#endif 27 28#ifndef _BMIINTRIN_H_INCLUDED 29#define _BMIINTRIN_H_INCLUDED 30 31#ifndef __BMI__ 32#pragma GCC push_options 33#pragma GCC target("bmi") 34#define __DISABLE_BMI__ 35#endif /* __BMI__ */ 36 37extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 38__tzcnt_u16 (unsigned short __X) 39{ 40 return __builtin_ia32_tzcnt_u16 (__X); 41} 42 43extern __inline unsigned short __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 44_tzcnt_u16 (unsigned short __X) 45{ 46 return __builtin_ia32_tzcnt_u16 (__X); 47} 48 49extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 50__andn_u32 (unsigned int __X, unsigned int __Y) 51{ 52 return ~__X & __Y; 53} 54 55extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 56_andn_u32 (unsigned int __X, unsigned int __Y) 57{ 58 return __andn_u32 (__X, __Y); 59} 60 61extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 62__bextr_u32 (unsigned int __X, unsigned int __Y) 63{ 64 return __builtin_ia32_bextr_u32 (__X, __Y); 65} 66 67extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 68_bextr_u32 (unsigned int __X, unsigned int __Y, unsigned __Z) 69{ 70 return __builtin_ia32_bextr_u32 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); 71} 72 73extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 74__blsi_u32 (unsigned int __X) 75{ 76 return __X & -__X; 77} 78 79extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 80_blsi_u32 (unsigned int __X) 81{ 82 return __blsi_u32 (__X); 83} 84 85extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 86__blsmsk_u32 (unsigned int __X) 87{ 88 return __X ^ (__X - 1); 89} 90 91extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 92_blsmsk_u32 (unsigned int __X) 93{ 94 return __blsmsk_u32 (__X); 95} 96 97extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 98__blsr_u32 (unsigned int __X) 99{ 100 return __X & (__X - 1); 101} 102 103extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 104_blsr_u32 (unsigned int __X) 105{ 106 return __blsr_u32 (__X); 107} 108 109extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 110__tzcnt_u32 (unsigned int __X) 111{ 112 return __builtin_ia32_tzcnt_u32 (__X); 113} 114 115extern __inline unsigned int __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 116_tzcnt_u32 (unsigned int __X) 117{ 118 return __builtin_ia32_tzcnt_u32 (__X); 119} 120 121 122#ifdef __x86_64__ 123extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 124__andn_u64 (unsigned long long __X, unsigned long long __Y) 125{ 126 return ~__X & __Y; 127} 128 129extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 130_andn_u64 (unsigned long long __X, unsigned long long __Y) 131{ 132 return __andn_u64 (__X, __Y); 133} 134 135extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 136__bextr_u64 (unsigned long long __X, unsigned long long __Y) 137{ 138 return __builtin_ia32_bextr_u64 (__X, __Y); 139} 140 141extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 142_bextr_u64 (unsigned long long __X, unsigned int __Y, unsigned int __Z) 143{ 144 return __builtin_ia32_bextr_u64 (__X, ((__Y & 0xff) | ((__Z & 0xff) << 8))); 145} 146 147extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 148__blsi_u64 (unsigned long long __X) 149{ 150 return __X & -__X; 151} 152 153extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 154_blsi_u64 (unsigned long long __X) 155{ 156 return __blsi_u64 (__X); 157} 158 159extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 160__blsmsk_u64 (unsigned long long __X) 161{ 162 return __X ^ (__X - 1); 163} 164 165extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 166_blsmsk_u64 (unsigned long long __X) 167{ 168 return __blsmsk_u64 (__X); 169} 170 171extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 172__blsr_u64 (unsigned long long __X) 173{ 174 return __X & (__X - 1); 175} 176 177extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 178_blsr_u64 (unsigned long long __X) 179{ 180 return __blsr_u64 (__X); 181} 182 183extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 184__tzcnt_u64 (unsigned long long __X) 185{ 186 return __builtin_ia32_tzcnt_u64 (__X); 187} 188 189extern __inline unsigned long long __attribute__((__gnu_inline__, __always_inline__, __artificial__)) 190_tzcnt_u64 (unsigned long long __X) 191{ 192 return __builtin_ia32_tzcnt_u64 (__X); 193} 194 195#endif /* __x86_64__ */ 196 197#ifdef __DISABLE_BMI__ 198#undef __DISABLE_BMI__ 199#pragma GCC pop_options 200#endif /* __DISABLE_BMI__ */ 201 202#endif /* _BMIINTRIN_H_INCLUDED */ 203