]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/rs6000/htmxlintrin.h
[simplify-rtx][trivial] Use std::swap instead of manually swapping
[thirdparty/gcc.git] / gcc / config / rs6000 / htmxlintrin.h
CommitLineData
0258b6e4 1/* XL compiler Hardware Transactional Memory (HTM) execution intrinsics.
5624e564 2 Copyright (C) 2013-2015 Free Software Foundation, Inc.
0258b6e4
PB
3 Contributed by Peter Bergner <bergner@vnet.ibm.com>.
4
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.
9
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.
14
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.
18
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/>. */
23
24#ifndef __HTM__
25# error "HTM instruction set not enabled"
26#endif /* __HTM__ */
27
28#ifndef _HTMXLINTRIN_H
29#define _HTMXLINTRIN_H
30
31#include <stdint.h>
32#include <htmintrin.h>
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
d8c55b91
PB
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
53
0258b6e4
PB
54extern __inline long
55__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
56__TM_simple_begin (void)
57{
58 if (__builtin_expect (__builtin_tbegin (0), 1))
d8c55b91 59 return _HTM_TBEGIN_STARTED;
0258b6e4
PB
60 return 0;
61}
62
63extern __inline long
64__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
65__TM_begin (void* const TM_buff)
66{
67 *_TEXASRL_PTR (TM_buff) = 0;
68 if (__builtin_expect (__builtin_tbegin (0), 1))
d8c55b91 69 return _HTM_TBEGIN_STARTED;
0258b6e4
PB
70#ifdef __powerpc64__
71 *_TEXASR_PTR (TM_buff) = __builtin_get_texasr ();
72#else
73 *_TEXASRU_PTR (TM_buff) = __builtin_get_texasru ();
74 *_TEXASRL_PTR (TM_buff) = __builtin_get_texasr ();
75#endif
76 *_TFIAR_PTR (TM_buff) = __builtin_get_tfiar ();
77 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__))
98__TM_named_abort (unsigned char const code)
99{
100 __builtin_tabort (code);
101}
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__))
119__TM_is_user_abort (void* const TM_buff)
120{
121 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
122 return _TEXASRU_ABORT (texasru);
123}
124
125extern __inline long
126__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
127__TM_is_named_user_abort (void* const TM_buff, unsigned char *code)
128{
129 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
130
131 *code = _TEXASRU_FAILURE_CODE (texasru);
132 return _TEXASRU_ABORT (texasru);
133}
134
135extern __inline long
136__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
137__TM_is_illegal (void* const TM_buff)
138{
139 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
140 return _TEXASRU_DISALLOWED (texasru);
141}
142
143extern __inline long
144__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
145__TM_is_footprint_exceeded (void* const TM_buff)
146{
147 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
148 return _TEXASRU_FOOTPRINT_OVERFLOW (texasru);
149}
150
151extern __inline long
152__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
153__TM_nesting_depth (void* const TM_buff)
154{
155 texasrl_t texasrl;
156
157 if (_HTM_STATE (__builtin_ttest ()) == _HTM_NONTRANSACTIONAL)
158 {
159 texasrl = *_TEXASRL_PTR (TM_buff);
160 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__))
171__TM_is_nested_too_deep(void* const TM_buff)
172{
173 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
174 return _TEXASRU_NESTING_OVERFLOW (texasru);
175}
176
177extern __inline long
178__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
179__TM_is_conflict(void* const TM_buff)
180{
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__))
189__TM_is_failure_persistent(void* const TM_buff)
190{
191 texasru_t texasru = *_TEXASRU_PTR (TM_buff);
192 return _TEXASRU_FAILURE_PERSISTENT (texasru);
193}
194
195extern __inline long
196__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
197__TM_failure_address(void* const TM_buff)
198{
199 return *_TFIAR_PTR (TM_buff);
200}
201
202extern __inline long long
203__attribute__ ((__gnu_inline__, __always_inline__, __artificial__))
204__TM_failure_code(void* const TM_buff)
205{
206 return *_TEXASR_PTR (TM_buff);
207}
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif /* _HTMXLINTRIN_H */