bmiintrin.h 5.5 KB

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