From patchwork Sun Mar 21 21:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153345 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.8 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,USER_AGENT_GIT autolearn=ham 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 8AAADC433E0 for ; Sun, 21 Mar 2021 21:56:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 382CF61943 for ; Sun, 21 Mar 2021 21:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231450AbhCUVze (ORCPT ); Sun, 21 Mar 2021 17:55:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231418AbhCUVzC (ORCPT ); Sun, 21 Mar 2021 17:55:02 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05CF2C061574; Sun, 21 Mar 2021 14:55:02 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id c3so8742230qkc.5; Sun, 21 Mar 2021 14:55:01 -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=a7JdQMPMgs8V6p2mIbAAMliZc+Q/jwU8V02vmoeVTgc=; b=i8nKqZlbUpoWJrvA3SGtK3S4Wou/OIZTIBqJKR2kMwz57vvwN260GX9fz7ZKc/Oi7W Oukvw0Lzn4khAl7Wa9hsqTxkyqeR6WuClBj+5Dp0p6Z5zsi6URFoDMD0Oqyk32+ittC+ q9dVt88Ppi5tjEA1uXwij/Mk8/HpX5YN18Yb2tM5M/tSKb/wV1rLBDo3F4h3kZREtI41 BPeQlUVdBsTzjl/ULZUpHP9SIGLooSSUT2l/UmILOkCX61J52d6CVvWiUlUIOiKIk3M7 Wk79OQtKwAPqq765O+tlhjw/LGOOm/ddQ4qZZXzD6gHmyTkcTqSuEKKrD1oM48cKXKNY xL2w== 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=a7JdQMPMgs8V6p2mIbAAMliZc+Q/jwU8V02vmoeVTgc=; b=C9IdFAmxIGFFrQ7wtiff8pgNjMKiwzdK70EqhlCCY53u8nmALyvA3GqU4j6MCOWQSv l0uH2zNK8Plu0xvOd1nsOLTMbV3ycA+DQGKTOrqOa8oNh77gAJnh19FQTQO+/o0gNREF SvD59MLTIBedSZtHw7AL+UR6+99uzboNpwECFO7luwZiS4nBO+K1zr0yrci9CqKHD3S2 C4T6ZadL+2CcMCRSnvx+MfFBaxeb13NQX9PIOmC9nWpzBkOG9DtuO0UeqGvQpBn06LcK do302ujhOHkLHcl/B7Rfb9fpTImfL8gPo/AxkwhyLJ0vh8mneJzqx9XpfKovi9FmOphT T5Pg== X-Gm-Message-State: AOAM533n+Jtg/ETeVUrJQqLWZJcd7L2ZB5ngHRfyGLM+IUvzeMnfsUb0 w00t+6FjNWUw528VJDdR9cO46ACrHKA= X-Google-Smtp-Source: ABdhPJxaXv9Xf37vBcTUmnfJmYRsajKHGinABLTlOhmsEfI1G0L3rHUlebwGQFQrpLkVUe5VpYtLfQ== X-Received: by 2002:ae9:eb58:: with SMTP id b85mr8274855qkg.168.1616363701088; Sun, 21 Mar 2021 14:55:01 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id s19sm9365819qks.130.2021.03.21.14.55.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:00 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 01/12] tools: disable -Wno-type-limits Date: Sun, 21 Mar 2021 14:54:46 -0700 Message-Id: <20210321215457.588554-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org GENMASK(h, l) may be passed with unsigned types. In such case, type-limits warning is generated for example in case of GENMASK(h, 0). Signed-off-by: Yury Norov --- tools/scripts/Makefile.include | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include index 84dbf61a7eca..15e99905cb7d 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -38,6 +38,7 @@ EXTRA_WARNINGS += -Wswitch-enum EXTRA_WARNINGS += -Wundef EXTRA_WARNINGS += -Wwrite-strings EXTRA_WARNINGS += -Wformat +EXTRA_WARNINGS += -Wno-type-limits CC_NO_CLANG := $(shell $(CC) -dM -E -x c /dev/null | grep -Fq "__clang__"; echo $$?) From patchwork Sun Mar 21 21:54:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153349 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.8 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,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 27377C433E8 for ; Sun, 21 Mar 2021 21:56:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE0E261947 for ; Sun, 21 Mar 2021 21:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbhCUVzh (ORCPT ); Sun, 21 Mar 2021 17:55:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbhCUVzD (ORCPT ); Sun, 21 Mar 2021 17:55:03 -0400 Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10DBFC061574; Sun, 21 Mar 2021 14:55:03 -0700 (PDT) Received: by mail-qk1-x729.google.com with SMTP id y5so7193400qkl.9; Sun, 21 Mar 2021 14:55:03 -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=zuXeb5K9/k1b38lIaOCwwXbJ1mWAiSIXqXWCN5QCoNc=; b=s9lHSs3gRQ3E5zlhoby0kbBKeodG6IcrIuXOXnz4Tcg0a9ICdpK47OrLHhCYftehWU yN0Bsr6/mFDNtPjCgIHYF+iX0uPLOymv06rMmEVxL+oP0yEND01oAWPkM55rXuMDNatG aJUXNIlDxD2dr2Liq+fIi/7tBQdOq9do0um6YUkfku4pFaFiUFWthPp1A4igmxmrZzIz TyPhVdmcmN8/Wg7M+6VZH1xZSFlNQz/EZnS7jFPkWXSEKH06rnCIVe7OTqGluXGUNZgk U4vg2pkG1zWTbkKD7RWgLk+8HfW46tAsGvD8Gic6gcqqH/9EXT4xYg2zqjNj53LqeBdq xDyA== 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=zuXeb5K9/k1b38lIaOCwwXbJ1mWAiSIXqXWCN5QCoNc=; b=Lwzon79AHYPRX8WgI4fkvLfPhLmq0BD90+eUAUdzj7+3IHs7GiEsRR4JZsYcdg+Xs4 K/9AIVpGlgr8m4N6it62TBUexW242dW6qP2LiHNy0BmTbDc5F6VmrmKxJEwLrYoUqbjy 6knJoVgdaSsW9XJhibaoaeIEZsdgF1S1Hi9YAXTcjLlUz+yCrIauI72fx32LB/9yGYZ+ GsH+8Qv1SsknFOmJ0r7jNBfXnhEUHozYF7pcJ4ydjhf7QMY53xM5cgbuN4hHK7nw8ooe c19es2ehTKhK5kGCaXyeSXufUKguV4N8toxyrnQJUCPqBHJP//tK0b/xUeerdM4gB/TV LOvQ== X-Gm-Message-State: AOAM5308hO127/2nHC24HqBUZxkSXKzdJYUowwC/9uxTjQv5PfMZamZs cOcXX0KyYpn+1fjrp0nEYBmW7FEnGyY= X-Google-Smtp-Source: ABdhPJzJOLQpna/mX/nLEN4dIo3troWR35bku2fgESfH5U1+gnu4l1WyiaPvZMXy3mstXRwAkZZM6A== X-Received: by 2002:a37:b6c4:: with SMTP id g187mr8447635qkf.162.1616363702099; Sun, 21 Mar 2021 14:55:02 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id h8sm9359220qkk.116.2021.03.21.14.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:01 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 02/12] tools: bitmap: sync function declarations with the kernel Date: Sun, 21 Mar 2021 14:54:47 -0700 Message-Id: <20210321215457.588554-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Some functions in tools/include/linux/bitmap.h declare nbits as int. In the kernel nbits is declared as unsigned int. Signed-off-by: Yury Norov Acked-by: Rasmus Villemoes --- tools/include/linux/bitmap.h | 8 ++++---- tools/lib/bitmap.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 477a1cae513f..7cbd23e56d48 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -30,7 +30,7 @@ void bitmap_clear(unsigned long *map, unsigned int start, int len); #define small_const_nbits(nbits) \ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) -static inline void bitmap_zero(unsigned long *dst, int nbits) +static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { if (small_const_nbits(nbits)) *dst = 0UL; @@ -66,7 +66,7 @@ static inline int bitmap_full(const unsigned long *src, unsigned int nbits) return find_first_zero_bit(src, nbits) == nbits; } -static inline int bitmap_weight(const unsigned long *src, int nbits) +static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) { if (small_const_nbits(nbits)) return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); @@ -74,7 +74,7 @@ static inline int bitmap_weight(const unsigned long *src, int nbits) } static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, - const unsigned long *src2, int nbits) + const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) *dst = *src1 | *src2; @@ -141,7 +141,7 @@ static inline void bitmap_free(unsigned long *bitmap) * @buf: buffer to store output * @size: size of @buf */ -size_t bitmap_scnprintf(unsigned long *bitmap, int nbits, +size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits, char *buf, size_t size); /** diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index 5043747ef6c5..f4e914712b6f 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -28,11 +28,11 @@ void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, dst[k] = bitmap1[k] | bitmap2[k]; } -size_t bitmap_scnprintf(unsigned long *bitmap, int nbits, +size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits, char *buf, size_t size) { /* current bit is 'cur', most recently seen range is [rbot, rtop] */ - int cur, rbot, rtop; + unsigned int cur, rbot, rtop; bool first = true; size_t ret = 0; From patchwork Sun Mar 21 21:54:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153351 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.8 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,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 7271CC433EC for ; Sun, 21 Mar 2021 21:56:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5404061944 for ; Sun, 21 Mar 2021 21:56:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231466AbhCUVzg (ORCPT ); Sun, 21 Mar 2021 17:55:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbhCUVzE (ORCPT ); Sun, 21 Mar 2021 17:55:04 -0400 Received: from mail-qk1-x732.google.com (mail-qk1-x732.google.com [IPv6:2607:f8b0:4864:20::732]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CF97C061763; Sun, 21 Mar 2021 14:55:04 -0700 (PDT) Received: by mail-qk1-x732.google.com with SMTP id g15so8759646qkl.4; Sun, 21 Mar 2021 14:55:04 -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=NvWIjd4skNqWEETdEjzpZ2tC0PHOwPqhgZwMIfQRVT0=; b=gygst6e6OzjxxG0tm7Q6v/mOApXmmwxuNIfrGfeVpdV/RARH0MtRZsfDvBaoT7XDfj gNshGuh3j1Nv2UMQCilK/XBXhxiUQxYdWNQMlLYYGqwRDCfRpoL1Y82JFhSP9rEqxWcq lnu/R1m9BLLvkOlU1khb0Ro0i6qF3ziw5gHdiKv3dsS7f6F0/jK6Bq80ZZN52UerQnfp ilfKSN0yop5uryKIQQ11aV7KbVoBWjrIckuhDZHXo0x7RHqawqseCFdzBkdHOORX633e /PG2lhGYOT7jRT5/XWhvuBZc6BzNY5Uox5I3CbqbASEvQqpDBgZwvV1rXMtlCXbfTqKy 9jKg== 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=NvWIjd4skNqWEETdEjzpZ2tC0PHOwPqhgZwMIfQRVT0=; b=grIquI8CUUoYy981WXsuinnm8Q4Zyzp9v9nVBPx1Yid8viuucXqFCOazCxJfzdHC1W +LDRnBUtLfuQNpAHLbW5VBqITCezjmyeWhE0qz/vXsk+DWPufYw4SX3aCaQEpxrj50bp 2wHEdWpSneEkURtDA1AuUYEdY1iMf/AUJ/DrTZMWEAZZFSQg2k2dHCxlUjjrvak9/GuW 32bn5NdXEgSY5R1/haAel7lbjBHDssEmXUQ25dCDojxehqNquaSCDAUsbEC3SIH46wrK RqHrO4RY8PVBSxvR1JFASx9d/YvPl+M+nTGmqJeuX6KmQ3DbJgFE5oe9A6VQGN1Mkr3S PruA== X-Gm-Message-State: AOAM531HzzQ7ZOjKr1hoGLB4wjB/fFFHE+fxLQDHqn7xj7sHbvWlhxRH W/HJ+kUaaWPMbZFPkfbryDx7umPTHXI= X-Google-Smtp-Source: ABdhPJzA+Z7qKEEkJtDFD/IuGE+l6ZW0/peFytdrb6ziic9Si9Z6+O5AIy2+9Vlc8kuFnF6iDWHfdQ== X-Received: by 2002:a05:620a:1292:: with SMTP id w18mr7991286qki.400.1616363703099; Sun, 21 Mar 2021 14:55:03 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id y1sm9234561qki.9.2021.03.21.14.55.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:02 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 03/12] tools: sync BITMAP_LAST_WORD_MASK() macro with the kernel Date: Sun, 21 Mar 2021 14:54:48 -0700 Message-Id: <20210321215457.588554-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Kernel version generates better code. Signed-off-by: Yury Norov --- tools/include/linux/bitmap.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 7cbd23e56d48..4aabc23ec747 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -20,12 +20,7 @@ int __bitmap_equal(const unsigned long *bitmap1, void bitmap_clear(unsigned long *map, unsigned int start, int len); #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) - -#define BITMAP_LAST_WORD_MASK(nbits) \ -( \ - ((nbits) % BITS_PER_LONG) ? \ - (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ -) +#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) #define small_const_nbits(nbits) \ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) From patchwork Sun Mar 21 21:54:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153357 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.8 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,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 6261DC433C1 for ; Sun, 21 Mar 2021 21:56:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E4B56194E for ; Sun, 21 Mar 2021 21:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231429AbhCUVzi (ORCPT ); Sun, 21 Mar 2021 17:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231426AbhCUVzF (ORCPT ); Sun, 21 Mar 2021 17:55:05 -0400 Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015ABC061574; Sun, 21 Mar 2021 14:55:05 -0700 (PDT) Received: by mail-qk1-x72c.google.com with SMTP id y5so7193461qkl.9; Sun, 21 Mar 2021 14:55:04 -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=DAuTHkwSalBqH8EpHoooy9z28mwSmA5j1f0I3O8Qj8s=; b=aWNdkiyG1pnPbHlRbaAr9/G0mrj2MDD7/dCcLcAXV9sC7zJY4HLC0dO6nZ27EhbdCb goDlKHanaXmeLSCYIxXB6QsDjfaEzIPF5lS5mVCa8XUiYnK/zubJ9iuM4DMm3lAOrpVY n2Kag4YbXxQwjayeXdN2p+oZ1+Oq2lyK442ZZkrc0qE3ImRn0i+ITtzz7XJ0XBPhXDFf CagB4ah28FV4y7H2hc/Jt0VQ0dIAA1VM+OdQDFSCzUjSgwro1nrFlxTN3scPuF7mBgav qLt46+O2gFKytRr0xWIio/EJ71kIVaWueIcctkJmTB81xPKUQH7hsfinzStw+4FyySIl iLoQ== 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=DAuTHkwSalBqH8EpHoooy9z28mwSmA5j1f0I3O8Qj8s=; b=dfgJV1Arrw1Sa7mrbj2i8uOyzyMoR5VEkLXl+f1W13g72D4OXvEG/rsTcVc0fSSasg eYNZIE1G7KjwZdRTNnrGy+7ddDNMz1sm7Qc8Nr00AxMdmtRlo76/jqQQ7o2ZcSCtuMFW ZUoiq1lDz6GW2S8VrQB71Mru/gc6x5dm8ynqt8vPMCa/w5u8HNO5O0WU+ykkS45Nzfzg uJHQMxStNOT9Zb4pvXg66ZPi7wEgF7noFams6iYS737nm8L7rbNNnTrRwvYfXIqMSQeh 49B0otwTa3rtIsDnpPu1Xc50fPmUYioHy0gF9uH38iJ9xWlkWq/EXC4AfmHIv5Vqy/8o EacQ== X-Gm-Message-State: AOAM531PWrfxg2n5PTb3Cw24+JXVi4uZg4HKpZKe2hWdKS9oJihOGvUZ U6Tv1vQwXBVdZgpi/7fbNH28M6Vb/Gk= X-Google-Smtp-Source: ABdhPJxv5U9VxhI021Y3roE5aLS9UT0amOR8ySPsbHE9GRgTfrypz9UKZMr6B/vS/YSvcPAEQ71/BA== X-Received: by 2002:ae9:ee07:: with SMTP id i7mr6920243qkg.233.1616363704020; Sun, 21 Mar 2021 14:55:04 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id v5sm7838933qtq.26.2021.03.21.14.55.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:03 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 04/12] arch: rearrange headers inclusion order in asm/bitops for m68k and sh Date: Sun, 21 Mar 2021 14:54:49 -0700 Message-Id: <20210321215457.588554-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org m68k and sh include bitmap/{find,le}.h prior to ffs/fls headers. New fast-path implementation in find.h requires ffs/fls. Reordering the headers inclusion sequence helps to prevent compile-time implicit function declaration error. Signed-off-by: Yury Norov Acked-by: Geert Uytterhoeven --- arch/m68k/include/asm/bitops.h | 6 +++--- arch/sh/include/asm/bitops.h | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/m68k/include/asm/bitops.h b/arch/m68k/include/asm/bitops.h index 10133a968c8e..7b414099e5fc 100644 --- a/arch/m68k/include/asm/bitops.h +++ b/arch/m68k/include/asm/bitops.h @@ -440,8 +440,6 @@ static inline unsigned long ffz(unsigned long word) #endif -#include - #ifdef __KERNEL__ #if defined(CONFIG_CPU_HAS_NO_BITFIELDS) @@ -525,10 +523,12 @@ static inline int __fls(int x) #define __clear_bit_unlock clear_bit_unlock #include -#include #include #include #include +#include #endif /* __KERNEL__ */ +#include + #endif /* _M68K_BITOPS_H */ diff --git a/arch/sh/include/asm/bitops.h b/arch/sh/include/asm/bitops.h index 450b5854d7c6..3b6c7b5b7ec9 100644 --- a/arch/sh/include/asm/bitops.h +++ b/arch/sh/include/asm/bitops.h @@ -58,15 +58,16 @@ static inline unsigned long __ffs(unsigned long word) return result; } -#include #include #include #include #include -#include #include #include #include #include +#include +#include + #endif /* __ASM_SH_BITOPS_H */ From patchwork Sun Mar 21 21:54:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153353 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.8 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,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 B4CB9C433ED for ; Sun, 21 Mar 2021 21:56:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9522D61943 for ; Sun, 21 Mar 2021 21:56:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231479AbhCUVzj (ORCPT ); Sun, 21 Mar 2021 17:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231431AbhCUVzG (ORCPT ); Sun, 21 Mar 2021 17:55:06 -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 CBE36C061764; Sun, 21 Mar 2021 14:55:05 -0700 (PDT) Received: by mail-qk1-x72e.google.com with SMTP id o5so8726850qkb.0; Sun, 21 Mar 2021 14:55:05 -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=f29jH9p39JWfD2RtS5iC7kXU7OOMGi9+Tjbr7N4HWDA=; b=FgfD9GTvPoa9YBhlZc011prSCq8qTC6AGGpN1pyaTQ34Us90lEiWDk+Y3RwpoNgqQM bVuGGx+62+cA8olEUeC/93lQi916ahpRX13jz/NMDQ6eshKlL5/tvWSSiWv8JiPC9LkH 3TQuSLG8OgMLhF7VaVqnUZA0X4hKDGx3o2Rxb+rkib9zlZ48hM7JVVzxsgoAMR69VuXz 2Kwzv56rulCVal4lDwq9/LeqKtCz6VSduIGWk65nk+sHy4JxtVBsDV9/nzwaBSmSvmcu xOzMHnM75++h4EvCbH+w4by9EpVBGPgf8rjuWywUP6F4LHqOf6jltCxvpcqlr3rVE7Yg 5jIw== 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=f29jH9p39JWfD2RtS5iC7kXU7OOMGi9+Tjbr7N4HWDA=; b=sVcB5j8ZZOUmPlYefE+Kxr4NyOxTFQqFtFkiN4FerdqZhzZR5CdghW3MCRelCIxwc5 P9j22eUDpxbMB/lIZTloeWNoW55KK+BuEMoa1EBPvwpamLc8N4iHS9A4KJyzDVEhZ17y JaE+ciUcksD1fb4J0tXIlQAAmo1QEwJQ+AdxqenOmEHbVJ8yol3rkPGSA3Gx6KUYuGI5 r1E3PsT6cPrgmWDl1uNumx+8iJCiaJ3GUiYy4KS18Q2d7aE7lT9NpINN6+l7y8MjRNDF vdcibLAX5ftrgGmH03Jty03aS48sfKhcfoXkp30UUqJMJowuGoPogGh+vZEd0fiiDXLb ZHJg== X-Gm-Message-State: AOAM53172/Lrs6QQGrVACNc2bcPi2uozvNhckJEQX6BG5U/6lgUYUnUx m76d7WhTw6ARFk6V89l9AiphlMo/1k8= X-Google-Smtp-Source: ABdhPJySPLg/YWK3a/H3R05lY9uZd84miNqrzHUkKCXCOynNx7ZqX/X/MDF+iUXO4/I98hSBuAYANA== X-Received: by 2002:a37:638f:: with SMTP id x137mr8169808qkb.199.1616363704823; Sun, 21 Mar 2021 14:55:04 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id 66sm9679104qkk.18.2021.03.21.14.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:04 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 05/12] lib: extend the scope of small_const_nbits() macro Date: Sun, 21 Mar 2021 14:54:50 -0700 Message-Id: <20210321215457.588554-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org find_bit would also benefit from small_const_nbits() optimizations. The detailed comment is provided by Rasmus Villemoes. Signed-off-by: Yury Norov Suggested-by: Rasmus Villemoes --- include/asm-generic/bitsperlong.h | 12 ++++++++++++ include/linux/bitmap.h | 8 -------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/asm-generic/bitsperlong.h b/include/asm-generic/bitsperlong.h index 3905c1c93dc2..1023e2a4bd37 100644 --- a/include/asm-generic/bitsperlong.h +++ b/include/asm-generic/bitsperlong.h @@ -23,4 +23,16 @@ #define BITS_PER_LONG_LONG 64 #endif +/* + * small_const_nbits(n) is true precisely when it is known at compile-time + * that BITMAP_SIZE(n) is 1, i.e. 1 <= n <= BITS_PER_LONG. This allows + * various bit/bitmap APIs to provide a fast inline implementation. Bitmaps + * of size 0 are very rare, and a compile-time-known-size 0 is most likely + * a sign of error. They will be handled correctly by the bit/bitmap APIs, + * but using the out-of-line functions, so that the inline implementations + * can unconditionally dereference the pointer(s). + */ +#define small_const_nbits(nbits) \ + (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0) + #endif /* __ASM_GENERIC_BITS_PER_LONG */ diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 70a932470b2d..8c4adfa5cceb 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -222,14 +222,6 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf, #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) -/* - * The static inlines below do not handle constant nbits==0 correctly, - * so make such users (should any ever turn up) call the out-of-line - * versions. - */ -#define small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0) - static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); From patchwork Sun Mar 21 21:54:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153355 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.8 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,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 F3041C433F2 for ; Sun, 21 Mar 2021 21:56:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB08D61943 for ; Sun, 21 Mar 2021 21:56:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231477AbhCUVzi (ORCPT ); Sun, 21 Mar 2021 17:55:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231432AbhCUVzH (ORCPT ); Sun, 21 Mar 2021 17:55:07 -0400 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0758C061762; Sun, 21 Mar 2021 14:55:06 -0700 (PDT) Received: by mail-qt1-x82e.google.com with SMTP id x9so11010182qto.8; Sun, 21 Mar 2021 14:55:06 -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=LKoW45iRrqJm4cP5Y0oqqtzPpwCuxVWTABg237jJhgc=; b=s14/AZMMT+1hwW+PkXEUIdWFB3GaXeYhVmjP/jQ89SI2MJnBLzaqoc6k6xAFA50MGM 5Wm/+S7MrbOmEzcPVJ2jxu2/2t6j47rUCKhZTvsdyXHKgkG+auMPwEq8HzdbFuXNH3Pl 0xSZlG9CXYdDDlHUr8LYS9SFFb372LPliYJOz5LFMyHkt4fdnD4Lo4s9B01OLxrf3ghC sQ8HZWIL6zdY13cDxGRkwCusoz0+pppAPtHT5NPoahyNgL8utqMBfT84UBPgn7bQSFt5 YAMmekb7QIEGRr/J0P/6G2MBTqRAgol/KGFLO/X79W6oeympuq3WGiLvXy5ufzct/1Xc vrZw== 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=LKoW45iRrqJm4cP5Y0oqqtzPpwCuxVWTABg237jJhgc=; b=j0mPzrA/5s0pOTGCB+2xC3MJKKCUOLCwnTYYJGWX/YLRTdGYfj1InwMxVu9C6oS8GZ QR8ojwuA8CaF7S43c7g2LeouKmCOOynV1VhlX01WYGCSrd4cT40MlfjlC3gZqLrgbjan NvxEnVLo5yZX42twqhe4pogRyEN1OmmtrOUzmIKpH/q51OpLuq02JmyOKgjz/wnCIRlF JU9/RHjU09QVmK2g/MldNx4HIinMYHqBvPYjcoIV0aUIvrB2YvDYX/YYSZg7MxMs6Hgk TpaNyeCz7EyYYcB6jlrFD6WC9UELfbujvMB+YTgv9FcYnA+hMcGVZn8EQAePsN9cnzD2 QT1A== X-Gm-Message-State: AOAM533hW/sQUGoIlhN8GGdv3wLKLkSdOO0JGg2A1MRVg6wj40KUedzn 4qaazIou70u73ynj14b+tyGFHDYSEEI= X-Google-Smtp-Source: ABdhPJxKdZTRfjjvJ/+gkigU1JnWkd+RKtYEVruDA4jBCAAnhQ4SC4APeVEEYD1eoQ5s5v0I/on7qw== X-Received: by 2002:a05:622a:486:: with SMTP id p6mr7440756qtx.98.1616363705695; Sun, 21 Mar 2021 14:55:05 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id i6sm5878249qkf.96.2021.03.21.14.55.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:05 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 06/12] tools: sync small_const_nbits() macro with the kernel Date: Sun, 21 Mar 2021 14:54:51 -0700 Message-Id: <20210321215457.588554-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Move the macro from tools/include/asm-generic/bitsperlong.h to tools/include/linux/bitmap.h Signed-off-by: Yury Norov Acked-by: Rasmus Villemoes Signed-off-by: Yury Norov --- tools/include/asm-generic/bitsperlong.h | 3 +++ tools/include/linux/bitmap.h | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/include/asm-generic/bitsperlong.h b/tools/include/asm-generic/bitsperlong.h index 8f2283052333..f530da2506cc 100644 --- a/tools/include/asm-generic/bitsperlong.h +++ b/tools/include/asm-generic/bitsperlong.h @@ -18,4 +18,7 @@ #define BITS_PER_LONG_LONG 64 #endif +#define small_const_nbits(nbits) \ + (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) + #endif /* __ASM_GENERIC_BITS_PER_LONG */ diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 4aabc23ec747..330dbf7509cc 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -22,9 +22,6 @@ void bitmap_clear(unsigned long *map, unsigned int start, int len); #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) -#define small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) - static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { if (small_const_nbits(nbits)) From patchwork Sun Mar 21 21:54: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: 12153359 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.8 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,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 B64A6C433E0 for ; Sun, 21 Mar 2021 21:56:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96FDD61944 for ; Sun, 21 Mar 2021 21:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231434AbhCUVzk (ORCPT ); Sun, 21 Mar 2021 17:55:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbhCUVzI (ORCPT ); Sun, 21 Mar 2021 17:55:08 -0400 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4998C061762; Sun, 21 Mar 2021 14:55:07 -0700 (PDT) Received: by mail-qk1-x72b.google.com with SMTP id x14so8742734qki.10; Sun, 21 Mar 2021 14:55:07 -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=TwA2cUb85T9JjpQPbY/6COGL/CUriqATjd8tfCcmoPM=; b=JbAfXjtAe15y1kS+7IaFTggfvujveF1cK3f5jZxEldzZ/m1Ho4Q9YknDuSePA4G8/D uTFhF/CviVNAYxBHcidYUsuJBQBCEfRVMSREyXI5UteU1kRyHsYozRkz+bluzvYq1qbF AwMBmIGFPF1K9eAoqUE4trcGPyicePZw3GGMqZE7NYRyJkXXE0KlybIDoVudFw35ftjw tfO9e+mlEQ/R+n/zlr6Il0wLAhA3NFaDcJgSF+OuRAZ+pQY/ZpnMmlPfrzrPH7oX5Q+M M9mwBA15z4/lo7hdvpJV4No7VfTs1NCyPXI98PWHDEKjcpztr/7dsup6/Q9I/FsO0UH3 Kt9w== 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=TwA2cUb85T9JjpQPbY/6COGL/CUriqATjd8tfCcmoPM=; b=QKic8S+Ke9pq7xa92zusiPySgQjnOzgGOEqwTQRb7gKJX4PAiXZcV2hhqaFkIO6YGy XHJFtquRX8Y0S+8D6XAU7q1a4xmsfHkoxCkZc7rVc8tchFBly3s8dw7rrGP0ut+Vyr+X kHwpehJHQ9XZdbW1yjJxBLaJRQd7HpMgGKbUYb2Rwuw3buIYcmp0KtvAVGqq2t/yH/SY 04IHLTysmMKKuo/zadKdPfBzHKkm31A6d55jbmjb5x/PdMQBfLS0zkVTxyCxRvlrT3Nk yEgObdvL7zigVBA2MfQBwbJ8ensvi4VyrWRp0I+3KbPTm52t16mr0bi1mXeRiY63Ki5+ Nhtw== X-Gm-Message-State: AOAM531mqVKi3Z0YXqKXI+lf+DowDJ9cXHNQ739aqS7trDa240q64M8n gVXSZu2JARuFhbTfyKUb0AWefi1JLFI= X-Google-Smtp-Source: ABdhPJxafm3glUkN+Jtk/wdMbfHF2M33p0SM3wF5hFkI6KCIrWJUzhkvYqpTPQLDwVzOpRuRDHwNmQ== X-Received: by 2002:a37:6115:: with SMTP id v21mr8399368qkb.239.1616363706780; Sun, 21 Mar 2021 14:55:06 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id w6sm7894605qtt.96.2021.03.21.14.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:06 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 07/12] lib: inline _find_next_bit() wrappers Date: Sun, 21 Mar 2021 14:54:52 -0700 Message-Id: <20210321215457.588554-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org lib/find_bit.c declares five single-line wrappers for _find_next_bit(). We may turn those wrappers to inline functions. It eliminates unneeded function calls and opens room for compile-time optimizations. Signed-off-by: Yury Norov --- include/asm-generic/bitops/find.h | 28 ++++++++++++---- include/asm-generic/bitops/le.h | 17 +++++++--- lib/find_bit.c | 56 ++----------------------------- 3 files changed, 37 insertions(+), 64 deletions(-) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 9fdf21302fdf..7ad70dab8e93 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -2,6 +2,10 @@ #ifndef _ASM_GENERIC_BITOPS_FIND_H_ #define _ASM_GENERIC_BITOPS_FIND_H_ +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); + #ifndef find_next_bit /** * find_next_bit - find the next set bit in a memory region @@ -12,8 +16,12 @@ * Returns the bit number for the next set bit * If no bits are set, returns @size. */ -extern unsigned long find_next_bit(const unsigned long *addr, unsigned long - size, unsigned long offset); +static inline +unsigned long find_next_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + return _find_next_bit(addr, NULL, size, offset, 0UL, 0); +} #endif #ifndef find_next_and_bit @@ -27,9 +35,13 @@ extern unsigned long find_next_bit(const unsigned long *addr, unsigned long * Returns the bit number for the next set bit * If no bits are set, returns @size. */ -extern unsigned long find_next_and_bit(const unsigned long *addr1, +static inline +unsigned long find_next_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size, - unsigned long offset); + unsigned long offset) +{ + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); +} #endif #ifndef find_next_zero_bit @@ -42,8 +54,12 @@ extern unsigned long find_next_and_bit(const unsigned long *addr1, * Returns the bit number of the next zero bit * If no bits are zero, returns @size. */ -extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned - long size, unsigned long offset); +static inline +unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); +} #endif #ifdef CONFIG_GENERIC_FIND_FIRST_BIT diff --git a/include/asm-generic/bitops/le.h b/include/asm-generic/bitops/le.h index 188d3eba3ace..21305f6cea0b 100644 --- a/include/asm-generic/bitops/le.h +++ b/include/asm-generic/bitops/le.h @@ -2,6 +2,7 @@ #ifndef _ASM_GENERIC_BITOPS_LE_H_ #define _ASM_GENERIC_BITOPS_LE_H_ +#include #include #include @@ -32,13 +33,21 @@ static inline unsigned long find_first_zero_bit_le(const void *addr, #define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7) #ifndef find_next_zero_bit_le -extern unsigned long find_next_zero_bit_le(const void *addr, - unsigned long size, unsigned long offset); +static inline +unsigned long find_next_zero_bit_le(const void *addr, unsigned + long size, unsigned long offset) +{ + return _find_next_bit(addr, NULL, size, offset, ~0UL, 1); +} #endif #ifndef find_next_bit_le -extern unsigned long find_next_bit_le(const void *addr, - unsigned long size, unsigned long offset); +static inline +unsigned long find_next_bit_le(const void *addr, unsigned + long size, unsigned long offset) +{ + return _find_next_bit(addr, NULL, size, offset, 0UL, 1); +} #endif #ifndef find_first_zero_bit_le diff --git a/lib/find_bit.c b/lib/find_bit.c index f67f86fd2f62..b03a101367f8 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -29,7 +29,7 @@ * searching it for one bits. * - The optional "addr2", which is anded with "addr1" if present. */ -static unsigned long _find_next_bit(const unsigned long *addr1, +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) { @@ -68,37 +68,7 @@ static unsigned long _find_next_bit(const unsigned long *addr1, return min(start + __ffs(tmp), nbits); } -#endif - -#ifndef find_next_bit -/* - * Find the next set bit in a memory region. - */ -unsigned long find_next_bit(const unsigned long *addr, unsigned long size, - unsigned long offset) -{ - return _find_next_bit(addr, NULL, size, offset, 0UL, 0); -} -EXPORT_SYMBOL(find_next_bit); -#endif - -#ifndef find_next_zero_bit -unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, - unsigned long offset) -{ - return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); -} -EXPORT_SYMBOL(find_next_zero_bit); -#endif - -#if !defined(find_next_and_bit) -unsigned long find_next_and_bit(const unsigned long *addr1, - const unsigned long *addr2, unsigned long size, - unsigned long offset) -{ - return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); -} -EXPORT_SYMBOL(find_next_and_bit); +EXPORT_SYMBOL(_find_next_bit); #endif #ifndef find_first_bit @@ -157,28 +127,6 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size) EXPORT_SYMBOL(find_last_bit); #endif -#ifdef __BIG_ENDIAN - -#ifndef find_next_zero_bit_le -unsigned long find_next_zero_bit_le(const void *addr, unsigned - long size, unsigned long offset) -{ - return _find_next_bit(addr, NULL, size, offset, ~0UL, 1); -} -EXPORT_SYMBOL(find_next_zero_bit_le); -#endif - -#ifndef find_next_bit_le -unsigned long find_next_bit_le(const void *addr, unsigned - long size, unsigned long offset) -{ - return _find_next_bit(addr, NULL, size, offset, 0UL, 1); -} -EXPORT_SYMBOL(find_next_bit_le); -#endif - -#endif /* __BIG_ENDIAN */ - unsigned long find_next_clump8(unsigned long *clump, const unsigned long *addr, unsigned long size, unsigned long offset) { From patchwork Sun Mar 21 21:54:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153361 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.8 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,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 26596C43445 for ; Sun, 21 Mar 2021 21:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA26E6194C for ; Sun, 21 Mar 2021 21:56:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231484AbhCUVzj (ORCPT ); Sun, 21 Mar 2021 17:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbhCUVzJ (ORCPT ); Sun, 21 Mar 2021 17:55:09 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA390C061764; Sun, 21 Mar 2021 14:55:08 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id r14so11003228qtt.7; Sun, 21 Mar 2021 14:55: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=1Fw/cm/i6XifIVH4DNb94Y5ofZtMxUzPCQFU6ODCPvU=; b=Nzc2sEsafDH3iTOPMqypNrn6OMfvn6OJXE5aXvx9xNr7vx7DkSVFlYF18HG+D1EyAG +KIUkVmp39/4CIlrzBAzSLQaHDAlSk1Xda4L40qsS02zy+2v2a1HB9yxFrIAprc7Vylt 14UjFSnxTqPXN55o20eNJCkpsdL1nwWH7bE4HFAtQH3dqRc0RYcvWKs+j+u1zIURO6u9 tftZly7r+DnZu8A5p+RTz+pAOcR4kUDTR6ogXz5azOFhqFdInQoCWOWc0a5IAg4vyN8x 8HT+9EobJvp1/DFzuUMnobZ8mIeskpny0uP3vb87q4C+y603I1vvv9vUcHFe8tEi7M/S xvYw== 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=1Fw/cm/i6XifIVH4DNb94Y5ofZtMxUzPCQFU6ODCPvU=; b=VBErC0SMmZr471dVoWSVaqVJ5U4C1KQs6KrFR4RJCUf1MAQ5gUQegSmT6JFwM5yxUa WQds4CQThQjJGkKRWhgLN9JD0VNHx7sLX1MrorXG4t15ZacScTVSogwQsXLksfk6SozR Z4u/hFyEBrERscE+QOImNjTKlf8yJu+q/aYcXxq5CbM8348COfikmXSwDmH3WmlHXZqk X2SaYB/Z9qQG8IsXR3W4+BcYDYo6tXWCFEdZBxuqhQRKO1z8tFH7Fs2M9xRwjd5GocVR ZDBDqvY90wVDc4RVU1vnQUw7RH3hZXj2MqVmbmDY9Yed+or0txib9MMpuca30DbS5j5Z ibCg== X-Gm-Message-State: AOAM533J6PCFkOSDTwtIGTvgUPG1ZpTwC39unVO/8uWPjX/mCq9aYRi1 2FR803vjp+xiWWAVQogI3XPKcEmOok4= X-Google-Smtp-Source: ABdhPJzhzKQ3PJDhejUl/WrEb4JJyX/rhBH0LAogvL3uyBp+SPb8iHnvsfDsxZWGtfQ06QBQ0UB/LA== X-Received: by 2002:aed:2ce3:: with SMTP id g90mr7354526qtd.308.1616363707766; Sun, 21 Mar 2021 14:55:07 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id n2sm7598617qta.61.2021.03.21.14.55.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:07 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 08/12] tools: sync find_next_bit implementation Date: Sun, 21 Mar 2021 14:54:53 -0700 Message-Id: <20210321215457.588554-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Sync the implementation with recent kernel changes. Signed-off-by: Yury Norov --- tools/include/asm-generic/bitops/find.h | 27 ++++++++++--- tools/lib/find_bit.c | 52 ++++++++++--------------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/tools/include/asm-generic/bitops/find.h b/tools/include/asm-generic/bitops/find.h index 16ed1982cb34..9fe62d10b084 100644 --- a/tools/include/asm-generic/bitops/find.h +++ b/tools/include/asm-generic/bitops/find.h @@ -2,6 +2,10 @@ #ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ #define _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ +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); + #ifndef find_next_bit /** * find_next_bit - find the next set bit in a memory region @@ -12,8 +16,12 @@ * Returns the bit number for the next set bit * If no bits are set, returns @size. */ -extern unsigned long find_next_bit(const unsigned long *addr, unsigned long - size, unsigned long offset); +static inline +unsigned long find_next_bit(const unsigned long *addr, unsigned long size, + unsigned long offset) +{ + return _find_next_bit(addr, NULL, size, offset, 0UL, 0); +} #endif #ifndef find_next_and_bit @@ -27,13 +35,16 @@ extern unsigned long find_next_bit(const unsigned long *addr, unsigned long * Returns the bit number for the next set bit * If no bits are set, returns @size. */ -extern unsigned long find_next_and_bit(const unsigned long *addr1, +static inline +unsigned long find_next_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size, - unsigned long offset); + unsigned long offset) +{ + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); +} #endif #ifndef find_next_zero_bit - /** * find_next_zero_bit - find the next cleared bit in a memory region * @addr: The address to base the search on @@ -43,8 +54,12 @@ extern unsigned long find_next_and_bit(const unsigned long *addr1, * Returns the bit number of the next zero bit * If no bits are zero, returns @size. */ +static inline unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, - unsigned long offset); + unsigned long offset) +{ + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); +} #endif #ifndef find_first_bit diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index ac37022e9486..589fd2f26f94 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -28,11 +28,12 @@ * searching it for one bits. * - The optional "addr2", which is anded with "addr1" if present. */ -static inline unsigned long _find_next_bit(const unsigned long *addr1, +unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert) + unsigned long start, unsigned long invert, unsigned long le) { - unsigned long tmp; + unsigned long tmp, mask; + (void) le; if (unlikely(start >= nbits)) return nbits; @@ -43,7 +44,19 @@ static inline unsigned long _find_next_bit(const unsigned long *addr1, tmp ^= invert; /* Handle 1st word. */ - tmp &= BITMAP_FIRST_WORD_MASK(start); + mask = BITMAP_FIRST_WORD_MASK(start); + + /* + * Due to the lack of swab() in tools, and the fact that it doesn't + * need little-endian support, just comment it out + */ +#if (0) + if (le) + mask = swab(mask); +#endif + + tmp &= mask; + start = round_down(start, BITS_PER_LONG); while (!tmp) { @@ -57,18 +70,12 @@ static inline unsigned long _find_next_bit(const unsigned long *addr1, tmp ^= invert; } - return min(start + __ffs(tmp), nbits); -} +#if (0) + if (le) + tmp = swab(tmp); #endif -#ifndef find_next_bit -/* - * Find the next set bit in a memory region. - */ -unsigned long find_next_bit(const unsigned long *addr, unsigned long size, - unsigned long offset) -{ - return _find_next_bit(addr, NULL, size, offset, 0UL); + return min(start + __ffs(tmp), nbits); } #endif @@ -105,20 +112,3 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) return size; } #endif - -#ifndef find_next_zero_bit -unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, - unsigned long offset) -{ - return _find_next_bit(addr, NULL, size, offset, ~0UL); -} -#endif - -#ifndef find_next_and_bit -unsigned long find_next_and_bit(const unsigned long *addr1, - const unsigned long *addr2, unsigned long size, - unsigned long offset) -{ - return _find_next_bit(addr1, addr2, size, offset, 0UL); -} -#endif From patchwork Sun Mar 21 21:54:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153363 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.8 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,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 C76A0C4345E for ; Sun, 21 Mar 2021 21:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7ED06194E for ; Sun, 21 Mar 2021 21:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbhCUVzl (ORCPT ); Sun, 21 Mar 2021 17:55:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231440AbhCUVzK (ORCPT ); Sun, 21 Mar 2021 17:55:10 -0400 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A66C8C061762; Sun, 21 Mar 2021 14:55:09 -0700 (PDT) Received: by mail-qk1-x734.google.com with SMTP id g20so8737401qkk.1; Sun, 21 Mar 2021 14:55:09 -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=N+ZJiIhOello7KIiJWn70PNFcjQDb7YzgmEeWxqS6i8=; b=tVBJcQ2Z1OeiE7yZJp00R0GWuGmbRMch1UIymsy+1icV5ZZl89V39I6APSsX5RC+du OidD6OAzApuYX0qRD8WDRahmthtEODOJprSx08RQiO/8rrxoBscsKiXt0re9LyIvwyGj UtQTsHJsb9CDgacCnK1DY2425TmkMPYuRlV4KT4R8XN25ezl1CqMoSFhah8YKQmSLt7W EcV5NxQTJj0qtvwR4Bo20BWEYha4lsHBvutrwYG5ABwq4FAR/9kjEROkIcHS7CPU6FI9 sR1VKee0hWx+JAOz72ZJnU8ex7PBNptS0K5UK6hIJ4yXVWUvP6z86I2uXrQ6HciYKI9Q HRaA== 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=N+ZJiIhOello7KIiJWn70PNFcjQDb7YzgmEeWxqS6i8=; b=MWkDbKn3i0/rEoBTzFMS1F/1afCWykE/Q3TjnNx1Zwite3Rp3G4O03TRY5tfpTClEi +CbkEvdpDadbrmrmt12eeDe1htAeyNNCUbREW00XXoPD8K1zxX4QDzFA010U57eVVX4/ sBjiWr07RijhkRKsIWOk5ofDJUQmlk+MSALm6+Dm6Aa6AaOHMqFDWHeHR+g4lUgxkaNv jRlZcQ/NkfYQVkUaLsHYUsjgHg4P1o4HsvRpCrz/P7TCXsgNVxjbhmfiL0iP0/ZqS+SZ iWrlby5eCkMaqgwCPCFrisf5UMEHaxDCkuivsMAUWBOPjwXwbqA8eaZFhyEyW7lqYP3m D0Dw== X-Gm-Message-State: AOAM531Y6mv9VcGKUcY9kShi2trrNTui+ISNfApUFpC+hkC2xquVjG2w 9utMeB9mZvvmJOYfk3Sm9QB5YlWJjVY= X-Google-Smtp-Source: ABdhPJzXJ/pBLcWQlCs9aYDoSEsrnNjRo+VU6WS1hwmYPn8C+33iM9tNZaO5kKLEbj9grKrbK3kImw== X-Received: by 2002:a05:620a:118f:: with SMTP id b15mr3068805qkk.5.1616363708628; Sun, 21 Mar 2021 14:55:08 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id y13sm7718612qto.39.2021.03.21.14.55.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:08 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 09/12] lib: add fast path for find_next_*_bit() Date: Sun, 21 Mar 2021 14:54:54 -0700 Message-Id: <20210321215457.588554-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Similarly to bitmap functions, find_next_*_bit() users will benefit if we'll handle a case of bitmaps that fit into a single word inline. In the very best case, the compiler may replace a function call with a few instructions. This is the quite typical find_next_bit() user: unsigned int cpumask_next(int n, const struct cpumask *srcp) { /* -1 is a legal arg here. */ if (n != -1) cpumask_check(n); return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n + 1); } EXPORT_SYMBOL(cpumask_next); Currently, on ARM64 the generated code looks like this: 0000000000000000 : 0: a9bf7bfd stp x29, x30, [sp, #-16]! 4: 11000402 add w2, w0, #0x1 8: aa0103e0 mov x0, x1 c: d2800401 mov x1, #0x40 // #64 10: 910003fd mov x29, sp 14: 93407c42 sxtw x2, w2 18: 94000000 bl 0 1c: a8c17bfd ldp x29, x30, [sp], #16 20: d65f03c0 ret 24: d503201f nop After applying this patch: 0000000000000140 : 140: 11000400 add w0, w0, #0x1 144: 93407c00 sxtw x0, w0 148: f100fc1f cmp x0, #0x3f 14c: 54000168 b.hi 178 // b.pmore 150: f9400023 ldr x3, [x1] 154: 92800001 mov x1, #0xffffffffffffffff // #-1 158: 9ac02020 lsl x0, x1, x0 15c: 52800802 mov w2, #0x40 // #64 160: 8a030001 and x1, x0, x3 164: dac00020 rbit x0, x1 168: f100003f cmp x1, #0x0 16c: dac01000 clz x0, x0 170: 1a800040 csel w0, w2, w0, eq // eq = none 174: d65f03c0 ret 178: 52800800 mov w0, #0x40 // #64 17c: d65f03c0 ret find_next_bit() call is replaced with 6 instructions. find_next_bit() itself is 41 instructions plus function call overhead. Despite inlining, the scripts/bloat-o-meter report smaller .text size after applying the series: add/remove: 11/9 grow/shrink: 233/176 up/down: 5780/-6768 (-988) Signed-off-by: Yury Norov --- include/asm-generic/bitops/find.h | 30 ++++++++++++++++++++++++++++++ include/asm-generic/bitops/le.h | 21 +++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 7ad70dab8e93..4148c74a1e4d 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -20,6 +20,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 +50,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 +78,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 diff --git a/include/asm-generic/bitops/le.h b/include/asm-generic/bitops/le.h index 21305f6cea0b..5a28629cbf4d 100644 --- a/include/asm-generic/bitops/le.h +++ b/include/asm-generic/bitops/le.h @@ -5,6 +5,7 @@ #include #include #include +#include #if defined(__LITTLE_ENDIAN) @@ -37,6 +38,16 @@ static inline unsigned long find_next_zero_bit_le(const void *addr, unsigned long size, unsigned long offset) { + if (small_const_nbits(size)) { + unsigned long val = *(const unsigned long *)addr; + + if (unlikely(offset >= size)) + return size; + + val = swab(val) | ~GENMASK(size - 1, offset); + return val == ~0UL ? size : ffz(val); + } + return _find_next_bit(addr, NULL, size, offset, ~0UL, 1); } #endif @@ -46,6 +57,16 @@ static inline unsigned long find_next_bit_le(const void *addr, unsigned long size, unsigned long offset) { + if (small_const_nbits(size)) { + unsigned long val = *(const unsigned long *)addr; + + if (unlikely(offset >= size)) + return size; + + val = swab(val) & GENMASK(size - 1, offset); + return val ? __ffs(val) : size; + } + return _find_next_bit(addr, NULL, size, offset, 0UL, 1); } #endif From patchwork Sun Mar 21 21:54:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153369 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.8 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,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 89D5CC4345C for ; Sun, 21 Mar 2021 21:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B4296194C for ; Sun, 21 Mar 2021 21:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231497AbhCUVzm (ORCPT ); Sun, 21 Mar 2021 17:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbhCUVzL (ORCPT ); Sun, 21 Mar 2021 17:55:11 -0400 Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5B22C061762; Sun, 21 Mar 2021 14:55:10 -0700 (PDT) Received: by mail-qv1-xf2c.google.com with SMTP id x16so7802486qvk.3; Sun, 21 Mar 2021 14:55:10 -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=Z09UKhjUsPp549NlGjJjuDwVUvyJFk5azpc9IJVoKXw=; b=ff3O7kw0AnZ6D/jRKh/AiUNyX8WMK2iV5gvkzBzLwPszePIMOhVW7UcKDBmDU9dxi5 r+Z+X/8+s0iSrEGTH+o3jJuQOqRPU+Bluplg0F/BBeHmRKN32A0Rj3yX9TfzCE9JKvY/ 7IyQCOXM/yr+PqnlXMxFnWqi5zT13Oyz7WsOC3uGeDDdbebr/vfDWmyqMT3x4DVpo+yV VIab37Q1O6dxgZzYtXEQmnYzS4A12IPQJbOXxWNAktCcJBk0l5GDbzPtY1kjRG9Zz3Ry dW7EDsy8NoBG4zFgaStUw6VlBr2nNB2EU6f5tcxOi2ujN8iXQL3LdE0rgzszB1tvDbg9 B+lA== 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=Z09UKhjUsPp549NlGjJjuDwVUvyJFk5azpc9IJVoKXw=; b=fhoy6+rB2UU7JTIYjfQSCrdJmMmHcBep/BigiDsT8hcbHKAd49QQrIbEcB/E5pkt6Z DTCtv1/LaJa1QKODsW44/e/pphmz43PCzYyM8O/JwkTl0+NtR5tIWfEp/H4zjDLIDU2I oPosISrtuYzjxL+RUOEpCQ1Q5SJQgbi3FiRChyTcJA6kEWTCGKbc2+g8uGuiuNdkTweC MRETt97hhIUTr7hlhMicaGsp1trN8E61QnKz+tNTqbv2msKut0oopmuGG/0oWNzqNfwC OSgWZxgF62b/E1b36D3RxXwoKgVPn10sKyLlLqz2vbtJKqxl2Uq9tT1hS0JHpGpe3ht7 r5cA== X-Gm-Message-State: AOAM531UhIYtmlPfHfwW2/4ApfLS1AFjD8c4zgKTW0qmP5fT7xwxxJUb YK0XODsEX+djccR1LK2EFxBKhrcIntg= X-Google-Smtp-Source: ABdhPJyhIor2iuifyo33ppbQHjUYaft9gYLZpoduYdVj2wnDgJkM3mbTBSCoWdXvhLk6w43Dcq/PUQ== X-Received: by 2002:a05:6214:1484:: with SMTP id bn4mr18961252qvb.8.1616363709651; Sun, 21 Mar 2021 14:55:09 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id l186sm9393878qke.92.2021.03.21.14.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:09 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 10/12] lib: add fast path for find_first_*_bit() and find_last_bit() Date: Sun, 21 Mar 2021 14:54:55 -0700 Message-Id: <20210321215457.588554-11-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Similarly to bitmap functions, users would 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. Signed-off-by: Yury Norov --- include/asm-generic/bitops/find.h | 50 ++++++++++++++++++++++++++++--- include/linux/bitops.h | 12 -------- lib/find_bit.c | 12 ++++---- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 4148c74a1e4d..0d132ee2a291 100644 --- a/include/asm-generic/bitops/find.h +++ b/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 /** @@ -102,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); +} /** * find_first_zero_bit - find the first cleared bit in a memory region @@ -113,8 +125,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. */ -extern 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); +} #else /* CONFIG_GENERIC_FIND_FIRST_BIT */ #ifndef find_first_bit @@ -126,6 +147,27 @@ extern unsigned long find_first_zero_bit(const unsigned long *addr, #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ +#ifndef find_last_bit +/** + * find_last_bit - find the last set bit in a memory region + * @addr: The address to start the search at + * @size: The number of bits to search + * + * Returns the bit number of the last set bit, or size. + */ +static inline +unsigned long find_last_bit(const unsigned long *addr, unsigned long size) +{ + if (small_const_nbits(size)) { + unsigned long val = *addr & GENMASK(size - 1, 0); + + return val ? __fls(val) : size; + } + + return _find_last_bit(addr, size); +} +#endif + /** * find_next_clump8 - find next 8-bit clump with set bits in a memory region * @clump: location to store copy of found clump diff --git a/include/linux/bitops.h b/include/linux/bitops.h index a5a48303b0f1..26bf15e6cd35 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -286,17 +286,5 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr, }) #endif -#ifndef find_last_bit -/** - * find_last_bit - find the last set bit in a memory region - * @addr: The address to start the search at - * @size: The number of bits to search - * - * Returns the bit number of the last set bit, or size. - */ -extern unsigned long find_last_bit(const unsigned long *addr, - unsigned long size); -#endif - #endif /* __KERNEL__ */ #endif diff --git a/lib/find_bit.c b/lib/find_bit.c index b03a101367f8..0f8e2e369b1d 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -75,7 +75,7 @@ EXPORT_SYMBOL(_find_next_bit); /* * 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; @@ -86,14 +86,14 @@ unsigned long find_first_bit(const unsigned long *addr, unsigned long size) return size; } -EXPORT_SYMBOL(find_first_bit); +EXPORT_SYMBOL(_find_first_bit); #endif #ifndef find_first_zero_bit /* * 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; @@ -104,11 +104,11 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) return size; } -EXPORT_SYMBOL(find_first_zero_bit); +EXPORT_SYMBOL(_find_first_zero_bit); #endif #ifndef find_last_bit -unsigned long find_last_bit(const unsigned long *addr, unsigned long size) +unsigned long _find_last_bit(const unsigned long *addr, unsigned long size) { if (size) { unsigned long val = BITMAP_LAST_WORD_MASK(size); @@ -124,7 +124,7 @@ unsigned long find_last_bit(const unsigned long *addr, unsigned long size) } return size; } -EXPORT_SYMBOL(find_last_bit); +EXPORT_SYMBOL(_find_last_bit); #endif unsigned long find_next_clump8(unsigned long *clump, const unsigned long *addr, From patchwork Sun Mar 21 21:54:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153365 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.8 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,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 A2459C43461 for ; Sun, 21 Mar 2021 21:56:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7185F6194C for ; Sun, 21 Mar 2021 21:56:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231504AbhCUVzm (ORCPT ); Sun, 21 Mar 2021 17:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231446AbhCUVzM (ORCPT ); Sun, 21 Mar 2021 17:55:12 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A159FC061762; Sun, 21 Mar 2021 14:55:11 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id m7so10990969qtq.11; Sun, 21 Mar 2021 14:55:11 -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=GJLTuGj5ztiML5kH6e3/bZFvphNBmQOwXj5Cz1PPJdA=; b=jt+ZptmhfuaHxmNiy42zhGeMP8U2TnHOhOxkpZAbngQb+A8Qpnx8xKeX+uLxRFpZUd PWzuvccOjB/VpBVXREm5XYiUhi0F9o9eSFpR/n/uXjrx9LTVXIGXmGik8bYIJ8dt9IxG xdLy7WO3heHvBrArSFdpr97+Xds2jNVIu6E2MMc0kcVid2BlIOe5OHO1EAd+4ZaTIDYX BarshRZJeuLc7+kHVUD/t5QnATvlnEfvw9k2NrNZLxDZMFvTNFfOCvyE5G84EX4Lhsfx Tg8jHF9m6AcTLdCpFJnPsmhBJ4JnDI0Y6UmYZShAX2Utfj5DgpbvisJrd5gPyJM7o2Xk sZhw== 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=GJLTuGj5ztiML5kH6e3/bZFvphNBmQOwXj5Cz1PPJdA=; b=QvWmV7bOantquABr7S+Al7EZmrR00sMzPUHMgk3TJDJNmgdW49eaEnk99Au4+iXVq7 R2iqMlRhObItOFa5BZNQkPjwFOFAoZMYtROVblbLsSW5TVveMipFxbd3dCBlH+RNKAVM oJqO8A9Q/lNWfDOXWZTssqwn3Cjha7wfIRFGN05C4YeEN+HXz3EiqZcytC+vdePf2Tcu kIrEqpWQdXIm+ehSZJnlBbndsHgFW3oyFfuMYUAk//4HAXi4fp7bKT8G71KDc3Mb7RaK 5xSLOrXUZE4fKCSM4YOJa4v/55F7mBqK6uBFGFPLfSGxzHByUsImhV94P/ms+KrjzYsa T8jA== X-Gm-Message-State: AOAM533dJTm1JhDfotxoGadrRQxo+RVmJRL3j25Q29xIsfjUijljQjSE c0PCb8sKy1RItgqDmp8z98tGmOBmHYo= X-Google-Smtp-Source: ABdhPJwhPykAlwdAbNtFUd+UY0ngstzC55emskuuEUOCrdzWVX86Yy50D9a9eRnKiNlON8P4hEa8XQ== X-Received: by 2002:ac8:7f07:: with SMTP id f7mr7324036qtk.134.1616363710576; Sun, 21 Mar 2021 14:55:10 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id 6sm7958201qth.82.2021.03.21.14.55.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:10 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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: Sun, 21 Mar 2021 14:54:56 -0700 Message-Id: <20210321215457.588554-12-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-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 --- 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; From patchwork Sun Mar 21 21:54:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12153367 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.8 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,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 0C295C4332E for ; Sun, 21 Mar 2021 21:56:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC41261943 for ; Sun, 21 Mar 2021 21:56:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231513AbhCUVzn (ORCPT ); Sun, 21 Mar 2021 17:55:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231447AbhCUVzM (ORCPT ); Sun, 21 Mar 2021 17:55:12 -0400 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DE2DC061574; Sun, 21 Mar 2021 14:55:12 -0700 (PDT) Received: by mail-qt1-x82b.google.com with SMTP id 94so11047563qtc.0; Sun, 21 Mar 2021 14:55:12 -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=/XStqP8D36CZJzw2TftI54Ck6LfKQaVMF+TC1pFq5UY=; b=boTqQ/9S6wam0P8nPn8btJusb093uXNIQ+5szswt4fPF0puRU1LwUoRPlSnbGlSVnf PG2rgmLg5ihl/HCy5l6yfzUd8TRaVTUDRyrRS1H1ZN87AK52jtsVD71/Pc/KZTdQLxDc Wp5oIZI69GG7YfRRGgLa4owGJIvKKbA9o8TvAOWvQvd/A3MKF5iNQOs6fjw6q9R7zHDp CMnjcoMcruP8lRHGDsx+Qwwphj2+AiLyk0LSQndypvb8zSM6Q53FFa3+B68Htng8VvfO 3EZJAhcrCniYhwdqvXwn1cXMpcdyfjpVfAwsNMEci4jRkx3E9kV5CyaOmbXCN7Dxz73k xafA== 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=/XStqP8D36CZJzw2TftI54Ck6LfKQaVMF+TC1pFq5UY=; b=jnRcepvG01cOaWeIsE+ib/BimKG58xKnhVPwEp5wOvA58s2svqLJWuNreKxoJIkwpA bMota5QQt4TBAryjgwKn196ea74EbVYAbkLZrHyfLUDCgno9S10M0nEfvBc+h3Dam1g0 xQTqf8dXoBsi8qFDQMI2vimVJW212wcE+KmqKdQ/f6Gja4WZA0eSeC4TWxE8+N1bjl1X r8JLBecwsSxJV6f0ZOL3Y5LtAGAj7O35ML/6jqd+CKd415MDyKoxCVVs8AlQdC1h/BtR 9w06aYyDt1qxCUtLbiWwek9rOVBlaDnucKgNQcW4J1QEzozzDqMTjmAaOLeL/gxVECb6 pRww== X-Gm-Message-State: AOAM533dkTkfKsccc+j11M6r1nwh6zeudnP1iNMTo98YVRlxv34kwJSw /THKMhnGt19uakB1WROiehF/4lS6HCA= X-Google-Smtp-Source: ABdhPJzuEUoa9KmXdMY9wULzE4YA/lfRLKC+pxc4pScjCeblaVmy7HRsyA9lMPhMUxxsJ6k5t5/hJw== X-Received: by 2002:ac8:6790:: with SMTP id b16mr7160203qtp.379.1616363711463; Sun, 21 Mar 2021 14:55:11 -0700 (PDT) Received: from localhost ([76.73.146.210]) by smtp.gmail.com with ESMTPSA id r133sm9655356qke.20.2021.03.21.14.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Mar 2021 14:55:11 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org Cc: Yury Norov , linux-m68k@lists.linux-m68k.org, linux-arch@vger.kernel.org, linux-sh@vger.kernel.org, Alexey Klimov , Andrew Morton , 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 12/12] MAINTAINERS: Add entry for the bitmap API Date: Sun, 21 Mar 2021 14:54:57 -0700 Message-Id: <20210321215457.588554-13-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210321215457.588554-1-yury.norov@gmail.com> References: <20210321215457.588554-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Add myself as maintainer for bitmap API and Andy and Rasmus as reviewers. Signed-off-by: Yury Norov Acked-by: Andy Shevchenko Acked-by: Rasmus Villemoes --- MAINTAINERS | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 38ee5c1a7c3a..62be169be25a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3163,6 +3163,22 @@ F: Documentation/filesystems/bfs.rst F: fs/bfs/ F: include/uapi/linux/bfs_fs.h +BITMAP API +M: Yury Norov +R: Andy Shevchenko +R: Rasmus Villemoes +S: Maintained +F: include/asm-generic/bitops/find.h +F: include/linux/bitmap.h +F: lib/bitmap.c +F: lib/find_bit.c +F: lib/find_bit_benchmark.c +F: lib/test_bitmap.c +F: tools/include/asm-generic/bitops/find.h +F: tools/include/linux/bitmap.h +F: tools/lib/bitmap.c +F: tools/lib/find_bit.c + BLINKM RGB LED DRIVER M: Jan-Simon Moeller S: Maintained