bmi2intrin.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (C) 2011-2022 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. #ifndef _X86GPRINTRIN_H_INCLUDED
  19. # error "Never use <bmi2intrin.h> directly; include <x86gprintrin.h> instead."
  20. #endif
  21. #ifndef _BMI2INTRIN_H_INCLUDED
  22. #define _BMI2INTRIN_H_INCLUDED
  23. #ifndef __BMI2__
  24. #pragma GCC push_options
  25. #pragma GCC target("bmi2")
  26. #define __DISABLE_BMI2__
  27. #endif /* __BMI2__ */
  28. extern __inline unsigned int
  29. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  30. _bzhi_u32 (unsigned int __X, unsigned int __Y)
  31. {
  32. return __builtin_ia32_bzhi_si (__X, __Y);
  33. }
  34. extern __inline unsigned int
  35. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  36. _pdep_u32 (unsigned int __X, unsigned int __Y)
  37. {
  38. return __builtin_ia32_pdep_si (__X, __Y);
  39. }
  40. extern __inline unsigned int
  41. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  42. _pext_u32 (unsigned int __X, unsigned int __Y)
  43. {
  44. return __builtin_ia32_pext_si (__X, __Y);
  45. }
  46. #ifdef __x86_64__
  47. extern __inline unsigned long long
  48. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  49. _bzhi_u64 (unsigned long long __X, unsigned long long __Y)
  50. {
  51. return __builtin_ia32_bzhi_di (__X, __Y);
  52. }
  53. extern __inline unsigned long long
  54. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  55. _pdep_u64 (unsigned long long __X, unsigned long long __Y)
  56. {
  57. return __builtin_ia32_pdep_di (__X, __Y);
  58. }
  59. extern __inline unsigned long long
  60. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  61. _pext_u64 (unsigned long long __X, unsigned long long __Y)
  62. {
  63. return __builtin_ia32_pext_di (__X, __Y);
  64. }
  65. extern __inline unsigned long long
  66. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  67. _mulx_u64 (unsigned long long __X, unsigned long long __Y,
  68. unsigned long long *__P)
  69. {
  70. unsigned __int128 __res = (unsigned __int128) __X * __Y;
  71. *__P = (unsigned long long) (__res >> 64);
  72. return (unsigned long long) __res;
  73. }
  74. #else /* !__x86_64__ */
  75. extern __inline unsigned int
  76. __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  77. _mulx_u32 (unsigned int __X, unsigned int __Y, unsigned int *__P)
  78. {
  79. unsigned long long __res = (unsigned long long) __X * __Y;
  80. *__P = (unsigned int) (__res >> 32);
  81. return (unsigned int) __res;
  82. }
  83. #endif /* !__x86_64__ */
  84. #ifdef __DISABLE_BMI2__
  85. #undef __DISABLE_BMI2__
  86. #pragma GCC pop_options
  87. #endif /* __DISABLE_BMI2__ */
  88. #endif /* _BMI2INTRIN_H_INCLUDED */