1 /*===---- htmxlintrin.h - XL compiler HTM execution intrinsics-------------===*\
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
21 \*===----------------------------------------------------------------------===*/
23 #ifndef __HTMXLINTRIN_H
24 #define __HTMXLINTRIN_H
27 #error "HTM instruction set not enabled"
30 #include <htmintrin.h>
38 #define _TEXASR_PTR(TM_BUF) ((texasr_t *)((char *)(TM_BUF) + 0))
39 #define _TEXASRU_PTR(TM_BUF) ((texasru_t *)((char *)(TM_BUF) + 0))
40 #define _TEXASRL_PTR(TM_BUF) ((texasrl_t *)((char *)(TM_BUF) + 4))
41 #define _TFIAR_PTR(TM_BUF) ((tfiar_t *)((char *)(TM_BUF) + 8))
43 typedef char TM_buff_type[16];
45 /* This macro can be used to determine whether a transaction was successfully
46 started from the __TM_begin() and __TM_simple_begin() intrinsic functions
48 #define _HTM_TBEGIN_STARTED 1
51 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
52 __TM_simple_begin (void)
54 if (__builtin_expect (__builtin_tbegin (0), 1))
55 return _HTM_TBEGIN_STARTED;
60 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
61 __TM_begin (void* const __TM_buff)
63 *_TEXASRL_PTR (__TM_buff) = 0;
64 if (__builtin_expect (__builtin_tbegin (0), 1))
65 return _HTM_TBEGIN_STARTED;
67 *_TEXASR_PTR (__TM_buff) = __builtin_get_texasr ();
69 *_TEXASRU_PTR (__TM_buff) = __builtin_get_texasru ();
70 *_TEXASRL_PTR (__TM_buff) = __builtin_get_texasr ();
72 *_TFIAR_PTR (__TM_buff) = __builtin_get_tfiar ();
77 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
80 if (__builtin_expect (__builtin_tend (0), 1))
86 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
93 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
94 __TM_named_abort (unsigned char const __code)
96 __builtin_tabort (__code);
100 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
103 __builtin_tresume ();
107 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
110 __builtin_tsuspend ();
114 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
115 __TM_is_user_abort (void* const __TM_buff)
117 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
118 return _TEXASRU_ABORT (texasru);
122 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
123 __TM_is_named_user_abort (void* const __TM_buff, unsigned char *__code)
125 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
127 *__code = _TEXASRU_FAILURE_CODE (texasru);
128 return _TEXASRU_ABORT (texasru);
132 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
133 __TM_is_illegal (void* const __TM_buff)
135 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
136 return _TEXASRU_DISALLOWED (texasru);
140 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
141 __TM_is_footprint_exceeded (void* const __TM_buff)
143 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
144 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);
148 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
149 __TM_nesting_depth (void* const __TM_buff)
153 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)
155 texasrl = *_TEXASRL_PTR (__TM_buff);
156 if (!_TEXASR_FAILURE_SUMMARY (texasrl))
160 texasrl = (texasrl_t) __builtin_get_texasr ();
162 return _TEXASR_TRANSACTION_LEVEL (texasrl);
166 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
167 __TM_is_nested_too_deep(void* const __TM_buff)
169 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
170 return _TEXASRU_NESTING_OVERFLOW (texasru);
174 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
175 __TM_is_conflict(void* const __TM_buff)
177 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
178 /* Return TEXASR bits 11 (Self-Induced Conflict) through
179 14 (Translation Invalidation Conflict). */
180 return (_TEXASRU_EXTRACT_BITS (texasru, 14, 4)) ? 1 : 0;
184 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
185 __TM_is_failure_persistent(void* const __TM_buff)
187 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
188 return _TEXASRU_FAILURE_PERSISTENT (texasru);
192 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
193 __TM_failure_address(void* const __TM_buff)
195 return *_TFIAR_PTR (__TM_buff);
198 extern __inline long long
199 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
200 __TM_failure_code(void* const __TM_buff)
202 return *_TEXASR_PTR (__TM_buff);
209 #endif /* __powerpc__ */
215 /* These intrinsics are being made available for compatibility with
216 the IBM XL compiler. For documentation please see the "z/OS XL
217 C/C++ Programming Guide" publically available on the web. */
219 static __inline long __attribute__((__always_inline__, __nodebug__))
222 return __builtin_tbegin_nofloat (0);
225 static __inline long __attribute__((__always_inline__, __nodebug__))
226 __TM_begin (void* const __tdb)
228 return __builtin_tbegin_nofloat (__tdb);
231 static __inline long __attribute__((__always_inline__, __nodebug__))
234 return __builtin_tend ();
237 static __inline void __attribute__((__always_inline__))
240 return __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE);
243 static __inline void __attribute__((__always_inline__, __nodebug__))
244 __TM_named_abort (unsigned char const __code)
246 return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE + __code);
249 static __inline void __attribute__((__always_inline__, __nodebug__))
250 __TM_non_transactional_store (void* const __addr, long long const __value)
252 __builtin_non_tx_store ((uint64_t*)__addr, (uint64_t)__value);
255 static __inline long __attribute__((__always_inline__, __nodebug__))
256 __TM_nesting_depth (void* const __tdb_ptr)
258 int depth = __builtin_tx_nesting_depth ();
259 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
264 if (tdb->format != 1)
266 return tdb->nesting_depth;
269 /* Transaction failure diagnostics */
271 static __inline long __attribute__((__always_inline__, __nodebug__))
272 __TM_is_user_abort (void* const __tdb_ptr)
274 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
276 if (tdb->format != 1)
279 return !!(tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE);
282 static __inline long __attribute__((__always_inline__, __nodebug__))
283 __TM_is_named_user_abort (void* const __tdb_ptr, unsigned char* __code)
285 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
287 if (tdb->format != 1)
290 if (tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE)
292 *__code = tdb->abort_code - _HTM_FIRST_USER_ABORT_CODE;
298 static __inline long __attribute__((__always_inline__, __nodebug__))
299 __TM_is_illegal (void* const __tdb_ptr)
301 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
303 return (tdb->format == 1
304 && (tdb->abort_code == 4 /* unfiltered program interruption */
305 || tdb->abort_code == 11 /* restricted instruction */));
308 static __inline long __attribute__((__always_inline__, __nodebug__))
309 __TM_is_footprint_exceeded (void* const __tdb_ptr)
311 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
313 return (tdb->format == 1
314 && (tdb->abort_code == 7 /* fetch overflow */
315 || tdb->abort_code == 8 /* store overflow */));
318 static __inline long __attribute__((__always_inline__, __nodebug__))
319 __TM_is_nested_too_deep (void* const __tdb_ptr)
321 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
323 return tdb->format == 1 && tdb->abort_code == 13; /* depth exceeded */
326 static __inline long __attribute__((__always_inline__, __nodebug__))
327 __TM_is_conflict (void* const __tdb_ptr)
329 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
331 return (tdb->format == 1
332 && (tdb->abort_code == 9 /* fetch conflict */
333 || tdb->abort_code == 10 /* store conflict */));
336 static __inline long __attribute__((__always_inline__, __nodebug__))
337 __TM_is_failure_persistent (long const __result)
339 return __result == _HTM_TBEGIN_PERSISTENT;
342 static __inline long __attribute__((__always_inline__, __nodebug__))
343 __TM_failure_address (void* const __tdb_ptr)
345 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
349 static __inline long __attribute__((__always_inline__, __nodebug__))
350 __TM_failure_code (void* const __tdb_ptr)
352 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
354 return tdb->abort_code;
357 #endif /* __s390__ */
359 #endif /* __HTMXLINTRIN_H */