blob: 28f7d025bb307ece1822f898d53a24265382f77f [file] [log] [blame]
Kit Barton8246f282015-03-25 19:41:41 +00001/*===---- 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
23#ifndef __HTMXLINTRIN_H
24#define __HTMXLINTRIN_H
25
26#ifndef __HTM__
27#error "HTM instruction set not enabled"
28#endif
29
30#include <htmintrin.h>
31
32#ifdef __powerpc__
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
Eric Christopher5ba576f2017-03-20 22:31:33 +000038#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))
Kit Barton8246f282015-03-25 19:41:41 +000042
43typedef char TM_buff_type[16];
44
Sean Silvae4c37602015-09-12 02:55:19 +000045/* This macro can be used to determine whether a transaction was successfully
Kit Barton8246f282015-03-25 19:41:41 +000046 started from the __TM_begin() and __TM_simple_begin() intrinsic functions
47 below. */
48#define _HTM_TBEGIN_STARTED 1
49
50extern __inline long
51__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
52__TM_simple_begin (void)
53{
54 if (__builtin_expect (__builtin_tbegin (0), 1))
55 return _HTM_TBEGIN_STARTED;
56 return 0;
57}
58
59extern __inline long
60__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +000061__TM_begin (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +000062{
Eric Christopher39a84d02016-02-12 02:22:53 +000063 *_TEXASRL_PTR (__TM_buff) = 0;
Kit Barton8246f282015-03-25 19:41:41 +000064 if (__builtin_expect (__builtin_tbegin (0), 1))
65 return _HTM_TBEGIN_STARTED;
66#ifdef __powerpc64__
Eric Christopher39a84d02016-02-12 02:22:53 +000067 *_TEXASR_PTR (__TM_buff) = __builtin_get_texasr ();
Kit Barton8246f282015-03-25 19:41:41 +000068#else
Eric Christopher39a84d02016-02-12 02:22:53 +000069 *_TEXASRU_PTR (__TM_buff) = __builtin_get_texasru ();
70 *_TEXASRL_PTR (__TM_buff) = __builtin_get_texasr ();
Kit Barton8246f282015-03-25 19:41:41 +000071#endif
Eric Christopher39a84d02016-02-12 02:22:53 +000072 *_TFIAR_PTR (__TM_buff) = __builtin_get_tfiar ();
Kit Barton8246f282015-03-25 19:41:41 +000073 return 0;
74}
75
76extern __inline long
77__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
78__TM_end (void)
79{
80 if (__builtin_expect (__builtin_tend (0), 1))
81 return 1;
82 return 0;
83}
84
85extern __inline void
86__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
87__TM_abort (void)
88{
89 __builtin_tabort (0);
90}
91
92extern __inline void
93__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +000094__TM_named_abort (unsigned char const __code)
Kit Barton8246f282015-03-25 19:41:41 +000095{
Eric Christopher39a84d02016-02-12 02:22:53 +000096 __builtin_tabort (__code);
Kit Barton8246f282015-03-25 19:41:41 +000097}
98
99extern __inline void
100__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
101__TM_resume (void)
102{
103 __builtin_tresume ();
104}
105
106extern __inline void
107__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
108__TM_suspend (void)
109{
110 __builtin_tsuspend ();
111}
112
113extern __inline long
114__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000115__TM_is_user_abort (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000116{
Eric Christopher39a84d02016-02-12 02:22:53 +0000117 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000118 return _TEXASRU_ABORT (texasru);
119}
120
121extern __inline long
122__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000123__TM_is_named_user_abort (void* const __TM_buff, unsigned char *__code)
Kit Barton8246f282015-03-25 19:41:41 +0000124{
Eric Christopher39a84d02016-02-12 02:22:53 +0000125 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000126
Eric Christopher39a84d02016-02-12 02:22:53 +0000127 *__code = _TEXASRU_FAILURE_CODE (texasru);
Kit Barton8246f282015-03-25 19:41:41 +0000128 return _TEXASRU_ABORT (texasru);
129}
130
131extern __inline long
132__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000133__TM_is_illegal (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000134{
Eric Christopher39a84d02016-02-12 02:22:53 +0000135 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000136 return _TEXASRU_DISALLOWED (texasru);
137}
138
139extern __inline long
140__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000141__TM_is_footprint_exceeded (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000142{
Eric Christopher39a84d02016-02-12 02:22:53 +0000143 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000144 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);
145}
146
147extern __inline long
148__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000149__TM_nesting_depth (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000150{
151 texasrl_t texasrl;
152
153 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)
154 {
Eric Christopher39a84d02016-02-12 02:22:53 +0000155 texasrl = *_TEXASRL_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000156 if (!_TEXASR_FAILURE_SUMMARY (texasrl))
157 texasrl = 0;
158 }
159 else
160 texasrl = (texasrl_t) __builtin_get_texasr ();
161
162 return _TEXASR_TRANSACTION_LEVEL (texasrl);
163}
164
165extern __inline long
166__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000167__TM_is_nested_too_deep(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000168{
Eric Christopher39a84d02016-02-12 02:22:53 +0000169 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000170 return _TEXASRU_NESTING_OVERFLOW (texasru);
171}
172
173extern __inline long
174__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000175__TM_is_conflict(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000176{
Eric Christopher5ba576f2017-03-20 22:31:33 +0000177 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000178 /* Return TEXASR bits 11 (Self-Induced Conflict) through
179 14 (Translation Invalidation Conflict). */
180 return (_TEXASRU_EXTRACT_BITS (texasru, 14, 4)) ? 1 : 0;
181}
182
183extern __inline long
184__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000185__TM_is_failure_persistent(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000186{
Eric Christopher39a84d02016-02-12 02:22:53 +0000187 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000188 return _TEXASRU_FAILURE_PERSISTENT (texasru);
189}
190
191extern __inline long
192__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000193__TM_failure_address(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000194{
Eric Christopher39a84d02016-02-12 02:22:53 +0000195 return *_TFIAR_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000196}
197
198extern __inline long long
199__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000200__TM_failure_code(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000201{
Eric Christopher39a84d02016-02-12 02:22:53 +0000202 return *_TEXASR_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000203}
204
205#ifdef __cplusplus
206}
207#endif
208
209#endif /* __powerpc__ */
210
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000211#ifdef __s390__
212
213#include <stdint.h>
214
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. */
218
219static __inline long __attribute__((__always_inline__, __nodebug__))
220__TM_simple_begin ()
221{
222 return __builtin_tbegin_nofloat (0);
223}
224
225static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000226__TM_begin (void* const __tdb)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000227{
Eric Christopher39a84d02016-02-12 02:22:53 +0000228 return __builtin_tbegin_nofloat (__tdb);
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000229}
230
231static __inline long __attribute__((__always_inline__, __nodebug__))
232__TM_end ()
233{
234 return __builtin_tend ();
235}
236
237static __inline void __attribute__((__always_inline__))
238__TM_abort ()
239{
240 return __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE);
241}
242
243static __inline void __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000244__TM_named_abort (unsigned char const __code)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000245{
Eric Christopher39a84d02016-02-12 02:22:53 +0000246 return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE + __code);
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000247}
248
249static __inline void __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000250__TM_non_transactional_store (void* const __addr, long long const __value)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000251{
Eric Christopher39a84d02016-02-12 02:22:53 +0000252 __builtin_non_tx_store ((uint64_t*)__addr, (uint64_t)__value);
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000253}
254
255static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000256__TM_nesting_depth (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000257{
258 int depth = __builtin_tx_nesting_depth ();
Eric Christopher39a84d02016-02-12 02:22:53 +0000259 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000260
261 if (depth != 0)
262 return depth;
263
264 if (tdb->format != 1)
265 return 0;
266 return tdb->nesting_depth;
267}
268
269/* Transaction failure diagnostics */
270
271static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000272__TM_is_user_abort (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000273{
Eric Christopher39a84d02016-02-12 02:22:53 +0000274 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000275
276 if (tdb->format != 1)
277 return 0;
278
279 return !!(tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE);
280}
281
282static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000283__TM_is_named_user_abort (void* const __tdb_ptr, unsigned char* __code)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000284{
Eric Christopher39a84d02016-02-12 02:22:53 +0000285 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000286
287 if (tdb->format != 1)
288 return 0;
289
290 if (tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE)
291 {
Eric Christopher39a84d02016-02-12 02:22:53 +0000292 *__code = tdb->abort_code - _HTM_FIRST_USER_ABORT_CODE;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000293 return 1;
294 }
295 return 0;
296}
297
298static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000299__TM_is_illegal (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000300{
Eric Christopher39a84d02016-02-12 02:22:53 +0000301 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000302
303 return (tdb->format == 1
304 && (tdb->abort_code == 4 /* unfiltered program interruption */
305 || tdb->abort_code == 11 /* restricted instruction */));
306}
307
308static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000309__TM_is_footprint_exceeded (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000310{
Eric Christopher39a84d02016-02-12 02:22:53 +0000311 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000312
313 return (tdb->format == 1
314 && (tdb->abort_code == 7 /* fetch overflow */
315 || tdb->abort_code == 8 /* store overflow */));
316}
317
318static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000319__TM_is_nested_too_deep (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000320{
Eric Christopher39a84d02016-02-12 02:22:53 +0000321 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000322
323 return tdb->format == 1 && tdb->abort_code == 13; /* depth exceeded */
324}
325
326static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000327__TM_is_conflict (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000328{
Eric Christopher39a84d02016-02-12 02:22:53 +0000329 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000330
331 return (tdb->format == 1
332 && (tdb->abort_code == 9 /* fetch conflict */
333 || tdb->abort_code == 10 /* store conflict */));
334}
335
336static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000337__TM_is_failure_persistent (long const __result)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000338{
Eric Christopher39a84d02016-02-12 02:22:53 +0000339 return __result == _HTM_TBEGIN_PERSISTENT;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000340}
341
342static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000343__TM_failure_address (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000344{
Eric Christopher39a84d02016-02-12 02:22:53 +0000345 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000346 return tdb->atia;
347}
348
349static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000350__TM_failure_code (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000351{
Eric Christopher39a84d02016-02-12 02:22:53 +0000352 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000353
354 return tdb->abort_code;
355}
356
357#endif /* __s390__ */
358
Kit Barton8246f282015-03-25 19:41:41 +0000359#endif /* __HTMXLINTRIN_H */