htmxlintrin.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*===---- htmxlintrin.h - XL compiler HTM execution 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. #ifndef __HTMXLINTRIN_H
  23. #define __HTMXLINTRIN_H
  24. #ifndef __HTM__
  25. #error "HTM instruction set not enabled"
  26. #endif
  27. #include <htmintrin.h>
  28. #ifdef __powerpc__
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #define _TEXASR_PTR(TM_BUF) ((texasr_t *)((char *)(TM_BUF) + 0))
  33. #define _TEXASRU_PTR(TM_BUF) ((texasru_t *)((char *)(TM_BUF) + 0))
  34. #define _TEXASRL_PTR(TM_BUF) ((texasrl_t *)((char *)(TM_BUF) + 4))
  35. #define _TFIAR_PTR(TM_BUF) ((tfiar_t *)((char *)(TM_BUF) + 8))
  36. typedef char TM_buff_type[16];
  37. /* This macro can be used to determine whether a transaction was successfully
  38. started from the __TM_begin() and __TM_simple_begin() intrinsic functions
  39. below. */
  40. #define _HTM_TBEGIN_STARTED 1
  41. extern __inline long
  42. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  43. __TM_simple_begin (void)
  44. {
  45. if (__builtin_expect (__builtin_tbegin (0), 1))
  46. return _HTM_TBEGIN_STARTED;
  47. return 0;
  48. }
  49. extern __inline long
  50. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  51. __TM_begin (void* const __TM_buff)
  52. {
  53. *_TEXASRL_PTR (__TM_buff) = 0;
  54. if (__builtin_expect (__builtin_tbegin (0), 1))
  55. return _HTM_TBEGIN_STARTED;
  56. #ifdef __powerpc64__
  57. *_TEXASR_PTR (__TM_buff) = __builtin_get_texasr ();
  58. #else
  59. *_TEXASRU_PTR (__TM_buff) = __builtin_get_texasru ();
  60. *_TEXASRL_PTR (__TM_buff) = __builtin_get_texasr ();
  61. #endif
  62. *_TFIAR_PTR (__TM_buff) = __builtin_get_tfiar ();
  63. return 0;
  64. }
  65. extern __inline long
  66. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  67. __TM_end (void)
  68. {
  69. if (__builtin_expect (__builtin_tend (0), 1))
  70. return 1;
  71. return 0;
  72. }
  73. extern __inline void
  74. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  75. __TM_abort (void)
  76. {
  77. __builtin_tabort (0);
  78. }
  79. extern __inline void
  80. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  81. __TM_named_abort (unsigned char const __code)
  82. {
  83. __builtin_tabort (__code);
  84. }
  85. extern __inline void
  86. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  87. __TM_resume (void)
  88. {
  89. __builtin_tresume ();
  90. }
  91. extern __inline void
  92. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  93. __TM_suspend (void)
  94. {
  95. __builtin_tsuspend ();
  96. }
  97. extern __inline long
  98. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  99. __TM_is_user_abort (void* const __TM_buff)
  100. {
  101. texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
  102. return _TEXASRU_ABORT (texasru);
  103. }
  104. extern __inline long
  105. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  106. __TM_is_named_user_abort (void* const __TM_buff, unsigned char *__code)
  107. {
  108. texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
  109. *__code = _TEXASRU_FAILURE_CODE (texasru);
  110. return _TEXASRU_ABORT (texasru);
  111. }
  112. extern __inline long
  113. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  114. __TM_is_illegal (void* const __TM_buff)
  115. {
  116. texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
  117. return _TEXASRU_DISALLOWED (texasru);
  118. }
  119. extern __inline long
  120. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  121. __TM_is_footprint_exceeded (void* const __TM_buff)
  122. {
  123. texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
  124. return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);
  125. }
  126. extern __inline long
  127. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  128. __TM_nesting_depth (void* const __TM_buff)
  129. {
  130. texasrl_t texasrl;
  131. if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)
  132. {
  133. texasrl = *_TEXASRL_PTR (__TM_buff);
  134. if (!_TEXASR_FAILURE_SUMMARY (texasrl))
  135. texasrl = 0;
  136. }
  137. else
  138. texasrl = (texasrl_t) __builtin_get_texasr ();
  139. return _TEXASR_TRANSACTION_LEVEL (texasrl);
  140. }
  141. extern __inline long
  142. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  143. __TM_is_nested_too_deep(void* const __TM_buff)
  144. {
  145. texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
  146. return _TEXASRU_NESTING_OVERFLOW (texasru);
  147. }
  148. extern __inline long
  149. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  150. __TM_is_conflict(void* const __TM_buff)
  151. {
  152. texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
  153. /* Return TEXASR bits 11 (Self-Induced Conflict) through
  154. 14 (Translation Invalidation Conflict). */
  155. return (_TEXASRU_EXTRACT_BITS (texasru, 14, 4)) ? 1 : 0;
  156. }
  157. extern __inline long
  158. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  159. __TM_is_failure_persistent(void* const __TM_buff)
  160. {
  161. texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
  162. return _TEXASRU_FAILURE_PERSISTENT (texasru);
  163. }
  164. extern __inline long
  165. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  166. __TM_failure_address(void* const __TM_buff)
  167. {
  168. return *_TFIAR_PTR (__TM_buff);
  169. }
  170. extern __inline long long
  171. __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
  172. __TM_failure_code(void* const __TM_buff)
  173. {
  174. return *_TEXASR_PTR (__TM_buff);
  175. }
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif /* __powerpc__ */
  180. #ifdef __s390__
  181. #include <stdint.h>
  182. /* These intrinsics are being made available for compatibility with
  183. the IBM XL compiler. For documentation please see the "z/OS XL
  184. C/C++ Programming Guide" publically available on the web. */
  185. static __inline long __attribute__((__always_inline__, __nodebug__))
  186. __TM_simple_begin ()
  187. {
  188. return __builtin_tbegin_nofloat (0);
  189. }
  190. static __inline long __attribute__((__always_inline__, __nodebug__))
  191. __TM_begin (void* const __tdb)
  192. {
  193. return __builtin_tbegin_nofloat (__tdb);
  194. }
  195. static __inline long __attribute__((__always_inline__, __nodebug__))
  196. __TM_end ()
  197. {
  198. return __builtin_tend ();
  199. }
  200. static __inline void __attribute__((__always_inline__))
  201. __TM_abort ()
  202. {
  203. return __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE);
  204. }
  205. static __inline void __attribute__((__always_inline__, __nodebug__))
  206. __TM_named_abort (unsigned char const __code)
  207. {
  208. return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE + __code);
  209. }
  210. static __inline void __attribute__((__always_inline__, __nodebug__))
  211. __TM_non_transactional_store (void* const __addr, long long const __value)
  212. {
  213. __builtin_non_tx_store ((uint64_t*)__addr, (uint64_t)__value);
  214. }
  215. static __inline long __attribute__((__always_inline__, __nodebug__))
  216. __TM_nesting_depth (void* const __tdb_ptr)
  217. {
  218. int depth = __builtin_tx_nesting_depth ();
  219. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  220. if (depth != 0)
  221. return depth;
  222. if (tdb->format != 1)
  223. return 0;
  224. return tdb->nesting_depth;
  225. }
  226. /* Transaction failure diagnostics */
  227. static __inline long __attribute__((__always_inline__, __nodebug__))
  228. __TM_is_user_abort (void* const __tdb_ptr)
  229. {
  230. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  231. if (tdb->format != 1)
  232. return 0;
  233. return !!(tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE);
  234. }
  235. static __inline long __attribute__((__always_inline__, __nodebug__))
  236. __TM_is_named_user_abort (void* const __tdb_ptr, unsigned char* __code)
  237. {
  238. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  239. if (tdb->format != 1)
  240. return 0;
  241. if (tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE)
  242. {
  243. *__code = tdb->abort_code - _HTM_FIRST_USER_ABORT_CODE;
  244. return 1;
  245. }
  246. return 0;
  247. }
  248. static __inline long __attribute__((__always_inline__, __nodebug__))
  249. __TM_is_illegal (void* const __tdb_ptr)
  250. {
  251. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  252. return (tdb->format == 1
  253. && (tdb->abort_code == 4 /* unfiltered program interruption */
  254. || tdb->abort_code == 11 /* restricted instruction */));
  255. }
  256. static __inline long __attribute__((__always_inline__, __nodebug__))
  257. __TM_is_footprint_exceeded (void* const __tdb_ptr)
  258. {
  259. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  260. return (tdb->format == 1
  261. && (tdb->abort_code == 7 /* fetch overflow */
  262. || tdb->abort_code == 8 /* store overflow */));
  263. }
  264. static __inline long __attribute__((__always_inline__, __nodebug__))
  265. __TM_is_nested_too_deep (void* const __tdb_ptr)
  266. {
  267. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  268. return tdb->format == 1 && tdb->abort_code == 13; /* depth exceeded */
  269. }
  270. static __inline long __attribute__((__always_inline__, __nodebug__))
  271. __TM_is_conflict (void* const __tdb_ptr)
  272. {
  273. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  274. return (tdb->format == 1
  275. && (tdb->abort_code == 9 /* fetch conflict */
  276. || tdb->abort_code == 10 /* store conflict */));
  277. }
  278. static __inline long __attribute__((__always_inline__, __nodebug__))
  279. __TM_is_failure_persistent (long const __result)
  280. {
  281. return __result == _HTM_TBEGIN_PERSISTENT;
  282. }
  283. static __inline long __attribute__((__always_inline__, __nodebug__))
  284. __TM_failure_address (void* const __tdb_ptr)
  285. {
  286. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  287. return tdb->atia;
  288. }
  289. static __inline long __attribute__((__always_inline__, __nodebug__))
  290. __TM_failure_code (void* const __tdb_ptr)
  291. {
  292. struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
  293. return tdb->abort_code;
  294. }
  295. #endif /* __s390__ */
  296. #endif /* __HTMXLINTRIN_H */