From f79c87f0c3d260c079a2906aaf574f50413d5517 Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Thu, 24 Feb 2011 06:31:47 +0000 Subject: [PATCH] Correct the assembly using xaddl for IA32. Add atomic functions for add and sub 32 and 64 bits for AMD64. This commit was SVN r24453. --- opal/include/opal/sys/amd64/atomic.h | 94 +++++++++++++++++++++++++++- opal/include/opal/sys/ia32/atomic.h | 6 +- 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/opal/include/opal/sys/amd64/atomic.h b/opal/include/opal/sys/amd64/atomic.h index 30fd8b2d5e..cf8d099bad 100644 --- a/opal/include/opal/sys/amd64/atomic.h +++ b/opal/include/opal/sys/amd64/atomic.h @@ -2,7 +2,7 @@ * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2005 The University of Tennessee and The University + * Copyright (c) 2004-2010 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, @@ -44,7 +44,6 @@ #define OPAL_HAVE_ATOMIC_CMPSET_64 1 - /********************************************************************** * * Memory Barriers @@ -120,4 +119,95 @@ static inline int opal_atomic_cmpset_64( volatile int64_t *addr, #define opal_atomic_cmpset_acq_64 opal_atomic_cmpset_64 #define opal_atomic_cmpset_rel_64 opal_atomic_cmpset_64 +#if OMPI_GCC_INLINE_ASSEMBLY + +#define OPAL_HAVE_ATOMIC_MATH_32 1 +#define OPAL_HAVE_ATOMIC_MATH_64 1 + +#define OPAL_HAVE_ATOMIC_ADD_32 1 + +/** + * atomic_add - add integer to atomic variable + * @i: integer value to add + * @v: pointer of type int + * + * Atomically adds @i to @v. + */ +static inline int32_t opal_atomic_add_32(volatile int32_t* v, int i) +{ + int ret = i; + __asm__ __volatile__( + SMPLOCK "xaddl %1,%0" + :"=m" (*v), "+r" (ret) + :"m" (*v) + :"memory", "cc" + ); + return (ret+i); +} + +#define OPAL_HAVE_ATOMIC_ADD_64 1 + +/** + * atomic_add - add integer to atomic variable + * @i: integer value to add + * @v: pointer of type int + * + * Atomically adds @i to @v. + */ +static inline int64_t opal_atomic_add_64(volatile int64_t* v, int64_t i) +{ + int64_t ret = i; + __asm__ __volatile__( + SMPLOCK "xaddq %1,%0" + :"=m" (*v), "+r" (ret) + :"m" (*v) + :"memory", "cc" + ); + return (ret+i); +} + +#define OPAL_HAVE_ATOMIC_SUB_32 1 + +/** + * atomic_sub - subtract the atomic variable + * @i: integer value to subtract + * @v: pointer of type int + * + * Atomically subtracts @i from @v. + */ +static inline int32_t opal_atomic_sub_32(volatile int32_t* v, int i) +{ + int ret = -i; + __asm__ __volatile__( + SMPLOCK "xaddl %1,%0" + :"=m" (*v), "+r" (ret) + :"m" (*v) + :"memory", "cc" + ); + return (ret-i); +} + +#define OPAL_HAVE_ATOMIC_SUB_64 1 + +/** + * atomic_sub - subtract the atomic variable + * @i: integer value to subtract + * @v: pointer of type int + * + * Atomically subtracts @i from @v. + */ +static inline int64_t opal_atomic_sub_64(volatile int64_t* v, int64_t i) +{ + int64_t ret = -i; + __asm__ __volatile__( + SMPLOCK "xaddq %1,%0" + :"=m" (*v), "+r" (ret) + :"m" (*v) + :"memory", "cc" + ); + return (ret-i); +} + +#endif /* OMPI_GCC_INLINE_ASSEMBLY */ + #endif /* ! OMPI_SYS_ARCH_ATOMIC_H */ diff --git a/opal/include/opal/sys/ia32/atomic.h b/opal/include/opal/sys/ia32/atomic.h index 6fdd47e130..f498fdcc0a 100644 --- a/opal/include/opal/sys/ia32/atomic.h +++ b/opal/include/opal/sys/ia32/atomic.h @@ -2,7 +2,7 @@ * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. - * Copyright (c) 2004-2005 The University of Tennessee and The University + * Copyright (c) 2004-2010 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, @@ -168,6 +168,8 @@ static inline int32_t opal_atomic_add_32(volatile int32_t* v, int i) __asm__ __volatile__( SMPLOCK "xaddl %1,%0" :"=m" (*v), "+r" (ret) + :"m" (*v) + :"memory", "cc" ); return (ret+i); } @@ -186,6 +188,8 @@ static inline int32_t opal_atomic_sub_32(volatile int32_t* v, int i) __asm__ __volatile__( SMPLOCK "xaddl %1,%0" :"=m" (*v), "+r" (ret) + :"m" (*v) + :"memory", "cc" ); return (ret-i); }