Skip to content

feat(runtime-include): support std::atomic_ref in C++ programs - #73

Open
Ignition wants to merge 1 commit into
MPI-SWS:masterfrom
Ignition:worktree-atomic-ref-issue-72
Open

feat(runtime-include): support std::atomic_ref in C++ programs#73
Ignition wants to merge 1 commit into
MPI-SWS:masterfrom
Ignition:worktree-atomic-ref-issue-72

Conversation

@Ignition

Copy link
Copy Markdown

The bundled derives _LIBCPP_STD_VER from __cplusplus, nothing else supplying it: upstream libc++ has its build system set the macro, whereas this copy is included straight by the compiler driver. Unset it reads as zero, so the header's dialect checks fail and it offers its C++11 subset whatever -std it is compiled under, withholding the std::atomic::is_always_lock_free it already carries. The C++20 additions here sit behind the same checks: atomic_ref, atomic_flag::test, and wait/notify on atomic, atomic_flag and atomic_ref.

An atomic_ref's referent keeps the type and layout it was declared with, so it cannot go through _Atomic(T) as atomic does, and uses the GCC-style atomic builtins on a plain T* instead; the interpreter models those as atomic accesses to the object. They act on whole objects, which shapes two things: a value's padding bits are zeroed before it is handed to one, so that a compare-exchange ignores them as specified, and required_alignment reports the natural alignment atomic access needs rather than the weaker figure a type may declare for itself. wait() polls, which the spin-assume transformation turns into an assume and which leaves notify_one() and notify_all() as no-ops. It compares value representations, so a wait on 0.0 does not sit on a -0.0 that has arrived.

The runtime headers are installed whatever they are called, the C++ ones having no extension to match against.

The bundled <atomic> derives _LIBCPP_STD_VER from __cplusplus, nothing else
supplying it: upstream libc++ has its build system set the macro, whereas this
copy is included straight by the compiler driver. Unset it reads as zero, so
the header's dialect checks fail and it offers its C++11 subset whatever -std
it is compiled under, withholding the std::atomic<T>::is_always_lock_free it
already carries. The C++20 additions here sit behind the same checks:
atomic_ref, atomic_flag::test, and wait/notify on atomic, atomic_flag and
atomic_ref.

An atomic_ref's referent keeps the type and layout it was declared with, so it
cannot go through _Atomic(T) as atomic<T> does, and uses the GCC-style atomic
builtins on a plain T* instead; the interpreter models those as atomic accesses
to the object. They act on whole objects, which shapes two things: a value's
padding bits are zeroed before it is handed to one, so that a compare-exchange
ignores them as specified, and required_alignment reports the natural alignment
atomic access needs rather than the weaker figure a type may declare for
itself. wait() polls, which the spin-assume transformation turns into an assume
and which leaves notify_one() and notify_all() as no-ops. It compares value
representations, so a wait on 0.0 does not sit on a -0.0 that has arrived.

The runtime headers are installed whatever they are called, the C++ ones having
no extension to match against.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant