From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7648 invoked by alias); 16 Sep 2016 10:56:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 7626 invoked by uid 89); 16 Sep 2016 10:56:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Sep 2016 10:56:11 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EFDB4DB14; Fri, 16 Sep 2016 10:56:10 +0000 (UTC) Received: from localhost (ovpn-116-87.ams2.redhat.com [10.36.116.87]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8GAu8oH014016; Fri, 16 Sep 2016 06:56:09 -0400 Date: Fri, 16 Sep 2016 11:12:00 -0000 From: Jonathan Wakely To: libstdc++@gcc.gnu.org Cc: Rainer Orth , Jason Merrill , Christophe Lyon , Andreas Schwab , gcc-patches List Subject: Re: RFA (libstdc++): PATCH to implement C++17 over-aligned new Message-ID: <20160916105608.GO17376@redhat.com> References: <20160916090427.GM17376@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) X-SW-Source: 2016-09/txt/msg01039.txt.bz2 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