gcc and 128-bit compare/exchange

Brian Inglis Brian.Inglis@SystematicSw.ab.ca
Tue Mar 10 20:35:42 GMT 2020

On 2020-03-08 20:59, Eliot Moss wrote:
> On 3/8/2020 10:29 PM, Eliot Moss wrote:
>> This is probably to the gcc maintainer ...
>> I am running on a processor that has compare/exchange 128-bit (cx16 capability),
>> and I compiler with -mcx16 and -latomic.  I'm on the latest release cygwin gcc
>> (9.2.0-3, I believe) and the corresponding libatomic.  I have a program with
>> this in it:
>> __atomic_compare_exchange((__int128 *)&s1, (__int128 *)&z, (__int128 *)&s2, 0,
>> This compiles to a call (nice if it would inline, but ...) to
>> __atomic_compare_exchange_16, which uses mutex's, not the CMPXCHG16B
>> instruction I was hoping for.  Note I am doing dynamic linking,
>> which on at least one other platform results in dynamic selection
>> of a lib_at implementation of the compare/exchange, which does use
>> the desired instruction.
>> Is this a limitation of cygwin gcc, or should I be doing something
>> different to achieve the desired effect?
>> Obviously it would be best not to going an asm inline if I can avoid it,
>> but I suppose I can dig into the libatomic source to get the right
>> incantation for it if need be ...
> A quick followup: I was able to get __sync_val_compare_and_swap_16 to work
> (and its bool form).  That will do for now, though of course it's deprecated.

You just needed to go to the next info page:

	$ info gcc __atomic

and use:

	#include <stdatomic.h>
	extern bool __atomic_compare_exchange ( TYPE *ptr,
						TYPE *expected,
						TYPE *desired,
						bool weak,
						int success_memorder,
						int failure_memorder);

or higher level macro:

	atomic_compare_exchange_strong(PTR, VAL, DES)

defined in /lib/gcc/x86_64-pc-cygwin/*/include/stdatomic.h

Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

More information about the Cygwin mailing list