public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
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 16:14:35 +0100	[thread overview]
Message-ID: <87zgql1db8.fsf@igel.home> (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")

On Nov 03 2021, H.J. Lu via Libc-alpha wrote:

> 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; })

Can't this cause the CAS to fail spuriously if the compiler used
some stale cached value for *mem?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

  reply	other threads:[~2021-11-03 18:00 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 [this message]
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
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=87zgql1db8.fsf@igel.home \
    --to=schwab@linux-m68k.org \
    --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).