From 6b92204a7ce5faf8dab2301c59aa69a26f6b8a19 Mon Sep 17 00:00:00 2001 From: Grazvydas Ignotas Date: Sun, 16 Aug 2015 18:10:34 +0200 Subject: [PATCH] add fallback blas_lock implementation to be used on armv5 and new platforms --- common.h | 14 ++++++++++++++ common_alpha.h | 1 + common_arm.h | 4 ++++ common_arm64.h | 1 + common_ia64.h | 2 ++ common_mips64.h | 1 + common_power.h | 1 + common_sparc.h | 1 + common_x86.h | 1 + common_x86_64.h | 1 + 10 files changed, 27 insertions(+) diff --git a/common.h b/common.h index 5998b56..6073f03 100644 --- a/common.h +++ b/common.h @@ -435,9 +435,23 @@ static inline unsigned long long rpcc(void){ #define RPCC64BIT #endif // !RPCC_DEFINED +#if !defined(BLAS_LOCK_DEFINED) && defined(__GNUC__) +static void __inline blas_lock(volatile BLASULONG *address){ + + do { + while (*address) {YIELDING;}; + + } while (!__sync_bool_compare_and_swap(address, 0, 1)); +} +#define BLAS_LOCK_DEFINED +#endif + #ifndef RPCC_DEFINED #error "rpcc() implementation is missing for your platform" #endif +#ifndef BLAS_LOCK_DEFINED +#error "blas_lock() implementation is missing for your platform" +#endif #endif // !ASSEMBLER #ifdef OS_LINUX diff --git a/common_alpha.h b/common_alpha.h index 86f5896..9739c94 100644 --- a/common_alpha.h +++ b/common_alpha.h @@ -76,6 +76,7 @@ static void __inline blas_lock(unsigned long *address){ "30:", address); #endif } +#define BLAS_LOCK_DEFINED static __inline unsigned int rpcc(void){ diff --git a/common_arm.h b/common_arm.h index 74b6378..84691d7 100644 --- a/common_arm.h +++ b/common_arm.h @@ -51,6 +51,8 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSEMBLER +#if defined(ARMV6) || defined(ARMV7) || defined(ARMV8) + static void __inline blas_lock(volatile BLASULONG *address){ int register ret; @@ -71,6 +73,8 @@ static void __inline blas_lock(volatile BLASULONG *address){ MB; } +#define BLAS_LOCK_DEFINED +#endif static inline int blas_quickdivide(blasint x, blasint y){ return x / y; diff --git a/common_arm64.h b/common_arm64.h index cc08fa7..c4e588d 100644 --- a/common_arm64.h +++ b/common_arm64.h @@ -69,6 +69,7 @@ static void __inline blas_lock(volatile BLASULONG *address){ } while (ret); } +#define BLAS_LOCK_DEFINED static inline int blas_quickdivide(blasint x, blasint y){ diff --git a/common_ia64.h b/common_ia64.h index d1f2107..72b75fc 100644 --- a/common_ia64.h +++ b/common_ia64.h @@ -68,6 +68,7 @@ static __inline void blas_lock(volatile unsigned long *address){ : "ar.ccv", "memory"); } while (ret); } +#define BLAS_LOCK_DEFINED static __inline unsigned long rpcc(void) { unsigned long clocks; @@ -100,6 +101,7 @@ static __inline void blas_lock(volatile unsigned long *address){ while (*address || _InterlockedCompareExchange((volatile int *) address,1,0)) ; } +#define BLAS_LOCK_DEFINED static __inline unsigned int rpcc(void) { return __getReg(_IA64_REG_AR_ITC); diff --git a/common_mips64.h b/common_mips64.h index bc1a52f..f5c0ec7 100644 --- a/common_mips64.h +++ b/common_mips64.h @@ -98,6 +98,7 @@ static void INLINE blas_lock(volatile unsigned long *address){ } while (ret); } +#define BLAS_LOCK_DEFINED static inline unsigned int rpcc(void){ unsigned long ret; diff --git a/common_power.h b/common_power.h index 3b9471a..ab331b0 100644 --- a/common_power.h +++ b/common_power.h @@ -87,6 +87,7 @@ static void INLINE blas_lock(volatile unsigned long *address){ #endif } while (ret); } +#define BLAS_LOCK_DEFINED static inline unsigned long rpcc(void){ unsigned long ret; diff --git a/common_sparc.h b/common_sparc.h index 8a16e3d..f99972d 100644 --- a/common_sparc.h +++ b/common_sparc.h @@ -58,6 +58,7 @@ static void __inline blas_lock(volatile unsigned long *address){ : "memory"); } while (ret); } +#define BLAS_LOCK_DEFINED static __inline unsigned long rpcc(void){ unsigned long clocks; diff --git a/common_x86.h b/common_x86.h index 9506716..6c90432 100644 --- a/common_x86.h +++ b/common_x86.h @@ -65,6 +65,7 @@ static void __inline blas_lock(volatile BLASULONG *address){ } while (ret); } +#define BLAS_LOCK_DEFINED static __inline unsigned long long rpcc(void){ unsigned int a, d; diff --git a/common_x86_64.h b/common_x86_64.h index 3a02bee..4c783b3 100644 --- a/common_x86_64.h +++ b/common_x86_64.h @@ -74,6 +74,7 @@ static void __inline blas_lock(volatile BLASULONG *address){ } while (ret); } +#define BLAS_LOCK_DEFINED static __inline BLASULONG rpcc(void){ BLASULONG a, d; -- 2.7.4