[SERVER-12064] AtomicIntrinsics is not portable Created: 12/Dec/13  Updated: 11/Jul/16  Resolved: 07/Jan/14

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 2.5.5

Type: Bug Priority: Major - P3
Reporter: Robie Basak Assignee: Andy Schwerin
Resolution: Done Votes: 0
Labels: pull-request
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-12283 Use gcc atomic builtins if available ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Pull request to follow. Existing tests in src/mongo/platform/atomic_word_test.cpp are sufficient to cover this change, as the AtomicIntrinsics API remains unchanged.



 Comments   
Comment by Githook User [ 09/May/14 ]

Author:

{u'name': u'Robie Basak', u'email': u'robie.basak@canonical.com'}

Message: SERVER-12064 SERVER-12283 Use gcc atomic builtins if available

Switch to using gcc atomic builtins for atomic operations if using a new
enough gcc and clang and support is available. Otherwise, fall back to
the old behaviour of existing non-portable inline assembly to continue
to support builds on older versions of gcc.

Signed-off-by: Benety Goh <benety@mongodb.com>
Branch: master
https://github.com/mongodb/mongo/commit/19cceceb780ab13104d5a4e44c373472ac5f430d

Comment by Matt Kangas [ 07/Jan/14 ]

Successor ticket for 2.7 is SERVER-12283

Comment by Githook User [ 07/Jan/14 ]

Author:

{u'name': u'Robie Basak', u'email': u'robie.basak@canonical.com'}

Message: SERVER-12064 Atomic operations for gcc non-Intel architectures

Add support for non-Intel architectures by using gcc builtins where
possible, but only on non-Intel builds. This permits builds to continue
to work on Intel architectures even with older gcc versions that do not
have the builtins.

atomic_intrinsics_gcc.h contains non-portable Intel assembly, so move it
to atomic_intrinsics_gcc_intel.h and add an
atomic_intrinsics_gcc_generic.h equivalent that uses only modern gcc
builtins.

Adjust atomic_intrinsics.h to use atomic_intrinsics_gcc_intel.h in the
Intel case, and atomic_instrinsics_gcc_generic.h in an additional
"otherwise" case.

This does not change behaviour or compatibility in the common IA-32 and
x86_64 cases. The previously existing code will continue to be used in
these cases. An older gcc without the modern gcc builtins will continue
to be able to build on these architectures because the previously
existing assembly will be used.

This does make this code fully portable to any architecture supported by
a modern gcc, since the new, generic code will be used in this case.
Branch: master
https://github.com/mongodb/mongo/commit/df3d84e688efbaa7c83666a1122761c29d10dfbe

Comment by Andy Schwerin [ 13/Dec/13 ]

Thanks, rwbb, for doing the extra work. I'll look it over and get back to you, hopefully early next week.

Comment by Robie Basak [ 13/Dec/13 ]

@Andy Schwerin,

Done, in https://github.com/mongodb/mongo/pull/582

I took a conservative approach initially, by adding use of gcc builtins as you suggest, but only in the case of non-Intel architectures, to minimise regression risk. But I've added a third commit for you to switch to using them on Intel architectures too where they are available.

Comment by Andy Schwerin [ 12/Dec/13 ]

rwbb, I recommend implementing a version in terms of the GCC intrinsics, if they're available on your platform. Those could actually be used on all platforms that support them, and would probably optimize better than the inline assembly, which the compiler is required to treat as opaque. A config check in the build system to look for the GCC intrinsics and setting an environment variable, and defaulting to them when available, would be a highly desirable implementation.

Generated at Thu Feb 08 03:27:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.