From 24081206a888807281c7b025c1314013333b487d Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Sun, 14 Jan 2024 13:15:12 -1000 Subject: [PATCH] SCP: Asynch I/O avoid interlocked instruction on Intel sim_asynch_queue read --- sim_scp_private.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sim_scp_private.h b/sim_scp_private.h index aa9e4273..cbe70335 100644 --- a/sim_scp_private.h +++ b/sim_scp_private.h @@ -265,16 +265,22 @@ extern int32 sim_asynch_inst_latency; } while (0) #ifdef _WIN32 #elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) || defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) -#define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) __sync_val_compare_and_swap(Destination, Comparand, Exchange) +#define InterlockedCompareExchangePointerAcquire(Destination, Exchange, Comparand) __sync_val_compare_and_swap(Destination, Comparand, Exchange) +#define InterlockedCompareExchangePointerRelease(Destination, Exchange, Comparand) __sync_val_compare_and_swap(Destination, Comparand, Exchange) #elif defined(__DECC_VER) -#define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) (void *)((int32)_InterlockedCompareExchange64(Destination, Exchange, Comparand)) +#define InterlockedCompareExchangePointerAcquire(Destination, Exchange, Comparand) (void *)((int32)_InterlockedCompareExchange64(Destination, Exchange, Comparand)) +#define InterlockedCompareExchangePointerRelease(Destination, Exchange, Comparand) (void *)((int32)_InterlockedCompareExchange64(Destination, Exchange, Comparand)) #else #error "Implementation of function InterlockedCompareExchangePointer() is needed to build with USE_AIO_INTRINSICS" #endif #define AIO_ILOCK AIO_LOCK #define AIO_IUNLOCK AIO_UNLOCK -#define AIO_QUEUE_VAL (UNIT *)(InterlockedCompareExchangePointer((void * volatile *)&sim_asynch_queue, (void *)sim_asynch_queue, NULL)) -#define AIO_QUEUE_SET(newval, oldval) (UNIT *)(InterlockedCompareExchangePointer((void * volatile *)&sim_asynch_queue, (void *)newval, oldval)) +#if defined(_M_IX86) || defined(_M_X64) +#define AIO_QUEUE_VAL ((UNIT *)sim_asynch_queue) +#else /* !defined(_M_IX86) || defined(_M_X64) */ +#define AIO_QUEUE_VAL (UNIT *)(InterlockedCompareExchangePointerAcquire((void * volatile *)&sim_asynch_queue, (void *)sim_asynch_queue, NULL)) +#endif /* defined(_M_IX86) || defined(_M_X64) */ +#define AIO_QUEUE_SET(newval, oldval) ((UNIT *)(InterlockedCompareExchangePointerRelease((void * volatile *)&sim_asynch_queue, (void *)newval, oldval))) #define AIO_UPDATE_QUEUE sim_aio_update_queue () #define AIO_ACTIVATE(caller, uptr, event_time) \ if (!pthread_equal ( pthread_self(), sim_asynch_main_threadid )) { \