htmintrin.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*===---- htmintrin.h - Standard header for PowerPC HTM ---------------===*\
  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. #ifndef __HTMINTRIN_H
  23. #define __HTMINTRIN_H
  24. #ifndef __HTM__
  25. #error "HTM instruction set not enabled"
  26. #endif
  27. #ifdef __powerpc__
  28. #include <stdint.h>
  29. typedef uint64_t texasr_t;
  30. typedef uint32_t texasru_t;
  31. typedef uint32_t texasrl_t;
  32. typedef uintptr_t tfiar_t;
  33. typedef uintptr_t tfhar_t;
  34. #define _HTM_STATE(CR0) ((CR0 >> 1) & 0x3)
  35. #define _HTM_NONTRANSACTIONAL 0x0
  36. #define _HTM_SUSPENDED 0x1
  37. #define _HTM_TRANSACTIONAL 0x2
  38. #define _TEXASR_EXTRACT_BITS(TEXASR,BITNUM,SIZE) \
  39. (((TEXASR) >> (63-(BITNUM))) & ((1<<(SIZE))-1))
  40. #define _TEXASRU_EXTRACT_BITS(TEXASR,BITNUM,SIZE) \
  41. (((TEXASR) >> (31-(BITNUM))) & ((1<<(SIZE))-1))
  42. #define _TEXASR_FAILURE_CODE(TEXASR) \
  43. _TEXASR_EXTRACT_BITS(TEXASR, 7, 8)
  44. #define _TEXASRU_FAILURE_CODE(TEXASRU) \
  45. _TEXASRU_EXTRACT_BITS(TEXASRU, 7, 8)
  46. #define _TEXASR_FAILURE_PERSISTENT(TEXASR) \
  47. _TEXASR_EXTRACT_BITS(TEXASR, 7, 1)
  48. #define _TEXASRU_FAILURE_PERSISTENT(TEXASRU) \
  49. _TEXASRU_EXTRACT_BITS(TEXASRU, 7, 1)
  50. #define _TEXASR_DISALLOWED(TEXASR) \
  51. _TEXASR_EXTRACT_BITS(TEXASR, 8, 1)
  52. #define _TEXASRU_DISALLOWED(TEXASRU) \
  53. _TEXASRU_EXTRACT_BITS(TEXASRU, 8, 1)
  54. #define _TEXASR_NESTING_OVERFLOW(TEXASR) \
  55. _TEXASR_EXTRACT_BITS(TEXASR, 9, 1)
  56. #define _TEXASRU_NESTING_OVERFLOW(TEXASRU) \
  57. _TEXASRU_EXTRACT_BITS(TEXASRU, 9, 1)
  58. #define _TEXASR_FOOTPRINT_OVERFLOW(TEXASR) \
  59. _TEXASR_EXTRACT_BITS(TEXASR, 10, 1)
  60. #define _TEXASRU_FOOTPRINT_OVERFLOW(TEXASRU) \
  61. _TEXASRU_EXTRACT_BITS(TEXASRU, 10, 1)
  62. #define _TEXASR_SELF_INDUCED_CONFLICT(TEXASR) \
  63. _TEXASR_EXTRACT_BITS(TEXASR, 11, 1)
  64. #define _TEXASRU_SELF_INDUCED_CONFLICT(TEXASRU) \
  65. _TEXASRU_EXTRACT_BITS(TEXASRU, 11, 1)
  66. #define _TEXASR_NON_TRANSACTIONAL_CONFLICT(TEXASR) \
  67. _TEXASR_EXTRACT_BITS(TEXASR, 12, 1)
  68. #define _TEXASRU_NON_TRANSACTIONAL_CONFLICT(TEXASRU) \
  69. _TEXASRU_EXTRACT_BITS(TEXASRU, 12, 1)
  70. #define _TEXASR_TRANSACTION_CONFLICT(TEXASR) \
  71. _TEXASR_EXTRACT_BITS(TEXASR, 13, 1)
  72. #define _TEXASRU_TRANSACTION_CONFLICT(TEXASRU) \
  73. _TEXASRU_EXTRACT_BITS(TEXASRU, 13, 1)
  74. #define _TEXASR_TRANSLATION_INVALIDATION_CONFLICT(TEXASR) \
  75. _TEXASR_EXTRACT_BITS(TEXASR, 14, 1)
  76. #define _TEXASRU_TRANSLATION_INVALIDATION_CONFLICT(TEXASRU) \
  77. _TEXASRU_EXTRACT_BITS(TEXASRU, 14, 1)
  78. #define _TEXASR_IMPLEMENTAION_SPECIFIC(TEXASR) \
  79. _TEXASR_EXTRACT_BITS(TEXASR, 15, 1)
  80. #define _TEXASRU_IMPLEMENTAION_SPECIFIC(TEXASRU) \
  81. _TEXASRU_EXTRACT_BITS(TEXASRU, 15, 1)
  82. #define _TEXASR_INSTRUCTION_FETCH_CONFLICT(TEXASR) \
  83. _TEXASR_EXTRACT_BITS(TEXASR, 16, 1)
  84. #define _TEXASRU_INSTRUCTION_FETCH_CONFLICT(TEXASRU) \
  85. _TEXASRU_EXTRACT_BITS(TEXASRU, 16, 1)
  86. #define _TEXASR_ABORT(TEXASR) \
  87. _TEXASR_EXTRACT_BITS(TEXASR, 31, 1)
  88. #define _TEXASRU_ABORT(TEXASRU) \
  89. _TEXASRU_EXTRACT_BITS(TEXASRU, 31, 1)
  90. #define _TEXASR_SUSPENDED(TEXASR) \
  91. _TEXASR_EXTRACT_BITS(TEXASR, 32, 1)
  92. #define _TEXASR_PRIVILEGE(TEXASR) \
  93. _TEXASR_EXTRACT_BITS(TEXASR, 35, 2)
  94. #define _TEXASR_FAILURE_SUMMARY(TEXASR) \
  95. _TEXASR_EXTRACT_BITS(TEXASR, 36, 1)
  96. #define _TEXASR_TFIAR_EXACT(TEXASR) \
  97. _TEXASR_EXTRACT_BITS(TEXASR, 37, 1)
  98. #define _TEXASR_ROT(TEXASR) \
  99. _TEXASR_EXTRACT_BITS(TEXASR, 38, 1)
  100. #define _TEXASR_TRANSACTION_LEVEL(TEXASR) \
  101. _TEXASR_EXTRACT_BITS(TEXASR, 63, 12)
  102. #endif /* __powerpc */
  103. #ifdef __s390__
  104. /* Condition codes generated by tbegin */
  105. #define _HTM_TBEGIN_STARTED 0
  106. #define _HTM_TBEGIN_INDETERMINATE 1
  107. #define _HTM_TBEGIN_TRANSIENT 2
  108. #define _HTM_TBEGIN_PERSISTENT 3
  109. /* The abort codes below this threshold are reserved for machine use. */
  110. #define _HTM_FIRST_USER_ABORT_CODE 256
  111. /* The transaction diagnostic block is it is defined in the Principles
  112. of Operation chapter 5-91. */
  113. struct __htm_tdb {
  114. unsigned char format; /* 0 */
  115. unsigned char flags;
  116. unsigned char reserved1[4];
  117. unsigned short nesting_depth;
  118. unsigned long long abort_code; /* 8 */
  119. unsigned long long conflict_token; /* 16 */
  120. unsigned long long atia; /* 24 */
  121. unsigned char eaid; /* 32 */
  122. unsigned char dxc;
  123. unsigned char reserved2[2];
  124. unsigned int program_int_id;
  125. unsigned long long exception_id; /* 40 */
  126. unsigned long long bea; /* 48 */
  127. unsigned char reserved3[72]; /* 56 */
  128. unsigned long long gprs[16]; /* 128 */
  129. } __attribute__((__packed__, __aligned__ (8)));
  130. /* Helper intrinsics to retry tbegin in case of transient failure. */
  131. static __inline int __attribute__((__always_inline__, __nodebug__))
  132. __builtin_tbegin_retry_null (int __retry)
  133. {
  134. int cc, i = 0;
  135. while ((cc = __builtin_tbegin(0)) == _HTM_TBEGIN_TRANSIENT
  136. && i++ < __retry)
  137. __builtin_tx_assist(i);
  138. return cc;
  139. }
  140. static __inline int __attribute__((__always_inline__, __nodebug__))
  141. __builtin_tbegin_retry_tdb (void *__tdb, int __retry)
  142. {
  143. int cc, i = 0;
  144. while ((cc = __builtin_tbegin(__tdb)) == _HTM_TBEGIN_TRANSIENT
  145. && i++ < __retry)
  146. __builtin_tx_assist(i);
  147. return cc;
  148. }
  149. #define __builtin_tbegin_retry(tdb, retry) \
  150. (__builtin_constant_p(tdb == 0) && tdb == 0 ? \
  151. __builtin_tbegin_retry_null(retry) : \
  152. __builtin_tbegin_retry_tdb(tdb, retry))
  153. static __inline int __attribute__((__always_inline__, __nodebug__))
  154. __builtin_tbegin_retry_nofloat_null (int __retry)
  155. {
  156. int cc, i = 0;
  157. while ((cc = __builtin_tbegin_nofloat(0)) == _HTM_TBEGIN_TRANSIENT
  158. && i++ < __retry)
  159. __builtin_tx_assist(i);
  160. return cc;
  161. }
  162. static __inline int __attribute__((__always_inline__, __nodebug__))
  163. __builtin_tbegin_retry_nofloat_tdb (void *__tdb, int __retry)
  164. {
  165. int cc, i = 0;
  166. while ((cc = __builtin_tbegin_nofloat(__tdb)) == _HTM_TBEGIN_TRANSIENT
  167. && i++ < __retry)
  168. __builtin_tx_assist(i);
  169. return cc;
  170. }
  171. #define __builtin_tbegin_retry_nofloat(tdb, retry) \
  172. (__builtin_constant_p(tdb == 0) && tdb == 0 ? \
  173. __builtin_tbegin_retry_nofloat_null(retry) : \
  174. __builtin_tbegin_retry_nofloat_tdb(tdb, retry))
  175. #endif /* __s390__ */
  176. #endif /* __HTMINTRIN_H */