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) \
39 ((texasr_t *)((TM_BUF)+0))
40 #define _TEXASRU_PTR(TM_BUF) \
41 ((texasru_t *)((TM_BUF)+0))
42 #define _TEXASRL_PTR(TM_BUF) \
43 ((texasrl_t *)((TM_BUF)+4))
44 #define _TFIAR_PTR(TM_BUF) \
45 ((tfiar_t *)((TM_BUF)+8))
47 typedef char TM_buff_type
[16];
49 /* This macro can be used to determine whether a transaction was successfully
50 started from the __TM_begin() and __TM_simple_begin() intrinsic functions
52 #define _HTM_TBEGIN_STARTED 1
55 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
56 __TM_simple_begin (void)
58 if (__builtin_expect (__builtin_tbegin (0), 1))
59 return _HTM_TBEGIN_STARTED
;
64 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
65 __TM_begin (void* const TM_buff
)
67 *_TEXASRL_PTR (TM_buff
) = 0;
68 if (__builtin_expect (__builtin_tbegin (0), 1))
69 return _HTM_TBEGIN_STARTED
;
71 *_TEXASR_PTR (TM_buff
) = __builtin_get_texasr ();
73 *_TEXASRU_PTR (TM_buff
) = __builtin_get_texasru ();
74 *_TEXASRL_PTR (TM_buff
) = __builtin_get_texasr ();
76 *_TFIAR_PTR (TM_buff
) = __builtin_get_tfiar ();
81 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
84 if (__builtin_expect (__builtin_tend (0), 1))
90 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
97 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
98 __TM_named_abort (unsigned char const code
)
100 __builtin_tabort (code
);
104 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
107 __builtin_tresume ();
111 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
114 __builtin_tsuspend ();
118 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
119 __TM_is_user_abort (void* const TM_buff
)
121 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
122 return _TEXASRU_ABORT (texasru
);
126 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
127 __TM_is_named_user_abort (void* const TM_buff
, unsigned char *code
)
129 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
131 *code
= _TEXASRU_FAILURE_CODE (texasru
);
132 return _TEXASRU_ABORT (texasru
);
136 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
137 __TM_is_illegal (void* const TM_buff
)
139 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
140 return _TEXASRU_DISALLOWED (texasru
);
144 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
145 __TM_is_footprint_exceeded (void* const TM_buff
)
147 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
148 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru
);
152 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
153 __TM_nesting_depth (void* const TM_buff
)
157 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL
)
159 texasrl
= *_TEXASRL_PTR (TM_buff
);
160 if (!_TEXASR_FAILURE_SUMMARY (texasrl
))
164 texasrl
= (texasrl_t
) __builtin_get_texasr ();
166 return _TEXASR_TRANSACTION_LEVEL (texasrl
);
170 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
171 __TM_is_nested_too_deep(void* const TM_buff
)
173 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
174 return _TEXASRU_NESTING_OVERFLOW (texasru
);
178 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
179 __TM_is_conflict(void* const TM_buff
)
181 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
182 /* Return TEXASR bits 11 (Self-Induced Conflict) through
183 14 (Translation Invalidation Conflict). */
184 return (_TEXASRU_EXTRACT_BITS (texasru
, 14, 4)) ? 1 : 0;
188 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
189 __TM_is_failure_persistent(void* const TM_buff
)
191 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
192 return _TEXASRU_FAILURE_PERSISTENT (texasru
);
196 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
197 __TM_failure_address(void* const TM_buff
)
199 return *_TFIAR_PTR (TM_buff
);
202 extern __inline
long long
203 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
204 __TM_failure_code(void* const TM_buff
)
206 return *_TEXASR_PTR (TM_buff
);
213 #endif /* __powerpc__ */
219 /* These intrinsics are being made available for compatibility with
220 the IBM XL compiler. For documentation please see the "z/OS XL
221 C/C++ Programming Guide" publically available on the web. */
223 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
226 return __builtin_tbegin_nofloat (0);
229 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
230 __TM_begin (void* const tdb
)
232 return __builtin_tbegin_nofloat (tdb
);
235 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
238 return __builtin_tend ();
241 static __inline
void __attribute__((__always_inline__
))
244 return __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE
);
247 static __inline
void __attribute__((__always_inline__
, __nodebug__
))
248 __TM_named_abort (unsigned char const code
)
250 return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE
+ code
);
253 static __inline
void __attribute__((__always_inline__
, __nodebug__
))
254 __TM_non_transactional_store (void* const addr
, long long const value
)
256 __builtin_non_tx_store ((uint64_t*)addr
, (uint64_t)value
);
259 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
260 __TM_nesting_depth (void* const tdb_ptr
)
262 int depth
= __builtin_tx_nesting_depth ();
263 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
268 if (tdb
->format
!= 1)
270 return tdb
->nesting_depth
;
273 /* Transaction failure diagnostics */
275 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
276 __TM_is_user_abort (void* const tdb_ptr
)
278 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
280 if (tdb
->format
!= 1)
283 return !!(tdb
->abort_code
>= _HTM_FIRST_USER_ABORT_CODE
);
286 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
287 __TM_is_named_user_abort (void* const tdb_ptr
, unsigned char* code
)
289 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
291 if (tdb
->format
!= 1)
294 if (tdb
->abort_code
>= _HTM_FIRST_USER_ABORT_CODE
)
296 *code
= tdb
->abort_code
- _HTM_FIRST_USER_ABORT_CODE
;
302 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
303 __TM_is_illegal (void* const tdb_ptr
)
305 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
307 return (tdb
->format
== 1
308 && (tdb
->abort_code
== 4 /* unfiltered program interruption */
309 || tdb
->abort_code
== 11 /* restricted instruction */));
312 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
313 __TM_is_footprint_exceeded (void* const tdb_ptr
)
315 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
317 return (tdb
->format
== 1
318 && (tdb
->abort_code
== 7 /* fetch overflow */
319 || tdb
->abort_code
== 8 /* store overflow */));
322 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
323 __TM_is_nested_too_deep (void* const tdb_ptr
)
325 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
327 return tdb
->format
== 1 && tdb
->abort_code
== 13; /* depth exceeded */
330 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
331 __TM_is_conflict (void* const tdb_ptr
)
333 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
335 return (tdb
->format
== 1
336 && (tdb
->abort_code
== 9 /* fetch conflict */
337 || tdb
->abort_code
== 10 /* store conflict */));
340 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
341 __TM_is_failure_persistent (long const result
)
343 return result
== _HTM_TBEGIN_PERSISTENT
;
346 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
347 __TM_failure_address (void* const tdb_ptr
)
349 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
353 static __inline
long __attribute__((__always_inline__
, __nodebug__
))
354 __TM_failure_code (void* const tdb_ptr
)
356 struct __htm_tdb
*tdb
= (struct __htm_tdb
*)tdb_ptr
;
358 return tdb
->abort_code
;
361 #endif /* __s390__ */
363 #endif /* __HTMXLINTRIN_H */