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 6CF14C4332B for ; Thu, 21 Jan 2021 12:56:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 422B923A01 for ; Thu, 21 Jan 2021 12:56:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731111AbhAUM43 (ORCPT ); Thu, 21 Jan 2021 07:56:29 -0500 Received: from mga02.intel.com ([134.134.136.20]:25764 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729492AbhAUKfm (ORCPT ); Thu, 21 Jan 2021 05:35:42 -0500 IronPort-SDR: DfxDX+FYLQd0kl4iU09XXKmAS6kIJTG3dGOyjZ6iyguVbvx39rzNVIioZQwLdtH1Fv3AbqVjqh ker18n62zJnA== X-IronPort-AV: E=McAfee;i="6000,8403,9870"; a="166347355" X-IronPort-AV: E=Sophos;i="5.79,363,1602572400"; d="scan'208";a="166347355" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2021 02:33:44 -0800 IronPort-SDR: t0/3SHCCmps/HIQS11ATR5hPbMpPuTorfoWhf5Y7rT93Ngh/CeE1NlXGpQo1QXCKDgpJ0yqs0j 8H3qxCqbE9uw== X-IronPort-AV: E=Sophos;i="5.79,363,1602572400"; d="scan'208";a="570685626" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jan 2021 02:33:40 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1l2XIY-007OH7-06; Thu, 21 Jan 2021 12:34:42 +0200 Date: Thu, 21 Jan 2021 12:34:41 +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 5/6] lib: add fast path for find_next_*_bit() Message-ID: References: <20210121000630.371883-1-yury.norov@gmail.com> <20210121000630.371883-6-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210121000630.371883-6-yury.norov@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 04:06:29PM -0800, Yury Norov wrote: > Similarly to bitmap functions, find_next_*_bit() users will benefit > if we'll handle a case of bitmaps that fit into a single word. In the > very best case, the compiler may replace a function call with a > single ffs or ffz instruction. > + if (small_const_nbits(size)) { > + unsigned long val; > + > + if (unlikely(offset >= size)) > + return size; > + val = *addr & BITMAP_FIRST_WORD_MASK(offset) > + & BITMAP_LAST_WORD_MASK(size); Seems like a new helper can be introduced (BITS or BITMAP namespace depending on the decision): #define _OFFSET_SIZE_MASK(o,s) \ (BITMAP_FIRST_WORD_MASK(o) & BITMAP_LAST_WORD_MASK(s)) val = *addr & BITMAP_OFFSET_SIZE_MASK(offset, size); And so on below. > + return val ? __ffs(val) : size; > + } -- With Best Regards, Andy Shevchenko