Ivan Maidanski [Fri, 27 Jan 2017 16:35:20 +0000 (19:35 +0300)]
Use generalized load/store if AO_PREFER_GENERALIZED (gcc/generic)
Note: AO_PREFER_GENERALIZED macro is for testing generalize.h mainly.
* src/atomic_ops/sysdeps/gcc/generic-small.template (AO_XSIZE_load,
AO_XSIZE_load_acquire, AO_XSIZE_store, AO_XSIZE_store_release): Do not
define if AO_GCC_HAVE_XSIZE_SYNC_CAS and AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/gcc/generic-small.h: Regenerate.
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE]
(AO_GCC_HAVE_double_SYNC_CAS): Move the definition upper to be before
AO_double_load.
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE]
(AO_double_load, AO_double_load_acquire, AO_double_store,
AO_double_store_release): Do not define if AO_GCC_HAVE_double_SYNC_CAS
and AO_PREFER_GENERALIZED.
Ivan Maidanski [Thu, 26 Jan 2017 20:07:57 +0000 (23:07 +0300)]
Enable limited testing in Makefile.msft without Cygwin
New target "check-noautogen" is introduced in Makefile.msft to build and
run only test_malloc and test_stack (which do not need test code
auto-generation by sed).
* src/Makefile.msft: Refine comment about tests execution; add comment
about "check-noautogen" target.
* src/Makefile.msft (check): Add dependency on check-noautogen;
move test_malloc and test_stack to check-noautogen.
* src/Makefile.msft (check-noautogen): New target (executes test_malloc
and test_stack only).
Ivan Maidanski [Thu, 26 Jan 2017 07:38:21 +0000 (10:38 +0300)]
Implement AO_CLEAR using C11 atomic intrinsic (GCC)
* src/atomic_ops/sysdeps/gcc/generic.h [!AO_PREFER_GENERALIZED]
(AO_CLEAR): Implement using GCC built-in __atomic_clear (thus
overriding the default one based on AO_char_store_release).
Hans Boehm [Thu, 26 Jan 2017 07:16:54 +0000 (10:16 +0300)]
Implement compiler_barrier using C11 __atomic_signal_fence (GCC)
Use __atomic_signal_fence(__ATOMIC_SEQ_CST) as AO_compiler_barrier.
That was the intended use of __atomic_signal_fence. The only
standards-relevant context in which you can tell apart a compiler and
real fence is in the case if signal handlers.
* src/atomic_ops/sysdeps/gcc/generic.h (AO_compiler_barrier): Redefine
using GCC atomic intrinsic (__atomic_signal_fence).
Ivan Maidanski [Tue, 24 Jan 2017 19:46:57 +0000 (22:46 +0300)]
Fix test_atomic failure caused unaligned AO_double_t access on x86
The failure is caused by violation of an assertion that checks
AO_double_t variable is 8-byte aligned on x86.
* doc/README.txt (AO_double_t): Add note about required alignment.
* src/atomic_ops/sysdeps/standard_ao_double_t.h (AO_double_t): Add
comment about alignment.
* src/atomic_ops_stack.h (AO_stack_t): Likewise.
* tests/test_atomic_include.template (test_atomicXX): Define old_w, w
local variables as static (as otherwise, e.g., they could have 4-byte
alignment on x86); add comment.
The failure is actually caused by the fact that default alignment of
stack on x86 is 4 bytes.
So, another solution should be proposed to fix the issue for other
compilers (and, potentially, other targets). E.g. do not place
AO_double_t volatile variables on stack.
Ivan Maidanski [Fri, 20 Jan 2017 08:58:13 +0000 (11:58 +0300)]
Fix test_atomic failure caused unaligned AO_double_t access on x86 (VC++)
Passing an unaligned AO_double_t pointer to AO double-wide primitives
results in an undefined behavior of the latter when running on x86 (or
violation of the corresponding assertion on the alignment).
MS VC++/x86 aligns AO_double_t values on a 4-byte boundary by default.
For the proper alignment, __declspec(align(8)) should be applied to
variables defined in the client code (which uses double-wide AO
primitives). Unfortunately, the attribute cannot be added to
AO_double_t definition itself because the compiler does not allow the
attribute for function arguments.
This patch introduces AO_DOUBLE_ALIGN attribute for use by clients of
the double-wide AO primitives (and, thus, AO_stack clients).
Matters only Visual Studio compiler for X86.
The inner clients (atomic_ops_malloc, test_atomic, test_stack) are
updated to use this attribute.
* doc/README_win32.txt [x86] (AO_DOUBLE_ALIGN): Document.
* src/atomic_ops/sysdeps/generic_pthread.h (AO_DOUBLE_ALIGN): Define
(as empty).
* src/atomic_ops/sysdeps/standard_ao_double_t.h [!_WIN64 && _WIN32
&& !__GNUC__ && _MSC_VER] (AO_DOUBLE_ALIGN): Define as declspec
align(8); document it.
* src/atomic_ops/sysdeps/standard_ao_double_t.h [!AO_DOUBLE_ALIGN]
(AO_DOUBLE_ALIGN): Define as empty (otherwise).
* src/atomic_ops_stack.h [AO_USE_ALMOST_LOCK_FREE && !AO_DOUBLE_ALIGN]
(AO_DOUBLE_ALIGN): Likewise.
* src/atomic_ops_malloc.c (AO_free_list): Use AO_DOUBLE_ALIGN attribute.
* tests/test_stack.c (the_list): Likewise.
* src/atomic_ops_stack.h [!AO_USE_ALMOST_LOCK_FREE] (AO_stack_t):
Document AO_DOUBLE_ALIGN usage (by clients).
* tests/test_atomic_include.template (test_atomicXX): Use
AO_DOUBLE_ALIGN attribute for old_w and w double-wide local variables
(to avoid alignment assertion violation or AO primitives undefined
behavior on x86 if the test code is compiled by VC++).
Ivan Maidanski [Fri, 20 Jan 2017 00:03:54 +0000 (03:03 +0300)]
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.
Ivan Maidanski [Thu, 19 Jan 2017 07:03:59 +0000 (10:03 +0300)]
Fix turn off optimization in case of configure --enable-gcov
(fix commit 0d0a16d)
* configure.ac [enable_gcov] (CFLAGS): Change sed regular expression
to avoid [] (as they are not properly handled during autogen), and to
also filter out -Os and -Ofast (-O0 is ignored).
Ivan Maidanski [Wed, 7 Dec 2016 09:35:47 +0000 (12:35 +0300)]
Eliminate 'printf format specifies type void*' GCC pedantic warnings
This commit also eliminates 'cast from pointer to integer' compiler
warnings and '32-bit value shift followed by expansion to 64-bit'
static analysis tool warning.
* src/atomic_ops_malloc.c [AO_TRACE_MALLOC] (AO_malloc, AO_free):
Use %p (instead of %x) format specifier to print pthread_self() value
(and cast pthread_self() to void*).
* src/atomic_ops_malloc.c [AO_TRACE_MALLOC] (AO_malloc): Cast result+1
to void* (to match %p printf format specifier).
* src/atomic_ops_malloc.c [AO_TRACE_MALLOC] (AO_free): Use "UL" suffix
for 1 and remove the cast to unsigned long (instead of performing left
shift of an integer value and extending the result to unsigned long).
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE
&& !AO_HAVE_double_store] (AO_double_store): Do not define if
AO_SKIPATOMIC_double_store.
* src/atomic_ops/sysdeps/gcc/generic.h [AO_HAVE_DOUBLE_PTR_STORAGE
&& !AO_HAVE_double_store_release] (AO_double_store_release): Do not
define if AO_SKIPATOMIC_double_load.
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& __clang__ && !__x86_64__ && !__APPLE_CC__ && !__CYGWIN__
&& !AO_PREFER_BUILTIN_ATOMICS] (AO_SKIPATOMIC_double_load,
AO_SKIPATOMIC_double_load_acquire, AO_SKIPATOMIC_double_store,
AO_SKIPATOMIC_double_store_release): Define internal macro (undefined
at the end of file).
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& (__clang__ && !__x86_64__ && !__APPLE_CC__ && !__CYGWIN__
&& !AO_PREFER_BUILTIN_ATOMICS) || (__APPLE_CC__ && __x86_64__))]
(AO_SKIPATOMIC_double_compare_and_swap_ANY): Move definition here
(remove at other places in this file); undefine at the end of the file.
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET]: Check
AO_SKIPATOMIC_double_compare_and_swap_ANY instead of checking multiple
macros to detect whether a workaround for the CAS (and others)
double-wide operations is needed.
Ivan Maidanski [Tue, 22 Nov 2016 01:18:08 +0000 (04:18 +0300)]
Report gcc/clang pedantic warnings (configure)
* configure.ac [GCC] (WPEDANTIC): New variable (set to
"-Wpedantic -Wno-long-long" if supported by the compiler).
* configure.ac [GCC] (CFLAGS): Add $WPEDANTIC.
Tobias Leich [Thu, 10 Nov 2016 08:02:56 +0000 (09:02 +0100)]
Implement fetch-CAS for s390[x] (gcc)
* src/atomic_ops/sysdeps/gcc/s390.h (AO_compare_and_swap_full): Do not
define if AO_GENERALIZE_ASM_BOOL_CAS.
* src/atomic_ops/sysdeps/gcc/s390.h (AO_fetch_compare_and_swap_full):
Implement; remove TODO item.
Ivan Maidanski [Tue, 1 Nov 2016 08:25:39 +0000 (11:25 +0300)]
Fix reporting about missing and/or/xor_dd_acquire_read (test_atomic)
AO_XSIZE_and/or/xor_dd_acquire_read are meaningless and not implemented,
thus their absence is not reported in the tests.
* tests/test_atomic_include.template [!AO_HAVE_orXX] (test_atomicXX):
Do not call MISSING(AO_or) if all AO_HAVE_or* excluding
AO_HAVE_or_dd_acquire_read are not defined.
* tests/test_atomic_include.template [!AO_HAVE_xorXX] (test_atomicXX):
Do not call MISSING(AO_xor) if all AO_HAVE_xor* excluding
AO_HAVE_xor_dd_acquire_read are not defined.
* tests/test_atomic_include.template [!AO_HAVE_andXX] (test_atomicXX):
Do not call MISSING(AO_and) if all AO_HAVE_and* excluding
AO_HAVE_and_dd_acquire_read are not defined.
This matters only if AO_double_compare_and_swap[_acquire_read] actually
defined in generalize.h too.
* src/atomic_ops/generalize.h
[!AO_HAVE_double_compare_and_swap_dd_acquire_read]
(AO_double_compare_and_swap_dd_acquire_read): Define (same as definition
as auto-generated in generalize-small.h).
Ivan Maidanski [Wed, 26 Oct 2016 08:57:13 +0000 (11:57 +0300)]
Workaround 'value of MAP_ANON unknown' cppcheck info message
(fix commit 4c303bc)
* src/atomic_ops_malloc.c [USE_MMAP_ANON && CPPCHECK] (OPT_MAP_ANON):
Define to immediate non-zero value (taken from Linux libc) instead of
MAP_ANON (because the latter is used in ifdef).
Ivan Maidanski [Tue, 18 Oct 2016 07:44:10 +0000 (10:44 +0300)]
Workaround 'value of macro is unknown' cppcheck information messages
* src/atomic_ops_malloc.c [USE_MMAP_ANON] (OPT_MAP_ANON): Define to 0
(do not use MAP_ANONYMOUS value) if CPPCHECK.
* src/atomic_ops_malloc.c [SIZE_MAX] (AO_SIZE_MAX): Do not use SIZE_MAX
value if CPPCHECK.
Ivan Maidanski [Mon, 17 Oct 2016 05:22:53 +0000 (08:22 +0300)]
Fix 'variable new value is never used' cppcheck style warning
Assertion for v value after fetch_and_sub1(&v) is added.
* tests/test_atomic_include.template (test_atomicXX): Call TA_assert
for s, b, zz values after they are decremented (use volatile pointer to
avoid "condition is always true" compiler warning).
Ivan Maidanski [Mon, 17 Oct 2016 05:08:18 +0000 (08:08 +0300)]
Workaround 'overflow in pointer subtraction' cppcheck warning
* src/atomic_ops_malloc.c (AO_free): Do not perform subtraction from
"p" argument if its value is null; change type of "base" local variable
from char* to AO_t*.
Ivan Maidanski [Tue, 11 Oct 2016 14:52:54 +0000 (17:52 +0300)]
Eliminate 'ISO C90 does not support long long' compiler pedantic warning
Long (32-bit) type is sufficient to represent time delta (duration)
in test_stack.
* tests/test_stack.c (get_msecs): Change return type from long long
to unsigned long (use lowest 32 bits of time value).
* tests/test_stack.c (main): Change type of start_time local variable
to unsigned long; remove redundant type cast.
Ivan Maidanski [Tue, 11 Oct 2016 07:01:35 +0000 (10:01 +0300)]
Eliminate 'scope of variable can be reduced' cppcheck warning in AO_stack
* src/atomic_ops_stack.c [AO_HAVE_compare_and_swap_double]
(AO_stack_push_release): Move local variable declaration to the inner
scope where the variable is actually used.
Jean Girardet [Mon, 10 Oct 2016 08:04:24 +0000 (11:04 +0300)]
Support AIX/ppc (gcc)
* src/atomic_ops/sysdeps/gcc/powerpc.h (AO_PPC_L, AO_PPC_BR_A): New
internal macros (undefined at the end of file); definition depends on
_AIX macro presence.
* src/atomic_ops/sysdeps/gcc/powerpc.h (AO_load_acquire,
AO_test_and_set, AO_compare_and_swap, AO_fetch_compare_and_swap,
AO_fetch_and_add): Use AO_PPC_L for label definitions; use AO_PPC_BR_A
to specify jump target.
Ivan Maidanski [Fri, 7 Oct 2016 16:27:09 +0000 (19:27 +0300)]
Code refactoring of gcc/powerpc.h to avoid code duplication
* src/atomic_ops/sysdeps/gcc/powerpc.h (AO_PPC_LD, AO_PPC_LxARX,
AO_PPC_CMPx, AO_PPC_STxCXd, AO_PPC_LOAD_CLOBBER): New internal macros
(undefined at the end of the file).
* src/atomic_ops/sysdeps/gcc/powerpc.h (AO_T_IS_INT): Move definition
upper (to have single check of __ppc64__).
* src/atomic_ops/sysdeps/gcc/powerpc.h (AO_load_acquire): Use AO_PPC_LD,
AO_PPC_LOAD_CLOBBER (and eliminate code duplication).
* src/atomic_ops/sysdeps/gcc/powerpc.h (AO_test_and_set,
AO_compare_and_swap, AO_fetch_compare_and_swap, AO_fetch_and_add): Use
AO_PPC_LxARX, AO_PPC_CMPx, AO_PPC_STxCXd (and eliminate code
duplication).
* tests/test_atomic_include.template (test_atomicXX): Treat "x"
variable as volatile one to suppress cppcheck warning that x==13 is
always true.
* tests/test_atomic_include.template (test_atomicXX): Make
TA_assert(x==117) unconditional to suppress cppcheck warning that the
value assigned by x=117 is never used.
Ivan Maidanski [Tue, 23 Aug 2016 21:50:49 +0000 (00:50 +0300)]
Eliminate 'scope of variable can be reduced' cppcheck warnings
* src/atomic_ops_malloc.c (msb): Declare "v" variable exactly in the
scope where the variable is used in.
* tests/run_parallel.h [USE_PTHREADS || USE_WINTHREADS] (run_parallel):
Declare "code" variable exactly in the scope where the variable is
used in.
Ivan Maidanski [Mon, 22 Aug 2016 17:12:19 +0000 (20:12 +0300)]
Fix size value wrap around in AO_malloc_large
AO_malloc(SIZE_MAX) should return NULL now.
* src/atomic_ops_malloc.c (SIZET_SAT_ADD): New macro.
* src/atomic_ops_malloc.c (AO_malloc_large): Use SIZET_SAT_ADD to
avoid integer overflow when computing the memory size to map (i.e.,
malloc should handle arguments close to SIZE_MAX correctly).
Ivan Maidanski [Sat, 20 Aug 2016 14:46:48 +0000 (17:46 +0300)]
Use C11 double-wide atomic intrinsics for Clang/x86 on Cygwin and OS X
Others (e.g., NDK clang/i686) still might need -latomic linker option.
* src/atomic_ops/sysdeps/gcc/x86.h
[AO_GCC_ATOMIC_TEST_AND_SET && __clang__]: Do not fallback to
non-intrinsic implementation if __APPLE_CC__ or __CYGWIN__.
Ivan Maidanski [Wed, 17 Aug 2016 16:51:30 +0000 (19:51 +0300)]
Fix (delete) comment for AO_and_full (x86)
* src/atomic_ops/sysdeps/gcc/x86.h [!AO_PREFER_GENERALIZED]
(AO_and_full): Remove incorrect comment (the code should work even for
i386).
* src/atomic_ops/sysdeps/sunc/x86.h [!AO_PREFER_GENERALIZED]
(AO_and_full): Likewise.