Date: Mon, 5 Jan 2026 09:36:37 +0100
On 04/01/2026 23:33, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Mon, Dec 29, 2025 at 1:35 AM Jonathan Wakely wrote:
>>
>>
>> You need -mcx16 to let GCC use that instruction, and even
>> with that option atomic ops will call into libatomic which decides
>> at runtime whether to use cmpxchg16b or not.
>
>
> I've been looking into this a bit. If I build the following program
> with GNU g++ trunk x86_64:
>
<snip long off-topic home-made disassembler stuff>
Why did you not simply look at the documentation for the flag if you
wanted to know what it does?
<https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-mcx16>
To quote from that page:
"""
This option enables GCC to generate CMPXCHG16B instructions in 64-bit
code to implement compare-and-exchange operations on 16-byte aligned
128-bit objects. This is useful for atomic updates of data structures
exceeding one machine word in size. The compiler uses this instruction
to implement Legacy __sync Built-in Functions for Atomic Memory Access.
However, for Built-in Functions for Memory Model Aware Atomic Operations
operating on 128-bit integers, a library call is always used.
"""
By some amazing coincidence, that is pretty much exactly what Jonathan
already told you. Who could have imagined that one of the key
developers of GCC and its C++ library would have been right?
None of this is relevant to the C++ standards process. If you feel the
need to write your own disassembler to verify that a compiler is doing
what the compiler documentation says it does, go ahead - but this is not
the place to post about it.
As a good rule of thumb for you, if anything you are thinking about
writing is not equally relevant to C++ on a small microcontroller as it
is to C++ on a top-range modern x86 processor, it is not relevant to the
C++ standards. x86 instructions are an implementation detail for
compilers, not part of the C++ language.
> On Mon, Dec 29, 2025 at 1:35 AM Jonathan Wakely wrote:
>>
>>
>> You need -mcx16 to let GCC use that instruction, and even
>> with that option atomic ops will call into libatomic which decides
>> at runtime whether to use cmpxchg16b or not.
>
>
> I've been looking into this a bit. If I build the following program
> with GNU g++ trunk x86_64:
>
<snip long off-topic home-made disassembler stuff>
Why did you not simply look at the documentation for the flag if you
wanted to know what it does?
<https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-mcx16>
To quote from that page:
"""
This option enables GCC to generate CMPXCHG16B instructions in 64-bit
code to implement compare-and-exchange operations on 16-byte aligned
128-bit objects. This is useful for atomic updates of data structures
exceeding one machine word in size. The compiler uses this instruction
to implement Legacy __sync Built-in Functions for Atomic Memory Access.
However, for Built-in Functions for Memory Model Aware Atomic Operations
operating on 128-bit integers, a library call is always used.
"""
By some amazing coincidence, that is pretty much exactly what Jonathan
already told you. Who could have imagined that one of the key
developers of GCC and its C++ library would have been right?
None of this is relevant to the C++ standards process. If you feel the
need to write your own disassembler to verify that a compiler is doing
what the compiler documentation says it does, go ahead - but this is not
the place to post about it.
As a good rule of thumb for you, if anything you are thinking about
writing is not equally relevant to C++ on a small microcontroller as it
is to C++ on a top-range modern x86 processor, it is not relevant to the
C++ standards. x86 instructions are an implementation detail for
compilers, not part of the C++ language.
Received on 2026-01-05 08:36:44
