From patchwork Thu Apr 1 00:31:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12176651 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 D4D06C001BF for ; Thu, 1 Apr 2021 00:33:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABC2B61139 for ; Thu, 1 Apr 2021 00:33:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233195AbhDAAci (ORCPT ); Wed, 31 Mar 2021 20:32:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233092AbhDAAcJ (ORCPT ); Wed, 31 Mar 2021 20:32:09 -0400 Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3EB2C06175F; Wed, 31 Mar 2021 17:32:08 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id y5so637203qkl.9; Wed, 31 Mar 2021 17:32:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OWHXje7aHb+2OQQ4sHpfObqcJeqb3/Y1e6oZgl+21cA=; b=sGTprdvoKyvEb9K8hmpQFNDJghLuuObLQ3aVFTwZ1kcFbQbug7Dz+45o7BxuQxAIQI bxBrIH8azroqP7QDqIKe8uUhoAE1YRqASRwt17TGmchjQBQPWEnawwZ2VkEaanK1VQEu SifRP4gzpH0Cs7JQYlDPmz1rl4gOgkk3qD8UUf8vPhhiplQLiv2wlIpqGqpXeync8JyA Ri5n/7RGCyf8DRC1gwnXc3Aj1LYjrRWhCrFziiGE5VC1qOqv+IogU3Oi+xJFkedJLf7V Akm9eIrg0rbyyah5vzNWpTaXW0fH+N0dw51Pg0AIEbZ+yj8T36o6U/3A2SdLrQ33Hdoj 1vIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OWHXje7aHb+2OQQ4sHpfObqcJeqb3/Y1e6oZgl+21cA=; b=oT6HNi0ANGg15a7EFxvnRodULDInP7d0fxDmVedbu8lBvd/VSXSH1/TS3DBvj2OP+D OCMN4rzVdAVOf3MzU0uEaJA5K/8p3kPKwj68jwgyrZNanoEfEt/42Mf/gWu6auwEYgWt O7jo4OoQqDCROK+CombTXs7TVCkwBV8kCP7sIbcVBMB8qdlh1quJWlxI8vPW0eOtUESN au+boszwhVnUBpplZgkoI+iU7/ao9z4kzzzRz+WD12IaW/oxq+Yt6b/GFwY/tVOrGKrH Nv4GabwhOUZ7YkyK+DKP7Ub2bVyuwMa8FTn/g542p65Suy43iksUSy3tVp68LAzOtbvw ZVoQ== X-Gm-Message-State: AOAM532czKamIm0HYxpPeA01M5R50Lj/hVOeI0s6g1vDPYh7gtpl6wFm f6iRpuiQNTT7hXsWTtQASsRRiUd8HLOH6g== X-Google-Smtp-Source: ABdhPJzfXvFWj5mMG8ykN+Zn8l46W+R1ArWFHf1M6eYUJklnBNeB+OQG48RDKLL5uIEBQpRMk97BHw== X-Received: by 2002:a05:620a:144a:: with SMTP id i10mr5950253qkl.431.1617237127874; Wed, 31 Mar 2021 17:32:07 -0700 (PDT) Received: from localhost ([207.98.216.60]) by smtp.gmail.com with ESMTPSA id k8sm2379342qth.74.2021.03.31.17.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Mar 2021 17:32:07 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, Andrew Morton Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andy Shevchenko , Arnd Bergmann , David Sterba , Dennis Zhou , Geert Uytterhoeven , Jianpeng Ma , Joe Perches , John Paul Adrian Glaubitz , Josh Poimboeuf , Rasmus Villemoes , Rich Felker , Stefano Brivio , Wei Yang , Wolfram Sang , Yoshinori Sato Subject: [PATCH 11/12] tools: sync lib/find_bit implementation Date: Wed, 31 Mar 2021 17:31:52 -0700 Message-Id: <20210401003153.97325-12-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210401003153.97325-1-yury.norov@gmail.com> References: <20210401003153.97325-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Add fast paths to find_*_bit() functions as per kernel implementation. Signed-off-by: Yury Norov Acked-by: Rasmus Villemoes --- tools/include/asm-generic/bitops/find.h | 58 +++++++++++++++++++++++-- tools/lib/find_bit.c | 4 +- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/tools/include/asm-generic/bitops/find.h b/tools/include/asm-generic/bitops/find.h index 9fe62d10b084..6481fd11012a 100644 --- a/tools/include/asm-generic/bitops/find.h +++ b/tools/include/asm-generic/bitops/find.h @@ -5,6 +5,9 @@ extern unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, unsigned long start, unsigned long invert, unsigned long le); +extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size); +extern unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size); +extern unsigned long _find_last_bit(const unsigned long *addr, unsigned long size); #ifndef find_next_bit /** @@ -20,6 +23,16 @@ static inline unsigned long find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr & GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + return _find_next_bit(addr, NULL, size, offset, 0UL, 0); } #endif @@ -40,6 +53,16 @@ unsigned long find_next_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size, unsigned long offset) { + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr1 & *addr2 & GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); } #endif @@ -58,6 +81,16 @@ static inline unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { + if (small_const_nbits(size)) { + unsigned long val; + + if (unlikely(offset >= size)) + return size; + + val = *addr | ~GENMASK(size - 1, offset); + return val == ~0UL ? size : ffz(val); + } + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); } #endif @@ -72,8 +105,17 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, * Returns the bit number of the first set bit. * If no bits are set, returns @size. */ -extern unsigned long find_first_bit(const unsigned long *addr, - unsigned long size); +static inline +unsigned long find_first_bit(const unsigned long *addr, unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr & GENMASK(size - 1, 0); + + return val ? __ffs(val) : size; + } + + return _find_first_bit(addr, size); +} #endif /* find_first_bit */ @@ -87,7 +129,17 @@ extern unsigned long find_first_bit(const unsigned long *addr, * Returns the bit number of the first cleared bit. * If no bits are zero, returns @size. */ -unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size); +static inline +unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr | ~GENMASK(size - 1, 0); + + return val == ~0UL ? size : ffz(val); + } + + return _find_first_zero_bit(addr, size); +} #endif #endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */ diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index 589fd2f26f94..109aa7ffcf97 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -83,7 +83,7 @@ unsigned long _find_next_bit(const unsigned long *addr1, /* * Find the first set bit in a memory region. */ -unsigned long find_first_bit(const unsigned long *addr, unsigned long size) +unsigned long _find_first_bit(const unsigned long *addr, unsigned long size) { unsigned long idx; @@ -100,7 +100,7 @@ unsigned long find_first_bit(const unsigned long *addr, unsigned long size) /* * Find the first cleared bit in a memory region. */ -unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) +unsigned long _find_first_zero_bit(const unsigned long *addr, unsigned long size) { unsigned long idx;