public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "peter at cordes dot ca" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/65146] alignment of _Atomic structure member is not correct
Date: Wed, 27 Apr 2022 12:37:16 +0000	[thread overview]
Message-ID: <bug-65146-4-AqHPyeShy1@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-65146-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65146

--- Comment #25 from Peter Cordes <peter at cordes dot ca> ---
(In reply to CVS Commits from comment #24)
> The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
> 
> https://gcc.gnu.org/g:04df5e7de2f3dd652a9cddc1c9adfbdf45947ae6
> 
> commit r11-2909-g04df5e7de2f3dd652a9cddc1c9adfbdf45947ae6
> Author: Jakub Jelinek <jakub@redhat.com>
> Date:   Thu Aug 27 18:44:40 2020 +0200
> 
>     ia32: Fix alignment of _Atomic fields [PR65146]
>     
>     For _Atomic fields, lowering the alignment of long long or double etc.
>     fields on ia32 is undesirable, because then one really can't perform
> atomic
>     operations on those using cmpxchg8b.


Just for the record, the description of this bugfix incorrectly mentioned
cmpxchg8b being a problem.  lock cmpxchg8b is *always* atomic, even if that
means the CPU has to take a bus lock (disastrously expensive affecting all
cores system-wide) instead of just delaying MESI response for one line
exclusively owned in this core's private cache (aka cache lock).

The correctness problem is __atomic_load_n / __atomic_store_n compiling to
actual 8-byte pure loads / pure stores using SSE2 movq, SSE1 movlps, or x87
fild/fistp (bouncing through the stack), such as

  movq  %xmm0, (%eax)

That's where correctness depends on Intel and AMD's atomicity guarantees which
are conditional on alignment.

(And if AVX is supported, same deal for 16-byte load/store.  Although we can
and should use movaps for that, which bakes alignment checking into the
instruction.  Intel did recently document that CPUs with AVX guarantee
atomicity of 16-byte aligned loads/stores, retroactive to all CPUs with AVX. 
It's about time, but yay.)

>     Not sure about iamcu_alignment change, I know next to nothing about IA
> MCU,
>     but unless it doesn't have cmpxchg8b instruction, it would surprise me
> if we
>     don't want to do it as well.


I had to google iamcu.  Apparently it's Pentium-like, but only has soft-FP (so
I assume no MMX or SSE as well as no x87).

If that leaves it no way to do 8-byte load/store except (lock) cmpxchg8b, that
may mean there's no need for alignment, unless cache-line-split lock is still a
performance issue.  If it's guaranteed unicore as well, we can even omit the
lock prefix and cmpxchg8b will still be an atomic RMW (or load or store) wrt.
interrupts.  (And being unicore would likely mean much less system-wide
overhead for a split lock.)

  parent reply	other threads:[~2022-04-27 12:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 19:58 [Bug c/65146] New: " alexey.lapshin at oracle dot com
2015-02-20 21:43 ` [Bug c/65146] " joseph at codesourcery dot com
2015-02-20 22:51 ` alexey.lapshin at oracle dot com
2015-02-20 23:32 ` joseph at codesourcery dot com
2020-08-26 14:59 ` [Bug target/65146] " jason at gcc dot gnu.org
2020-08-26 16:03 ` jakub at gcc dot gnu.org
2020-08-26 17:33 ` jakub at gcc dot gnu.org
2020-08-26 17:58 ` hjl.tools at gmail dot com
2020-08-27 16:45 ` cvs-commit at gcc dot gnu.org
2022-04-27 12:37 ` peter at cordes dot ca [this message]
2023-12-04 10:10 ` egallager at gcc dot gnu.org

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=bug-65146-4-AqHPyeShy1@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).