From d5958252fb4116cfb6ad2081b7067b89f87c4e59 Mon Sep 17 00:00:00 2001 From: Erik Lindahl Date: Fri, 8 Aug 2014 23:37:49 +0200 Subject: [PATCH] Replace __LP64__ with check for pointer size The __LP64__ define is not set e.g. on PGI compilers, so instead we use a portable way of checking for pointer size based on defines from stdint.h. Change-Id: Ib2dd6e45c2b168add07f5478d59aec487a91ab9e --- cmake/TestInlineASM_gcc_x86.c | 11 +++++++--- .../include/thread_mpi/atomic/gcc_x86.h | 21 +++++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cmake/TestInlineASM_gcc_x86.c b/cmake/TestInlineASM_gcc_x86.c index 27f7a07d56..f5b184b782 100644 --- a/cmake/TestInlineASM_gcc_x86.c +++ b/cmake/TestInlineASM_gcc_x86.c @@ -4,19 +4,24 @@ main() unsigned int _eax,_ebx,_ecx,_edx; unsigned int level = 0; - /* Test gcc inline asm for x86 */ -#if defined (__LP64__) || defined (_M_X64) + /* Test gcc inline asm for x86. Note that we CANNOT plainly use __x86_64__ + * to correspond to a 64-bit environment without also checking that __ILP32__ + * is NOT set, since x32 uses __x86_64__. + */ +#if (defined(__x86_64__) && !defined(__ILP32__)) __asm__("push %%rbx \n\t" "cpuid \n\t" "movl %%ebx, %1 \n\t" "pop %%rbx \n\t" : "=a"(_eax), "=r"(_ebx), "=c"(_ecx), "=d"(_edx) : "0"(level)); -#else +#elif (defined(__x86_64__) && defined(__ILP32__)) || defined(__i386__) __asm__("push %%ebx \n\t" "cpuid \n\t" "movl %%ebx, %1 \n\t" "pop %%ebx \n\t" : "=a"(_eax), "=r"(_ebx), "=c"(_ecx), "=d"(_edx) : "0"(level)); +#else +# error Cannot detect whether this is a 32-bit or 64-bit x86 build. #endif return 0; diff --git a/src/external/thread_mpi/include/thread_mpi/atomic/gcc_x86.h b/src/external/thread_mpi/include/thread_mpi/atomic/gcc_x86.h index 559258e8d8..1dc5d995d8 100644 --- a/src/external/thread_mpi/include/thread_mpi/atomic/gcc_x86.h +++ b/src/external/thread_mpi/include/thread_mpi/atomic/gcc_x86.h @@ -162,16 +162,18 @@ static inline int tMPI_Atomic_ptr_cas(tMPI_Atomic_ptr_t *a, void *newval) { void* prev; -#ifndef __x86_64__ - __asm__ __volatile__("lock ; cmpxchgl %1,%2" +#if (defined(__x86_64__) && !defined(__ILP32__)) + __asm__ __volatile__("lock ; cmpxchgq %1,%2" : "=a" (prev) : "q" (newval), "m" (a->value), "0" (oldval) : "memory"); -#else - __asm__ __volatile__("lock ; cmpxchgq %1,%2" +#elif (defined(__x86_64__) && defined(__ILP32__)) || defined(__i386__) + __asm__ __volatile__("lock ; cmpxchgl %1,%2" : "=a" (prev) : "q" (newval), "m" (a->value), "0" (oldval) : "memory"); +#else +# error Cannot detect whether this is a 32-bit or 64-bit x86 build. #endif return prev == oldval; } @@ -194,17 +196,18 @@ static inline int tMPI_Atomic_swap(tMPI_Atomic_t *a, int b) static inline void *tMPI_Atomic_ptr_swap(tMPI_Atomic_ptr_t *a, void *b) { void *volatile *ret = (void* volatile*)b; -#ifndef __LP64__ - __asm__ __volatile__("\txchgl %0, %1;" +#if (defined(__x86_64__) && !defined(__ILP32__)) + __asm__ __volatile__("\txchgq %0, %1;" : "+r" (ret), "+m" (a->value) : : "memory"); - -#else - __asm__ __volatile__("\txchgq %0, %1;" +#elif (defined(__x86_64__) && defined(__ILP32__)) || defined(__i386__) + __asm__ __volatile__("\txchgl %0, %1;" : "+r" (ret), "+m" (a->value) : : "memory"); +#else +# error Cannot detect whether this is a 32-bit or 64-bit x86 build. #endif return (void*)ret; } -- 2.22.0