diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2021-10-19 09:47:19 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2021-10-19 17:48:04 +0300 |
commit | 9831779d8417472161ac1545074f128448e4c99f (patch) | |
tree | 356163a1126f898744e8ecb7a5c6a67e80dd306f /src | |
parent | 23c491eddc49890a315c86d133c4a2328fcbda8d (diff) | |
download | libatomic_ops-9831779d8417472161ac1545074f128448e4c99f.tar.gz |
Move all non-double intrinsic-based primitives to msftc/common32_defs.h
(refactoring)
* src/atomic_ops/sysdeps/msftc/arm.h: Include common32_defs.h (and
define AO_ASSUME_WINDOWS98) after include test_and_set_t_is_ao_t.h and
all_aligned_atomic_load_store.h.
* src/atomic_ops/sysdeps/msftc/arm.h (AO_T_IS_INT): Define before
include common32_defs.h.
* src/atomic_ops/sysdeps/msftc/x86.h (AO_T_IS_INT): Likewise.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER<=1400]: Add
comment about WIN32_LEAN_AND_MEAN.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800
|| _MSC_VER>1400 && !_M_ARM] (_InterlockedAnd8, _InterlockedOr8,
_InterlockedXor8): Do not declare via pragma if _MSC_VER>=1800 and
AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800
|| _MSC_VER>1400 && !_M_ARM] (AO_char_and_full, AO_char_or_full,
AO_char_xor_full): Do not define if _MSC_VER>=1800 and
AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/msftc/common32_defs.h
[(!AO_PREFER_GENERALIZED || !AO_ASSUME_WINDOWS98) && !AO_T_IS_INT]
(_InterlockedIncrement64, _InterlockedDecrement64,
_InterlockedExchangeAdd64): Add pragma intrinsic.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [!AO_T_IS_INT]
(_InterlockedCompareExchange64): Likewise.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [(!AO_PREFER_GENERALIZED
|| !AO_ASSUME_WINDOWS98) && !AO_T_IS_INT] (AO_fetch_and_add_full,
AO_fetch_and_add1_full, AO_fetch_and_sub1_full): Use 64-bit intrinsic.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [AO_ASSUME_WINDOWS98
&& !AO_T_IS_INT] (AO_fetch_compare_and_swap_full): Likewise.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [!AO_T_IS_INT
&& !AO_PREFER_GENERALIZED] (AO_int_fetch_and_add_full,
AO_int_fetch_and_add1_full, AO_int_fetch_and_sub1_full): Implement
(move it from x86_64.h).
* src/atomic_ops/sysdeps/msftc/common32_defs.h [AO_ASSUME_WINDOWS98
&& !AO_T_IS_INT] (AO_int_fetch_compare_and_swap_full): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [!AO_ASSUME_WINDOWS98]
(AO_ASSUME_WINDOWS98): Define.
* src/atomic_ops/sysdeps/msftc/x86_64.h: Include common32_defs.h;
do not include intrin.h (directly).
* src/atomic_ops/sysdeps/msftc/x86_64.h (_InterlockedIncrement,
_InterlockedIncrement64, _InterlockedDecrement,
_InterlockedDecrement64, _InterlockedExchangeAdd,
_InterlockedExchangeAdd64, _InterlockedCompareExchange,
_InterlockedCompareExchange64, _InterlockedAnd8,
_InterlockedCompareExchange16, _InterlockedOr8, _InterlockedXor8,
_InterlockedIncrement16, _InterlockedDecrement16,
_InterlockedCompareExchange8, _InterlockedExchangeAdd16,
_InterlockedExchangeAdd8): Remove pragma.
* src/atomic_ops/sysdeps/msftc/x86_64.h [AO_PREFER_GENERALIZED]
(AO_fetch_and_add_full, AO_fetch_and_add1_full, AO_fetch_and_sub1_full,
AO_int_fetch_and_add_full, AO_int_fetch_and_add1_full,
AO_int_fetch_and_sub1_full): Remove implementation.
* src/atomic_ops/sysdeps/msftc/x86_64.h
(AO_fetch_compare_and_swap_full, AO_int_fetch_compare_and_swap_full):
Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>1400]
(AO_char_and_full, AO_char_or_full, AO_char_xor_full,
AO_short_fetch_compare_and_swap_full): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>1400
&& AO_PREFER_GENERALIZED] (AO_short_fetch_and_add1_full,
AO_short_fetch_and_sub1_full): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>=1800]
(AO_char_fetch_compare_and_swap_full): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>=1800
&& AO_PREFER_GENERALIZED] (AO_char_fetch_and_add_full,
AO_short_fetch_and_add_full): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [AO_CMPXCHG16B_AVAILABLE]:
Remove misleading comment; reformat code.
Diffstat (limited to 'src')
-rw-r--r-- | src/atomic_ops/sysdeps/msftc/arm.h | 18 | ||||
-rw-r--r-- | src/atomic_ops/sysdeps/msftc/common32_defs.h | 153 | ||||
-rw-r--r-- | src/atomic_ops/sysdeps/msftc/x86.h | 5 | ||||
-rw-r--r-- | src/atomic_ops/sysdeps/msftc/x86_64.h | 231 |
4 files changed, 153 insertions, 254 deletions
diff --git a/src/atomic_ops/sysdeps/msftc/arm.h b/src/atomic_ops/sysdeps/msftc/arm.h index 8ea238c..2a66551 100644 --- a/src/atomic_ops/sysdeps/msftc/arm.h +++ b/src/atomic_ops/sysdeps/msftc/arm.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2003 Hewlett-Packard Development Company, L.P. - * Copyright (c) 2009-2017 Ivan Maidanski + * Copyright (c) 2009-2021 Ivan Maidanski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,12 +21,6 @@ * SOFTWARE. */ -#ifndef AO_ASSUME_WINDOWS98 - /* CAS is always available */ -# define AO_ASSUME_WINDOWS98 -#endif -#include "common32_defs.h" - #include "../test_and_set_t_is_ao_t.h" /* AO_test_and_set_full() is emulated using CAS. */ @@ -36,6 +30,14 @@ /* Unaligned accesses are not guaranteed to be atomic. */ #include "../all_aligned_atomic_load_store.h" +#define AO_T_IS_INT + +#ifndef AO_ASSUME_WINDOWS98 + /* CAS is always available */ +# define AO_ASSUME_WINDOWS98 +#endif +#include "common32_defs.h" + /* If only a single processor is used, we can define AO_UNIPROCESSOR. */ #ifdef AO_UNIPROCESSOR AO_INLINE void AO_nop_full(void) @@ -58,5 +60,3 @@ /* TODO: implement AO_test_and_set_full using SWP. */ #endif /* _M_ARM < 6 */ - -#define AO_T_IS_INT diff --git a/src/atomic_ops/sysdeps/msftc/common32_defs.h b/src/atomic_ops/sysdeps/msftc/common32_defs.h index fa7ee95..1644ab0 100644 --- a/src/atomic_ops/sysdeps/msftc/common32_defs.h +++ b/src/atomic_ops/sysdeps/msftc/common32_defs.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. - * Copyright (c) 2009-2018 Ivan Maidanski + * Copyright (c) 2009-2021 Ivan Maidanski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -35,6 +35,9 @@ # include <windows.h> /* Seems like over-kill, but that's what MSDN recommends. */ /* And apparently winbase.h is not always self-contained. */ + /* Optionally, client could define WIN32_LEAN_AND_MEAN before */ + /* include atomic_ops.h to reduce amount of Windows internal */ + /* headers included by windows.h one. */ #endif #if _MSC_VER < 1310 || !defined(AO_USE_INTERLOCKED_INTRINSICS) @@ -71,34 +74,78 @@ # pragma intrinsic (_InterlockedIncrement) # pragma intrinsic (_InterlockedDecrement) # pragma intrinsic (_InterlockedExchangeAdd) +# ifndef AO_T_IS_INT +# pragma intrinsic (_InterlockedIncrement64) +# pragma intrinsic (_InterlockedDecrement64) +# pragma intrinsic (_InterlockedExchangeAdd64) +# endif # endif /* !AO_PREFER_GENERALIZED */ + # pragma intrinsic (_InterlockedCompareExchange) +# ifndef AO_T_IS_INT +# pragma intrinsic (_InterlockedCompareExchange64) +# endif # define AO_INTERLOCKED_VOLATILE volatile #endif /* _MSC_VER >= 1310 */ #if !defined(AO_PREFER_GENERALIZED) || !defined(AO_ASSUME_WINDOWS98) -AO_INLINE AO_t -AO_fetch_and_add_full(volatile AO_t *p, AO_t incr) -{ - return _InterlockedExchangeAdd((long AO_INTERLOCKED_VOLATILE *)p, incr); -} -#define AO_HAVE_fetch_and_add_full - -AO_INLINE AO_t -AO_fetch_and_add1_full(volatile AO_t *p) -{ - return _InterlockedIncrement((long AO_INTERLOCKED_VOLATILE *)p) - 1; -} -#define AO_HAVE_fetch_and_add1_full - -AO_INLINE AO_t -AO_fetch_and_sub1_full(volatile AO_t *p) -{ - return _InterlockedDecrement((long AO_INTERLOCKED_VOLATILE *)p) + 1; -} -#define AO_HAVE_fetch_and_sub1_full + AO_INLINE AO_t + AO_fetch_and_add_full(volatile AO_t *p, AO_t incr) + { +# ifdef AO_T_IS_INT + return _InterlockedExchangeAdd((long AO_INTERLOCKED_VOLATILE *)p, incr); +# else + return _InterlockedExchangeAdd64((__int64 volatile *)p, incr); +# endif + } +# define AO_HAVE_fetch_and_add_full + + AO_INLINE AO_t + AO_fetch_and_add1_full(volatile AO_t *p) + { +# ifdef AO_T_IS_INT + return _InterlockedIncrement((long AO_INTERLOCKED_VOLATILE *)p) - 1; +# else + return _InterlockedIncrement64((__int64 volatile *)p) - 1; +# endif + } +# define AO_HAVE_fetch_and_add1_full + + AO_INLINE AO_t + AO_fetch_and_sub1_full(volatile AO_t *p) + { +# ifdef AO_T_IS_INT + return _InterlockedDecrement((long AO_INTERLOCKED_VOLATILE *)p) + 1; +# else + return _InterlockedDecrement64((__int64 volatile *)p) + 1; +# endif + } +# define AO_HAVE_fetch_and_sub1_full + +# ifndef AO_T_IS_INT + AO_INLINE unsigned int + AO_int_fetch_and_add_full(volatile unsigned int *p, unsigned int incr) + { + return _InterlockedExchangeAdd((long volatile *)p, incr); + } +# define AO_HAVE_int_fetch_and_add_full + + AO_INLINE unsigned int + AO_int_fetch_and_add1_full(volatile unsigned int *p) + { + return _InterlockedIncrement((long volatile *)p) - 1; + } +# define AO_HAVE_int_fetch_and_add1_full + + AO_INLINE unsigned int + AO_int_fetch_and_sub1_full(volatile unsigned int *p) + { + return _InterlockedDecrement((long volatile *)p) + 1; + } +# define AO_HAVE_int_fetch_and_sub1_full +# endif /* !AO_T_IS_INT */ #endif /* !AO_PREFER_GENERALIZED */ #ifdef AO_ASSUME_WINDOWS98 @@ -106,7 +153,10 @@ AO_fetch_and_sub1_full(volatile AO_t *p) AO_fetch_compare_and_swap_full(volatile AO_t *addr, AO_t old_val, AO_t new_val) { -# ifdef AO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE +# ifndef AO_T_IS_INT + return (AO_t)_InterlockedCompareExchange64((__int64 volatile *)addr, + new_val, old_val); +# elif defined(AO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE) return (AO_t)_InterlockedCompareExchange( (void *AO_INTERLOCKED_VOLATILE *)addr, (void *)new_val, (void *)old_val); @@ -116,35 +166,50 @@ AO_fetch_and_sub1_full(volatile AO_t *p) # endif } # define AO_HAVE_fetch_compare_and_swap_full + +# ifndef AO_T_IS_INT + AO_INLINE unsigned int + AO_int_fetch_compare_and_swap_full(volatile unsigned int *addr, + unsigned int old_val, + unsigned int new_val) + { + return _InterlockedCompareExchange((long volatile *)addr, + new_val, old_val); + } +# define AO_HAVE_int_fetch_compare_and_swap_full +# endif /* !AO_T_IS_INT */ #endif /* AO_ASSUME_WINDOWS98 */ #if (_MSC_VER > 1400) && (!defined(_M_ARM) || _MSC_VER >= 1800) -# pragma intrinsic (_InterlockedAnd8) -# pragma intrinsic (_InterlockedCompareExchange16) -# pragma intrinsic (_InterlockedOr8) -# pragma intrinsic (_InterlockedXor8) +# if _MSC_VER < 1800 || !defined(AO_PREFER_GENERALIZED) +# pragma intrinsic (_InterlockedAnd8) +# pragma intrinsic (_InterlockedOr8) +# pragma intrinsic (_InterlockedXor8) - AO_INLINE void - AO_char_and_full(volatile unsigned char *p, unsigned char value) - { - _InterlockedAnd8((char volatile *)p, value); - } -# define AO_HAVE_char_and_full + AO_INLINE void + AO_char_and_full(volatile unsigned char *p, unsigned char value) + { + _InterlockedAnd8((char volatile *)p, value); + } +# define AO_HAVE_char_and_full - AO_INLINE void - AO_char_or_full(volatile unsigned char *p, unsigned char value) - { - _InterlockedOr8((char volatile *)p, value); - } -# define AO_HAVE_char_or_full + AO_INLINE void + AO_char_or_full(volatile unsigned char *p, unsigned char value) + { + _InterlockedOr8((char volatile *)p, value); + } +# define AO_HAVE_char_or_full - AO_INLINE void - AO_char_xor_full(volatile unsigned char *p, unsigned char value) - { - _InterlockedXor8((char volatile *)p, value); - } -# define AO_HAVE_char_xor_full + AO_INLINE void + AO_char_xor_full(volatile unsigned char *p, unsigned char value) + { + _InterlockedXor8((char volatile *)p, value); + } +# define AO_HAVE_char_xor_full +# endif /* _MSC_VER < 1800 || !AO_PREFER_GENERALIZED */ + +# pragma intrinsic (_InterlockedCompareExchange16) AO_INLINE unsigned short AO_short_fetch_compare_and_swap_full(volatile unsigned short *addr, diff --git a/src/atomic_ops/sysdeps/msftc/x86.h b/src/atomic_ops/sysdeps/msftc/x86.h index d290fc7..c96561f 100644 --- a/src/atomic_ops/sysdeps/msftc/x86.h +++ b/src/atomic_ops/sysdeps/msftc/x86.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2009-2021 Ivan Maidanski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,6 +34,8 @@ # define AO_ASSUME_WINDOWS98 #endif +#define AO_T_IS_INT + #ifndef AO_USE_INTERLOCKED_INTRINSICS /* _Interlocked primitives (Inc, Dec, Xchg, Add) are always available */ # define AO_USE_INTERLOCKED_INTRINSICS @@ -134,8 +137,6 @@ AO_test_and_set_full(volatile AO_TS_t *addr) # define AO_HAVE_double_compare_and_swap_full #endif /* AO_ASSUME_VISTA */ -#define AO_T_IS_INT - /* Real X86 implementations, except for some old WinChips, appear */ /* to enforce ordering between memory operations, EXCEPT that a later */ /* read can pass earlier writes, presumably due to the visible */ diff --git a/src/atomic_ops/sysdeps/msftc/x86_64.h b/src/atomic_ops/sysdeps/msftc/x86_64.h index 196fc65..d620179 100644 --- a/src/atomic_ops/sysdeps/msftc/x86_64.h +++ b/src/atomic_ops/sysdeps/msftc/x86_64.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2003-2011 Hewlett-Packard Development Company, L.P. + * Copyright (c) 2009-2021 Ivan Maidanski * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,176 +38,15 @@ # include "../test_and_set_t_is_ao_t.h" #endif -/* Assume _MSC_VER >= 1400 */ -#include <intrin.h> - -#pragma intrinsic (_InterlockedCompareExchange) -#pragma intrinsic (_InterlockedCompareExchange64) - -#ifndef AO_PREFER_GENERALIZED - -# pragma intrinsic (_InterlockedIncrement) -# pragma intrinsic (_InterlockedIncrement64) -# pragma intrinsic (_InterlockedDecrement) -# pragma intrinsic (_InterlockedDecrement64) -# pragma intrinsic (_InterlockedExchangeAdd) -# pragma intrinsic (_InterlockedExchangeAdd64) - -AO_INLINE AO_t -AO_fetch_and_add_full (volatile AO_t *p, AO_t incr) -{ - return _InterlockedExchangeAdd64((__int64 volatile *)p, incr); -} -#define AO_HAVE_fetch_and_add_full - -AO_INLINE AO_t -AO_fetch_and_add1_full (volatile AO_t *p) -{ - return _InterlockedIncrement64((__int64 volatile *)p) - 1; -} -#define AO_HAVE_fetch_and_add1_full - -AO_INLINE AO_t -AO_fetch_and_sub1_full (volatile AO_t *p) -{ - return _InterlockedDecrement64((__int64 volatile *)p) + 1; -} -#define AO_HAVE_fetch_and_sub1_full -#endif /* !AO_PREFER_GENERALIZED */ - -AO_INLINE AO_t -AO_fetch_compare_and_swap_full(volatile AO_t *addr, AO_t old_val, - AO_t new_val) -{ - return (AO_t)_InterlockedCompareExchange64((__int64 volatile *)addr, - new_val, old_val); -} -#define AO_HAVE_fetch_compare_and_swap_full - -AO_INLINE unsigned int -AO_int_fetch_compare_and_swap_full(volatile unsigned int *addr, - unsigned int old_val, unsigned int new_val) -{ - return _InterlockedCompareExchange((long volatile *)addr, new_val, old_val); -} -#define AO_HAVE_int_fetch_compare_and_swap_full - -#ifndef AO_PREFER_GENERALIZED -AO_INLINE unsigned int -AO_int_fetch_and_add_full(volatile unsigned int *p, unsigned int incr) -{ - return _InterlockedExchangeAdd((long volatile *)p, incr); -} -#define AO_HAVE_int_fetch_and_add_full - - AO_INLINE unsigned int - AO_int_fetch_and_add1_full(volatile unsigned int *p) - { - return _InterlockedIncrement((long volatile *)p) - 1; - } -# define AO_HAVE_int_fetch_and_add1_full - - AO_INLINE unsigned int - AO_int_fetch_and_sub1_full(volatile unsigned int *p) - { - return _InterlockedDecrement((long volatile *)p) + 1; - } -# define AO_HAVE_int_fetch_and_sub1_full -#endif /* !AO_PREFER_GENERALIZED */ - -#if _MSC_VER > 1400 -# pragma intrinsic (_InterlockedAnd8) -# pragma intrinsic (_InterlockedCompareExchange16) -# pragma intrinsic (_InterlockedOr8) -# pragma intrinsic (_InterlockedXor8) - - AO_INLINE void - AO_char_and_full(volatile unsigned char *p, unsigned char value) - { - _InterlockedAnd8((char volatile *)p, value); - } -# define AO_HAVE_char_and_full - - AO_INLINE void - AO_char_or_full(volatile unsigned char *p, unsigned char value) - { - _InterlockedOr8((char volatile *)p, value); - } -# define AO_HAVE_char_or_full - - AO_INLINE void - AO_char_xor_full(volatile unsigned char *p, unsigned char value) - { - _InterlockedXor8((char volatile *)p, value); - } -# define AO_HAVE_char_xor_full - - AO_INLINE unsigned short - AO_short_fetch_compare_and_swap_full(volatile unsigned short *addr, - unsigned short old_val, - unsigned short new_val) - { - return _InterlockedCompareExchange16((short volatile *)addr, - new_val, old_val); - } -# define AO_HAVE_short_fetch_compare_and_swap_full - -# ifndef AO_PREFER_GENERALIZED -# pragma intrinsic (_InterlockedIncrement16) -# pragma intrinsic (_InterlockedDecrement16) - - AO_INLINE unsigned short - AO_short_fetch_and_add1_full(volatile unsigned short *p) - { - return _InterlockedIncrement16((short volatile *)p) - 1; - } -# define AO_HAVE_short_fetch_and_add1_full - - AO_INLINE unsigned short - AO_short_fetch_and_sub1_full(volatile unsigned short *p) - { - return _InterlockedDecrement16((short volatile *)p) + 1; - } -# define AO_HAVE_short_fetch_and_sub1_full -# endif /* !AO_PREFER_GENERALIZED */ -#endif /* _MSC_VER > 1400 */ - -#if _MSC_VER >= 1800 /* Visual Studio 2013+ */ - -# pragma intrinsic (_InterlockedCompareExchange8) - - AO_INLINE unsigned char - AO_char_fetch_compare_and_swap_full(volatile unsigned char *addr, - unsigned char old_val, - unsigned char new_val) - { - return _InterlockedCompareExchange8((char volatile *)addr, - new_val, old_val); - } -# define AO_HAVE_char_fetch_compare_and_swap_full - -# ifndef AO_PREFER_GENERALIZED -# pragma intrinsic (_InterlockedExchangeAdd16) -# pragma intrinsic (_InterlockedExchangeAdd8) - - AO_INLINE unsigned char - AO_char_fetch_and_add_full(volatile unsigned char *p, unsigned char incr) - { - return _InterlockedExchangeAdd8((char volatile *)p, incr); - } -# define AO_HAVE_char_fetch_and_add_full - - AO_INLINE unsigned short - AO_short_fetch_and_add_full(volatile unsigned short *p, - unsigned short incr) - { - return _InterlockedExchangeAdd16((short volatile *)p, incr); - } -# define AO_HAVE_short_fetch_and_add_full -# endif /* !AO_PREFER_GENERALIZED */ +#ifndef AO_ASSUME_WINDOWS98 + /* CAS is always available */ +# define AO_ASSUME_WINDOWS98 +#endif +#include "common32_defs.h" -#elif defined(AO_ASM_X64_AVAILABLE) +#ifdef AO_ASM_X64_AVAILABLE +#if _MSC_VER < 1800 AO_INLINE unsigned char AO_char_fetch_and_add_full(volatile unsigned char *p, unsigned char incr) { @@ -230,13 +70,10 @@ AO_int_fetch_and_add_full(volatile unsigned int *p, unsigned int incr) } } # define AO_HAVE_short_fetch_and_add_full +#endif /* _MSC_VER < 1800 */ -#endif /* _MSC_VER < 1800 && AO_ASM_X64_AVAILABLE */ - -#ifdef AO_ASM_X64_AVAILABLE - -/* As far as we can tell, the lfence and sfence instructions are not */ -/* currently needed or useful for cached memory accesses. */ + /* As far as we can tell, the lfence and sfence instructions are not */ + /* currently needed or useful for cached memory accesses. */ AO_INLINE void AO_nop_full(void) @@ -261,42 +98,38 @@ AO_int_fetch_and_add_full(volatile unsigned int *p, unsigned int incr) #endif /* AO_ASM_X64_AVAILABLE */ #ifdef AO_CMPXCHG16B_AVAILABLE -/* AO_compare_double_and_swap_double_full needs implementation for Win64. - * Also see ../gcc/x86.h for partial old Opteron workaround. - */ # if _MSC_VER >= 1500 - # include "../standard_ao_double_t.h" - # pragma intrinsic (_InterlockedCompareExchange128) -AO_INLINE int -AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, - AO_t old_val1, AO_t old_val2, - AO_t new_val1, AO_t new_val2) -{ - __int64 comparandResult[2]; - - AO_ASSERT_ADDR_ALIGNED(addr); - comparandResult[0] = old_val1; /* low */ - comparandResult[1] = old_val2; /* high */ - return _InterlockedCompareExchange128((volatile __int64 *)addr, - new_val2 /* high */, new_val1 /* low */, comparandResult); -} + AO_INLINE int + AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, + AO_t old_val1, AO_t old_val2, + AO_t new_val1, AO_t new_val2) + { + __int64 comparandResult[2]; + + AO_ASSERT_ADDR_ALIGNED(addr); + comparandResult[0] = old_val1; /* low */ + comparandResult[1] = old_val2; /* high */ + return _InterlockedCompareExchange128((volatile __int64 *)addr, + new_val2 /* high */, + new_val1 /* low */, + comparandResult); + } # define AO_HAVE_compare_double_and_swap_double_full # elif defined(AO_ASM_X64_AVAILABLE) - # include "../standard_ao_double_t.h" /* If there is no intrinsic _InterlockedCompareExchange128 then we */ /* need basically what's given below. */ -AO_INLINE int -AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, - AO_t old_val1, AO_t old_val2, - AO_t new_val1, AO_t new_val2) -{ + AO_INLINE int + AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, + AO_t old_val1, AO_t old_val2, + AO_t new_val1, AO_t new_val2) + { __asm { mov rdx,QWORD PTR [old_val2] ; @@ -306,7 +139,7 @@ AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, lock cmpxchg16b [addr] ; setz rax ; } -} + } # define AO_HAVE_compare_double_and_swap_double_full # endif /* AO_ASM_X64_AVAILABLE && (_MSC_VER < 1500) */ |