Mercurial > hg > beaglert
changeset 292:3d26df8a8a6c
Updated Heavy files to match latest Heavy API
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 24 May 2016 01:10:04 +0100 |
parents | 46c12546664f |
children | 48d36405e987 |
files | scripts/hvresources/HvUtils.h |
diffstat | 1 files changed, 56 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/hvresources/HvUtils.h Sat May 21 15:28:03 2016 +0100 +++ b/scripts/hvresources/HvUtils.h Tue May 24 01:10:04 2016 +0100 @@ -25,6 +25,8 @@ #endif #elif __APPLE__ #define HV_APPLE 1 +#elif __ANDROID__ + #define HV_ANDROID 1 #elif __unix__ || __unix #define HV_UNIX 1 #else @@ -45,10 +47,12 @@ #define hv_uint16_t uint16_t // SIMD-specific includes -#ifndef HV_SIMD_NONE +#if !(HV_SIMD_NONE || HV_SIMD_NEON || HV_SIMD_SSE || HV_SIMD_AVX) #define HV_SIMD_NEON __ARM_NEON__ #define HV_SIMD_SSE (__SSE__ && __SSE2__ && __SSE3__ && __SSSE3__ && __SSE4_1__) #define HV_SIMD_AVX (__AVX__ && HV_SIMD_SSE) +#endif +#ifndef HV_SIMD_FMA #define HV_SIMD_FMA __FMA__ #endif @@ -139,11 +143,17 @@ #elif HV_APPLE #define hv_alloca(_n) alloca(_n) #if HV_SIMD_AVX + #include <mm_malloc.h> #define hv_malloc(_n) _mm_malloc(_n, 32) #define hv_free(x) _mm_free(x) - #elif HV_SIMD_SSE || HV_SIMD_NEON + #elif HV_SIMD_SSE + #include <mm_malloc.h> #define hv_malloc(_n) _mm_malloc(_n, 16) #define hv_free(x) _mm_free(x) + #elif HV_SIMD_NEON + // malloc on ios always has 16-byte alignment + #define hv_malloc(_n) malloc(_n) + #define hv_free(x) free(x) #else // HV_SIMD_NONE #define hv_malloc(_n) malloc(_n) #define hv_free(x) free(x) @@ -154,10 +164,18 @@ #if HV_SIMD_AVX #define hv_malloc(_n) aligned_alloc(32, _n) #define hv_free(x) free(x) - #elif HV_SIMD_SSE || HV_SIMD_NEON - //#define hv_malloc(_n) aligned_alloc(16, _n) - #define hv_malloc(_n) memalign(16, _n) + #elif HV_SIMD_SSE + #define hv_malloc(_n) aligned_alloc(16, _n) #define hv_free(x) free(x) + #elif HV_SIMD_NEON + #if HV_ANDROID + #define hv_malloc(_n) memalign(16, _n) + #define hv_free(x) free(x) + #else + //#define hv_malloc(_n) aligned_alloc(16, _n) + #define hv_malloc(_n) memalign(16, _n) + #define hv_free(x) free(x) + #endif #else // HV_SIMD_NONE #define hv_malloc(_n) malloc(_n) #define hv_free(_n) free(_n) @@ -209,7 +227,12 @@ #define hv_abs_f(a) fabsf(a) #define hv_sqrt_f(a) sqrtf(a) #define hv_log_f(a) logf(a) -#define hv_log2_f(a) log2f(a) +#if HV_ANDROID + // NOTE(mhroth): for whatever silly reason, log2f is not defined! + #define hv_log2_f(a) (1.44269504088896f*logf(a)) +#else + #define hv_log2_f(a) log2f(a) +#endif // HV_ANDROID #define hv_log10_f(a) log10f(a) #define hv_ceil_f(a) ceilf(a) #define hv_floor_f(a) floorf(a) @@ -231,4 +254,31 @@ #endif #define hv_min_max_log2(a) __hv_utils_min_max_log2(a) +// Atomics +#if HV_WIN +#include <Windows.h> +#define hv_atomic_bool volatile LONG +#define HV_SPINLOCK_ACQUIRE(_x) \ +while (InterlockedCompareExchange(&_x, true, false)) { } +#define HV_SPINLOCK_RELEASE(_x) (_x = false) +#elif defined(__has_include) +#if __has_include(<stdatomic.h>) +#include <stdatomic.h> +#define hv_atomic_bool volatile atomic_bool +#define HV_SPINLOCK_ACQUIRE(_x) \ +bool expected = false; \ +while (!atomic_compare_exchange_strong(&_x, &expected, true)) { expected = false; } +#define HV_SPINLOCK_RELEASE(_x) atomic_store(&_x, false) +#else +#define hv_atomic_bool volatile bool +#define HV_SPINLOCK_ACQUIRE(_x) _x = true; +#define HV_SPINLOCK_RELEASE(_x) _x = false; +#endif +#else +#define hv_atomic_bool volatile bool +#define HV_SPINLOCK_ACQUIRE(_x) _x = true; +#define HV_SPINLOCK_RELEASE(_x) _x = false; +#endif + + #endif // _HEAVY_UTILS_H_