1 /* XL compiler Hardware Transactional Memory (HTM) execution intrinsics.
2 Copyright (C) 2013-2017 Free Software Foundation, Inc.
3 Contributed by Peter Bergner <bergner@vnet.ibm.com>.
5 This file is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3 of the License, or (at your option)
10 This file is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
25 # error "HTM instruction set not enabled"
28 #ifndef _HTMXLINTRIN_H
29 #define _HTMXLINTRIN_H
32 #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 /* Compatibility macro with s390. This macro can be used to determine
50 whether a transaction was successfully started from the __TM_begin()
51 and __TM_simple_begin() intrinsic functions below. */
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 unsigned char status
= _HTM_STATE (__builtin_tend (0));
85 if (__builtin_expect (status
, _HTM_TRANSACTIONAL
))
91 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
98 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
99 __TM_named_abort (unsigned char const code
)
101 __builtin_tabort (code
);
105 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
108 __builtin_tresume ();
112 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
115 __builtin_tsuspend ();
119 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
120 __TM_is_user_abort (void* const TM_buff
)
122 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
123 return _TEXASRU_ABORT (texasru
);
127 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
128 __TM_is_named_user_abort (void* const TM_buff
, unsigned char *code
)
130 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
132 *code
= _TEXASRU_FAILURE_CODE (texasru
);
133 return _TEXASRU_ABORT (texasru
);
137 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
138 __TM_is_illegal (void* const TM_buff
)
140 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
141 return _TEXASRU_DISALLOWED (texasru
);
145 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
146 __TM_is_footprint_exceeded (void* const TM_buff
)
148 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
149 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru
);
153 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
154 __TM_nesting_depth (void* const TM_buff
)
158 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL
)
160 texasrl
= *_TEXASRL_PTR (TM_buff
);
161 if (!_TEXASR_FAILURE_SUMMARY (texasrl
))
165 texasrl
= (texasrl_t
) __builtin_get_texasr ();
167 return _TEXASR_TRANSACTION_LEVEL (texasrl
);
171 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
172 __TM_is_nested_too_deep(void* const TM_buff
)
174 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
175 return _TEXASRU_NESTING_OVERFLOW (texasru
);
179 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
180 __TM_is_conflict(void* const TM_buff
)
182 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
183 /* Return TEXASR bits 11 (Self-Induced Conflict) through
184 14 (Translation Invalidation Conflict). */
185 return (_TEXASRU_EXTRACT_BITS (texasru
, 14, 4)) ? 1 : 0;
189 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
190 __TM_is_failure_persistent(void* const TM_buff
)
192 texasru_t texasru
= *_TEXASRU_PTR (TM_buff
);
193 return _TEXASRU_FAILURE_PERSISTENT (texasru
);
197 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
198 __TM_failure_address(void* const TM_buff
)
200 return *_TFIAR_PTR (TM_buff
);
203 extern __inline
long long
204 __attribute__ ((__gnu_inline__
, __always_inline__
, __artificial__
))
205 __TM_failure_code(void* const TM_buff
)
207 return *_TEXASR_PTR (TM_buff
);
214 #endif /* _HTMXLINTRIN_H */