]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgomp/config/linux/x86/futex.h
Update copyright years.
[thirdparty/gcc.git] / libgomp / config / linux / x86 / futex.h
CommitLineData
8d9254fc 1/* Copyright (C) 2005-2020 Free Software Foundation, Inc.
953ff289
DN
2 Contributed by Richard Henderson <rth@redhat.com>.
3
f1f3453e
TS
4 This file is part of the GNU Offloading and Multi Processing Library
5 (libgomp).
953ff289
DN
6
7 Libgomp is free software; you can redistribute it and/or modify it
748086b7
JJ
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
953ff289
DN
11
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
748086b7 14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
953ff289
DN
15 more details.
16
748086b7
JJ
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
953ff289
DN
25
26/* Provide target-specific access to the futex system call. */
27
c01ecafc 28#ifdef __x86_64__
953ff289
DN
29# ifndef SYS_futex
30# define SYS_futex 202
31# endif
32
33static inline void
34futex_wait (int *addr, int val)
35{
953ff289
DN
36 long res;
37
6aa54a8b 38 register long r10 __asm__("%r10") = 0;
953ff289
DN
39 __asm volatile ("syscall"
40 : "=a" (res)
a68ab351
JJ
41 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
42 "d" (val), "r" (r10)
953ff289 43 : "r11", "rcx", "memory");
a68ab351
JJ
44 if (__builtin_expect (res == -ENOSYS, 0))
45 {
46 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
47 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
a68ab351
JJ
48 __asm volatile ("syscall"
49 : "=a" (res)
50 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
51 "d" (val), "r" (r10)
52 : "r11", "rcx", "memory");
53 }
953ff289
DN
54}
55
56static inline void
57futex_wake (int *addr, int count)
58{
59 long res;
60
61 __asm volatile ("syscall"
62 : "=a" (res)
a68ab351
JJ
63 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake),
64 "d" (count)
953ff289 65 : "r11", "rcx", "memory");
a68ab351
JJ
66 if (__builtin_expect (res == -ENOSYS, 0))
67 {
68 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
69 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
70 __asm volatile ("syscall"
71 : "=a" (res)
72 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake),
73 "d" (count)
74 : "r11", "rcx", "memory");
75 }
953ff289
DN
76}
77#else
78# ifndef SYS_futex
79# define SYS_futex 240
80# endif
81
bb3caa35
UB
82static inline void
83futex_wait (int *addr, int val)
953ff289
DN
84{
85 long res;
86
87 __asm volatile ("int $0x80"
88 : "=a" (res)
bb3caa35
UB
89 : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wait),
90 "d" (val), "S" (0)
953ff289 91 : "memory");
a68ab351
JJ
92 if (__builtin_expect (res == -ENOSYS, 0))
93 {
94 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
95 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
bb3caa35
UB
96 __asm volatile ("int $0x80"
97 : "=a" (res)
98 : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wait),
99 "d" (val), "S" (0)
100 : "memory");
a68ab351 101 }
953ff289
DN
102}
103
104static inline void
105futex_wake (int *addr, int count)
106{
bb3caa35
UB
107 long res;
108
109 __asm volatile ("int $0x80"
110 : "=a" (res)
111 : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wake),
112 "d" (count)
113 : "memory");
a68ab351
JJ
114 if (__builtin_expect (res == -ENOSYS, 0))
115 {
116 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
117 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
bb3caa35
UB
118 __asm volatile ("int $0x80"
119 : "=a" (res)
120 : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wake),
121 "d" (count)
122 : "memory");
a68ab351 123 }
953ff289 124}
c01ecafc 125#endif /* __x86_64__ */
a68ab351
JJ
126
127static inline void
128cpu_relax (void)
129{
68a12ef3 130 __builtin_ia32_pause ();
a68ab351 131}