@@ -207,6 +207,7 @@ static inline hv_size_t __hv_utils_max_ui(hv_size_t x, hv_size_t y) { return (x
207207static inline hv_size_t __hv_utils_min_ui (hv_size_t x , hv_size_t y ) { return (x < y ) ? x : y ; }
208208static inline hv_int32_t __hv_utils_max_i (hv_int32_t x , hv_int32_t y ) { return (x > y ) ? x : y ; }
209209static inline hv_int32_t __hv_utils_min_i (hv_int32_t x , hv_int32_t y ) { return (x < y ) ? x : y ; }
210+
210211#define hv_max_ui (a , b ) __hv_utils_max_ui(a, b)
211212#define hv_min_ui (a , b ) __hv_utils_min_ui(a, b)
212213#define hv_max_i (a , b ) __hv_utils_max_i(a, b)
@@ -238,7 +239,12 @@ static inline hv_int32_t __hv_utils_min_i(hv_int32_t x, hv_int32_t y) { return (
238239#define hv_exp_f (a ) expf(a)
239240#define hv_abs_f (a ) fabsf(a)
240241#define hv_log_f (a ) logf(a)
241- #define hv_log2_f (a ) log2f(a)
242+ #if HV_ANDROID
243+ // NOTE(mhroth): for whatever silly reason, log2f is not defined!
244+ #define hv_log2_f (a ) (1.44269504088896f*logf(a))
245+ #else
246+ #define hv_log2_f (a ) log2f(a)
247+ #endif // HV_ANDROID
242248#define hv_log10_f (a ) log10f(a)
243249#define hv_ceil_f (a ) ceilf(a)
244250#define hv_floor_f (a ) floorf(a)
@@ -260,4 +266,31 @@ static inline hv_int32_t __hv_utils_min_i(hv_int32_t x, hv_int32_t y) { return (
260266#endif
261267#define hv_min_max_log2 (a ) __hv_utils_min_max_log2(a)
262268
269+ // Atomics
270+ #if HV_WIN
271+ #include <Windows.h>
272+ #define hv_atomic_bool volatile LONG
273+ #define HV_SPINLOCK_ACQUIRE (_x ) \
274+ while (InterlockedCompareExchange(&_x, true, false)) { }
275+ #define HV_SPINLOCK_RELEASE (_x ) (_x = false)
276+ #elif defined(__has_include )
277+ #if __has_include (< stdatomic .h > )
278+ #include <stdatomic.h>
279+ #define hv_atomic_bool volatile atomic_bool
280+ #define HV_SPINLOCK_ACQUIRE (_x ) \
281+ bool expected = false; \
282+ while (!atomic_compare_exchange_strong(&_x, &expected, true)) { expected = false; }
283+ #define HV_SPINLOCK_RELEASE (_x ) atomic_store(&_x, false)
284+ #else
285+ #define hv_atomic_bool volatile bool
286+ #define HV_SPINLOCK_ACQUIRE (_x ) _x = true;
287+ #define HV_SPINLOCK_RELEASE (_x ) _x = false;
288+ #endif
289+ #else
290+ #define hv_atomic_bool volatile bool
291+ #define HV_SPINLOCK_ACQUIRE (_x ) _x = true;
292+ #define HV_SPINLOCK_RELEASE (_x ) _x = false;
293+ #endif
294+
295+
263296#endif // _HEAVY_UTILS_H_
0 commit comments