From 84c08ec96a558fcb648e27f3f4a2e7532079d5bd Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 16 Sep 2016 19:09:14 +0100 Subject: [PATCH] Replace modulus with mask operation in over-aligned new 2016-09-16 Jonathan Wakely Marc Glisse * libsupc++/new_opa.cc [_GLIBCXX_HAVE_ALIGNED_ALLOC] (operator new(size_t, align_val_t)): Replace modulus operator with mask. Co-Authored-By: Marc Glisse From-SVN: r240192 --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/libsupc++/new_opa.cc | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cddff99..21ee3fd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,4 +1,11 @@ 2016-09-16 Jonathan Wakely + Marc Glisse + + * libsupc++/new_opa.cc [_GLIBCXX_HAVE_ALIGNED_ALLOC] + (operator new(size_t, align_val_t)): Replace modulus operator with + mask. + +2016-09-16 Jonathan Wakely * libsupc++/new_opa.cc [_GLIBCXX_HAVE_POSIX_MEMALIGN] (aligned_alloc): Increase alignment if less than sizeof(void*). 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 -- 2.7.4