From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B31F3C433DB for ; Thu, 21 Jan 2021 10:41:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67F7D235FF for ; Thu, 21 Jan 2021 10:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728989AbhAUKlZ (ORCPT ); Thu, 21 Jan 2021 05:41:25 -0500 Received: from mga04.intel.com ([192.55.52.120]:6031 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728685AbhAUKlK (ORCPT ); Thu, 21 Jan 2021 05:41:10 -0500 IronPort-SDR: Nos6cvgUB10j5PU29r+BacRKqFbF0NpEqOpHb5KbeQv4gTLbzNsTapraRCyx6QXvBx1ZkOi6Ro WyQO1DzubqGg== X-IronPort-AV: E=McAfee;i="6000,8403,9870"; a="176678784" X-IronPort-AV: E=Sophos;i="5.79,363,1602572400"; d="scan'208";a="176678784" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2021 02:39:23 -0800 IronPort-SDR: st5LNOVlRwOFFvLjpqR0nt4yjWk02rcI/4LtDur741eNR7Puwcd1q/4NcCWCNTw3/ssRE/aphb 8APS1z6r0EVw== X-IronPort-AV: E=Sophos;i="5.79,363,1602572400"; d="scan'208";a="403145896" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2021 02:39:19 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1l2XO0-007Obd-Ny; Thu, 21 Jan 2021 12:40:20 +0200 Date: Thu, 21 Jan 2021 12:40:20 +0200 From: Andy Shevchenko To: Yury Norov Cc: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org, Geert Uytterhoeven , Yoshinori Sato , Rich Felker , Arnd Bergmann , Dennis Zhou , Andrew Morton , Wolfram Sang , David Sterba , Stefano Brivio , "Ma, Jianpeng" , Wei Yang , Josh Poimboeuf , Rasmus Villemoes Subject: Re: [PATCH 6/6] lib: add fast path for find_first_*_bit() and find_last_bit() Message-ID: References: <20210121000630.371883-1-yury.norov@gmail.com> <20210121000630.371883-7-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210121000630.371883-7-yury.norov@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org On Wed, Jan 20, 2021 at 04:06:30PM -0800, Yury Norov wrote: > Similarly to bitmap functions, users will benefit if we'll handle > a case of small-size bitmaps that fit into a single word. > > While here, move the find_last_bit() declaration to bitops/find.h > where other find_*_bit() functions sit. ... > +static inline > +unsigned long find_first_bit(const unsigned long *addr, unsigned long size) > +{ > + if (small_const_nbits(size)) { > + unsigned long idx; > + > + if (!*addr) > + return size; > + > + idx = __ffs(*addr); > + return idx < size ? idx : size; But can't we mask it first, then check for 0 (no bit set) otherwise return the result of __ffs directly? Same comment for other similar places. > + } > + > + return _find_first_bit(addr, size); > +} -- With Best Regards, Andy Shevchenko