public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "juki at gcc dot mail.kapsi.fi" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/113025] Pointer is sometimes assumed to be 16-byte aligned even when there is no such guarantee
Date: Mon, 18 Dec 2023 21:30:09 +0000	[thread overview]
Message-ID: <bug-113025-4-omI2qdTwPI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113025-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from juki at gcc dot mail.kapsi.fi ---
(In reply to Xi Ruoyao from comment #4)
> (In reply to Xi Ruoyao from comment #3)
> > 
> > This won't work if ptr is a __m128i *.  It is allowed to optimize
> > (uintptr_t)(__m128i *)foo % 15 to 0 because the standard says (__m128i *)foo
> 
> I mean % 16, not % 15.
> 
> > invokes undefined behavior when foo is a pointer not aligned to 16-byte
> > boundary (C23 section 6.3.2.3p6).

ptr on this case is one of the parameter types defined for various memory load
intrinsics of NEON instruction set like vld1q_u8(const uint8_t *ptr) or
vld1q_u16(const uint16_t *ptr). These instructions expect natural alignment of
that type which is why unaligned load is needed for SSE operation to work with
them in general case.

The same macro is used to implement all those different loads that just need to
read 128 bits of memory into a vector. Alignment of ptr is something smaller
than 16 and can be as low as 1 for const uint8_t which it is has been for the
cases that have been crashing for me.

  parent reply	other threads:[~2023-12-18 21:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14 21:39 [Bug c++/113025] New: " juki at gcc dot mail.kapsi.fi
2023-12-14 21:44 ` [Bug c++/113025] " pinskia at gcc dot gnu.org
2023-12-18 17:10 ` juki at gcc dot mail.kapsi.fi
2023-12-18 17:13 ` pinskia at gcc dot gnu.org
2023-12-18 21:14 ` xry111 at gcc dot gnu.org
2023-12-18 21:14 ` xry111 at gcc dot gnu.org
2023-12-18 21:30 ` juki at gcc dot mail.kapsi.fi [this message]
2023-12-18 21:41 ` xry111 at gcc dot gnu.org
2023-12-18 22:01 ` juki at gcc dot mail.kapsi.fi

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-113025-4-omI2qdTwPI@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).