tbmintrin.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*===---- tbmintrin.h - TBM 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. #ifndef __TBM__
  24. #error "TBM instruction set is not enabled"
  25. #endif
  26. #ifndef __X86INTRIN_H
  27. #error "Never use <tbmintrin.h> directly; include <x86intrin.h> instead."
  28. #endif
  29. #ifndef __TBMINTRIN_H
  30. #define __TBMINTRIN_H
  31. /* Define the default attributes for the functions in this file. */
  32. #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
  33. #define __bextri_u32(a, b) (__builtin_ia32_bextri_u32((a), (b)))
  34. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  35. __blcfill_u32(unsigned int a)
  36. {
  37. return a & (a + 1);
  38. }
  39. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  40. __blci_u32(unsigned int a)
  41. {
  42. return a | ~(a + 1);
  43. }
  44. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  45. __blcic_u32(unsigned int a)
  46. {
  47. return ~a & (a + 1);
  48. }
  49. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  50. __blcmsk_u32(unsigned int a)
  51. {
  52. return a ^ (a + 1);
  53. }
  54. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  55. __blcs_u32(unsigned int a)
  56. {
  57. return a | (a + 1);
  58. }
  59. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  60. __blsfill_u32(unsigned int a)
  61. {
  62. return a | (a - 1);
  63. }
  64. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  65. __blsic_u32(unsigned int a)
  66. {
  67. return ~a | (a - 1);
  68. }
  69. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  70. __t1mskc_u32(unsigned int a)
  71. {
  72. return ~a | (a + 1);
  73. }
  74. static __inline__ unsigned int __DEFAULT_FN_ATTRS
  75. __tzmsk_u32(unsigned int a)
  76. {
  77. return ~a & (a - 1);
  78. }
  79. #ifdef __x86_64__
  80. #define __bextri_u64(a, b) (__builtin_ia32_bextri_u64((a), (int)(b)))
  81. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  82. __blcfill_u64(unsigned long long a)
  83. {
  84. return a & (a + 1);
  85. }
  86. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  87. __blci_u64(unsigned long long a)
  88. {
  89. return a | ~(a + 1);
  90. }
  91. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  92. __blcic_u64(unsigned long long a)
  93. {
  94. return ~a & (a + 1);
  95. }
  96. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  97. __blcmsk_u64(unsigned long long a)
  98. {
  99. return a ^ (a + 1);
  100. }
  101. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  102. __blcs_u64(unsigned long long a)
  103. {
  104. return a | (a + 1);
  105. }
  106. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  107. __blsfill_u64(unsigned long long a)
  108. {
  109. return a | (a - 1);
  110. }
  111. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  112. __blsic_u64(unsigned long long a)
  113. {
  114. return ~a | (a - 1);
  115. }
  116. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  117. __t1mskc_u64(unsigned long long a)
  118. {
  119. return ~a | (a + 1);
  120. }
  121. static __inline__ unsigned long long __DEFAULT_FN_ATTRS
  122. __tzmsk_u64(unsigned long long a)
  123. {
  124. return ~a & (a - 1);
  125. }
  126. #endif
  127. #undef __DEFAULT_FN_ATTRS
  128. #endif /* __TBMINTRIN_H */