mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Joakim Sindholt <opensource@zhasha.com>
To: musl@lists.openwall.com
Subject: Re: max_align_t mess on i386
Date: Sun, 15 Dec 2019 19:23:14 +0100	[thread overview]
Message-ID: <20191215182314.GB986899@wirbelwind.zhasha.com> (raw)
In-Reply-To: <CAH8yC8kKok5EuXoRBdNANvEum3R5aSr8e2HNidhfJ9qW9nxwKQ@mail.gmail.com>

On Sun, Dec 15, 2019 at 01:06:29PM -0500, Jeffrey Walton wrote:
> On Sat, Dec 14, 2019 at 10:19 AM Rich Felker <dalias@libc.org> wrote:
> >
> > In reserching how much memory could be saved, and how practical it
> > would be, for the new malloc to align only to 8-byte boundaries
> > instead of 16-byte on archs where alignof(max_align_t) is 8 (pretty
> > much all 32-bit archs), I discovered that GCC quietly changed its
> > idead of i386 max_align_t to 16-byte alignment in GCC 7, to better
> > accommodate the new _Float128 access via SSE. Presumably (I haven't
> > checked) the change is reflected with changes in the psABI document to
> > make it "official".
> 
> Be careful with policy changes like this. The malloc (3) man page says:
> 
>     The malloc() and calloc() functions return a pointer to the
>     allocated memory that is suitably aligned for any kind of variable.

Your man pages are not the standard, but the standard does have this to
say:
> The pointer returned if the allocation succeeds shall be suitably
> aligned so that it may be assigned to a pointer to any type of object
> and then used to access such an object in the space allocated (until the
> space is explicitly freed or reallocated).

To me this sounds like my next suggestion is technically disallowed.

> I expect to be able to use a pointer returned by malloc (and friends)
> in MMX, SSE and AVX functions.

I might agree, but would it not be feasible to have the alignment of the
returned pointer be dependent on the size of the allocation? That way,
if you allocate <16 bytes you can get 8 byte alignment. You might even
be able to go all the way down to 4 byte alignment for <8 byte
allocations.
It might violate the standard technically speaking, but I don't know of
any examples of types smaller than 16 bytes that require 16 byte
alignment.


  parent reply	other threads:[~2019-12-15 18:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-14 15:19 Rich Felker
2019-12-14 17:51 ` Florian Weimer
2019-12-14 18:17   ` Rich Felker
2019-12-14 18:53     ` Daniel Kolesa
2019-12-15 18:04   ` Rich Felker
2019-12-15  5:47 ` Markus Wichmann
2019-12-15 18:06 ` Jeffrey Walton
2019-12-15 18:22   ` Rich Felker
2019-12-16 15:30     ` Jeffrey Walton
2019-12-16 15:56       ` Rich Felker
2019-12-16 16:36         ` Jeffrey Walton
2019-12-16 17:49           ` Rich Felker
2019-12-16 16:40         ` Florian Weimer
2019-12-16 17:45           ` Rich Felker
2019-12-16 17:49             ` Florian Weimer
2019-12-16 17:51               ` Rich Felker
2019-12-15 18:23   ` Joakim Sindholt [this message]
2019-12-15 18:51     ` Rich Felker
2019-12-15 20:03       ` Alexander Monakov
2019-12-15 20:50         ` Szabolcs Nagy
2019-12-15 21:51         ` Jeffrey Walton

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=20191215182314.GB986899@wirbelwind.zhasha.com \
    --to=opensource@zhasha.com \
    --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).