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