On 16/09/16 13:12 +0100, Jonathan Wakely wrote:
On 16/09/16 11:56 +0100, Jonathan Wakely wrote:
On 16/09/16 11:37 +0200, Marc Glisse wrote:
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've committed the patch now, to fix the failures for Solaris. I'll
revisit it when I get clarification from the committee about invalid
alignment arguments.

I missed 18.6.2/1 which is clear that we don't have to support invalid
alignments passed to operator new, so I'm committing this.

Tested x86_64-linux.



commit 0a70fa595953ff1e6e46266d7f86bc6d7e3400a4
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Fri Sep 16 17:36:44 2016 +0100

    Replace modulus with mask operation in over-aligned new
    
    2016-09-16  Jonathan Wakely  <jwak...@redhat.com>
    	    Marc Glisse  <marc.gli...@inria.fr>
    
    	* libsupc++/new_opa.cc [_GLIBCXX_HAVE_ALIGNED_ALLOC]
    	(operator new(size_t, align_val_t)): Replace modulus operator with
    	mask.

diff --git a/libstdc++-v3/libsupc++/new_opa.cc b/libstdc++-v3/libsupc++/new_opa.cc
index 9c859c1..91e53a8 100644
--- a/libstdc++-v3/libsupc++/new_opa.cc
+++ b/libstdc++-v3/libsupc++/new_opa.cc
@@ -69,7 +69,7 @@ operator new (std::size_t sz, std::align_val_t al)
 
 #if _GLIBCXX_HAVE_ALIGNED_ALLOC
   /* C11: the value of size shall be an integral multiple of alignment.  */
-  if (std::size_t rem = sz % align)
+  if (std::size_t rem = sz & (align - 1))
     sz += align - rem;
 #endif
 

Reply via email to