#error UNDEFINED OS TYPE
#endif /* __linux__ */
-#if !defined (__i386__) && !defined (__ia64__) && !defined(__x86_64__)
+#if !defined (__i386__) && !defined (__ia64__) && !defined(__x86_64__) && !defined(__PPC64__)
#error UNDEFINED ARCH
#endif
#include <sys/socket.h>
#include <ctype.h>
-#ifdef __ia64__
+#if defined(__ia64__) || defined(__PPC64__)
#include <asm/atomic.h>
#include <asm/system.h>
#endif
IA64_FETCHADD(old_value,v,1,4);
# endif
+#elif defined(__PPC64__)
+ atomic_inc((atomic_t *) v);
#else /* !__ia64__ */
__asm__ __volatile__ (
"lock;" "incl %0"
IA64_FETCHADD(old_value,v,-1,4);
# endif
+#elif defined (__PPC64__)
+ atomic_dec((atomic_t *)v);
+
#else /* !__ia64__ */
__asm__ __volatile__ (
"lock;" "decl %0"
current_value = ia64_cmpxchg("acq",v,match_value,new_value,4);
#else
current_value = ia64_cmpxchg(acq,v,match_value,new_value,4);
-#endif
+#endif /* __ia64__ */
+#elif defined(__PPC64__)
+ __asm__ __volatile__ (
+ EIEIO_ON_SMP
+"1: lwarx %0,0,%2 # __cmpxchg_u64\n\
+ cmpd 0,%0,%3\n\
+ bne- 2f\n\
+ stwcx. %4,0,%2\n\
+ bne- 1b"
+ ISYNC_ON_SMP
+ "\n\
+2:"
+ : "=&r" (current_value), "=m" (*v)
+ : "r" (v), "r" (match_value), "r" (new_value), "m" (*v)
+ : "cc", "memory");
#else
__asm__ __volatile__ (
"lock; cmpxchgl %1, %2"
x = get_cycles ();
return x;
#else
-#error "Non-Pentium Linux - unimplemented"
+#if defined(__PPC64__)
+ unsigned int tbl, tbu0, tbu1;
+ do {
+ __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0));
+ __asm__ __volatile__ ("mftb %0" : "=r"(tbl));
+ __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1));
+ } while (tbu0 != tbu1);
+ return (((unsigned long long)tbu0) << 32) | tbl;
+#else
+#error "Non-Pentium and Non-PPC Linux - unimplemented"
+#endif
#endif
#endif
}