public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eliot Moss <moss@cs.umass.edu>
To: cygwin@cygwin.com, Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
Subject: Re: gcc and 128-bit compare/exchange
Date: Tue, 10 Mar 2020 17:13:56 -0400	[thread overview]
Message-ID: <de26ff04-596e-1dad-f2ae-4b91ba53f5c1@cs.umass.edu> (raw)
In-Reply-To: <66f51c13-4c87-3bd6-3b8e-01901155ef2a@SystematicSw.ab.ca>

On 3/10/2020 4:35 PM, Brian Inglis wrote:
> 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,
>>> __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
>>>
>>> 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

That is what I was already doing :-) .... it compiles and runs,
landing at libat_compare_exchange_16, which uses mutexes, not the
16-byte compare-exchange instruction.  So how do I get the compare-
exchange instruction to be used in the library?

Regards - EM

  reply	other threads:[~2020-03-10 21:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09  2:29 Eliot Moss
2020-03-09  2:59 ` Eliot Moss
2020-03-10 20:35   ` Brian Inglis
2020-03-10 21:13     ` Eliot Moss [this message]
2020-03-11  5:31       ` Brian Inglis
2020-03-11  6:13         ` Eliot Moss
2020-03-11 16:30           ` Brian Inglis
2020-03-12  3:36             ` Eliot Moss
2020-03-12 21:13               ` Brian Inglis
2020-03-12 22:49                 ` Eliot Moss
2020-03-13  5:35                   ` Brian Inglis
2020-03-11 17:31           ` Achim Gratz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=de26ff04-596e-1dad-f2ae-4b91ba53f5c1@cs.umass.edu \
    --to=moss@cs.umass.edu \
    --cc=Brian.Inglis@SystematicSw.ab.ca \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).