Skip to content

Use C++20 atomics for packed bit-vector helpers - #646

Merged
adamant-pwn merged 1 commit into
codex/cxx20-dependency-updatefrom
codex/atomic-memory-orders
Oct 11, 2026
Merged

adamant-pwn merged 1 commit into
codex/cxx20-dependency-updatefrom
codex/atomic-memory-orders

Conversation

@adamant-pwn

@adamant-pwn adamant-pwn commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Use C++20 std::atomic_ref for packed bit-vector words and 64-bit differential counters. The bit-vector helpers accept std::memory_order directly, so the compiler-order conversion switch is removed. Keep the existing builtin operations for packed 8/16/32-bit counters; all counter call sites already use relaxed ordering, so their unused ordering parameter is removed.

A small load-only wrapper works around libc++ versions that cannot instantiate atomic_ref::load. The new header uses a project-prefixed guard. Extend concurrent coverage to both setting and clearing bits.

Validation: GCC, Clang and Clang/libc++ concurrency checks pass, as does UBSan. Before/after instruction lists match for 11 bit operations on each compiler (33 comparisons). Targeted translation units and the committed regression test pass. Full CI will rerun after restacking.

Stacked on #649. Review/merge order: #647 → #648 → #649 → #646 → #644.


Summary by cubic

Switches the packed bit-vector atomic helpers from compiler builtins and integer memory orders to std::atomic_ref with std::memory_order, since the implicit conversion between them breaks under C++20. A new utils::atomic_load wrapper covers const access, which libc++'s atomic_ref<const T> cannot instantiate.

  • Callers using the atomic flag now pass std::memory_order_*; external callers passing __ATOMIC_* constants must switch to the standard enum.
  • atomic_fetch and atomic_fetch_and_add dropped their memory-order parameter and are always relaxed; 64-bit counters use atomic_ref while 8/16/32-bit counters keep the builtin operations.
  • Adds a concurrent test verifying each bit transitions exactly once across five memory orders, for both setting and clearing.

Written for commit 40a6222. Summary will update on new commits.

View guided diff Turn on auto-fix

Base automatically changed from codex/ci-native-macos to master October 11, 2026 17:03
@adamant-pwn
adamant-pwn marked this pull request as ready for review October 11, 2026 17:03
@adamant-pwn
adamant-pwn added this pull request to stack #650 October 11, 2026 17:05
@adamant-pwn
adamant-pwn force-pushed the codex/atomic-memory-orders branch from 0e9f586 to 0fde72c Compare October 11, 2026 17:06

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread metagraph/src/common/utils/atomic.hpp Resolved
@adamant-pwn
adamant-pwn removed this pull request from stack #650 October 11, 2026 19:01
@adamant-pwn
adamant-pwn force-pushed the codex/atomic-memory-orders branch from 0fde72c to b36b1d3 Compare October 11, 2026 19:01
@adamant-pwn adamant-pwn changed the title Use typed memory orders for packed-vector atomic helpers Use C++20 atomics for packed bit-vector helpers Oct 11, 2026
@adamant-pwn
adamant-pwn changed the base branch from master to codex/cxx20-dependency-update October 11, 2026 19:01
@adamant-pwn
adamant-pwn added this pull request to stack #652 October 11, 2026 19:01
@adamant-pwn
adamant-pwn force-pushed the codex/atomic-memory-orders branch 3 times, most recently from 6228ec6 to bad6d1d Compare October 11, 2026 22:19
adamant-pwn added a commit that referenced this pull request Oct 11, 2026
@adamant-pwn
adamant-pwn force-pushed the codex/atomic-memory-orders branch from 75c6e7a to 40a6222 Compare October 11, 2026 22:40
@adamant-pwn
adamant-pwn merged commit 40a6222 into master Oct 11, 2026
14 of 25 checks passed
@adamant-pwn
adamant-pwn deleted the codex/atomic-memory-orders branch October 11, 2026 22:48
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