aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/x86_64/bits
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-03-20 10:18:24 +0000
committerUlrich Drepper <drepper@redhat.com>2003-03-20 10:18:24 +0000
commitf79466a8e909930237d882da8916bbbb1401edf6 (patch)
tree460afefe452e8550b56d9a01d90dc129012dfd27 /sysdeps/x86_64/bits
parent5132931e18d50a1caf7399aa46dafd0142a7c7ae (diff)
downloadglibc-f79466a8e909930237d882da8916bbbb1401edf6.tar
glibc-f79466a8e909930237d882da8916bbbb1401edf6.tar.gz
glibc-f79466a8e909930237d882da8916bbbb1401edf6.tar.bz2
glibc-f79466a8e909930237d882da8916bbbb1401edf6.zip
Update.
2003-03-20 Ulrich Drepper <drepper@redhat.com> * include/atomic.h: Define atomic_exchange and atomic_decrement_if_positive if not already defined. Add some __builtin_expect. * sysdeps/i386/i486/bits/atomic.h: Define atomic_exchange. * sysdeps/x86_64/bits/atomic.h: Likewise. * sysdeps/ia64/bits/atomic.h: Pretty printing. Define atomic_exchange. * sysdeps/powerpc/bits/atomic.h: Pretty printing. Define atomic_exchange, atomic_exchange_and_add, and atomic_decrement_if_positive
Diffstat (limited to 'sysdeps/x86_64/bits')
-rw-r--r--sysdeps/x86_64/bits/atomic.h24
1 files changed, 23 insertions, 1 deletions
diff --git a/sysdeps/x86_64/bits/atomic.h b/sysdeps/x86_64/bits/atomic.h
index f72f16c501..22d3ab0267 100644
--- a/sysdeps/x86_64/bits/atomic.h
+++ b/sysdeps/x86_64/bits/atomic.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@@ -84,6 +84,28 @@ typedef uintmax_t uatomic_max_t;
ret; })
+/* Note that we need no lock prefix. */
+#define atomic_exchange(mem, newvalue) \
+ ({ __typeof (*mem) result; \
+ if (sizeof (*mem) == 1) \
+ __asm __volatile ("xchgb %b0, %1" \
+ : "=r" (result), "=m" (*mem) \
+ : "0" (newvalue), "1" (*mem)); \
+ else if (sizeof (*mem) == 2) \
+ __asm __volatile ("xchgw %w0, %1" \
+ : "=r" (result), "=m" (*mem) \
+ : "0" (newvalue), "1" (*mem)); \
+ else if (sizeof (*mem) == 4) \
+ __asm __volatile ("xchgl %0, %1" \
+ : "=r" (result), "=m" (*mem) \
+ : "0" (newvalue), "1" (*mem)); \
+ else \
+ __asm __volatile ("xchgq %q0, %1" \
+ : "=r" (result), "=m" (*mem) \
+ : "0" (newvalue), "1" (*mem)); \
+ result; })
+
+
#define atomic_exchange_and_add(mem, value) \
({ __typeof (*mem) result; \
if (sizeof (*mem) == 1) \