C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::atomic_pointer_pair

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Mon, 29 Dec 2025 17:53:08 +0300
On 29 Dec 2025 17:17, Frederick Virchanza Gotham via Std-Proposals wrote:
>
> I think it's clear what I need to do here:
>
> I need to edit the GNU g++ compiler to add a new command line option "-
> mcx16-force", but actually I will name it "-mlockfree2ptrs". When this
> command line option is given, the following boolean is true at compile time:
>
> atomic< __uint128_t >::is_always_lock_free
>
> And when you work with this type, the assembler is placed inline (i.e.
> it doesn't call into libatomic).

I think, this should already be the case if you specify a recent enough
-march (or a sufficient combination of -m flags). It partly is with
clang, but not with gcc. I think, you should report bugs to compiler devs.

https://godbolt.org/z/5j8aseGMG

> I will also add a second command line option, "-mlockfree2ptrs-
> main=main2". If you use this command line option, then the '_start'
> routine gets extra instructions as follows:
>
> mov $1, %eax
> cpuid
> bt $13, %ecx # CF = ECX[13]
> jnc main2
>
> So basically if 'cmpxchg16b' is not supported, it jumps into 'main2',
> where you can do something like:
>
> void main2(void)
> {
> puts("Contact Stephen on stephen_at_[hidden]
> <mailto:stephen_at_[hidden]> to get the build you need for your system
> -- you need the x86_64 build without atomic pointer pairs");
> }

Why do you need a separate main2() if you can already do all of this in
the standard main()?

Received on 2025-12-29 14:53:11