1/*===---- 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) ((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)) 42 43typedef char TM_buff_type[16]; 44 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 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__)) 61__TM_begin (void* const __TM_buff) 62{ 63 *_TEXASRL_PTR (__TM_buff) = 0; 64 if (__builtin_expect (__builtin_tbegin (0), 1)) 65 return _HTM_TBEGIN_STARTED; 66#ifdef __powerpc64__ 67 *_TEXASR_PTR (__TM_buff) = __builtin_get_texasr (); 68#else 69 *_TEXASRU_PTR (__TM_buff) = __builtin_get_texasru (); 70 *_TEXASRL_PTR (__TM_buff) = __builtin_get_texasr (); 71#endif 72 *_TFIAR_PTR (__TM_buff) = __builtin_get_tfiar (); 73 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__)) 94__TM_named_abort (unsigned char const __code) 95{ 96 __builtin_tabort (__code); 97} 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__)) 115__TM_is_user_abort (void* const __TM_buff) 116{ 117 texasru_t texasru = *_TEXASRU_PTR (__TM_buff); 118 return _TEXASRU_ABORT (texasru); 119} 120 121extern __inline long 122__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 123__TM_is_named_user_abort (void* const __TM_buff, unsigned char *__code) 124{ 125 texasru_t texasru = *_TEXASRU_PTR (__TM_buff); 126 127 *__code = _TEXASRU_FAILURE_CODE (texasru); 128 return _TEXASRU_ABORT (texasru); 129} 130 131extern __inline long 132__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 133__TM_is_illegal (void* const __TM_buff) 134{ 135 texasru_t texasru = *_TEXASRU_PTR (__TM_buff); 136 return _TEXASRU_DISALLOWED (texasru); 137} 138 139extern __inline long 140__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 141__TM_is_footprint_exceeded (void* const __TM_buff) 142{ 143 texasru_t texasru = *_TEXASRU_PTR (__TM_buff); 144 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru); 145} 146 147extern __inline long 148__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 149__TM_nesting_depth (void* const __TM_buff) 150{ 151 texasrl_t texasrl; 152 153 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL) 154 { 155 texasrl = *_TEXASRL_PTR (__TM_buff); 156 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__)) 167__TM_is_nested_too_deep(void* const __TM_buff) 168{ 169 texasru_t texasru = *_TEXASRU_PTR (__TM_buff); 170 return _TEXASRU_NESTING_OVERFLOW (texasru); 171} 172 173extern __inline long 174__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 175__TM_is_conflict(void* const __TM_buff) 176{ 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; 181} 182 183extern __inline long 184__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 185__TM_is_failure_persistent(void* const __TM_buff) 186{ 187 texasru_t texasru = *_TEXASRU_PTR (__TM_buff); 188 return _TEXASRU_FAILURE_PERSISTENT (texasru); 189} 190 191extern __inline long 192__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 193__TM_failure_address(void* const __TM_buff) 194{ 195 return *_TFIAR_PTR (__TM_buff); 196} 197 198extern __inline long long 199__attribute__ ((__gnu_inline__, __always_inline__, __artificial__)) 200__TM_failure_code(void* const __TM_buff) 201{ 202 return *_TEXASR_PTR (__TM_buff); 203} 204 205#ifdef __cplusplus 206} 207#endif 208 209#endif /* __powerpc__ */ 210 211#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__)) 226__TM_begin (void* const __tdb) 227{ 228 return __builtin_tbegin_nofloat (__tdb); 229} 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__)) 244__TM_named_abort (unsigned char const __code) 245{ 246 return __builtin_tabort ((int)_HTM_FIRST_USER_ABORT_CODE + __code); 247} 248 249static __inline void __attribute__((__always_inline__, __nodebug__)) 250__TM_non_transactional_store (void* const __addr, long long const __value) 251{ 252 __builtin_non_tx_store ((uint64_t*)__addr, (uint64_t)__value); 253} 254 255static __inline long __attribute__((__always_inline__, __nodebug__)) 256__TM_nesting_depth (void* const __tdb_ptr) 257{ 258 int depth = __builtin_tx_nesting_depth (); 259 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 260 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__)) 272__TM_is_user_abort (void* const __tdb_ptr) 273{ 274 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 275 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__)) 283__TM_is_named_user_abort (void* const __tdb_ptr, unsigned char* __code) 284{ 285 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 286 287 if (tdb->format != 1) 288 return 0; 289 290 if (tdb->abort_code >= _HTM_FIRST_USER_ABORT_CODE) 291 { 292 *__code = tdb->abort_code - _HTM_FIRST_USER_ABORT_CODE; 293 return 1; 294 } 295 return 0; 296} 297 298static __inline long __attribute__((__always_inline__, __nodebug__)) 299__TM_is_illegal (void* const __tdb_ptr) 300{ 301 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 302 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__)) 309__TM_is_footprint_exceeded (void* const __tdb_ptr) 310{ 311 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 312 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__)) 319__TM_is_nested_too_deep (void* const __tdb_ptr) 320{ 321 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 322 323 return tdb->format == 1 && tdb->abort_code == 13; /* depth exceeded */ 324} 325 326static __inline long __attribute__((__always_inline__, __nodebug__)) 327__TM_is_conflict (void* const __tdb_ptr) 328{ 329 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 330 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__)) 337__TM_is_failure_persistent (long const __result) 338{ 339 return __result == _HTM_TBEGIN_PERSISTENT; 340} 341 342static __inline long __attribute__((__always_inline__, __nodebug__)) 343__TM_failure_address (void* const __tdb_ptr) 344{ 345 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 346 return tdb->atia; 347} 348 349static __inline long __attribute__((__always_inline__, __nodebug__)) 350__TM_failure_code (void* const __tdb_ptr) 351{ 352 struct __htm_tdb *tdb = (struct __htm_tdb*)__tdb_ptr; 353 354 return tdb->abort_code; 355} 356 357#endif /* __s390__ */ 358 359#endif /* __HTMXLINTRIN_H */ 360