From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34110 invoked by alias); 16 Sep 2016 09:37:53 -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 34050 invoked by uid 89); 16 Sep 2016 09:37:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.0 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=msg00001html, msg00001.html, skips, UD:msg00001.html X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail2-relais-roc.national.inria.fr Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Sep 2016 09:37:47 +0000 Received: from ip-118.net-89-2-234.rev.numericable.fr (HELO laptop-mg.local) ([89.2.234.118]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Sep 2016 11:37:45 +0200 Date: Fri, 16 Sep 2016 09:51:00 -0000 From: Marc Glisse Reply-To: libstdc++@gcc.gnu.org To: Jonathan Wakely cc: Rainer Orth , Jason Merrill , Christophe Lyon , Andreas Schwab , "libstdc++@gcc.gnu.org" , gcc-patches List Subject: Re: RFA (libstdc++): PATCH to implement C++17 over-aligned new In-Reply-To: <20160916090427.GM17376@redhat.com> Message-ID: References: <20160916090427.GM17376@redhat.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-SW-Source: 2016-09/txt/msg01024.txt.bz2 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?) > 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? Since align has to be a power of 2, x % align should be the same as x & (align - 1), for instance. 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