From a013152ae8fb09223b91f3183b40869960a7a79e Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Tue, 24 Jan 2017 01:32:41 +0300 Subject: Implement short inc/dec directly for msftc ARM and X86[_64] * src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>1400 && !AO_PREFER_GENERALIZED] (_InterlockedIncrement16, _InterlockedDecrement16): Declare intrinsic. * src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>1400 && !AO_PREFER_GENERALIZED] (_InterlockedIncrement16, _InterlockedDecrement16): Likewise. * src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>1400 && !AO_PREFER_GENERALIZED] (AO_short_fetch_and_add1_full, AO_short_fetch_and_sub1_full): Implement using intrinsic. * 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/common32_defs.h | 18 ++++++++++++++++++ src/atomic_ops/sysdeps/msftc/x86_64.h | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'src') diff --git a/src/atomic_ops/sysdeps/msftc/common32_defs.h b/src/atomic_ops/sysdeps/msftc/common32_defs.h index dfb8cf6..c3f5ee9 100644 --- a/src/atomic_ops/sysdeps/msftc/common32_defs.h +++ b/src/atomic_ops/sysdeps/msftc/common32_defs.h @@ -155,4 +155,22 @@ AO_fetch_and_sub1_full(volatile AO_t *p) } # 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 */ diff --git a/src/atomic_ops/sysdeps/msftc/x86_64.h b/src/atomic_ops/sysdeps/msftc/x86_64.h index 86fa2b7..b5eb298 100644 --- a/src/atomic_ops/sysdeps/msftc/x86_64.h +++ b/src/atomic_ops/sysdeps/msftc/x86_64.h @@ -151,6 +151,24 @@ AO_int_fetch_and_add_full(volatile unsigned int *p, unsigned int incr) } # 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 */ #ifdef AO_ASM_X64_AVAILABLE -- cgit v1.2.1