lzcntintrin.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*===---- lzcntintrin.h - LZCNT intrinsics ---------------------------------===
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. *
  21. *===-----------------------------------------------------------------------===
  22. */
  23. #if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
  24. #error "Never use <lzcntintrin.h> directly; include <x86intrin.h> instead."
  25. #endif
  26. #ifndef __LZCNTINTRIN_H
  27. #define __LZCNTINTRIN_H
  28. /* Define the default attributes for the functions in this file. */
  29. #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lzcnt")))
  30. /// Counts the number of leading zero bits in the operand.
  31. ///
  32. /// \headerfile <x86intrin.h>
  33. ///
  34. /// This intrinsic corresponds to the \c LZCNT instruction.
  35. ///
  36. /// \param __X
  37. /// An unsigned 16-bit integer whose leading zeros are to be counted.
  38. /// \returns An unsigned 16-bit integer containing the number of leading zero
  39. /// bits in the operand.
  40. static __inline__ unsigned short __DEFAULT_FN_ATTRS
  41. __lzcnt16(unsigned short __X)
  42. {
  43. return __builtin_ia32_lzcnt_u16(__X);
  44. }
  45. /// Counts the number of leading zero bits in the operand.
  46. ///
  47. /// \headerfile <x86intrin.h>
  48. ///
  49. /// This intrinsic corresponds to the \c LZCNT instruction.
  50. ///
  51. /// \param __X
  52. /// An unsigned 32-bit integer whose leading zeros are to be counted.
  53. /// \returns An unsigned 32-bit integer containing the number of leading zero
  54. /// bits in the operand.
  55. /// \see _lzcnt_u32
  56. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  57. __lzcnt32(unsigned int __X)
  58. {
  59. return __builtin_ia32_lzcnt_u32(__X);
  60. }
  61. /// Counts the number of leading zero bits in the operand.
  62. ///
  63. /// \headerfile <x86intrin.h>
  64. ///
  65. /// This intrinsic corresponds to the \c LZCNT instruction.
  66. ///
  67. /// \param __X
  68. /// An unsigned 32-bit integer whose leading zeros are to be counted.
  69. /// \returns An unsigned 32-bit integer containing the number of leading zero
  70. /// bits in the operand.
  71. /// \see __lzcnt32
  72. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  73. _lzcnt_u32(unsigned int __X)
  74. {
  75. return __builtin_ia32_lzcnt_u32(__X);
  76. }
  77. #ifdef __x86_64__
  78. /// Counts the number of leading zero bits in the operand.
  79. ///
  80. /// \headerfile <x86intrin.h>
  81. ///
  82. /// This intrinsic corresponds to the \c LZCNT instruction.
  83. ///
  84. /// \param __X
  85. /// An unsigned 64-bit integer whose leading zeros are to be counted.
  86. /// \returns An unsigned 64-bit integer containing the number of leading zero
  87. /// bits in the operand.
  88. /// \see _lzcnt_u64
  89. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  90. __lzcnt64(unsigned long long __X)
  91. {
  92. return __builtin_ia32_lzcnt_u64(__X);
  93. }
  94. /// Counts the number of leading zero bits in the operand.
  95. ///
  96. /// \headerfile <x86intrin.h>
  97. ///
  98. /// This intrinsic corresponds to the \c LZCNT instruction.
  99. ///
  100. /// \param __X
  101. /// An unsigned 64-bit integer whose leading zeros are to be counted.
  102. /// \returns An unsigned 64-bit integer containing the number of leading zero
  103. /// bits in the operand.
  104. /// \see __lzcnt64
  105. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  106. _lzcnt_u64(unsigned long long __X)
  107. {
  108. return __builtin_ia32_lzcnt_u64(__X);
  109. }
  110. #endif
  111. #undef __DEFAULT_FN_ATTRS
  112. #endif /* __LZCNTINTRIN_H */