From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752577AbbCXWxI (ORCPT ); Tue, 24 Mar 2015 18:53:08 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38261 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752234AbbCXWxF (ORCPT ); Tue, 24 Mar 2015 18:53:05 -0400 Date: Tue, 24 Mar 2015 15:53:03 -0700 From: Andrew Morton To: Yury Norov Cc: linux@horizon.com, klimov.linux@gmail.com, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org Subject: Re: [PATCH] lib: bitmap_[empty,full]: remove code duplication Message-Id: <20150324155303.f5ced0c3395e315319a0c9e6@linux-foundation.org> In-Reply-To: <1426528599-3735-1-git-send-email-yury.norov@gmail.com> References: <1426528599-3735-1-git-send-email-yury.norov@gmail.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 16 Mar 2015 20:56:39 +0300 Yury Norov wrote: > Function 'bitmap_empty' has it's own implementation. > But it's clearly as simple as: > "find_first_bit(src, nbits) == nbits" > The same is true for 'bitmap_full'. > > Underscored versions of 'bitmap_[empty,full]' are not > needed anymore and so removed too. > > Boot-tested on Core i7-2630QM. > > --- a/include/linux/bitmap.h > +++ b/include/linux/bitmap.h > @@ -285,18 +285,12 @@ static inline int bitmap_subset(const unsigned long *src1, > > static inline int bitmap_empty(const unsigned long *src, unsigned nbits) > { > - if (small_const_nbits(nbits)) > - return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); > - else > - return __bitmap_empty(src, nbits); > + return find_first_bit(src, nbits) == nbits; > } But we lost the small_const_nbits() optimization, and that will be a common case. Would it be better to do if (small_const_nbits(...)) ... else find_first_bit(...); ?