]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgomp/config/linux/ia64/futex.h
Update copyright years.
[thirdparty/gcc.git] / libgomp / config / linux / ia64 / futex.h
CommitLineData
a945c346 1/* Copyright (C) 2005-2024 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>
29
953ff289
DN
30
31
a68ab351 32static inline long
8ed501f1 33sys_futex0(int *addr, int op, int val)
953ff289
DN
34{
35 register long out0 asm ("out0") = (long) addr;
36 register long out1 asm ("out1") = op;
37 register long out2 asm ("out2") = val;
38 register long out3 asm ("out3") = 0;
a68ab351
JJ
39 register long r8 asm ("r8");
40 register long r10 asm ("r10");
953ff289
DN
41 register long r15 asm ("r15") = SYS_futex;
42
43 __asm __volatile ("break 0x100000"
a68ab351
JJ
44 : "=r"(r15), "=r"(out0), "=r"(out1), "=r"(out2), "=r"(out3),
45 "=r"(r8), "=r"(r10)
953ff289 46 : "r"(r15), "r"(out0), "r"(out1), "r"(out2), "r"(out3)
a68ab351 47 : "memory", "out4", "out5", "out6", "out7",
9c47a019
AS
48 /* Non-stacked integer registers, minus r8, r10, r12, r15. */
49 "r2", "r3", "r9", "r11", "r13", "r14", "r16", "r17", "r18",
953ff289
DN
50 "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27",
51 "r28", "r29", "r30", "r31",
52 /* Predicate registers. */
53 "p6", "p7", "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
54 /* Non-rotating fp registers. */
55 "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
56 /* Branch registers. */
57 "b6");
a68ab351 58 return r8 & r10;
953ff289
DN
59}
60
61static inline void
62futex_wait (int *addr, int val)
63{
a68ab351
JJ
64 long err = sys_futex0 (addr, gomp_futex_wait, val);
65 if (__builtin_expect (err == ENOSYS, 0))
66 {
67 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
68 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
69 sys_futex0 (addr, gomp_futex_wait, val);
70 }
953ff289
DN
71}
72
73static inline void
74futex_wake (int *addr, int count)
75{
a68ab351
JJ
76 long err = sys_futex0 (addr, gomp_futex_wake, count);
77 if (__builtin_expect (err == ENOSYS, 0))
78 {
79 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
80 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
81 sys_futex0 (addr, gomp_futex_wake, count);
82 }
83}
84
85static inline void
86cpu_relax (void)
87{
88 __asm volatile ("hint @pause" : : : "memory");
89}