1 /*===---- htmxlintrin.h - XL compiler HTM execution intrinsics-------------===*\
3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 * See https://llvm.org/LICENSE.txt for license information.
5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 \*===----------------------------------------------------------------------===*/
9 #ifndef __HTMXLINTRIN_H
10 #define __HTMXLINTRIN_H
13 #error "HTM instruction set not enabled"
16 #include <htmintrin.h>
24 #define _TEXASR_PTR(TM_BUF) ((texasr_t *)((char *)(TM_BUF) + 0))
25 #define _TEXASRU_PTR(TM_BUF) ((texasru_t *)((char *)(TM_BUF) + 0))
26 #define _TEXASRL_PTR(TM_BUF) ((texasrl_t *)((char *)(TM_BUF) + 4))
27 #define _TFIAR_PTR(TM_BUF) ((tfiar_t *)((char *)(TM_BUF) + 8))
29 typedef char TM_buff_type[16];
31 /* This macro can be used to determine whether a transaction was successfully
32 started from the __TM_begin() and __TM_simple_begin() intrinsic functions
34 #define _HTM_TBEGIN_STARTED 1
37 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
38 __TM_simple_begin (void)
40 if (__builtin_expect (__builtin_tbegin (0), 1))
41 return _HTM_TBEGIN_STARTED;
46 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
47 __TM_begin (void* const __TM_buff)
49 *_TEXASRL_PTR (__TM_buff) = 0;
50 if (__builtin_expect (__builtin_tbegin (0), 1))
51 return _HTM_TBEGIN_STARTED;
53 *_TEXASR_PTR (__TM_buff) = __builtin_get_texasr ();
55 *_TEXASRU_PTR (__TM_buff) = __builtin_get_texasru ();
56 *_TEXASRL_PTR (__TM_buff) = __builtin_get_texasr ();
58 *_TFIAR_PTR (__TM_buff) = __builtin_get_tfiar ();
63 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
66 if (__builtin_expect (__builtin_tend (0), 1))
72 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
79 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
80 __TM_named_abort (unsigned char const __code)
82 __builtin_tabort (__code);
86 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
93 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
96 __builtin_tsuspend ();
100 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
101 __TM_is_user_abort (void* const __TM_buff)
103 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
104 return _TEXASRU_ABORT (texasru);
108 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
109 __TM_is_named_user_abort (void* const __TM_buff, unsigned char *__code)
111 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
113 *__code = _TEXASRU_FAILURE_CODE (texasru);
114 return _TEXASRU_ABORT (texasru);
118 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
119 __TM_is_illegal (void* const __TM_buff)
121 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
122 return _TEXASRU_DISALLOWED (texasru);
126 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
127 __TM_is_footprint_exceeded (void* const __TM_buff)
129 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
130 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);
134 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
135 __TM_nesting_depth (void* const __TM_buff)
139 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)
141 texasrl = *_TEXASRL_PTR (__TM_buff);
142 if (!_TEXASR_FAILURE_SUMMARY (texasrl))
146 texasrl = (texasrl_t) __builtin_get_texasr ();
148 return _TEXASR_TRANSACTION_LEVEL (texasrl);
152 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
153 __TM_is_nested_too_deep(void* const __TM_buff)
155 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
156 return _TEXASRU_NESTING_OVERFLOW (texasru);
160 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
161 __TM_is_conflict(void* const __TM_buff)
163 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
164 /* Return TEXASR bits 11 (Self-Induced Conflict) through
165 14 (Translation Invalidation Conflict). */
166 return (_TEXASRU_EXTRACT_BITS (texasru, 14, 4)) ? 1 : 0;
170 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
171 __TM_is_failure_persistent(void* const __TM_buff)
173 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
174 return _TEXASRU_FAILURE_PERSISTENT (texasru);
178 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
179 __TM_failure_address(void* const __TM_buff)
181 return *_TFIAR_PTR (__TM_buff);
184 extern __inline long long
185 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
186 __TM_failure_code(void* const __TM_buff)
188 return *_TEXASR_PTR (__TM_buff);
195 #endif /* __powerpc__ */
201 /* These intrinsics are being made available for compatibility with
202 the IBM XL compiler. For documentation please see the "z/OS XL
203 C/C++ Programming Guide" publicly available on the web. */
205 static __inline long __attribute__((__always_inline__, __nodebug__))
208 return __builtin_tbegin_nofloat (0);
211 static __inline long __attribute__((__always_inline__, __nodebug__))
212 __TM_begin (void* const __tdb)
214 return __builtin_tbegin_nofloat (__tdb);
217 static __inline long __attribute__((__always_inline__, __nodebug__))
220 return __builtin_tend ();
223 static __inline void __attribute__((__always_inline__))
226 return __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE);
229 static __inline void __attribute__((__always_inline__, __nodebug__))
230 __TM_named_abort (unsigned char const __code)
232 return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE + __code);
235 static __inline void __attribute__((__always_inline__, __nodebug__))
236 __TM_non_transactional_store (void* const __addr, long long const __value)
238 __builtin_non_tx_store ((uint64_t*)__addr, (uint64_t)__value);
241 static __inline long __attribute__((__always_inline__, __nodebug__))
242 __TM_nesting_depth (void* const __tdb_ptr)
244 int depth = __builtin_tx_nesting_depth ();
245 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
250 if (tdb->format != 1)
252 return tdb->nesting_depth;
255 /* Transaction failure diagnostics */
257 static __inline long __attribute__((__always_inline__, __nodebug__))
258 __TM_is_user_abort (void* const __tdb_ptr)
260 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
262 if (tdb->format != 1)
265 return !!(tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE);
268 static __inline long __attribute__((__always_inline__, __nodebug__))
269 __TM_is_named_user_abort (void* const __tdb_ptr, unsigned char* __code)
271 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
273 if (tdb->format != 1)
276 if (tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE)
278 *__code = tdb->abort_code - _HTM_FIRST_USER_ABORT_CODE;
284 static __inline long __attribute__((__always_inline__, __nodebug__))
285 __TM_is_illegal (void* const __tdb_ptr)
287 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
289 return (tdb->format == 1
290 && (tdb->abort_code == 4 /* unfiltered program interruption */
291 || tdb->abort_code == 11 /* restricted instruction */));
294 static __inline long __attribute__((__always_inline__, __nodebug__))
295 __TM_is_footprint_exceeded (void* const __tdb_ptr)
297 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
299 return (tdb->format == 1
300 && (tdb->abort_code == 7 /* fetch overflow */
301 || tdb->abort_code == 8 /* store overflow */));
304 static __inline long __attribute__((__always_inline__, __nodebug__))
305 __TM_is_nested_too_deep (void* const __tdb_ptr)
307 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
309 return tdb->format == 1 && tdb->abort_code == 13; /* depth exceeded */
312 static __inline long __attribute__((__always_inline__, __nodebug__))
313 __TM_is_conflict (void* const __tdb_ptr)
315 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
317 return (tdb->format == 1
318 && (tdb->abort_code == 9 /* fetch conflict */
319 || tdb->abort_code == 10 /* store conflict */));
322 static __inline long __attribute__((__always_inline__, __nodebug__))
323 __TM_is_failure_persistent (long const __result)
325 return __result == _HTM_TBEGIN_PERSISTENT;
328 static __inline long __attribute__((__always_inline__, __nodebug__))
329 __TM_failure_address (void* const __tdb_ptr)
331 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
335 static __inline long __attribute__((__always_inline__, __nodebug__))
336 __TM_failure_code (void* const __tdb_ptr)
338 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
340 return tdb->abort_code;
343 #endif /* __s390__ */
345 #endif /* __HTMXLINTRIN_H */