Move syscall asms to static inline wrapper functions to improve #ifdeffery.
Also correct output type to int and timeout type to void *.
No functional changes.
Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}.
OK for mainline?
2021-02-11 Uroš Bizjak
libgomp/
* config/linux/x86/futex.h (__futex_wait): New static inline
wrapper function. Correct output type to int and
timeout type to void *.
(__futex_wake): New static inline wrapper function.
Correct output type to int.
(futex_wait): Use __futex_wait.
(futex_wake): Use __futex_wake.
Uros.
diff --git a/libgomp/config/linux/x86/futex.h b/libgomp/config/linux/x86/futex.h
index 1e01b681401..1e5f9d4357d 100644
--- a/libgomp/config/linux/x86/futex.h
+++ b/libgomp/config/linux/x86/futex.h
@@ -30,99 +30,92 @@
# define SYS_futex202
# endif
-static inline void
-futex_wait (int *addr, int val)
+static inline int
+__futex_wait (int *uaddr, int futex_op, int val)
{
- long res;
+ int res;
- register long r10 __asm__("%r10") = 0;
+ register void *timeout __asm ("r10") = NULL;
__asm volatile ("syscall"
: "=a" (res)
- : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
- "d" (val), "r" (r10)
+ : "0" (SYS_futex), "D" (uaddr), "S" (futex_op),
+ "d" (val), "r" (timeout)
: "r11", "rcx", "memory");
- if (__builtin_expect (res == -ENOSYS, 0))
-{
- gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
- gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
- __asm volatile ("syscall"
- : "=a" (res)
- : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wait),
- "d" (val), "r" (r10)
- : "r11", "rcx", "memory");
-}
+ return res;
}
-static inline void
-futex_wake (int *addr, int count)
+static inline int
+__futex_wake (int *uaddr, int futex_op, int count)
{
- long res;
+ int res;
__asm volatile ("syscall"
: "=a" (res)
- : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake),
+ : "0" (SYS_futex), "D" (uaddr), "S" (futex_op),
"d" (count)
: "r11", "rcx", "memory");
- if (__builtin_expect (res == -ENOSYS, 0))
-{
- gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
- gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
- __asm volatile ("syscall"
- : "=a" (res)
- : "0" (SYS_futex), "D" (addr), "S" (gomp_futex_wake),
- "d" (count)
- : "r11", "rcx", "memory");
-}
+ return res;
}
#else
# ifndef SYS_futex
# define SYS_futex240
# endif
-static inline void
-futex_wait (int *addr, int val)
+static inline int
+__futex_wait (int *uaddr, int futex_op, int val)
+{
+ int res;
+
+ void *timeout = NULL;
+ __asm volatile ("int $0x80"
+ : "=a" (res)
+ : "0" (SYS_futex), "b" (uaddr), "c" (futex_op),
+ "d" (val), "S" (timeout)
+ : "memory");
+ return res;
+}
+
+static inline int
+__futex_wake (int *uaddr, int futex_op, int count)
{
- long res;
+ int res;
__asm volatile ("int $0x80"
: "=a" (res)
- : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wait),
- "d" (val), "S" (0)
+ : "0" (SYS_futex), "b" (uaddr), "c" (futex_op),
+ "d" (count)
: "memory");
+ return res;
+}
+#endif /* __x86_64__ */
+
+static inline void
+futex_wait (int *addr, int val)
+{
+ int res = __futex_wait (addr, gomp_futex_wait, val);
+
if (__builtin_expect (res == -ENOSYS, 0))
{
gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
- __asm volatile ("int $0x80"
- : "=a" (res)
- : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wait),
- "d" (val), "S" (0)
- : "memory");
+
+ __futex_wait (addr, gomp_futex_wait, val);
}
}
static inline void
futex_wake (int *addr, int count)
{
- long res;
+ int res = __futex_wake (addr, gomp_futex_wake, count);
- __asm volatile ("int $0x80"
- : "=a" (res)
- : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wake),
- "d" (count)
- : "memory");
if (__builtin_expect (res == -ENOSYS, 0))
{
gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG;
gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG;
- __asm volatile ("int $0x80"
- : "=a" (res)
- : "0" (SYS_futex), "b" (addr), "c" (gomp_futex_wake),
- "d" (count)
- : "memory");
+
+ __futex_wake (addr, gomp_futex_wake, count);
}
}
-#endif /* __x86_64__ */
static inline void
cpu_relax (void)