platform/upstream/libatomic_ops.git
7 years agoFix a typo in comment belonging to double_ptr_storage
Ivan Maidanski [Tue, 31 Jan 2017 07:56:23 +0000 (10:56 +0300)]
Fix a typo in comment belonging to double_ptr_storage
(fix commit 7633154)

* src/atomic_ops/sysdeps/standard_ao_double_t.h [!__ILP32__ && !__clang__
&& (__x86_64__ && AO_GCC_ATOMIC_TEST_AND_SET || __aarch64__)]
(double_ptr_storage): Fix typo in comment ("pedantic").

7 years agoFix test_atomic fail caused by AO_double_t misaligned load (Linux/i686)
Ivan Maidanski [Tue, 31 Jan 2017 07:29:44 +0000 (10:29 +0300)]
Fix test_atomic fail caused by AO_double_t misaligned load (Linux/i686)

* src/atomic_ops/sysdeps/standard_ao_double_t.h [__i386__ && __GNUC__]
(double_ptr_storage): Add aligned(8) attribute (so that AO_double_t
global/static variables to have proper (double-word) alignment).

7 years agoTravis CI: Exclude osx/gcc builds
Ivan Maidanski [Fri, 27 Jan 2017 21:36:09 +0000 (00:36 +0300)]
Travis CI: Exclude osx/gcc builds
(gcc is an alias to clang on OS X)

7 years agoTravis CI: Fix CFLAGS_EXTRA value with 2 options
Ivan Maidanski [Fri, 27 Jan 2017 21:29:16 +0000 (00:29 +0300)]
Travis CI: Fix CFLAGS_EXTRA value with 2 options
(fix commit e294a77)

7 years agoTravis CI: compile both for x86 and x64
Ivan Maidanski [Fri, 27 Jan 2017 17:20:31 +0000 (20:20 +0300)]
Travis CI: compile both for x86 and x64

7 years agoUse generalized double-wide load/store if AO_PREFER_GENERALIZED (gcc/x86)
Ivan Maidanski [Fri, 27 Jan 2017 16:46:07 +0000 (19:46 +0300)]
Use generalized double-wide load/store if AO_PREFER_GENERALIZED (gcc/x86)

* src/atomic_ops/sysdeps/gcc/x86.h [!__x86_64__ || __ILP32__]: Do not
include double_atomic_load_store.h if AO_PREFER_GENERALIZED.

7 years agoUse generalized load/store if AO_PREFER_GENERALIZED (gcc/generic)
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.

7 years agoAppveyor CI: Test double-wide CAS in debug builds (x86/x64)
Ivan Maidanski [Fri, 27 Jan 2017 16:11:22 +0000 (19:11 +0300)]
Appveyor CI: Test double-wide CAS in debug builds (x86/x64)

7 years agoSupport CFLAGS_EXTRA to pass extra user-defined compiler flags (MS VC)
Ivan Maidanski [Fri, 27 Jan 2017 16:05:17 +0000 (19:05 +0300)]
Support CFLAGS_EXTRA to pass extra user-defined compiler flags (MS VC)

* src/Makefile.msft: Remove commented out variable assignments.
* src/Makefile.msft (CFLAGS_EXTRA): New variable (empty by default).
* src/Makefile.msft (CFLAGS): Append CFLAGS_EXTRA value.

7 years ago.gitignore: Ignore test_atomic_generalized
Ivan Maidanski [Fri, 27 Jan 2017 06:47:03 +0000 (09:47 +0300)]
.gitignore: Ignore test_atomic_generalized

7 years agoAdd test_atomic_generalized to Makefile and Makefile.msft
Ivan Maidanski [Fri, 27 Jan 2017 06:37:15 +0000 (09:37 +0300)]
Add test_atomic_generalized to Makefile and Makefile.msft

* src/Makefile.msft (test_atomic_generalized): New target (same as
test_atomic but with -D AO_PREFER_GENERALIZED).
* src/Makefile.msft (check): Add dependency on test_atomic_generalized;
run test_atomic_generalized.
* tests/Makefile.am (TESTS): Add test_atomic_generalized.
* tests/Makefile.am [HAVE_PTHREAD_H] (TEST): Add test_atomic_pthreads
instead of specifying all tests.
* tests/Makefile.am (test_atomic_generalized_SOURCES,
test_atomic_generalized_LDADD): Define (same as for test_atomic).
* tests/Makefile.am (test_atomic_generalized_CPPFLAGS): Define
specifying -D AO_PREFER_GENERALIZED.

7 years agoAppveyor CI: run test_malloc/stack
Ivan Maidanski [Thu, 26 Jan 2017 20:10:57 +0000 (23:10 +0300)]
Appveyor CI: run test_malloc/stack

7 years agoEnable limited testing in Makefile.msft without Cygwin
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).

7 years agoTravis CI: compile for host CPU (to test double-wide primitives)
Ivan Maidanski [Thu, 26 Jan 2017 07:43:08 +0000 (10:43 +0300)]
Travis CI: compile for host CPU (to test double-wide primitives)

7 years agoImplement AO_CLEAR using C11 atomic intrinsic (GCC)
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).

7 years agoImplement compiler_barrier using C11 __atomic_signal_fence (GCC)
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).

7 years agoFix type of general AO_TS_INITIALIZER
Ivan Maidanski [Thu, 26 Jan 2017 06:46:57 +0000 (09:46 +0300)]
Fix type of general AO_TS_INITIALIZER

* src/atomic_ops.h (AO_TS_INITIALIZER): Change type from AO_t to
AO_TS_t; add outermost parentheses.

7 years agoFix test_atomic failure caused unaligned AO_double_t access on x86
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.

7 years agoRevert "Fix test_atomic fail caused unaligned AO_double_t access (VC/x86)"
Ivan Maidanski [Tue, 24 Jan 2017 14:49:58 +0000 (17:49 +0300)]
Revert "Fix test_atomic fail caused unaligned AO_double_t access (VC/x86)"

This reverts commit 69c4010c1b3d43e2e179421e27379aaa5aeeb6d8.

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.

7 years agoImplement char CAS and char/short add for msftc X86[_64] (VS 2013+)
Ivan Maidanski [Mon, 23 Jan 2017 22:42:06 +0000 (01:42 +0300)]
Implement char CAS and char/short add for msftc X86[_64] (VS 2013+)

* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800]
(_InterlockedCompareExchange8): Declare intrinsic.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800
&& !AO_PREFER_GENERALIZED && !_M_ARM] (_InterlockedExchangeAdd16,
_InterlockedExchangeAdd8): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>=1800]
(_InterlockedCompareExchange8): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>=1800
&& !AO_PREFER_GENERALIZED] (_InterlockedExchangeAdd16,
_InterlockedExchangeAdd8): Likewise.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800]
(AO_char_fetch_compare_and_swap_full): Implement using intrinsic.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>=1800
&& !AO_PREFER_GENERALIZED && !_M_ARM] (AO_char_fetch_and_add_full,
AO_short_fetch_and_add_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.h [!AO_NO_ASM_XADD]
(AO_char_fetch_and_add_full, AO_short_fetch_and_add_full): Do not
define if AO_HAVE_char_fetch_and_add_full.
* src/atomic_ops/sysdeps/msftc/x86_64.h [AO_ASM_X64_AVAILABLE]
(AO_char_fetch_and_add_full, AO_short_fetch_and_add_full): Do not use
asm-based implementation if _MSC_VER>=1800.

7 years agoImplement short inc/dec directly for msftc ARM and X86[_64]
Ivan Maidanski [Mon, 23 Jan 2017 22:32:41 +0000 (01:32 +0300)]
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.

7 years agoReally implement char and/or/xor and short CAS for msftc ARM (VS 2013+)
Ivan Maidanski [Mon, 23 Jan 2017 21:26:23 +0000 (00:26 +0300)]
Really implement char and/or/xor and short CAS for msftc ARM (VS 2013+)
(fix commit 9182c62)

* src/atomic_ops/sysdeps/msftc/common32_defs.h [_M_ARM]
(_InterlockedAnd8, _InterlockedCompareExchange16, _InterlockedOr8,
_InterlockedXor8): Declare intrinsic if _MSC_VER>=1800.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_M_ARM]
(AO_char_and_full, AO_char_or_full, AO_char_xor_full,
AO_short_fetch_compare_and_swap_full): Implement (using intrinsic) if
_MSC_VER>=1800.

7 years agoImplement char and/or/xor and short CAS for msftc ARM and X86[_64]
Ivan Maidanski [Sat, 21 Jan 2017 06:55:44 +0000 (09:55 +0300)]
Implement char and/or/xor and short CAS for msftc ARM and X86[_64]

* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>1400
&& !_M_ARM] (_InterlockedAnd8, _InterlockedCompareExchange16,
_InterlockedOr8, _InterlockedXor8): Declare intrinsic.
* src/atomic_ops/sysdeps/msftc/x86_64.h [_MSC_VER>1400]
(_InterlockedAnd8, _InterlockedCompareExchange16, _InterlockedOr8,
_InterlockedXor8): Likewise.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [_MSC_VER>1400
&& !_M_ARM] (AO_char_and_full, AO_char_or_full, AO_char_xor_full,
AO_short_fetch_compare_and_swap_full): Implement (using intrinsic).
* 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.

7 years agoRemove redundant include windows.h from headers (msftc/x86[_64])
Ivan Maidanski [Fri, 20 Jan 2017 16:23:45 +0000 (19:23 +0300)]
Remove redundant include windows.h from headers (msftc/x86[_64])

* src/atomic_ops/sysdeps/msftc/common32_defs.h: Do not include windows.h
if _MSC_VER > 1400 && AO_USE_INTERLOCKED_INTRINSICS && !_WIN32_WCE.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [!AO_PREFER_GENERALIZED
|| !AO_ASSUME_WINDOWS98] (AO_fetch_and_add_full, AO_fetch_and_add1_full,
AO_fetch_and_sub1_full): Replace LONG to long; remove unnecessary cast
to LONG.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [AO_ASSUME_WINDOWS98]
(AO_fetch_compare_and_swap_full): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h
(AO_int_fetch_compare_and_swap_full): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h [!AO_PREFER_GENERALIZED]
(AO_int_fetch_and_add_full, AO_int_fetch_and_add1_full,
AO_int_fetch_and_sub1_full): Likewise.
* src/atomic_ops/sysdeps/msftc/common32_defs.h [AO_ASSUME_WINDOWS98]
(AO_fetch_compare_and_swap_full): Replace PVOID to void*; remove
unnecessary cast to AO_t.
* src/atomic_ops/sysdeps/msftc/x86_64.h: Remove include windows.h.
* 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):
Replace LONGLONG to __int64; remove unnecessary cast to LONGLONG.
* src/atomic_ops/sysdeps/msftc/x86_64.h
(AO_fetch_compare_and_swap_full): Likewise.

7 years agoAlways define word-wide CAS for x86 (MS VC++ 8 or later)
Ivan Maidanski [Fri, 20 Jan 2017 15:10:05 +0000 (18:10 +0300)]
Always define word-wide CAS for x86 (MS VC++ 8 or later)

Visual Studio 2005 (MS VC++ 8.0) discontinued support of Windows 95.
This patch deprecates AO_ASSUME_WINDOWS98 macro.

* configure.ac (AO_ASSUME_WINDOWS98): Remove AH template.
* doc/README.txt (AO_ASSUME_WINDOWS98): Remove documentation (as
relates only to Win95).
* doc/README_win32.txt (AO_ASSUME_WINDOWS98): Likwise.
* doc/README_win32.txt (AO_ASSUME_VISTA): Update documentation.
* src/Makefile.msft (CFLAGS): Remove "-D AO_ASSUME_WINDOWS98".
* src/Makefile.msft (test_atomic_w95): Remove target.
* src/Makefile.msft (check): Do not call test_atomic_w95; remove the
corresponding printed message.
* src/atomic_ops/sysdeps/msftc/x86.h: Remove AO_ASSUME_WINDOWS98 from
comment.
* src/atomic_ops/sysdeps/msftc/x86.h (AO_ASSUME_WINDOWS98): Define
(implicitly) if _MSC_VER >= 1400.

7 years agoFix test_atomic failure caused unaligned AO_double_t access on x86 (VC++)
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++).

7 years agoAdd assertion that double-wide CAS target is aligned (msftc/x86[_64])
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.

7 years agoFix turn off optimization in case of configure --enable-gcov
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).

7 years agoAdd asm-based char/short/int CAS implementation for gcc/x86[_64]
Ivan Maidanski [Mon, 16 Jan 2017 22:48:48 +0000 (01:48 +0300)]
Add asm-based char/short/int CAS implementation for gcc/x86[_64]

* src/atomic_ops/sysdeps/gcc/x86.h [!AO_GCC_ATOMIC_TEST_AND_SET]
(AO_char_and_full, AO_char_or_full, AO_char_xor_full, AO_short_and_full,
AO_short_or_full, AO_short_xor_full): Do not define if
AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/gcc/x86.h [!AO_GCC_ATOMIC_TEST_AND_SET]
(AO_char_fetch_compare_and_swap_full,
AO_short_fetch_compare_and_swap_full): Implement.
* src/atomic_ops/sysdeps/gcc/x86.h [!AO_GCC_ATOMIC_TEST_AND_SET
&& __x86_64__ && !__ILP32__] (AO_int_fetch_compare_and_swap_full):
Likewise.
* src/atomic_ops/sysdeps/gcc/x86.h [!AO_GCC_ATOMIC_TEST_AND_SET
&& __x86_64__ && !__ILP32__] (AO_int_fetch_and_add_full,
AO_int_and_full, AO_int_or_full, AO_int_xor_full): Do not define if
AO_PREFER_GENERALIZED.

7 years agoImplement int CAS/inc/dec for msftc/x86_64
Ivan Maidanski [Mon, 16 Jan 2017 21:34:48 +0000 (00:34 +0300)]
Implement int CAS/inc/dec for msftc/x86_64

* src/atomic_ops/sysdeps/msftc/x86_64.h (_InterlockedExchangeAdd):
Declare (as intrinsic) only unless AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/msftc/x86_64.h (_InterlockedCompareExchange):
Declare intrinsic.
* src/atomic_ops/sysdeps/msftc/x86_64.h [!AO_PREFER_GENERALIZED]
(_InterlockedIncrement, _InterlockedDecrement): Likewise.
* src/atomic_ops/sysdeps/msftc/x86_64.h
(AO_int_fetch_compare_and_swap_full): Define inline function (using
_InterlockedCompareExchange).
* src/atomic_ops/sysdeps/msftc/x86_64.h (AO_int_fetch_and_add_full):
Do not define if AO_PREFER_GENERALIZED.
* src/atomic_ops/sysdeps/msftc/x86_64.h [!AO_PREFER_GENERALIZED]
(AO_int_fetch_and_add1_full, AO_int_fetch_and_sub1_full): Define inline
function _InterlockedIncrement/Decrement).

7 years agoRemove outdated FIXME in msftc/arm.h about _InterlockedOps memory barrier
Ivan Maidanski [Mon, 16 Jan 2017 20:55:01 +0000 (23:55 +0300)]
Remove outdated FIXME in msftc/arm.h about _InterlockedOps memory barrier

* src/atomic_ops/sysdeps/msftc/arm.h: Remove FIXME about memory barrier
of _InterlockedOps (they have the correct one according to the MSDN).

7 years agoAdd configure --enable-gcov option (enable code coverage analysis)
Ivan Maidanski [Fri, 13 Jan 2017 17:47:35 +0000 (20:47 +0300)]
Add configure --enable-gcov option (enable code coverage analysis)

* configure.ac (gcov): New --enable-* option.
* configure.ac [enable_gcov] (CFLAGS): Add "--coverage" option; filter
out "-O" options.

7 years ago.gitignore: Ignore gcov c/h output files
Ivan Maidanski [Fri, 13 Jan 2017 17:31:12 +0000 (20:31 +0300)]
.gitignore: Ignore gcov c/h output files

7 years agoFix 'atomic_load/store symbols undefined' error on OS X 10.8 i386
Ivan Maidanski [Thu, 12 Jan 2017 20:36:18 +0000 (23:36 +0300)]
Fix 'atomic_load/store symbols undefined' error on OS X 10.8 i386

Issue #23 (libatomic_ops).

* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& !__x86_64__ && __APPLE__ && __MACH__]: Include AvailabilityMacros.h
unless MAC_OS_X_VERSION_MIN_REQUIRED already defined.
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& !__x86_64__ && __APPLE__ && __MACH__
&& MAC_OS_X_VERSION_MIN_REQUIRED < 1090] (AO_SKIPATOMIC_double_load,
AO_SKIPATOMIC_double_load_acquire, AO_SKIPATOMIC_double_store,
AO_SKIPATOMIC_double_store_release): Define.

7 years agoFix AO_stack build failure on OS X 10.7 because of missing CAS (x86)
Ivan Maidanski [Wed, 28 Dec 2016 23:02:27 +0000 (02:02 +0300)]
Fix AO_stack build failure on OS X 10.7 because of missing CAS (x86)
(fix commit 7a6a7cc)

Issue #23 (libatomic_ops).

* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& __APPLE_CC__] (AO_GCC_FORCE_HAVE_CAS): Define also for arch i386;
refine comment.

7 years agoFix AO_stack build failure on OS X 10.7 because of missing CAS (x86_64)
Ivan Maidanski [Wed, 28 Dec 2016 20:43:05 +0000 (23:43 +0300)]
Fix AO_stack build failure on OS X 10.7 because of missing CAS (x86_64)

Issue #23 (libatomic_ops).

* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& __APPLE_CC__ && __x86_64__] (AO_GCC_FORCE_HAVE_CAS): Define (to
workaround missing __GCC_HAVE_SYNC_COMPARE_AND_SWAP_<n> predefined
macro in Apple clang-425/x86_64); add comment.

7 years ago.gitignore: Properly ignore sym-linked folders of code analysis tools
Ivan Maidanski [Wed, 14 Dec 2016 16:29:58 +0000 (19:29 +0300)]
.gitignore: Properly ignore sym-linked folders of code analysis tools
(fix commit fa3ebc3)

7 years ago.gitignore: Ignore folders and files of static code analysis tools
Ivan Maidanski [Mon, 12 Dec 2016 21:46:56 +0000 (00:46 +0300)]
.gitignore: Ignore folders and files of static code analysis tools

7 years agoSupport CFLAGS_EXTRA to pass extra user-defined compiler flags (configure)
Ivan Maidanski [Fri, 9 Dec 2016 21:31:25 +0000 (00:31 +0300)]
Support CFLAGS_EXTRA to pass extra user-defined compiler flags (configure)

* configure.ac: Add AC_SUBST(CFLAGS_EXTRA).
* src/Makefile.am (CFLAGS): Append $(CFLAGS_EXTRA).
* tests/Makefile.am (CFLAGS): Likewise.

7 years agoTravis CI configuration: turn on assertion checking
Ivan Maidanski [Wed, 7 Dec 2016 23:00:12 +0000 (02:00 +0300)]
Travis CI configuration: turn on assertion checking

7 years agoEliminate 'printf format specifies type void*' GCC pedantic warnings
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).

7 years agoWorkaround 'uninitialized memory use' MemorySanitizer warning (test_atomic)
Ivan Maidanski [Mon, 5 Dec 2016 17:26:16 +0000 (20:26 +0300)]
Workaround 'uninitialized memory use' MemorySanitizer warning (test_atomic)

* tests/test_atomic_include.template (test_atomicXX): Ensure old_w is
always initialized before AO_double_storeXX; add comment about MSan
false warning.

7 years agoUpdate ChangeLog file
Ivan Maidanski [Sat, 26 Nov 2016 18:58:00 +0000 (21:58 +0300)]
Update ChangeLog file

7 years agoUpdate ChangeLog file (v7.4 changes)
Ivan Maidanski [Sat, 26 Nov 2016 18:49:24 +0000 (21:49 +0300)]
Update ChangeLog file (v7.4 changes)

7 years agoWorkaround a bug in double-wide intrinsics of Clang/x64 with ASan enabled
Ivan Maidanski [Thu, 24 Nov 2016 17:13:06 +0000 (20:13 +0300)]
Workaround a bug in double-wide intrinsics of Clang/x64 with ASan enabled

As of clang-3.8, double-wide arguments are incorrectly passed to
atomic intrinsic operations for x64 target if Address Sanitizer is
enabled.

* src/atomic_ops.h [__has_feature(address_sanitizer)]
(AO_ADDRESS_SANITIZER): New internal macro.
* src/atomic_ops/sysdeps/gcc/x86.h [AO_GCC_ATOMIC_TEST_AND_SET
&& __clang__ && __x86_64__ && !__ILP32__]
(AO_SKIPATOMIC_double_compare_and_swap_ANY, AO_SKIPATOMIC_double_load,
AO_SKIPATOMIC_double_load_acquire, AO_SKIPATOMIC_double_store,
AO_SKIPATOMIC_double_store_release): Define also if AO_ADDRESS_SANITIZER;
update comment.

7 years agoCode refactoring of Clang double-wide intrinsic workarounds (gcc/x86)
Ivan Maidanski [Wed, 23 Nov 2016 10:55:00 +0000 (13:55 +0300)]
Code refactoring of Clang double-wide intrinsic workarounds (gcc/x86)
(fix commits 9803386, f6a1b68, eb6d4fd)

* 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.

7 years agoUndefine internal macros that are defined solely for generic.h
Ivan Maidanski [Wed, 23 Nov 2016 17:02:39 +0000 (20:02 +0300)]
Undefine internal macros that are defined solely for generic.h
(fix commits 03a0465f3c52619c66f7a4d3)

* src/atomic_ops/sysdeps/gcc/aarch64.h (AO_SKIPATOMIC_double_load,
AO_SKIPATOMIC_double_load_acquire): Undefine at the end of file.
* src/atomic_ops/sysdeps/gcc/arm.h (AO_SKIPATOMIC_ANY_and_ANY,
AO_SKIPATOMIC_ANY_or_ANY, AO_SKIPATOMIC_ANY_xor_ANY,
AO_SKIPATOMIC_char_store, AO_SKIPATOMIC_char_store_release,
AO_SKIPATOMIC_int_store, AO_SKIPATOMIC_int_store_release,
AO_SKIPATOMIC_short_store, AO_SKIPATOMIC_short_store_release,
AO_SKIPATOMIC_store, AO_SKIPATOMIC_store_release): Likewise.

7 years agoFix GCC -Wpedantic checking in configure
Ivan Maidanski [Tue, 22 Nov 2016 01:48:41 +0000 (04:48 +0300)]
Fix GCC -Wpedantic checking in configure
(fix commit 96a8fd9)

* configure.ac [GCC] (ac_cv_cc_pedantic): Compile code that contains
"extern int quiet" (since the translation unit cannot be empty).

7 years agoReport gcc/clang pedantic warnings (configure)
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.

7 years agoRefine AO_nop_write comment for ARM big.LITTLE architecture
Ivan Maidanski [Fri, 18 Nov 2016 15:22:00 +0000 (18:22 +0300)]
Refine AO_nop_write comment for ARM big.LITTLE architecture

* src/atomic_ops/sysdeps/gcc/arm.h [!AO_UNIPROCESSOR && AO_ARM_HAVE_DMB
&& !AO_PREFER_BUILTIN_ATOMICS] (AO_nop_write): Refine comment about
"dmb ishst" for big.LITTLE architecture.

7 years agoFix powerpc detection on AIX (gcc)
Tobias Leich [Thu, 17 Nov 2016 22:05:42 +0000 (01:05 +0300)]
Fix powerpc detection on AIX (gcc)

GCC/powerpc-ibm-aix does not define any of __powerpc__, __ppc__,
__PPC__, __powerpc64__, __ppc64__; but it does define _ARCH_PPC (and
_POWER).

* src/atomic_ops.h [_ARCH_PPC]: Include gcc/powerpc.h.

7 years agoDo not define print_list() unless used (tests)
Ivan Maidanski [Mon, 14 Nov 2016 20:09:57 +0000 (23:09 +0300)]
Do not define print_list() unless used (tests)

* tests/test_malloc.c (print_list): Define only if DEBUG_RUN_ONE_TEST.
* tests/test_stack.c (print_list): Define only if VERBOSE.

7 years agoFix indentation of #endif in s390.h
Ivan Maidanski [Sat, 12 Nov 2016 06:47:57 +0000 (09:47 +0300)]
Fix indentation of #endif in s390.h
(fix commit c2edeab)

* src/atomic_ops/sysdeps/gcc/s390.h (AO_fetch_compare_and_swap_full):
Adjust indentation of #endif.

7 years agoUpdate AUTHORS file (add 'Tobias Leich')
Ivan Maidanski [Thu, 10 Nov 2016 09:28:35 +0000 (12:28 +0300)]
Update AUTHORS file (add 'Tobias Leich')

7 years agoImplement fetch-CAS for s390[x] (gcc)
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.

7 years agoUpdate ChangeLog file
Ivan Maidanski [Tue, 8 Nov 2016 17:24:53 +0000 (20:24 +0300)]
Update ChangeLog file

7 years agoUpdate ChangeLog file (v7.4 changes)
Ivan Maidanski [Tue, 8 Nov 2016 06:04:28 +0000 (09:04 +0300)]
Update ChangeLog file (v7.4 changes)

7 years agoUpdate ChangeLog file (v7.2 - v7.4 changes only)
Ivan Maidanski [Fri, 4 Nov 2016 21:34:00 +0000 (00:34 +0300)]
Update ChangeLog file (v7.2 - v7.4 changes only)
(Cherry-pick commit 03a1704 from 'release-7_4' branch.)

7 years agoRemove spaces at EOLn in asm code
Ivan Maidanski [Tue, 8 Nov 2016 05:31:21 +0000 (08:31 +0300)]
Remove spaces at EOLn in asm code

* src/atomic_ops/sysdeps/gcc/hexagon.h (AO_test_and_set,
AO_compare_and_swap, AO_fetch_compare_and_swap): Remove spaces
preceding "\n".
* src/atomic_ops/sysdeps/gcc/mips.h (AO_nop_full, AO_fetch_and_add,
AO_test_and_set, AO_compare_and_swap): Likewise.
* src/atomic_ops/sysdeps/gcc/hexagon.h (AO_fetch_and_add,
AO_test_and_set, AO_fetch_compare_and_swap): Align comments.

7 years agoFix (improve) AO_REQUIRE_CAS description in README
Ivan Maidanski [Wed, 2 Nov 2016 08:15:15 +0000 (11:15 +0300)]
Fix (improve) AO_REQUIRE_CAS description in README

* doc/README.txt: Document AO_REQUIRE_CAS better (replace
"compare-and-swap" with "AO_compare_and_swap*").

7 years agoAdd *_and/or/xor* and *_[fetch_]compare_and_swap* tests to test_atomic
Ivan Maidanski [Tue, 1 Nov 2016 09:18:33 +0000 (12:18 +0300)]
Add *_and/or/xor* and *_[fetch_]compare_and_swap* tests to test_atomic

Previously, only AO_and/or/xor and AO_[fetch]_CAS tests (for AO_t)
existed in test_atomic.

* tests/test_atomic_include.template (test_atomicXX): Add minimal
testing of AO_short_compare_and_swapXX, AO_short_orXX, AO_short_xorXX,
AO_short_andXX, AO_short_fetch_compare_and_swapXX,
AO_char_compare_and_swapXX, AO_char_orXX, AO_char_xorXX, AO_char_andXX,
AO_char_fetch_compare_and_swapXX, AO_int_compare_and_swapXX,
AO_int_orXX, AO_int_xorXX, AO_int_andXX,
AO_int_fetch_compare_and_swapXX.

7 years agoFix reporting about missing and/or/xor_dd_acquire_read (test_atomic)
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.

7 years agoFix missing double_compare_and_swap_dd_acquire_read
Ivan Maidanski [Tue, 1 Nov 2016 08:12:21 +0000 (11:12 +0300)]
Fix missing double_compare_and_swap_dd_acquire_read

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).

7 years agoWorkaround 'value of MAP_ANON unknown' cppcheck info message
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).

7 years agoSuppress 'ISO C does not support __int128 type' GCC/Clang pedantic warning
Ivan Maidanski [Tue, 25 Oct 2016 08:13:05 +0000 (11:13 +0300)]
Suppress 'ISO C does not support __int128 type' GCC/Clang pedantic warning

* src/atomic_ops/sysdeps/standard_ao_double_t.h [!__ILP32__
&& (__GNUC__ >= 4.7 ||  __clang__ >= 3.6)] (double_ptr_storage): Turn
off pedantic warnings reporting (for this typedef only).

7 years agoFix test_malloc failure if CPPCHECK is defined
Ivan Maidanski [Tue, 25 Oct 2016 07:31:29 +0000 (10:31 +0300)]
Fix test_malloc failure if CPPCHECK is defined
(fix commit c1a7aad)

* src/atomic_ops_malloc.c [USE_MMAP_ANON && MAP_ANONYMOUS]
(OPT_MAP_ANON): Define to MAP_ANON (instead of 0) if CPPCHECK.

7 years agoWorkaround 'function is never used' cppcheck style warnings
Ivan Maidanski [Tue, 25 Oct 2016 07:13:35 +0000 (10:13 +0300)]
Workaround 'function is never used' cppcheck style warnings

* src/atomic_ops.h [AO_CAN_EMUL_CAS]: Include emul_cas.h also if
CPPCHECK (to define AO_store_full as AO_store_full_emulation).
* tests/test_atomic_include.template [CPPCHECK] (list_atomicXX,
char_list_atomicXX, short_list_atomicXX, int_list_atomicXX,
double_list_atomicXX): Declare function.
* tests/test_atomic_include.template test_atomicXX (test_atomicXX):
Call list_atomicXX, char_list_atomicXX, short_list_atomicXX,
int_list_atomicXX and double_list_atomicXX if CPPCHECK.

7 years agoAdd dd_acquire_read case to test_atomic
Ivan Maidanski [Mon, 24 Oct 2016 22:07:49 +0000 (01:07 +0300)]
Add dd_acquire_read case to test_atomic

* tests/Makefile.am (test_atomic_include.h): Add "_dd_acquire_read"
test generation.
* tests/test_atomic.c [!AO_NO_PTHREADS || !AO_USE_PTHREAD_DEFS] (main):
Call test_atomic_dd_acquire_read().

7 years agoHide AO_locks symbol
Ivan Maidanski [Mon, 24 Oct 2016 21:53:20 +0000 (00:53 +0300)]
Hide AO_locks symbol

* src/atomic_ops.c [!_MSC_VER && !__MINGW32__] (AO_locks): Define as
static.

7 years agoWorkaround 'value of macro is unknown' cppcheck information messages
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.

7 years agoMerge branch 'ppc-aix'
Ivan Maidanski [Mon, 17 Oct 2016 05:35:43 +0000 (08:35 +0300)]
Merge branch 'ppc-aix'

7 years agoFix 'variable new value is never used' cppcheck style warning
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).

7 years agoWorkaround 'overflow in pointer subtraction' cppcheck 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*.

7 years agoEliminate 'ISO C90 does not support long long' compiler pedantic warning
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.

7 years agoEliminate 'cast to long from void*' compiler warning in test_atomic
Ivan Maidanski [Wed, 12 Oct 2016 06:17:01 +0000 (09:17 +0300)]
Eliminate 'cast to long from void*' compiler warning in test_atomic

* tests/run_parallel.h (AO_PTRDIFF_T): Define to ptrdiff_t for all
targets.

7 years agoFix missing printed value names (test_stack)
Ivan Maidanski [Tue, 11 Oct 2016 14:45:01 +0000 (17:45 +0300)]
Fix missing printed value names (test_stack)

* tests/test_stack.c [VERBOSE] (main): Print value name along with the
value itself; print "ms" for time value; remove extra get_msecs() call.

7 years agoEliminate 'scope of variable can be reduced' cppcheck warning in AO_stack
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.

7 years agoUpdate AUTHORS file
Ivan Maidanski [Mon, 10 Oct 2016 20:15:06 +0000 (23:15 +0300)]
Update AUTHORS file

7 years agoSupport AIX/ppc (gcc)
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.

7 years agoCode refactoring of gcc/powerpc.h to avoid code duplication
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).

7 years agoFix 'visibility' of some CPU-specific internal macros
Ivan Maidanski [Thu, 6 Oct 2016 22:14:08 +0000 (01:14 +0300)]
Fix 'visibility' of some CPU-specific internal macros

Undefine internal macros that are defined and used solely in a single
CPU-specific file.

* src/atomic_ops/sysdeps/gcc/arm.h (AO_BR_ALIGN, AO_MASK_PTR,
AO_THUMB_GO_ARM, AO_THUMB_RESTORE_MODE, AO_THUMB_SWITCH_CLOBBERS):
Undefine at the end of file.
* src/atomic_ops/sysdeps/gcc/hppa.h (AO_PA_LDCW_ALIGNMENT, AO_ldcw,
AO_ldcw_align): Likewise.
* src/atomic_ops/sysdeps/gcc/ia64.h (AO_IN_ADDR, AO_LEN, AO_MASK,
AO_OUT_ADDR, AO_SWIZZLE): Likewise.
* src/atomic_ops/sysdeps/gcc/mips.h (AO_MIPS_LL, AO_MIPS_LL_1,
AO_MIPS_SC, AO_MIPS_SET_ISA): Likewise.
* src/atomic_ops/sysdeps/hpc/hppa.h (AO_PA_LDCW_ALIGNMENT, AO_ldcw,
AO_ldcw_align): Likewise.
* src/atomic_ops/sysdeps/hpc/ia64.h (AO_T_FASIZE, AO_T_SIZE): Likewise.
* src/atomic_ops/sysdeps/icc/ia64.h (AO_INTEL_PTR_t): Likewise.
* src/atomic_ops/sysdeps/test_and_set_t_is_char.h (AO_TS_SET_TRUEVAL):
Likewise.

7 years agoWorkaround '#error' cppcheck error messages
Ivan Maidanski [Wed, 5 Oct 2016 19:13:13 +0000 (22:13 +0300)]
Workaround '#error' cppcheck error messages

* src/atomic_ops.h [AO_REQUIRE_CAS && !AO_CAN_EMUL_CAS]: Skip #error
pragma if CPPCHECK.
* src/atomic_ops/generalize.h [AO_HAVE_nop_acquire]: Likewise.
* src/atomic_ops/generalize.h [AO_HAVE_nop_release]: Likewise.
* src/atomic_ops/sysdeps/armcc/arm_v6.h [__TARGET_ARCH_ARM < 6]:
Likewise.

7 years agoFix typos in 'error' pragma messages
Ivan Maidanski [Wed, 5 Oct 2016 18:47:35 +0000 (21:47 +0300)]
Fix typos in 'error' pragma messages

* src/atomic_ops.h [_HPUX_SOURCE && !__ia64] (AO_barrier_dummy):
Fix typo ("do not") in comment.
* src/atomic_ops/generalize.h [AO_HAVE_nop_acquire]: Fix typo
("do not") in #error message.
* src/atomic_ops/generalize.h [AO_HAVE_nop_release]: Likewise.
* src/atomic_ops/sysdeps/armcc/arm_v6.h [__TARGET_ARCH_ARM < 6]:
Likewise.
* src/atomic_ops/sysdeps/armcc/arm_v6.h [__TARGET_ARCH_ARM < 6]: Add
#error pragma.
* src/atomic_ops_stack.c [AO_HAVE_compare_and_swap_double]: Fix typo
("does not") in #error message.

7 years agoFix SIZET_SAT_ADD for the case of size_t is signed (SunOS 4.X)
Ivan Maidanski [Fri, 16 Sep 2016 17:45:32 +0000 (20:45 +0300)]
Fix SIZET_SAT_ADD for the case of size_t is signed (SunOS 4.X)

Negative size_t value is impossible in a correct C implementation,
but quite possible under SunOS 4.X.

* src/atomic_ops_malloc.c: Include limits.h (unless SIZE_MAX already
defined).
* src/atomic_ops_malloc.c (AO_SIZE_MAX): New macro.
* src/atomic_ops_malloc.c (SIZET_SAT_ADD): Use AO_SIZE_MAX instead of
~(size_t)0.

7 years agoWorkaround 'condition always true', 'unused stored value' cppcheck warnings
Ivan Maidanski [Wed, 24 Aug 2016 08:22:56 +0000 (11:22 +0300)]
Workaround 'condition always true', 'unused stored value' cppcheck warnings

* 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.

7 years agoFix assertions style in test_atomic_include
Ivan Maidanski [Wed, 24 Aug 2016 08:07:38 +0000 (11:07 +0300)]
Fix assertions style in test_atomic_include

Use TA_assert consistently (not assert).

* tests/test_atomic_include.template (test_atomicXX): Replace assert()
calls with TA_assert().

7 years agoEliminate 'scope of variable can be reduced' cppcheck warnings
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.

7 years agoFix size value wrap around in AO_malloc_large
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).

7 years agoWorkaround a bug in double-wide CAS intrinsic of Apple clang-600/x64
Ivan Maidanski [Sat, 20 Aug 2016 15:39:25 +0000 (18:39 +0300)]
Workaround a bug in double-wide CAS intrinsic of Apple clang-600/x64

The bug causes test_stack failure.

* src/atomic_ops/sysdeps/gcc/x86.h
[AO_GCC_ATOMIC_TEST_AND_SET && __APPLE_CC__ && __x86_64__]: Fall-back
to asm-based implementation of double-wide CAS
(AO_compare_double_and_swap_double_full); add comment explaining the
reason.
* src/atomic_ops/sysdeps/gcc/x86.h
[__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 && AO_GCC_ATOMIC_TEST_AND_SET
&& __APPLE_CC__] (AO_SKIPATOMIC_double_compare_and_swap_ANY): Define.

7 years agoUse C11 double-wide atomic intrinsics for Clang/x86 on Cygwin and OS X
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__.

7 years agoCode refactoring of int-wide primitives in gcc/x86.h
Ivan Maidanski [Sat, 20 Aug 2016 14:12:08 +0000 (17:12 +0300)]
Code refactoring of int-wide primitives in gcc/x86.h

* src/atomic_ops/sysdeps/gcc/x86.h (AO_int_fetch_and_add_full,
AO_int_and_full, AO_int_or_full, AO_int_xor_full, AO_T_IS_INT): Move
to separate 'ifdef' block (inside AO_DISABLE_GCC_ATOMICS case).

7 years agoAvoid extra nop_full in stack_pop_acquire if atomic intrinsics used (x86)
Ivan Maidanski [Thu, 18 Aug 2016 22:05:39 +0000 (01:05 +0300)]
Avoid extra nop_full in stack_pop_acquire if atomic intrinsics used (x86)

* src/atomic_ops/generalize.h [AO_HAVE_double_compare_and_swap_acquire]
(AO_compare_double_and_swap_double_acquire): Implement (by redirecting
to AO_double_compare_and_swap_acquire).
* src/atomic_ops/generalize.h [AO_HAVE_double_compare_and_swap_release]
(AO_compare_double_and_swap_double_release): Implement (by redirecting
to AO_double_compare_and_swap_release).

7 years agoAdd CI (continuous integration) badges to README
Ivan Maidanski [Thu, 18 Aug 2016 18:04:00 +0000 (21:04 +0300)]
Add CI (continuous integration) badges to README

7 years agoRefine README how to build the library source from the repository
Ivan Maidanski [Thu, 18 Aug 2016 09:10:51 +0000 (12:10 +0300)]
Refine README how to build the library source from the repository

* README.md (Installation and Usage): Add information that autogen.sh
should be launched first if building from the development repository.

7 years agoRefine README about library downloading
Ivan Maidanski [Thu, 18 Aug 2016 09:03:15 +0000 (12:03 +0300)]
Refine README about library downloading

* README.md (Download): New section; add link to Download page (located
on GitHub); add information about the code repository.

7 years agoAdd asm-based and/or/xor implementation for char/short/int (gcc/x86)
Ivan Maidanski [Thu, 18 Aug 2016 08:03:32 +0000 (11:03 +0300)]
Add asm-based and/or/xor implementation for char/short/int (gcc/x86)

* src/atomic_ops/sysdeps/gcc/x86.h [AO_DISABLE_GCC_ATOMICS]
(AO_char_and_full, AO_char_or_full, AO_char_xor_full,
AO_short_and_full, AO_short_or_full, AO_short_xor_full): New inline
function.
* src/atomic_ops/sysdeps/gcc/x86.h [AO_DISABLE_GCC_ATOMICS
&& !AO_T_IS_INT] (AO_int_and_full, AO_int_or_full, AO_int_xor_full):
Likewise.

7 years agoFix (delete) comment for AO_and_full (x86)
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.

7 years agoAdd configuration file for AppVeyor CI
Ivan Maidanski [Mon, 15 Aug 2016 19:44:10 +0000 (22:44 +0300)]
Add configuration file for AppVeyor CI

* appveyor.yml: New file (not a part of the distribution archive).

7 years agoAdd configure '--disable-atomic-intrinsics' option
Ivan Maidanski [Mon, 15 Aug 2016 17:08:56 +0000 (20:08 +0300)]
Add configure '--disable-atomic-intrinsics' option

* configure.ac (atomic-intrinsics): New configure option.
* configure.ac (AO_DISABLE_GCC_ATOMICS): Replace AH_TEMPLATE with
AC_DEFINE depending atomic-intrinsics option.

7 years agoFix store-load ordering in AO_stack_pop_explicit_aux_acquire (PowerPC)
Hans Boehm [Mon, 15 Aug 2016 08:32:33 +0000 (11:32 +0300)]
Fix store-load ordering in AO_stack_pop_explicit_aux_acquire (PowerPC)

Issue #15.

The core issue is that AO_stack_pop_explicit_aux_acquire really needs
to ensure that the store to the blacklist via
AO_compare_and_swap_acquire becomes visible before the load to check
the list head.  This effectively needs store-load ordering.
Currently the only ordering here is imposed by the _acquire on the
compare_and_swap.  On PowerPC that turns into an lwsync, which is too
weak to enforce store to load ordering.

This patch should fix the issue.  But this is suboptimal on x86, and
we may want to make the fence conditional on "not x86", where the CAS
already includes sufficient ordering.  (With C++11 atomics, this would
also be tricky and probably involve making a bunch of accesses seq_cst.)

* src/atomic_ops_stack.c [AO_USE_ALMOST_LOCK_FREE]
(AO_stack_pop_explicit_aux_acquire): Call AO_compare_and_swap instead
of AO_compare_and_swap_acquire; call AO_nop_full just before
(first != AO_load(list)).