From 23e7532f81864ecb93f7ca7868854301284ba2ac Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 25 Nov 2025 00:10:07 +0100 Subject: [PATCH] Move the platform-specific atomics to 86box.h and add ADD and SUB macro's, in preparation for applying to the mouse code as well. --- src/include/86box/86box.h | 32 +++++++++++++++++++++++++++ src/include/86box/vid_voodoo_common.h | 28 ----------------------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/include/86box/86box.h b/src/include/86box/86box.h index 88acf5209..8f88d20cc 100644 --- a/src/include/86box/86box.h +++ b/src/include/86box/86box.h @@ -98,6 +98,38 @@ # define LIKELY(x) (x) #endif +/* Platform-specific atomic handling */ +#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) + /* On x86/x64, aligned int/uint32_t accesses are naturally atomic */ + /* Use volatile for performance, as the original code did */ + #define ATOMIC_INT volatile int + #define ATOMIC_UINT volatile uint32_t + #define ATOMIC_LOAD(var) (var) + #define ATOMIC_STORE(var, val) ((var) = (val)) + #define ATOMIC_INC(var) (++(var)) + #define ATOMIC_DEC(var) (--(var)) + #define ATOMIC_ADD(var, val) ((var) += (val)) + #define ATOMIC_SUB(var, val) ((var) -= (val)) +#else + /* On ARM and other architectures, use proper atomics */ + #ifdef __cplusplus + # include + using atomic_int = std::atomic; + using atomic_uint = std::atomic; + #else + # include + #endif + + #define ATOMIC_INT atomic_int + #define ATOMIC_UINT atomic_uint + #define ATOMIC_LOAD(var) atomic_load(&(var)) + #define ATOMIC_STORE(var, val) atomic_store(&(var), (val)) + #define ATOMIC_INC(var) atomic_fetch_add(&(var), 1) + #define ATOMIC_DEC(var) atomic_fetch_sub(&(var), 1) + #define ATOMIC_ADD(var, val) atomic_fetch_add(&(var), val) + #define ATOMIC_SUB(var, val) atomic_fetch_sub(&(var), val) +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/src/include/86box/vid_voodoo_common.h b/src/include/86box/vid_voodoo_common.h index 4c2e5dc08..d87c1f731 100644 --- a/src/include/86box/vid_voodoo_common.h +++ b/src/include/86box/vid_voodoo_common.h @@ -29,34 +29,6 @@ #define TEX_CACHE_MAX 64 -/* Platform-specific atomic handling */ -#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) - /* On x86/x64, aligned int/uint32_t accesses are naturally atomic */ - /* Use volatile for performance, as the original code did */ - #define ATOMIC_INT volatile int - #define ATOMIC_UINT volatile uint32_t - #define ATOMIC_LOAD(var) (var) - #define ATOMIC_STORE(var, val) ((var) = (val)) - #define ATOMIC_INC(var) (++(var)) - #define ATOMIC_DEC(var) (--(var)) -#else - /* On ARM and other architectures, use proper atomics */ - #ifdef __cplusplus - # include - using atomic_int = std::atomic; - using atomic_uint = std::atomic; - #else - # include - #endif - - #define ATOMIC_INT atomic_int - #define ATOMIC_UINT atomic_uint - #define ATOMIC_LOAD(var) atomic_load(&(var)) - #define ATOMIC_STORE(var, val) atomic_store(&(var), (val)) - #define ATOMIC_INC(var) atomic_fetch_add(&(var), 1) - #define ATOMIC_DEC(var) atomic_fetch_sub(&(var), 1) -#endif - enum { VOODOO_1 = 0, VOODOO_SB50,