From patchwork Thu Jan 21 00:06:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12034105 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 0BD34C433E9 for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAA4523788 for ; Thu, 21 Jan 2021 01:47:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732524AbhAUA5n (ORCPT ); Wed, 20 Jan 2021 19:57:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729634AbhAUAHX (ORCPT ); Wed, 20 Jan 2021 19:07:23 -0500 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 BA1A2C0613D3; Wed, 20 Jan 2021 16:06:37 -0800 (PST) Received: by mail-qk1-x729.google.com with SMTP id 19so94770qkm.8; Wed, 20 Jan 2021 16:06:37 -0800 (PST) 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=VJyAeNkICLzobewilotYyvHX3yTrS03Tp5qJyqqjL0g=; b=irEJfFhw75j0zxYyv1AJTNPEoITdlEq7ViAShlWlaluOp16XsYOBe6kv5B7Gs1yMLk Bz23HPNwKq9hVgiS9Lw7ph5GtM0TcGmHGx+oH45vktz+664CXPQi1TO/hEq9zM6h9NZq Lwr3XWL12PINo5J6vj1wK5NrvFfXCIORz9SJ8bFDJvoSm1w2qvvgNAoGaUcd3IEzHNkF ZL5nkVm220A+txnXZm4wu7L+y3gptXZ/92SG1hq1S4viIF8WD5qSDGqgvgBCl8NJzPcC aq4ZTVsaLNOM3QREMOhSzOhjSQ24ZjeKjWnlUCytjGkn3cF9+HIS6gVrTTedDSNAqdhe HGhw== 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=VJyAeNkICLzobewilotYyvHX3yTrS03Tp5qJyqqjL0g=; b=VMEjCdl2RT1bj9Cf96mLdproxdrqH3B7bw80CJrb4z/JK30Est0yLEZcbeb3Of/frk OxWD+K/NLT0KMAf65ir7rhyCNNlj+O25hzgzcdlD8s0+dfdXdpba+AjScQRDpCYNsBys +flD6HbgP8VPS8zs4n7Hgh/QwIJ1jCpGr8Kp1jbmp/QAO1Uq0sE0Rpvi7uXw0oowaZ5D X0D2K2W78Mg5Deh9jAZqdQ8dmS08ydcrt0hmd8a2ztP10Mujsrz96eOpSaVZH1aeZKba soPABRJTWDtc87OkaqHm8Ngp0mTFVSL+9cQCJXGJOe2dpy2q27jU6dk0lzdBHwc+hlUa 7FRg== X-Gm-Message-State: AOAM531m4FMs5BJdqqvqOe8OkiZSDAQveWxntZ1WY4yc3+T6COJsnyqC xtarV26HYQ45seoU4m7S4zY= X-Google-Smtp-Source: ABdhPJwK96z5HSohBB4jgawql1ys9+J+U8m5f6SbrirOJTJj1+oKcKeFV63KJtEdZZ6RU5gOTh2EvA== X-Received: by 2002:a37:4286:: with SMTP id p128mr3589516qka.337.1611187597005; Wed, 20 Jan 2021 16:06:37 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id j124sm2505020qkf.113.2021.01.20.16.06.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 16:06:36 -0800 (PST) From: Yury Norov To: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org Cc: Yury Norov , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , Arnd Bergmann , Dennis Zhou , Andrew Morton , Wolfram Sang , David Sterba , Andy Shevchenko , Stefano Brivio , "Ma, Jianpeng" , Wei Yang , Josh Poimboeuf , Rasmus Villemoes Subject: [PATCH 1/6] arch: rearrahge headers inclusion order in asm/bitops for m68k and sh Date: Wed, 20 Jan 2021 16:06:25 -0800 Message-Id: <20210121000630.371883-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210121000630.371883-1-yury.norov@gmail.com> References: <20210121000630.371883-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.h prior to ffs/fls headers. New fast-path implementation in find.h requires ffs/fls. Reordering the order of headers inclusion helps to prevent compile-time implicit-function-declaration error. Signed-off-by: Yury Norov Acked-by: Geert Uytterhoeven --- arch/m68k/include/asm/bitops.h | 4 ++-- arch/sh/include/asm/bitops.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/m68k/include/asm/bitops.h b/arch/m68k/include/asm/bitops.h index 10133a968c8e..093590c9e70f 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) @@ -531,4 +529,6 @@ static inline int __fls(int x) #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..792bbe1237dc 100644 --- a/arch/sh/include/asm/bitops.h +++ b/arch/sh/include/asm/bitops.h @@ -58,7 +58,6 @@ static inline unsigned long __ffs(unsigned long word) return result; } -#include #include #include #include @@ -69,4 +68,6 @@ static inline unsigned long __ffs(unsigned long word) #include #include +#include + #endif /* __ASM_SH_BITOPS_H */ From patchwork Thu Jan 21 00:06:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12034107 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 4BB15C43381 for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AE0D2388B for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732649AbhAUA6J (ORCPT ); Wed, 20 Jan 2021 19:58:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388272AbhAUAI4 (ORCPT ); Wed, 20 Jan 2021 19:08:56 -0500 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 05450C0613ED; Wed, 20 Jan 2021 16:06:39 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id h19so350990qtq.13; Wed, 20 Jan 2021 16:06:38 -0800 (PST) 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=PLzDDsb43NyMx0AvE6OrGjVNnyH2PAQsA/iidjpcD/E=; b=OuPs6iN5DNL3e4a0wi5/M6GUhCYOFv7vYm1pW29MUWITn3Ao17PBRlFphOLfb3AUP+ wKADPHJSHBkrXY4UDmFXuOvgHOXchkk29iQt0nVWV9qbWTLdP77KQvv5NN2Wb1IB1y7b ZZUncR1F1faGkm6WPt7F0fSGjuOiLMJnGzO4oJcaXYVGCnN5sxABXgW6RP2Y1//7cNnb LhpozcCLY74/7m17FnqAiOlE8DsDMlPCOJ1dwy3tIrkvTPUrH/fB26MEePjjPBQu9IN/ Aqaf3PT7zLl29GgzKBepaIswcL4foYFDUdA2q6byv/7VGw3LH4xsxn1htTa1AOLu1Jpt v2lQ== 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=PLzDDsb43NyMx0AvE6OrGjVNnyH2PAQsA/iidjpcD/E=; b=Qo8UXQMBYtHDYD/sDq+/ZJ49zRnUKux+/rOh/dwUIvCEMKqH2XoDSRLWlNMYZqLkHZ B3C7PxhEW0p9r3UtijSqAsAQrCeJJXp/pVBvdgp76Nzo4NJpiCeTPICJiU5ykyk1EOCm ZzVHJDRxiMXza8q1WX6yAfwrYyrLZL/GD0iEsDVbb8xRg1kb0Im2OdrPAzCzG5rjbSiW JZxfnRPT5C252IZrAjM1xI4alxJMNdONxB8Q/BFuaYz84fb0G/wjKusDQlSbajPQA0Hi Ag7zbzphDzwYRkiYNJRJggj+Z9I0Xf6I+o6WMnMAEhhO1yG7kV/7cz/yQv+DZ2Vz22Xy UZrg== X-Gm-Message-State: AOAM531PoZTRGb/XmGCBlfLgNu+8x4KtwKDNcQy547wXHyGyjDAUR/5/ 9GcpRk6DFFppE4de0HDZDMc= X-Google-Smtp-Source: ABdhPJzDAtae1ksWkHrhXovCS3XTS6Wj+QkJyM8BOP2ByMYHXOIPvEX7HVJIB1jrXMK8dV5JEOtqng== X-Received: by 2002:ac8:36e2:: with SMTP id b31mr11511989qtc.19.1611187598218; Wed, 20 Jan 2021 16:06:38 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id b12sm2346703qtt.74.2021.01.20.16.06.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 16:06:37 -0800 (PST) From: Yury Norov To: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org Cc: Yury Norov , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , Arnd Bergmann , Dennis Zhou , Andrew Morton , Wolfram Sang , David Sterba , Andy Shevchenko , Stefano Brivio , "Ma, Jianpeng" , Wei Yang , Josh Poimboeuf , Rasmus Villemoes Subject: [PATCH 2/6] bitmap: move some macros from linux/bitmap.h to linux/bitops.h Date: Wed, 20 Jan 2021 16:06:26 -0800 Message-Id: <20210121000630.371883-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210121000630.371883-1-yury.norov@gmail.com> References: <20210121000630.371883-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org In the following patches of the series they are used by find_bit subsystem. Signed-off-by: Yury Norov --- include/linux/bitmap.h | 11 ----------- include/linux/bitops.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 70a932470b2d..5bacbc8785eb 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -219,17 +219,6 @@ extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int extern int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, int nmaskbits); -#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); diff --git a/include/linux/bitops.h b/include/linux/bitops.h index a5a48303b0f1..a0e138bbb8ce 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -7,6 +7,17 @@ #include +#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) + /* Set bits in the first 'n' bytes when loaded from memory */ #ifdef __LITTLE_ENDIAN # define aligned_byte_mask(n) ((1UL << 8*(n))-1) From patchwork Thu Jan 21 00:06:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12034109 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 9A10CC4332E for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7336B2388B for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732849AbhAUA6O (ORCPT ); Wed, 20 Jan 2021 19:58:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390150AbhAUAI4 (ORCPT ); Wed, 20 Jan 2021 19:08:56 -0500 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2254CC061793; Wed, 20 Jan 2021 16:06:40 -0800 (PST) Received: by mail-qk1-x733.google.com with SMTP id 19so117584qkh.3; Wed, 20 Jan 2021 16:06:40 -0800 (PST) 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=u1+v9PN1Uu2cLPRFWSGLmx3QT1L/QFpePD0yoTSiiK0=; b=HrQFRw+5hk0kZek6NOt9rxQ2j5aMRX5yWhHyefWYvSFs/+iQKMbRq/2PloSq3xZJgn wmbk94fwu0QfRMOInCiScjQrZoypNt1QxmtVmCwVt19G/gDhV2FB6/ZPNuzKCVq+2uxp g/1Ay3zC5NzKjiE3zDS4hKEh99dIx/cMvXaT78m25u/0sK5lAwpvO11CypKch466J0jG lVj0cHbLboX51SHINKwvXJVtqtvUmf5oNeSORLiisdd9teVI3gEbEHql/ppbzqnNdpOs 4C9P/bQ0sKAMDvHyf/Vx+VPf+N4Cq9iQ/3k2Jkk4L0sV8yfZGVhoAwpg3rQm4a1U7aP+ +U0g== 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=u1+v9PN1Uu2cLPRFWSGLmx3QT1L/QFpePD0yoTSiiK0=; b=a/cnYCHf/JJOs9ymVRyI8ofexjmVWk+l/lz683ZM6EoAY5I43AMykuMjQN/+j+0S/E ZLrJWFbSB5F7HuoWO1RyumOV+9XN9+l7s7qTu+2TZBoHqEaymNDbvAiz3qLy6zngKPpl p/sjx/KmhjlE2W2cQir/ZNuaBOjbvSVFl8+MhGSdresXv+gSwT5VYYWaBkwC1oLHhV+y NDpSPSVmKW6fONdvkfX8iyD46SfG8w8vOX/EYCKY7VE5A5tK/Q2HVu25JnDvBjZOSNx7 3YCgv8XFjk2g5iIJQahdc2K3ay7yPlGkhqK44pGq/n3lrkZUim4UN4/RtCX6kJUsxxMK NPxw== X-Gm-Message-State: AOAM531erY/FAokyJX48/cDPueWJjMIa+kj54pv9owIhFZJteahzEfuH SPrsf9urVZJQROFIJB1UjTQ= X-Google-Smtp-Source: ABdhPJym8sxUBV8IVA+jlYKc3NALcR/rEHBGw31xie5ZX+g9RtMimSfF0h6MmVcZ7xHV+S0h+Ei3+w== X-Received: by 2002:ae9:e854:: with SMTP id a81mr12180102qkg.77.1611187599372; Wed, 20 Jan 2021 16:06:39 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id o64sm2457701qka.43.2021.01.20.16.06.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 16:06:38 -0800 (PST) From: Yury Norov To: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org Cc: Yury Norov , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , Arnd Bergmann , Dennis Zhou , Andrew Morton , Wolfram Sang , David Sterba , Andy Shevchenko , Stefano Brivio , "Ma, Jianpeng" , Wei Yang , Josh Poimboeuf , Rasmus Villemoes Subject: [PATCH 3/6] tools: sync bitops macro definitions with the kernel Date: Wed, 20 Jan 2021 16:06:27 -0800 Message-Id: <20210121000630.371883-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210121000630.371883-1-yury.norov@gmail.com> References: <20210121000630.371883-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Signed-off-by: Yury Norov --- tools/include/linux/bitmap.h | 11 ----------- tools/include/linux/bitops.h | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 477a1cae513f..266a9291dd1f 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -19,17 +19,6 @@ int __bitmap_equal(const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int bits); 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 small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) - static inline void bitmap_zero(unsigned long *dst, int nbits) { if (small_const_nbits(nbits)) diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h index 5fca38fe1ba8..1c70919cb216 100644 --- a/tools/include/linux/bitops.h +++ b/tools/include/linux/bitops.h @@ -14,6 +14,17 @@ #include #include +#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) + #define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE) #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(long)) #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u64)) From patchwork Thu Jan 21 00:06:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12034111 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 CA5F7C43332 for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98C9B23788 for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732915AbhAUA6S (ORCPT ); Wed, 20 Jan 2021 19:58:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392207AbhAUAKD (ORCPT ); Wed, 20 Jan 2021 19:10:03 -0500 Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C489C061795; Wed, 20 Jan 2021 16:06:41 -0800 (PST) Received: by mail-qv1-xf30.google.com with SMTP id az16so126362qvb.5; Wed, 20 Jan 2021 16:06:41 -0800 (PST) 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=VjoQ5qusNzQLb2JDxSVbTW4dQgrN6MvvxrltYUjtBfM=; b=F6BNWYr8cXOX0IpQyqQhpA4Po7SyfJo8bimD8NpQndaBhuMIvimhbXdB8KQDB08eXO Tl2zK9L+KiTRdIAoaVZSUXwWkbxLSRGYkPO9IyNesVADOn6xmdKLbtoKbE/Ls/U9KBOv gWEdE08lDibEJdvNr9699iNWbxCxjvPHROlEZYhGJUo+FQUaJ6y4wpgXKsaUVlfR7xx2 00T0arBr6TXoid/DlrTR4Gcefi9RDl26xWGzqhgPjk5PdovrW1NZd3mEQhfutaJwy3yg 2YTeoi+CkGmC6rxWNW6An3KVxv7+v3Jra1XqChCYLcfSv++asKFForrjZh2PaQKkwuRS 3OXQ== 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=VjoQ5qusNzQLb2JDxSVbTW4dQgrN6MvvxrltYUjtBfM=; b=pTLG4eKMyo0+pKzkQNrvCVI9meC7H2O8AmHCJBJWryD5W2UY+RoPBaUu/Pppg9wUs0 YYDHENs20UPnNz23bTOGPXiWl+Eh8FGMc5UcK9tjI+ID/Q3Z2JYUT2yxthASIunGMRZK I0GcxiT3FOBHV8WoSNtgP38MChXqAm1OzuHTPQ2MD+q1S1D89UqFh2ZsEtx0bN7t7DsY 6fis/CzEHjUJK1Bj1ez/pXZwPYea+hqvezfknILfbD7mSC/k8rjB7wKKx5UhIZsg2BSy P97s9Q5K3TiOgpbreZUY0MGkaM4LM5kFt82W/4tS3wMepKgi2iho9jqnleyzuGmkrYk3 cbOQ== X-Gm-Message-State: AOAM530Q8DeVyEyhcCaGVQNYB6peoN8T7mlFX+p0ORpodUbge6MNVMsL ZPrusVaEw2fe6ulLA68bcMo= X-Google-Smtp-Source: ABdhPJyfvweaPAwoiJNooJ/a9FPpNrA7RfXSU1z+h9CKbsg6oOMNOa5t80UZF07EFKodjUU2Xc7lig== X-Received: by 2002:a0c:b990:: with SMTP id v16mr11717292qvf.16.1611187600645; Wed, 20 Jan 2021 16:06:40 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id d1sm2512482qkf.102.2021.01.20.16.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 16:06:40 -0800 (PST) From: Yury Norov To: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org Cc: Yury Norov , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , Arnd Bergmann , Dennis Zhou , Andrew Morton , Wolfram Sang , David Sterba , Andy Shevchenko , Stefano Brivio , "Ma, Jianpeng" , Wei Yang , Josh Poimboeuf , Rasmus Villemoes Subject: [PATCH 4/6] lib: inline _find_next_bit() wrappers Date: Wed, 20 Jan 2021 16:06:28 -0800 Message-Id: <20210121000630.371883-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210121000630.371883-1-yury.norov@gmail.com> References: <20210121000630.371883-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..4cf44ea16ec0 100644 --- a/include/asm-generic/bitops/le.h +++ b/include/asm-generic/bitops/le.h @@ -4,6 +4,7 @@ #include #include +#include #if defined(__LITTLE_ENDIAN) @@ -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 Thu Jan 21 00:06:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12034029 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 66469C4332E for ; Thu, 21 Jan 2021 00:59:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42FC723602 for ; Thu, 21 Jan 2021 00:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733111AbhAUA6W (ORCPT ); Wed, 20 Jan 2021 19:58:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392380AbhAUAKV (ORCPT ); Wed, 20 Jan 2021 19:10:21 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBF35C061798; Wed, 20 Jan 2021 16:06:42 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id r9so360682qtp.11; Wed, 20 Jan 2021 16:06:42 -0800 (PST) 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=EJvVbTcrFXhal00Em+TPrjdhMeNVT/fqvfLLy70dJMA=; b=vWXwiNJ+21L5NEAcfTJmnhSL+ca7W/dNzSA0tHOF6ctG1i3z5n4FSbFYnxtaZrR9Kh QjVy8Jh2Am8Z92TXHZRypNlqkefGFQtSusL0K++LpxONvZDQo0eFqK0oJ2lEl/45CRM1 u+pm8Va4XWVGO98mkSD0pse4jEYTHvwGD4OpmsCDndOSgyLTmdLPsYNKy5TQeJKlnZiU cOj2LpXcBUQxU9GLNF1y7Ow0FoeuexvQ9aJoIesaEW0rOnSykNBIVw4hcnehcN9f02h3 4ixz1k+SkNiIJDj6EREawv9zhd17ejqFPmosZtYBPyBNPcps75wadIV5QKB3IX0TgQDW n+vQ== 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=EJvVbTcrFXhal00Em+TPrjdhMeNVT/fqvfLLy70dJMA=; b=RdbEY0Wz9gyhu0zdEWBmgd+ttu6FLfMO0QAKKNKt4mI9mKpbJiCfv8zwdo+/pPYG9M 5bmyRMf+vD59IBIy4ea/RYhtKzSAIjQp/2GOEEaGwm1HoGnSNFjHxUVDTmy9zT0JDlow CpV0wDyn4WlNeVKEYqilQALcIMIqiXPD/da4j6HHzrKeUKRRPW2564R3Fxwy4lMAwtNk VD/c9/UeTtJPWkeNWfCbD5c+0wvZqffkfKM2IC83LKyQ+ytbMF+qmiMJZDvy95zJW79Y z9iff+Ye1RHM6lc0GZVw77IickfdvZ66SjQ0mXsZ/4IuxxI+WKmy1WEC7urUs2vAekh+ unkg== X-Gm-Message-State: AOAM531Z/+i7/8jR7tLRpJaH8O7M036wAPFAvByjVw2EBl5I/wQ0cZ6e UbWDrPTFOHNxno3wR4xHhMM= X-Google-Smtp-Source: ABdhPJzyA0gTkmmj57pbH5DOx/IkC97OqDS83dP13BmJv9Nnz4vmLR/AQG7HSaZwFjqG70KYKkP4DA== X-Received: by 2002:ac8:5e83:: with SMTP id r3mr11322397qtx.261.1611187601929; Wed, 20 Jan 2021 16:06:41 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id i41sm2421673qtc.33.2021.01.20.16.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 16:06:41 -0800 (PST) From: Yury Norov To: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org Cc: Yury Norov , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , Arnd Bergmann , Dennis Zhou , Andrew Morton , Wolfram Sang , David Sterba , Andy Shevchenko , Stefano Brivio , "Ma, Jianpeng" , Wei Yang , Josh Poimboeuf , Rasmus Villemoes Subject: [PATCH 5/6] lib: add fast path for find_next_*_bit() Date: Wed, 20 Jan 2021 16:06:29 -0800 Message-Id: <20210121000630.371883-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210121000630.371883-1-yury.norov@gmail.com> References: <20210121000630.371883-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. In the very best case, the compiler may replace a function call with a single ffs or ffz instruction. Signed-off-by: Yury Norov --- include/asm-generic/bitops/find.h | 39 +++++++++++++++++++++++++++++++ include/asm-generic/bitops/le.h | 28 ++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 7ad70dab8e93..d45096069011 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -20,6 +20,18 @@ 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 & BITMAP_FIRST_WORD_MASK(offset) + & BITMAP_LAST_WORD_MASK(size); + + return val ? __ffs(val) : size; + } + return _find_next_bit(addr, NULL, size, offset, 0UL, 0); } #endif @@ -40,6 +52,18 @@ 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 & BITMAP_FIRST_WORD_MASK(offset) + & BITMAP_LAST_WORD_MASK(size); + + return val ? __ffs(val) : size; + } + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); } #endif @@ -58,6 +82,21 @@ 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, idx; + + if (unlikely(offset >= size)) + return size; + + val = *addr | ~BITMAP_FIRST_WORD_MASK(offset); + if (val == ~0UL) + return size; + + idx = ffz(val); + + return idx < size ? idx : size; + } + 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 4cf44ea16ec0..f4a76d3d145f 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,21 @@ 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, idx; + + if (unlikely(offset >= size)) + return size; + + val = swab(val) | ~BITMAP_FIRST_WORD_MASK(offset); + if (val == ~0UL) + return size; + + idx = ffz(val); + + return idx < size ? idx : size; + } + return _find_next_bit(addr, NULL, size, offset, ~0UL, 1); } #endif @@ -46,6 +62,18 @@ 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) & BITMAP_FIRST_WORD_MASK(offset) + & BITMAP_LAST_WORD_MASK(size); + + return val ? __ffs(val) : size; + } + return _find_next_bit(addr, NULL, size, offset, 0UL, 1); } #endif From patchwork Thu Jan 21 00:06:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12034113 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 19D52C43333 for ; Thu, 21 Jan 2021 01:47:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DAA0923788 for ; Thu, 21 Jan 2021 01:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733007AbhAUA6U (ORCPT ); Wed, 20 Jan 2021 19:58:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392390AbhAUAKV (ORCPT ); Wed, 20 Jan 2021 19:10:21 -0500 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 2BC18C06179A; Wed, 20 Jan 2021 16:06:44 -0800 (PST) Received: by mail-qv1-xf2c.google.com with SMTP id bd6so116379qvb.9; Wed, 20 Jan 2021 16:06:44 -0800 (PST) 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=H9Hwndwgsgmr7xB4y1K4SBbnbogFtSSFcJExBJcwKqk=; b=RFMh/FHAbkE/EyNL0tG3uk11bRPE7HfZOd+r83jpDiJ9/caa1G1q6WinVhCnF6nGar +L47b9SY2mmHr8Tuof3oot/OR/J3hTRWaXPGHBNHlhttiGcpWt7e/AIO6+duRIice8fC BIwck75PqQT5IA6GM5oUR/0JPnOaVcaS3/saA2WDYoshJh2d5cv2TXZhIxycO4G66+BG WhljZsj2oLZwlCx2Zm1YAxdhEhQrz8oUhJCy/Z5W7TAlde1eKpwmnI0B4MD9ToPGjRlH 8jiFyyUiZa5vxgtDxjDq+d55nZyKPsODHEiVAMKT0QcnJp868UGJOQr8o9/etbHkcCe4 PEPw== 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=H9Hwndwgsgmr7xB4y1K4SBbnbogFtSSFcJExBJcwKqk=; b=jO+UI3hw3wHlTRxKGtP3KfdgZEDB2FFT5xHmr+V2Jom/IxO+5VbmNtwO4KCT4B9ez2 eROxuuotyz92pxoN0r78x0fXeYU65rZqs76fEjxu/BkkRO9pSfEi46kx7wiU8sG7s+w1 OWCGLRXInTefr8Iw+c9oCOuftm9df4wAzXQffddxj/vMu5H5FDuMVpXpS4L2xRH05RJF SG3XWE3NfMh36dCxmsVudc1cUI6XthzF//t3/LW02CcvvP0gXD7Gp3Vct286STI5YC7c MgV9FRTnZvSSBGo5ux5pNDyhjtk44XX30jgpLfaH433UszMYqGbjssoSoucZSpaRqKpG uQbg== X-Gm-Message-State: AOAM532zmXO7SxNRd+CubT19F3OdJlRmQ5D/tDpSXmCSQPWIffcVzY+C 1T2ng0FG5zOt3Itc49YZMYGpjbGE7JM5U/6G X-Google-Smtp-Source: ABdhPJyjalt+WEFMHkhW/LDfaKg2ipFqZPf0duKC+2s16rFC0iS3CXo8zoD0SMDTux3fT9YyITk1MQ== X-Received: by 2002:a05:6214:54d:: with SMTP id ci13mr12143305qvb.30.1611187603357; Wed, 20 Jan 2021 16:06:43 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id i13sm2508093qkk.83.2021.01.20.16.06.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 16:06:42 -0800 (PST) From: Yury Norov To: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org, linux-arch@vger.kernel.org Cc: Yury Norov , Geert Uytterhoeven , Yoshinori Sato , Rich Felker , Arnd Bergmann , Dennis Zhou , Andrew Morton , Wolfram Sang , David Sterba , Andy Shevchenko , Stefano Brivio , "Ma, Jianpeng" , Wei Yang , Josh Poimboeuf , Rasmus Villemoes Subject: [PATCH 6/6] lib: add fast path for find_first_*_bit() and find_last_bit() Date: Wed, 20 Jan 2021 16:06:30 -0800 Message-Id: <20210121000630.371883-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210121000630.371883-1-yury.norov@gmail.com> References: <20210121000630.371883-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 will benefit if we'll handle a case of small-size bitmaps that fit into a single word. While here, move the find_last_bit() declaration to bitops/find.h where other find_*_bit() functions sit. Signed-off-by: Yury Norov --- include/asm-generic/bitops/find.h | 56 ++++++++++++++++++++++++++++--- include/linux/bitops.h | 12 ------- lib/find_bit.c | 12 +++---- 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index d45096069011..8708e333fc69 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 /** @@ -111,8 +114,21 @@ 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 idx; + + if (!*addr) + return size; + + idx = __ffs(*addr); + return idx < size ? idx : size; + } + + return _find_first_bit(addr, size); +} /** * find_first_zero_bit - find the first cleared bit in a memory region @@ -122,8 +138,20 @@ 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 idx; + if (*addr == ~0UL) + return size; + + idx = ffz(*addr); + return idx < size ? idx : size; + } + + return _find_first_zero_bit(addr, size); +} #else /* CONFIG_GENERIC_FIND_FIRST_BIT */ #ifndef find_first_bit @@ -135,6 +163,26 @@ 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 & BITMAP_LAST_WORD_MASK(size); + 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 a0e138bbb8ce..1d41193be4ab 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -297,17 +297,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,