]> git.ipfire.org Git - thirdparty/gcc.git/blame - libitm/config/powerpc/target.h
Update copyright years in libitm/
[thirdparty/gcc.git] / libitm / config / powerpc / target.h
CommitLineData
f93608e6 1/* Copyright (C) 2012-2014 Free Software Foundation, Inc.
a32e5e93
RH
2 Contributed by Richard Henderson <rth@redhat.com>.
3
4 This file is part of the GNU Transactional Memory Library (libitm).
5
6 Libitm is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
24
0258b6e4
PB
25#ifdef HAVE_SYS_AUXV_H
26#include <sys/auxv.h>
27#endif
28
a32e5e93
RH
29namespace GTM HIDDEN {
30
31typedef int v128 __attribute__((vector_size(16), may_alias, aligned(16)));
32typedef struct gtm_jmpbuf
33{
34#if defined(__ALTIVEC__) || defined(__VSX__)
35 v128 vr[12]; /* vr20-vr31 */
36 unsigned long long vscr; /* long long for padding only */
37#endif
38#ifndef _SOFT_FLOAT
39 double fr[18]; /* f14-f31 */
40 double fpscr;
41#endif
42 unsigned long gr[18]; /* r14-r31 */
43 void *cfa;
44 unsigned long pc;
45 unsigned long toc; /* r2 on aix, r13 on darwin */
46 unsigned long cr;
47} gtm_jmpbuf;
48
49/* The size of one line in hardware caches (in bytes). */
50#if defined (__powerpc64__) || defined (__ppc64__)
51# define HW_CACHELINE_SIZE 128
52#else
53# define HW_CACHELINE_SIZE 32
54#endif
55
56static inline void
57cpu_relax (void)
58{
59 __asm volatile ("" : : : "memory");
60}
61
0258b6e4
PB
62// Use HTM if it is supported by the system.
63// See gtm_thread::begin_transaction for how these functions are used.
64#if defined (__linux__) \
65 && defined (HAVE_AS_HTM) \
66 && defined (HAVE_GETAUXVAL) \
67 && defined (AT_HWCAP2) \
68 && defined (PPC_FEATURE2_HAS_HTM)
69
70#include <htmintrin.h>
71
72#define USE_HTM_FASTPATH
73
74#define _TBEGIN_STARTED 0
75#define _TBEGIN_INDETERMINATE 1
76#define _TBEGIN_PERSISTENT 2
77
78/* Number of retries for transient failures. */
79#define _HTM_RETRIES 10
80
81static inline bool
82htm_available (void)
83{
84 return (getauxval (AT_HWCAP2) & PPC_FEATURE2_HAS_HTM) ? true : false;
85}
86
87static inline uint32_t
88htm_init (void)
89{
90 // Maximum number of times we try to execute a transaction
91 // as a HW transaction.
92 return htm_available () ? _HTM_RETRIES : 0;
93}
94
95static inline uint32_t
96htm_begin (void)
97{
98 if (__builtin_expect (__builtin_tbegin (0), 1))
99 return _TBEGIN_STARTED;
100
101 if (_TEXASRU_FAILURE_PERSISTENT (__builtin_get_texasru ()))
102 return _TBEGIN_PERSISTENT;
103
104 return _TBEGIN_INDETERMINATE;
105}
106
107static inline bool
108htm_begin_success (uint32_t begin_ret)
109{
110 return begin_ret == _TBEGIN_STARTED;
111}
112
113static inline void
114htm_commit (void)
115{
116 __builtin_tend (0);
117}
118
119static inline void
120htm_abort (void)
121{
122 __builtin_tabort (0);
123}
124
125static inline bool
126htm_abort_should_retry (uint32_t begin_ret)
127{
128 return begin_ret != _TBEGIN_PERSISTENT;
129}
130
131/* Returns true iff a hardware transaction is currently being executed. */
132static inline bool
133htm_transaction_active (void)
134{
135 return (_HTM_STATE (__builtin_ttest ()) == _HTM_TRANSACTIONAL);
136}
137
138#endif
139
a32e5e93 140} // namespace GTM