]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgomp/config/linux/powerpc/futex.h
Update copyright years.
[thirdparty/gcc.git] / libgomp / config / linux / powerpc / futex.h
CommitLineData
7adcbafe 1/* Copyright (C) 2005-2022 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
28#include <sys/syscall.h>
953ff289 29
a68ab351 30static inline long
953ff289
DN
31sys_futex0 (int *addr, int op, int val)
32{
33 register long int r0 __asm__ ("r0");
34 register long int r3 __asm__ ("r3");
35 register long int r4 __asm__ ("r4");
36 register long int r5 __asm__ ("r5");
37 register long int r6 __asm__ ("r6");
38
39 r0 = SYS_futex;
40 r3 = (long) addr;
41 r4 = op;
42 r5 = val;
43 r6 = 0;
44
45 /* ??? The powerpc64 sysdep.h file clobbers ctr; the powerpc32 sysdep.h
46 doesn't. It doesn't much matter for us. In the interest of unity,
47 go ahead and clobber it always. */
48
a68ab351 49 __asm volatile ("sc; mfcr %0"
953ff289
DN
50 : "=r"(r0), "=r"(r3), "=r"(r4), "=r"(r5), "=r"(r6)
51 : "r"(r0), "r"(r3), "r"(r4), "r"(r5), "r"(r6)
52 : "r7", "r8", "r9", "r10", "r11", "r12",
53 "cr0", "ctr", "memory");
a68ab351
JJ
54 if (__builtin_expect (r0 & (1 << 28), 0))
55 return r3;
56 return 0;
953ff289
DN
57}
58
59static inline void
60futex_wait (int *addr, int val)
61{
a68ab351
JJ
62 long err = sys_futex0 (addr, gomp_futex_wait, val);
63 if (__builtin_expect (err == ENOSYS, 0))
64 {
65 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
66 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
67 sys_futex0 (addr, gomp_futex_wait, val);
68 }
953ff289
DN
69}
70
71static inline void
72futex_wake (int *addr, int count)
73{
a68ab351
JJ
74 long err = sys_futex0 (addr, gomp_futex_wake, count);
75 if (__builtin_expect (err == ENOSYS, 0))
76 {
77 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
78 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
79 sys_futex0 (addr, gomp_futex_wake, count);
80 }
81}
82
83static inline void
84cpu_relax (void)
85{
86 __asm volatile ("" : : : "memory");
87}