From: Ivan Maidanski Date: Fri, 20 Jan 2017 00:03:54 +0000 (+0300) Subject: Add assertion that double-wide CAS target is aligned (msftc/x86[_64]) X-Git-Tag: v7.4.6~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82258fade80917f1c9872a75f8e16a7af9bf06a3;p=libatomic_ops Add assertion that double-wide CAS target is aligned (msftc/x86[_64]) * src/atomic_ops/sysdeps/msftc/x86.h [AO_ASSUME_VISTA] (AO_double_compare_and_swap_full): Add assert() that addr pointer is aligned according to the size of AO_double_t. * src/atomic_ops/sysdeps/msftc/x86_64.h [AO_CMPXCHG16B_AVAILABLE && _MSC_VER>=1500] (AO_compare_double_and_swap_double_full): Likewise. --- diff --git a/src/atomic_ops/sysdeps/msftc/x86.h b/src/atomic_ops/sysdeps/msftc/x86.h index 7c2995a..1f87a12 100644 --- a/src/atomic_ops/sysdeps/msftc/x86.h +++ b/src/atomic_ops/sysdeps/msftc/x86.h @@ -124,6 +124,7 @@ AO_test_and_set_full(volatile AO_TS_t *addr) AO_double_compare_and_swap_full(volatile AO_double_t *addr, AO_double_t old_val, AO_double_t new_val) { + assert(((size_t)addr & (sizeof(AO_double_t) - 1)) == 0); return (double_ptr_storage)_InterlockedCompareExchange64( (__int64 volatile *)addr, new_val.AO_whole /* exchange */, diff --git a/src/atomic_ops/sysdeps/msftc/x86_64.h b/src/atomic_ops/sysdeps/msftc/x86_64.h index b4b0a3c..2bbc3fd 100644 --- a/src/atomic_ops/sysdeps/msftc/x86_64.h +++ b/src/atomic_ops/sysdeps/msftc/x86_64.h @@ -159,6 +159,8 @@ AO_compare_double_and_swap_double_full(volatile AO_double_t *addr, AO_t new_val1, AO_t new_val2) { __int64 comparandResult[2]; + + assert(((size_t)addr & (sizeof(AO_double_t) - 1)) == 0); comparandResult[0] = old_val1; /* low */ comparandResult[1] = old_val2; /* high */ return _InterlockedCompareExchange128((volatile __int64 *)addr,