[gcc]
[official-gcc.git] / gcc / config / rs6000 / htmxlintrin.h
blob38dc066d30e65b75e2a070a15fb46609f7deb853
1 /* XL compiler Hardware Transactional Memory (HTM) execution intrinsics.
2 Copyright (C) 2013-2014 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)
8 any later version.
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
13 for more details.
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/>. */
24 #ifndef __HTM__
25 # error "HTM instruction set not enabled"
26 #endif /* __HTM__ */
28 #ifndef _HTMXLINTRIN_H
29 #define _HTMXLINTRIN_H
31 #include <stdint.h>
32 #include <htmintrin.h>
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
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 extern __inline long
50 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
51 __TM_simple_begin (void)
53 if (__builtin_expect (__builtin_tbegin (0), 1))
54 return 1;
55 return 0;
58 extern __inline long
59 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
60 __TM_begin (void* const TM_buff)
62 *_TEXASRL_PTR (TM_buff) = 0;
63 if (__builtin_expect (__builtin_tbegin (0), 1))
64 return 1;
65 #ifdef __powerpc64__
66 *_TEXASR_PTR (TM_buff) = __builtin_get_texasr ();
67 #else
68 *_TEXASRU_PTR (TM_buff) = __builtin_get_texasru ();
69 *_TEXASRL_PTR (TM_buff) = __builtin_get_texasr ();
70 #endif
71 *_TFIAR_PTR (TM_buff) = __builtin_get_tfiar ();
72 return 0;
75 extern __inline long
76 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
77 __TM_end (void)
79 if (__builtin_expect (__builtin_tend (0), 1))
80 return 1;
81 return 0;
84 extern __inline void
85 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
86 __TM_abort (void)
88 __builtin_tabort (0);
91 extern __inline void
92 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
93 __TM_named_abort (unsigned char const code)
95 __builtin_tabort (code);
98 extern __inline void
99 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
100 __TM_resume (void)
102 __builtin_tresume ();
105 extern __inline void
106 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
107 __TM_suspend (void)
109 __builtin_tsuspend ();
112 extern __inline long
113 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
114 __TM_is_user_abort (void* const TM_buff)
116 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
117 return _TEXASRU_ABORT (texasru);
120 extern __inline long
121 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
122 __TM_is_named_user_abort (void* const TM_buff, unsigned char *code)
124 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
126 *code = _TEXASRU_FAILURE_CODE (texasru);
127 return _TEXASRU_ABORT (texasru);
130 extern __inline long
131 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
132 __TM_is_illegal (void* const TM_buff)
134 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
135 return _TEXASRU_DISALLOWED (texasru);
138 extern __inline long
139 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
140 __TM_is_footprint_exceeded (void* const TM_buff)
142 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
143 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);
146 extern __inline long
147 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
148 __TM_nesting_depth (void* const TM_buff)
150 texasrl_t texasrl;
152 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)
154 texasrl = *_TEXASRL_PTR (TM_buff);
155 if (!_TEXASR_FAILURE_SUMMARY (texasrl))
156 texasrl = 0;
158 else
159 texasrl = (texasrl_t) __builtin_get_texasr ();
161 return _TEXASR_TRANSACTION_LEVEL (texasrl);
164 extern __inline long
165 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
166 __TM_is_nested_too_deep(void* const TM_buff)
168 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
169 return _TEXASRU_NESTING_OVERFLOW (texasru);
172 extern __inline long
173 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
174 __TM_is_conflict(void* const TM_buff)
176 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
177 /* Return TEXASR bits 11 (Self-Induced Conflict) through
178 14 (Translation Invalidation Conflict). */
179 return (_TEXASRU_EXTRACT_BITS (texasru, 14, 4)) ? 1 : 0;
182 extern __inline long
183 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
184 __TM_is_failure_persistent(void* const TM_buff)
186 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
187 return _TEXASRU_FAILURE_PERSISTENT (texasru);
190 extern __inline long
191 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
192 __TM_failure_address(void* const TM_buff)
194 return *_TFIAR_PTR (TM_buff);
197 extern __inline long long
198 __attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
199 __TM_failure_code(void* const TM_buff)
201 return *_TEXASR_PTR (TM_buff);
204 #ifdef __cplusplus
206 #endif
208 #endif /* _HTMXLINTRIN_H */