comparison libgomp/config/linux/x86/futex.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents a06113de4d67
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc. 1 /* Copyright (C) 2005-2017 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>. 2 Contributed by Richard Henderson <rth@redhat.com>.
3 3
4 This file is part of the GNU OpenMP Library (libgomp). 4 This file is part of the GNU Offloading and Multi Processing Library
5 (libgomp).
5 6
6 Libgomp is free software; you can redistribute it and/or modify it 7 Libgomp 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 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option) 9 the Free Software Foundation; either version 3, or (at your option)
9 any later version. 10 any later version.
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */ 24 <http://www.gnu.org/licenses/>. */
24 25
25 /* Provide target-specific access to the futex system call. */ 26 /* Provide target-specific access to the futex system call. */
26 27
27 #ifdef __LP64__ 28 #ifdef __x86_64__
28 # ifndef SYS_futex 29 # ifndef SYS_futex
29 # define SYS_futex 202 30 # define SYS_futex 202
30 # endif 31 # endif
31 32
32 static inline void 33 static inline void
33 futex_wait (int *addr, int val) 34 futex_wait (int *addr, int val)
34 { 35 {
35 register long r10 __asm__("%r10");
36 long res; 36 long res;
37 37
38 r10 = 0; 38 register long r10 __asm__("%r10") = 0;
39 __asm volatile ("syscall" 39 __asm volatile ("syscall"
40 : "=a" (res) 40 : "=a" (res)
41 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait), 41 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
42 "d" (val), "r" (r10) 42 "d" (val), "r" (r10)
43 : "r11", "rcx", "memory"); 43 : "r11", "rcx", "memory");
44 if (__builtin_expect (res == -ENOSYS, 0)) 44 if (__builtin_expect (res == -ENOSYS, 0))
45 { 45 {
46 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; 46 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
47 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; 47 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
48 r10 = 0;
49 __asm volatile ("syscall" 48 __asm volatile ("syscall"
50 : "=a" (res) 49 : "=a" (res)
51 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait), 50 : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
52 "d" (val), "r" (r10) 51 "d" (val), "r" (r10)
53 : "r11", "rcx", "memory"); 52 : "r11", "rcx", "memory");
78 #else 77 #else
79 # ifndef SYS_futex 78 # ifndef SYS_futex
80 # define SYS_futex 240 79 # define SYS_futex 240
81 # endif 80 # endif
82 81
83 # ifdef __PIC__ 82 static inline void
84 83 futex_wait (int *addr, int val)
85 static inline long
86 sys_futex0 (int *addr, int op, int val)
87 {
88 long res;
89
90 __asm volatile ("xchgl\t%%ebx, %2\n\t"
91 "int\t$0x80\n\t"
92 "xchgl\t%%ebx, %2"
93 : "=a" (res)
94 : "0"(SYS_futex), "r" (addr), "c"(op),
95 "d"(val), "S"(0)
96 : "memory");
97 return res;
98 }
99
100 # else
101
102 static inline long
103 sys_futex0 (int *addr, int op, int val)
104 { 84 {
105 long res; 85 long res;
106 86
107 __asm volatile ("int $0x80" 87 __asm volatile ("int $0x80"
108 : "=a" (res) 88 : "=a" (res)
109 : "0"(SYS_futex), "b" (addr), "c"(op), 89 : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wait),
110 "d"(val), "S"(0) 90 "d" (val), "S" (0)
111 : "memory"); 91 : "memory");
112 return res;
113 }
114
115 # endif /* __PIC__ */
116
117 static inline void
118 futex_wait (int *addr, int val)
119 {
120 long res = sys_futex0 (addr, gomp_futex_wait, val);
121 if (__builtin_expect (res == -ENOSYS, 0)) 92 if (__builtin_expect (res == -ENOSYS, 0))
122 { 93 {
123 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; 94 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
124 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; 95 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
125 sys_futex0 (addr, gomp_futex_wait, val); 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");
126 } 101 }
127 } 102 }
128 103
129 static inline void 104 static inline void
130 futex_wake (int *addr, int count) 105 futex_wake (int *addr, int count)
131 { 106 {
132 long res = sys_futex0 (addr, gomp_futex_wake, count); 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");
133 if (__builtin_expect (res == -ENOSYS, 0)) 114 if (__builtin_expect (res == -ENOSYS, 0))
134 { 115 {
135 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; 116 gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
136 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; 117 gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
137 sys_futex0 (addr, gomp_futex_wake, count); 118 __asm volatile ("int $0x80"
119 : "=a" (res)
120 : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wake),
121 "d" (count)
122 : "memory");
138 } 123 }
139 } 124 }
140 125 #endif /* __x86_64__ */
141 #endif /* __LP64__ */
142 126
143 static inline void 127 static inline void
144 cpu_relax (void) 128 cpu_relax (void)
145 { 129 {
146 __asm volatile ("rep; nop" : : : "memory"); 130 __builtin_ia32_pause ();
147 } 131 }
148
149 static inline void
150 atomic_write_barrier (void)
151 {
152 __sync_synchronize ();
153 }