blob: 16dc7056c6b08c751902c6c5d241ab059d31ed00 [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
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))
46
47typedef char TM_buff_type[16];
48
Sean Silvae4c37602015-09-12 02:55:19 +000049/* This macro can be used to determine whether a transaction was successfully
Kit Barton8246f282015-03-25 19:41:41 +000050 started from the __TM_begin() and __TM_simple_begin() intrinsic functions
51 below. */
52#define _HTM_TBEGIN_STARTED 1
53
54extern __inline long
55__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
56__TM_simple_begin (void)
57{
58 if (__builtin_expect (__builtin_tbegin (0), 1))
59 return _HTM_TBEGIN_STARTED;
60 return 0;
61}
62
63extern __inline long
64__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +000065__TM_begin (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +000066{
Eric Christopher39a84d02016-02-12 02:22:53 +000067 *_TEXASRL_PTR (__TM_buff) = 0;
Kit Barton8246f282015-03-25 19:41:41 +000068 if (__builtin_expect (__builtin_tbegin (0), 1))
69 return _HTM_TBEGIN_STARTED;
70#ifdef __powerpc64__
Eric Christopher39a84d02016-02-12 02:22:53 +000071 *_TEXASR_PTR (__TM_buff) = __builtin_get_texasr ();
Kit Barton8246f282015-03-25 19:41:41 +000072#else
Eric Christopher39a84d02016-02-12 02:22:53 +000073 *_TEXASRU_PTR (__TM_buff) = __builtin_get_texasru ();
74 *_TEXASRL_PTR (__TM_buff) = __builtin_get_texasr ();
Kit Barton8246f282015-03-25 19:41:41 +000075#endif
Eric Christopher39a84d02016-02-12 02:22:53 +000076 *_TFIAR_PTR (__TM_buff) = __builtin_get_tfiar ();
Kit Barton8246f282015-03-25 19:41:41 +000077 return 0;
78}
79
80extern __inline long
81__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
82__TM_end (void)
83{
84 if (__builtin_expect (__builtin_tend (0), 1))
85 return 1;
86 return 0;
87}
88
89extern __inline void
90__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
91__TM_abort (void)
92{
93 __builtin_tabort (0);
94}
95
96extern __inline void
97__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +000098__TM_named_abort (unsigned char const __code)
Kit Barton8246f282015-03-25 19:41:41 +000099{
Eric Christopher39a84d02016-02-12 02:22:53 +0000100 __builtin_tabort (__code);
Kit Barton8246f282015-03-25 19:41:41 +0000101}
102
103extern __inline void
104__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
105__TM_resume (void)
106{
107 __builtin_tresume ();
108}
109
110extern __inline void
111__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
112__TM_suspend (void)
113{
114 __builtin_tsuspend ();
115}
116
117extern __inline long
118__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000119__TM_is_user_abort (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000120{
Eric Christopher39a84d02016-02-12 02:22:53 +0000121 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000122 return _TEXASRU_ABORT (texasru);
123}
124
125extern __inline long
126__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000127__TM_is_named_user_abort (void* const __TM_buff, unsigned char *__code)
Kit Barton8246f282015-03-25 19:41:41 +0000128{
Eric Christopher39a84d02016-02-12 02:22:53 +0000129 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000130
Eric Christopher39a84d02016-02-12 02:22:53 +0000131 *__code = _TEXASRU_FAILURE_CODE (texasru);
Kit Barton8246f282015-03-25 19:41:41 +0000132 return _TEXASRU_ABORT (texasru);
133}
134
135extern __inline long
136__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000137__TM_is_illegal (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000138{
Eric Christopher39a84d02016-02-12 02:22:53 +0000139 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000140 return _TEXASRU_DISALLOWED (texasru);
141}
142
143extern __inline long
144__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000145__TM_is_footprint_exceeded (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000146{
Eric Christopher39a84d02016-02-12 02:22:53 +0000147 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000148 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);
149}
150
151extern __inline long
152__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000153__TM_nesting_depth (void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000154{
155 texasrl_t texasrl;
156
157 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)
158 {
Eric Christopher39a84d02016-02-12 02:22:53 +0000159 texasrl = *_TEXASRL_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000160 if (!_TEXASR_FAILURE_SUMMARY (texasrl))
161 texasrl = 0;
162 }
163 else
164 texasrl = (texasrl_t) __builtin_get_texasr ();
165
166 return _TEXASR_TRANSACTION_LEVEL (texasrl);
167}
168
169extern __inline long
170__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000171__TM_is_nested_too_deep(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000172{
Eric Christopher39a84d02016-02-12 02:22:53 +0000173 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000174 return _TEXASRU_NESTING_OVERFLOW (texasru);
175}
176
177extern __inline long
178__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000179__TM_is_conflict(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000180{
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;
185}
186
187extern __inline long
188__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000189__TM_is_failure_persistent(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000190{
Eric Christopher39a84d02016-02-12 02:22:53 +0000191 texasru_t texasru = *_TEXASRU_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000192 return _TEXASRU_FAILURE_PERSISTENT (texasru);
193}
194
195extern __inline long
196__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000197__TM_failure_address(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000198{
Eric Christopher39a84d02016-02-12 02:22:53 +0000199 return *_TFIAR_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000200}
201
202extern __inline long long
203__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000204__TM_failure_code(void* const __TM_buff)
Kit Barton8246f282015-03-25 19:41:41 +0000205{
Eric Christopher39a84d02016-02-12 02:22:53 +0000206 return *_TEXASR_PTR (__TM_buff);
Kit Barton8246f282015-03-25 19:41:41 +0000207}
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif /* __powerpc__ */
214
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000215#ifdef __s390__
216
217#include <stdint.h>
218
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. */
222
223static __inline long __attribute__((__always_inline__, __nodebug__))
224__TM_simple_begin ()
225{
226 return __builtin_tbegin_nofloat (0);
227}
228
229static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000230__TM_begin (void* const __tdb)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000231{
Eric Christopher39a84d02016-02-12 02:22:53 +0000232 return __builtin_tbegin_nofloat (__tdb);
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000233}
234
235static __inline long __attribute__((__always_inline__, __nodebug__))
236__TM_end ()
237{
238 return __builtin_tend ();
239}
240
241static __inline void __attribute__((__always_inline__))
242__TM_abort ()
243{
244 return __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE);
245}
246
247static __inline void __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000248__TM_named_abort (unsigned char const __code)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000249{
Eric Christopher39a84d02016-02-12 02:22:53 +0000250 return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE + __code);
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000251}
252
253static __inline void __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000254__TM_non_transactional_store (void* const __addr, long long const __value)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000255{
Eric Christopher39a84d02016-02-12 02:22:53 +0000256 __builtin_non_tx_store ((uint64_t*)__addr, (uint64_t)__value);
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000257}
258
259static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000260__TM_nesting_depth (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000261{
262 int depth = __builtin_tx_nesting_depth ();
Eric Christopher39a84d02016-02-12 02:22:53 +0000263 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000264
265 if (depth != 0)
266 return depth;
267
268 if (tdb->format != 1)
269 return 0;
270 return tdb->nesting_depth;
271}
272
273/* Transaction failure diagnostics */
274
275static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000276__TM_is_user_abort (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000277{
Eric Christopher39a84d02016-02-12 02:22:53 +0000278 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000279
280 if (tdb->format != 1)
281 return 0;
282
283 return !!(tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE);
284}
285
286static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000287__TM_is_named_user_abort (void* const __tdb_ptr, unsigned char* __code)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000288{
Eric Christopher39a84d02016-02-12 02:22:53 +0000289 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000290
291 if (tdb->format != 1)
292 return 0;
293
294 if (tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE)
295 {
Eric Christopher39a84d02016-02-12 02:22:53 +0000296 *__code = tdb->abort_code - _HTM_FIRST_USER_ABORT_CODE;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000297 return 1;
298 }
299 return 0;
300}
301
302static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000303__TM_is_illegal (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000304{
Eric Christopher39a84d02016-02-12 02:22:53 +0000305 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000306
307 return (tdb->format == 1
308 && (tdb->abort_code == 4 /* unfiltered program interruption */
309 || tdb->abort_code == 11 /* restricted instruction */));
310}
311
312static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000313__TM_is_footprint_exceeded (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000314{
Eric Christopher39a84d02016-02-12 02:22:53 +0000315 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000316
317 return (tdb->format == 1
318 && (tdb->abort_code == 7 /* fetch overflow */
319 || tdb->abort_code == 8 /* store overflow */));
320}
321
322static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000323__TM_is_nested_too_deep (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000324{
Eric Christopher39a84d02016-02-12 02:22:53 +0000325 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000326
327 return tdb->format == 1 && tdb->abort_code == 13; /* depth exceeded */
328}
329
330static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000331__TM_is_conflict (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000332{
Eric Christopher39a84d02016-02-12 02:22:53 +0000333 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000334
335 return (tdb->format == 1
336 && (tdb->abort_code == 9 /* fetch conflict */
337 || tdb->abort_code == 10 /* store conflict */));
338}
339
340static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000341__TM_is_failure_persistent (long const __result)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000342{
Eric Christopher39a84d02016-02-12 02:22:53 +0000343 return __result == _HTM_TBEGIN_PERSISTENT;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000344}
345
346static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000347__TM_failure_address (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000348{
Eric Christopher39a84d02016-02-12 02:22:53 +0000349 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000350 return tdb->atia;
351}
352
353static __inline long __attribute__((__always_inline__, __nodebug__))
Eric Christopher39a84d02016-02-12 02:22:53 +0000354__TM_failure_code (void* const __tdb_ptr)
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000355{
Eric Christopher39a84d02016-02-12 02:22:53 +0000356 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr;
Ulrich Weigand3a610eb2015-04-01 12:54:25 +0000357
358 return tdb->abort_code;
359}
360
361#endif /* __s390__ */
362
Kit Barton8246f282015-03-25 19:41:41 +0000363#endif /* __HTMXLINTRIN_H */