From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751523AbdFGVQm (ORCPT ); Wed, 7 Jun 2017 17:16:42 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:36269 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751252AbdFGVQk (ORCPT ); Wed, 7 Jun 2017 17:16:40 -0400 From: Rasmus Villemoes To: Matthew Wilcox Cc: linux-kernel@vger.kernel.org, Andrew Morton , Martin Schwidefsky , Matthew Wilcox Subject: Re: [PATCH 2/3] Turn bitmap_set and bitmap_clear into memset when possible Organization: D03 References: <20170607142924.28552-1-willy@infradead.org> <20170607142924.28552-3-willy@infradead.org> X-Hashcash: 1:20:170607:schwidefsky@de.ibm.com::fI4zZ8Q5DpCQ4NL8:0000000000000000000000000000000000000000INi X-Hashcash: 1:20:170607:mawilcox@microsoft.com::1mtfuRx7MdJFOUSN:0000000000000000000000000000000000000001hgj X-Hashcash: 1:20:170607:akpm@linux-foundation.org::KJtvrG34CoKmMUVP:00000000000000000000000000000000000061Q6 X-Hashcash: 1:20:170607:linux-kernel@vger.kernel.org::eIKzPEn7F0Kd4u0e:0000000000000000000000000000000005DRY X-Hashcash: 1:20:170607:willy@infradead.org::3aTGjmNgxd2koIAx:0000000000000000000000000000000000000000004lPO Date: Wed, 07 Jun 2017 23:16:37 +0200 In-Reply-To: <20170607142924.28552-3-willy@infradead.org> (Matthew Wilcox's message of "Wed, 7 Jun 2017 07:29:23 -0700") Message-ID: <87bmpzbiru.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 07 2017, Matthew Wilcox wrote: > From: Matthew Wilcox > > Several callers have constant 'start' and an 'nbits' that is a multiple of > 8, so we can turn them into calls to memset. We don't need the entirety > of 'start' and 'nbits' to be constant, we just need to know whether > they're divisible by 8. > > Signed-off-by: Matthew Wilcox > --- > include/linux/bitmap.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h > index 4e0f0c8167af..0b3e4452b054 100644 > --- a/include/linux/bitmap.h > +++ b/include/linux/bitmap.h > @@ -319,6 +319,9 @@ static __always_inline void bitmap_set(unsigned long *map, unsigned int start, > { > if (__builtin_constant_p(nbits) && nbits == 1) > __set_bit(start, map); > + else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) && > + __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8)) > + memset(map + start / 8, 0xff, nbits / 8); > else Isn't the pointer arithmetic wrong here? I think you need to cast map to (char*). > > __bitmap_set(map, start, nbits); > } > @@ -328,6 +331,9 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start, > { > if (__builtin_constant_p(nbits) && nbits == 1) > __clear_bit(start, map); > + else if (__builtin_constant_p(start & 7) && IS_ALIGNED(start, 8) && > + __builtin_constant_p(nbits & 7) && IS_ALIGNED(nbits, 8)) > + memset(map + start / 8, 0, nbits / 8); > else Ditto. Do you have an example of how the generated code changes, both in the case of actual constants and a case where gcc can see that start and nbits are byte-aligned without knowing their actual values?