From 3286bf5ab66c5ea00237af642967a25043581353 Mon Sep 17 00:00:00 2001 From: Ken Steele Date: Wed, 20 Mar 2013 12:54:38 -0400 Subject: [PATCH] On the Tile architecture, use atomic instructions for atomic ptr and counter. For atomic_counter and atomic_ptr classes, detect the Tile architecture using #if defined __tile__ matching ARM and Solaris and then use the Tile atomic instructions. Without this change, the default Mutex implementation is used, which is slower. --- AUTHORS | 1 + src/atomic_counter.hpp | 10 ++++++++++ src/atomic_ptr.hpp | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/AUTHORS b/AUTHORS index 55d55614..232d77dc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -41,6 +41,7 @@ Jacob Rideout Joe Thornber Jon Dyte Kamil Shakirov +Ken Steele Marc Rossi Martin Hurton Martin Lucina diff --git a/src/atomic_counter.hpp b/src/atomic_counter.hpp index c87642a4..45cfe88d 100644 --- a/src/atomic_counter.hpp +++ b/src/atomic_counter.hpp @@ -33,6 +33,8 @@ #define ZMQ_ATOMIC_COUNTER_WINDOWS #elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD) #define ZMQ_ATOMIC_COUNTER_ATOMIC_H +#elif defined __tile__ +#define ZMQ_ATOMIC_COUNTER_TILE #else #define ZMQ_ATOMIC_COUNTER_MUTEX #endif @@ -43,6 +45,8 @@ #include "windows.hpp" #elif defined ZMQ_ATOMIC_COUNTER_ATOMIC_H #include +#elif defined ZMQ_ATOMIC_COUNTER_TILE +#include #endif namespace zmq @@ -82,6 +86,8 @@ namespace zmq #elif defined ZMQ_ATOMIC_COUNTER_ATOMIC_H integer_t new_value = atomic_add_32_nv (&value, increment_); old_value = new_value - increment_; +#elif defined ZMQ_ATOMIC_COUNTER_TILE + old_value = arch_atomic_add (&value, increment_); #elif defined ZMQ_ATOMIC_COUNTER_X86 __asm__ volatile ( "lock; xadd %0, %1 \n\t" @@ -123,6 +129,10 @@ namespace zmq int32_t delta = - ((int32_t) decrement); integer_t nv = atomic_add_32_nv (&value, delta); return nv != 0; +#elif defined ZMQ_ATOMIC_COUNTER_TILE + int32_t delta = - ((int32_t) decrement); + integer_t nv = arch_atomic_add (&value, delta); + return nv != 0; #elif defined ZMQ_ATOMIC_COUNTER_X86 integer_t oldval = -decrement; volatile integer_t *val = &value; diff --git a/src/atomic_ptr.hpp b/src/atomic_ptr.hpp index 59d78882..066d54be 100644 --- a/src/atomic_ptr.hpp +++ b/src/atomic_ptr.hpp @@ -28,6 +28,8 @@ #define ZMQ_ATOMIC_PTR_X86 #elif defined __ARM_ARCH_7A__ && defined __GNUC__ #define ZMQ_ATOMIC_PTR_ARM +#elif defined __tile__ +#define ZMQ_ATOMIC_PTR_TILE #elif defined ZMQ_HAVE_WINDOWS #define ZMQ_ATOMIC_PTR_WINDOWS #elif (defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_NETBSD) @@ -42,6 +44,8 @@ #include "windows.hpp" #elif defined ZMQ_ATOMIC_PTR_ATOMIC_H #include +#elif defined ZMQ_ATOMIC_PTR_TILE +#include #endif namespace zmq @@ -80,6 +84,8 @@ namespace zmq return (T*) InterlockedExchangePointer ((PVOID*) &ptr, val_); #elif defined ZMQ_ATOMIC_PTR_ATOMIC_H return (T*) atomic_swap_ptr (&ptr, val_); +#elif defined ZMQ_ATOMIC_PTR_TILE + return (T*) arch_atomic_exchange (&ptr, val_); #elif defined ZMQ_ATOMIC_PTR_X86 T *old; __asm__ volatile ( @@ -123,6 +129,8 @@ namespace zmq (volatile PVOID*) &ptr, val_, cmp_); #elif defined ZMQ_ATOMIC_PTR_ATOMIC_H return (T*) atomic_cas_ptr (&ptr, cmp_, val_); +#elif defined ZMQ_ATOMIC_PTR_TILE + return (T*) arch_atomic_val_compare_and_exchange (&ptr, cmp_, val_); #elif defined ZMQ_ATOMIC_PTR_X86 T *old; __asm__ volatile (