From: Florian Weimer <fweimer@redhat.com>
To: "H.J. Lu via Libc-alpha" <libc-alpha@sourceware.org>
Subject: Re: [PATCH] x86: Optimize atomic_compare_and_exchange_[val|bool]_acq [BZ #28537]
Date: Wed, 03 Nov 2021 17:35:54 +0100 [thread overview]
Message-ID: <871r3xb3it.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20211103150415.1211388-1-hjl.tools@gmail.com> (H. J. Lu via Libc-alpha's message of "Wed, 3 Nov 2021 08:04:15 -0700")
* H. J. Lu via Libc-alpha:
> diff --git a/sysdeps/x86/atomic-machine.h b/sysdeps/x86/atomic-machine.h
> index 2692d94a92..92c7cf58b7 100644
> --- a/sysdeps/x86/atomic-machine.h
> +++ b/sysdeps/x86/atomic-machine.h
> @@ -73,9 +73,19 @@ typedef uintmax_t uatomic_max_t;
> #define ATOMIC_EXCHANGE_USES_CAS 0
>
> #define atomic_compare_and_exchange_val_acq(mem, newval, oldval) \
> - __sync_val_compare_and_swap (mem, oldval, newval)
> + ({ __typeof (*(mem)) oldmem = *(mem), ret; \
> + ret = (oldmem == (oldval) \
> + ? __sync_val_compare_and_swap (mem, oldval, newval) \
> + : oldmem); \
> + ret; })
> #define atomic_compare_and_exchange_bool_acq(mem, newval, oldval) \
> - (! __sync_bool_compare_and_swap (mem, oldval, newval))
> + ({ __typeof (*(mem)) old = *(mem); \
> + int ret; \
> + if (old != (oldval)) \
> + ret = 1; \
> + else \
> + ret = !__sync_bool_compare_and_swap (mem, oldval, newval); \
> + ret; })
Shouldn't GCC be fixed to generate the appropriate instruction sequence
for this architecture? Should we perhaps switch to compiler atomics for
x86 instead of defining our own?
Thanks,
Florian
next prev parent reply other threads:[~2021-11-03 16:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-03 15:04 H.J. Lu
2021-11-03 15:14 ` Andreas Schwab
2021-11-03 15:50 ` Oleh Derevenko
2021-11-03 16:59 ` Arjan van de Ven
2021-11-03 17:17 ` Andreas Schwab
2021-11-03 19:21 ` Arjan van de Ven
2021-11-03 19:48 ` H.J. Lu
2021-11-03 20:38 ` Oleh Derevenko
2021-11-03 22:12 ` H.J. Lu
2021-11-04 8:58 ` Oleh Derevenko
2021-11-04 9:44 ` Oleh Derevenko
2021-11-03 17:26 ` Oleh Derevenko
2021-11-03 17:30 ` Arjan van de Ven
2021-11-03 17:55 ` Oleh Derevenko
2021-11-03 19:22 ` Arjan van de Ven
2021-11-04 11:42 ` Oleh Derevenko
2021-11-04 14:15 ` Arjan van de Ven
2021-11-03 16:35 ` Florian Weimer [this message]
2021-11-03 19:13 ` H.J. Lu
2021-11-04 10:15 ` Florian Weimer
2021-11-04 14:31 ` H.J. Lu
2021-11-04 14:59 ` H.J. Lu
2021-11-03 17:25 ` Noah Goldstein
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=871r3xb3it.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
/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).