mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: _STRING_ARCH_unaligned or equivalent definition
Date: Sat, 24 Oct 2015 15:43:48 -0400	[thread overview]
Message-ID: <20151024194348.GT8645@brightrain.aerifal.cx> (raw)
In-Reply-To: <20151024115704.GM10551@port70.net>

On Sat, Oct 24, 2015 at 01:57:04PM +0200, Szabolcs Nagy wrote:
> * P?draig Brady <P@draigBrady.com> [2015-10-24 10:21:31 +0100]:
> > I was writing some code which uses faster word at a time
> > but possibly unaligned access when we know that unaligned
> > access is OK, i.e. #if _STRING_ARCH_unaligned provided by glibc.
> > 
> > I would like not to fall back to the slower path on musl.
> > Is there a similar define for musl. Is is worth proposing
> > a standard define somewhere?
> > 
> 
> you have to negotiate with the compiler about this,
> not with the libc.

Indeed. Just because i386 allows misaligned accesses at the hardware
level doesn't mean it's safe to write them in C code. A compiler is
perfectly justified in assuming that, if _Alignof(int) is 4, reaching
a statement that evaluates or assigns to *p (where p has type int*)
implies that the low 2 bits of p are 0. It could use this knowledge to
reduce the number of special cases needed for vectorization, or to
optimize out a conditional like if ((uintptr_t)p % 4). I would
actually not be surprised if firm's constbits analysis is capable of
doing the latter.

GCC may agree not to do these things for compatibility with legacy
code, but that's compiler-specific and not something libc can promise.

Rich


      reply	other threads:[~2015-10-24 19:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-24  9:21 Pádraig Brady
2015-10-24 11:57 ` Szabolcs Nagy
2015-10-24 19:43   ` Rich Felker [this message]

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=20151024194348.GT8645@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).