public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org
Cc: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>,
	       Jason Merrill <jason@redhat.com>,
	       Christophe Lyon <christophe.lyon@linaro.org>,
	       Andreas Schwab <schwab@linux-m68k.org>,
	       gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: RFA (libstdc++): PATCH to implement C++17 over-aligned new
Date: Fri, 16 Sep 2016 11:12:00 -0000	[thread overview]
Message-ID: <20160916105608.GO17376@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1609161116130.3301@laptop-mg.saclay.inria.fr>

On 16/09/16 11:37 +0200, Marc Glisse wrote:
>On Fri, 16 Sep 2016, Jonathan Wakely wrote:
>
>>On 16/09/16 09:04 +0200, Rainer Orth wrote:
>>>Hi Jason,
>>>
>>>>OK, one more:
>>>
>>>this works just fine on both sparc-sun-solaris2.12 and
>>>i386-pc-solaris2.12.
>>>
>>>Once Jonathan's patch to heed aligned_alloc's requirement on size being
>>>a multiple of alignment is in, all is fine on Solaris.
>>
>>I've got a slightly different fix now.
>>
>>We only need to make the size a multiple of alignment for
>>aligned_alloc, however for posix_memalign we need to ensure the
>>alignment is a multiple of sizeof(void*).
>>
>>I'm testing this now (but only on x86_64 GNU/Linux where it wasn't
>>failing anyway).
>
>+  // The value of alignment shall be a power of two multiple of sizeof(void *).
>+  if (al < sizeof(void*))
>+    al = sizeof(void*);
>
>The code doesn't exactly match the comment. I can't find the 
>precondition in the standard that says operator new can only be called 
>on a power of 2... (maybe we can add it if it is really missing?)

[basic.align] says "Every alignment value shall be a non-negative
integral power of two." So asking operator new for any other value
doesn't make sense, but I can't find a restriction on doing so.

I was assuming we only need to ensure it's possible to use valid
alignments such as align_val_t(2) which are not valid arguments to
posix_memalign. For other values such as align_val_t(15) I was
assuming it's OK for posix_memalign to fail, so we throw bad_alloc.

If that's not the case then we need to round up all alignments that
aren't power of two multiples of sizeof(void*). I'd like to avoid
that.

>>Would using __builtin_expect (sz == 0, false) make sense?  Surely it's
>>rare to try to allocate zero bytes.
>
>https://gcc.gnu.org/ml/libstdc++/2014-03/msg00001.html
>
>gcc already guesses that a test like sz == 0 is usually false (not 
>with as large a probability as if you use __builtin_expect, but enough 
>that the generated code is unlikely to differ). But adding 
>__builtin_expect cannot hurt...
>
>Is the division (by a non-constant denominator) really necessary? 

Probably not, but I've asked the committee for clarification what this
function should do when called with an invalid alignment.

>Since align has to be a power of 2, x % align should be the same as x 
>& (align - 1), for instance.

Thanks, if it's UB to call it with alignments that aren't a power of
two then we can do that.

>I guess people interested in performance will do for aligned new the 
>same as for the old new: provide an inline version that skips all the 
>overhead to forward directly to malloc/aligned_alloc (and avoid 
>questionable calls in their code).
>
>-- 
>Marc Glisse

  reply	other threads:[~2016-09-16 10:56 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-08  7:10 Jason Merrill
2016-09-08  8:32 ` Marc Glisse
2016-09-08 11:18   ` Jonathan Wakely
2016-09-09 21:40     ` Jason Merrill
2016-09-10  7:03       ` Christophe Lyon
2016-09-10 10:14         ` Marc Glisse
2016-09-10 10:35           ` Jonathan Wakely
2016-09-11  9:14         ` Christophe Lyon
2016-09-11  9:55           ` Jonathan Wakely
2016-09-11  9:56             ` Jonathan Wakely
2016-09-11 10:20             ` Christophe Lyon
2016-09-11 12:09               ` Jonathan Wakely
2016-09-13 13:04         ` Szabolcs Nagy
2016-09-10 10:14       ` Jonathan Wakely
2016-09-11  7:09       ` Andreas Schwab
2016-09-12 21:13         ` Jason Merrill
2016-09-13  8:41           ` Christophe Lyon
2016-09-13 12:37           ` Andreas Schwab
2016-09-13 12:54             ` Jason Merrill
2016-09-13 13:18               ` Andreas Schwab
2016-09-13 13:21                 ` Jason Merrill
2016-09-14 12:13                   ` Andreas Schwab
2016-09-14 16:11                     ` Christophe Lyon
2016-09-14 16:37                       ` Jason Merrill
2016-09-15 10:00                         ` Rainer Orth
2016-09-15 12:23                           ` Christophe Lyon
2016-09-15 20:09                             ` Jason Merrill
2016-09-16  7:12                               ` Rainer Orth
2016-09-16  8:15                                 ` Christophe Lyon
2016-09-16  9:14                                 ` Jonathan Wakely
2016-09-16  9:51                                   ` Marc Glisse
2016-09-16 11:12                                     ` Jonathan Wakely [this message]
2016-09-16 13:13                                       ` Jonathan Wakely
2016-09-16 13:17                                         ` Rainer Orth
2016-09-16 18:19                                         ` Jonathan Wakely
2016-09-12 14:15       ` Rainer Orth
2016-09-12 16:19         ` Jonathan Wakely
2016-09-12 18:57           ` Jason Merrill
2016-09-14 12:11           ` Rainer Orth
2016-09-08 11:00 ` Jonathan Wakely
2017-11-24 14:26 ` Marc Glisse
2017-11-29 21:23   ` Jason Merrill

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=20160916105608.GO17376@redhat.com \
    --to=jwakely@redhat.com \
    --cc=christophe.lyon@linaro.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ro@CeBiTec.Uni-Bielefeld.DE \
    --cc=schwab@linux-m68k.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).