From patchwork Thu Feb 18 04:04:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 C8AF0C433E0 for ; Thu, 18 Feb 2021 04:06:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 848F964E4B for ; Thu, 18 Feb 2021 04:06:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbhBREGG (ORCPT ); Wed, 17 Feb 2021 23:06:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230184AbhBREF6 (ORCPT ); Wed, 17 Feb 2021 23:05:58 -0500 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B09C061786; Wed, 17 Feb 2021 20:05:17 -0800 (PST) Received: by mail-qv1-xf32.google.com with SMTP id t18so363531qvn.8; Wed, 17 Feb 2021 20:05:17 -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=GjM51SO6l5RqBw16sI+XBv1f2Gk72M+10GN/T1hPkUw=; b=tQD4PA1ZBz9hxO1fyxA0bTFp7t+2ASMYO+EIZp4idJBNB/NBrvx1/7R2yVz8hvu4Z/ GgydpSGyzq5aMZa7vLHYCFBJmhZzBc3ni4C0scnFIa5WP6TUGAwWIywJx36+b4GKL9/B 8utCzLs3iZCzjoJFh0S8kZaopfa70aAph47r0N9yzQ9jd2u24vz0p2oiaumk5EK+uCuP ML5Wjjz1qQYUajAajveO0n4NbiPyaYHqpMBHDoiYhU59bel0CiLsMb8ZAPHP3q7n9Zk5 3eJ4nfdMlY7wSImEMDwEL83hljZKbQ1PXze+s/jm8Ov4JNFm7oAZGzAsAg+kUIsrX2JJ nQjw== 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=GjM51SO6l5RqBw16sI+XBv1f2Gk72M+10GN/T1hPkUw=; b=hxMSJJBnsfxNxfkUv+M1uYZeZged0AMb31hVCWf9Ka0OT7rkv/oFC3sx/+ykbdDgvO va2PTbS5nBMKIofCMBlmPghUkOTiTyghFQtpPigUeDxb9zQrJ28RaTP836Zt5LdtACwo D/ji7YVAZVdmsKMgUHATHl6FpHw/4jOYm9t5+nrwUX/jyROVEefaalC1/WiwnYXiTLgx 4jAxwrYwbx8Bg8OYNDef9BXauUhx9/bWXabSKh8vkC72f9C5pfgeZ17smGOE+nrqryNH o6nKcLqjqditxU+81rTKzhbu0B3qZC3Q0XIAoB9qQacQCj1M7Yiv13GcD5qb0vSLuqp3 pGcQ== X-Gm-Message-State: AOAM5306yBybS4z9zLYGzHKr8SNxsuc8Ml0gMnLaYGoXDO4mMkML9KrN ctoPxASfkScLXte9IZr4mD53yxfrg38nxg== X-Google-Smtp-Source: ABdhPJzUGxM5w3clGHJ2cVX0U5vK1IU1016oKufuc6XJS0RDTugjR4Ry5eXkXQJ/RyYQCnMm/efkUA== X-Received: by 2002:a05:6214:1643:: with SMTP id f3mr2726787qvw.4.1613621116807; Wed, 17 Feb 2021 20:05:16 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id g8sm3111922qki.119.2021.02.17.20.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:16 -0800 (PST) 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/14] tools: disable -Wno-type-limits Date: Wed, 17 Feb 2021 20:04:59 -0800 Message-Id: <20210218040512.709186-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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 4255e71f72b7..457c9a31690f 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 Thu Feb 18 04:05:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 9AFCAC433E0 for ; Thu, 18 Feb 2021 04:06:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 49A7C64E4B for ; Thu, 18 Feb 2021 04:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230263AbhBREGl (ORCPT ); Wed, 17 Feb 2021 23:06:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbhBREGj (ORCPT ); Wed, 17 Feb 2021 23:06:39 -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 1BE9DC06178A; Wed, 17 Feb 2021 20:05:19 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id w20so556630qta.0; Wed, 17 Feb 2021 20:05:19 -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=toVAwo2dUrJDJv2KD4vMo0d0JQ5JY+mx3c/7901LESo=; b=P/8d8V5t7YyqbVTxXGqOGHiKpVx3UZK9jFy8tU2SBKlS4a1nND7T3fkGy7zGHIjLGL v6/QE3RmcMlVgwp6RJ8b0bqOijjDihWLTYw+ZZzJwkYVQ+tdRKWV7cBncWyewwnfK5tG S5iCkAXPO0pgQYf0RYrWvCr6eNfh7Uei4e56QD9y64/PA7QDqIohBZrx2PMo8cTSWeNO bchDoAdE2Jgg/ONLQ6u+1rnj+m4bmMBK3FjSc/xJHDlhWrAeV952u6ebhi4pPRyX8rO3 rJmUWgk4k6SEA8kZTpFsfJhv4knvsK22eDvnpesqHmndPxp5Pg/Gc18WDhh1RRjhDckh 0FQA== 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=toVAwo2dUrJDJv2KD4vMo0d0JQ5JY+mx3c/7901LESo=; b=BfMo7pC2mvBbVdi2A02JxyhX0g0So03+qr/seoal5NUkkjerCiVlaHoLJg6pszD0HU iPXcpl0zp7fEENdsuQpuNkZMRQsLnx1pFuCk5Q7uZi/lVTCOgwsSF6okz2RFh447eojn lHDGCcJEH9lzNHBpp2e4hsBDJ4cwglx3KnQOlzfmQtO01q8yen+ncJJzXR3IOWR2di/Y sIDu9l/S/OD6GfL4H663ttaT+LB46pF9whkYsw2r9ARSzvvYt3ZqeR0Jko7NsCVZZyxg fZhhe6SKsGQkoAFSrltPpzylnS5B1oE5e47x1gr8qWtJ+45OBxKrhU9hSH0P5jvis5gv hVGg== X-Gm-Message-State: AOAM53110TBDWS8/WRUJbjELPBl/9pd04rNj+pi7/hD1bUkapNncougE Cj745qnn2tvjYgBqklDr3w7qD55jEQltuQ== X-Google-Smtp-Source: ABdhPJxlk1mwoh0ClcudKh0i3H1OAdDGVjCtqQj4A2CjLRBilq+sZT8IrEH1d5fv+s/SpCSJ3nE7mA== X-Received: by 2002:ac8:44d2:: with SMTP id b18mr2562511qto.251.1613621118068; Wed, 17 Feb 2021 20:05:18 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id b17sm416159qtq.56.2021.02.17.20.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:17 -0800 (PST) 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/14] tools: bitmap: sync function declarations with the kernel Date: Wed, 17 Feb 2021 20:05:00 -0800 Message-Id: <20210218040512.709186-3-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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 --- 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 Thu Feb 18 04:05:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41CBCC4332D for ; Thu, 18 Feb 2021 04:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0058C64E79 for ; Thu, 18 Feb 2021 04:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbhBREGn (ORCPT ); Wed, 17 Feb 2021 23:06:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbhBREGm (ORCPT ); Wed, 17 Feb 2021 23:06:42 -0500 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F593C06178C; Wed, 17 Feb 2021 20:05:20 -0800 (PST) Received: by mail-qv1-xf31.google.com with SMTP id gi9so357119qvb.10; Wed, 17 Feb 2021 20:05:20 -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=JJENUVTTVrzVSsRoDJyoUWRsHsS22gYzvu4pIcEBs2g=; b=cNJUvLFqphk0K/lqrq0Qjn312xs1KS/3LK1bGTa2ELl9lD7az5WCGmCXVfKWK+5r7c ZtT/USGeWcVn+HKxgmLxPOP6UQFVJa0PNXbaO2nRqBjcowYlIBCFPW+Wm2l9qlhw77u1 wuWJqmcMjZkG/GtkEqRpgYv3CHz5W1SqXk/E8aHXvVIEqht/2dCNBJo/HaIJgBI3bD8V 7iyCFP+tN1/YPyLgotriolwMI25DHmzh7EEBv5kFZXhMHrYOaTOA4EyqiED4CbbuCdgB rnw6Qc4epf9pIxgL22Qq6Ml0RJxgZXdCSZC3ssNnoYSlLO/wxAIUBmo8ZDv9P2bxhu8o eEOg== 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=JJENUVTTVrzVSsRoDJyoUWRsHsS22gYzvu4pIcEBs2g=; b=ItCQAu2cpvijbPc1IWJm+S9uLmT+StUFPh5LP6SMBDx50hYKuR9NUFnXvtxqOhs3Ei X6N/lDUGxBMTzBIofy0hLWylVLcF6D7iKJ9TD7zgrUT9e13LkYxahqRa2xXheOnLwhss gw1CXHq1B8viVrI/bFZIzsUNm/H3c8EptfLMadFw9658kBptRnEmcrTaIHUQKOfn0Nzm oY7+j/z5D0+g91ergNWc4P2lq27L+5Tn2rIWF79j8ss5CUdHcn/oyq3wJLaM9DlP1Z5b bUfrFEN7uc31JUwpIaFO0fnc9Wdn2WLl2kjL83o0PpMz6olXiQgawzjKVE13+CIOG9a9 yjmA== X-Gm-Message-State: AOAM531lrX0gMcoWOnp96H1gSn5dlBp/cbbmg6xaxsu5UTOgcq1IuOnZ 0o74dO/7mG+Ip8xCE9WSuDG3Tcr3J4seOQ== X-Google-Smtp-Source: ABdhPJy0+QbSdvRColmCZHyYPmh/qO2RwqalAYB5I6htKRTN4sc2ZFQ9tkLgGhBq4G8GGqGf5zkcMg== X-Received: by 2002:a0c:fb41:: with SMTP id b1mr2589507qvq.26.1613621119021; Wed, 17 Feb 2021 20:05:19 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id e92sm2554283qtd.96.2021.02.17.20.05.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:18 -0800 (PST) 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/14] arch: rearrange headers inclusion order in asm/bitops for m68k and sh Date: Wed, 17 Feb 2021 20:05:01 -0800 Message-Id: <20210218040512.709186-4-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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 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 | 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 Feb 18 04:05:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 C8F97C433DB for ; Thu, 18 Feb 2021 04:06:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92D5864E45 for ; Thu, 18 Feb 2021 04:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230308AbhBREGy (ORCPT ); Wed, 17 Feb 2021 23:06:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230309AbhBREGo (ORCPT ); Wed, 17 Feb 2021 23:06:44 -0500 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADD28C061794; Wed, 17 Feb 2021 20:05:21 -0800 (PST) Received: by mail-qk1-x736.google.com with SMTP id m144so933958qke.10; Wed, 17 Feb 2021 20:05:21 -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=Lcwxjl/dsuyts/RranSp981+qqM56LtakHjNiOSMBAs=; b=uozEFLdsh2DdZzhW6IYZkYUGgUCWwOwh763sTzo9ape+5Y8Wyprk+znfiiYHc1XgNp ylaeq/mCS4PvVGBknotIBLld5IXK/OEUC9YCI6q8PadX1+C2a6a2WJDNALAxO5LV3Hmo zrXy2A8VmFUtRsDU1XpcGmYsgTmWo8Vd/AayOIQ7gzSIRIcyKwFytXSADfd2SCkIFTPk gi+9kHqBmbic037a68ZTwXE+vtS9w3Qwi0UAC+2BckETOrY9VN21ZCE2w14NYaGqY3mO p3xLjk1CHgJpcHDW7nfLz1gHypRVJY99M25WpXNtPNw4L3hB8MufK6M8yMKIKvX0+fpG sR+g== 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=Lcwxjl/dsuyts/RranSp981+qqM56LtakHjNiOSMBAs=; b=bfOPpFi5HhYZMpyPHfDlid/HMsMWj0MM90iN31qcoXMZb1Y6Il2cMKzN/p2LCSGcR1 DgFtTNx6i8Wy6QHy1Hx438Q0UuoWlYHzr6MhQJqqo2CaWrCbxFUDze/YOnADeMwFFLhR GcBktdBtx/ljBYcCp30bYuqky4kBSXwfAxebl/EAIsQpAXOeNv4yQDV+WRsaS12utc4t n8YK4MnSlzr9NghFHNMoEDtUcKyio2GFwaa1+CgxoSu8YwumfzYuTQjlqmuA8j6SAzCE yWiQkUq/HhbgxeKo2tfhxsckKQ6PtUvjA7MLrkvgz57wxe7tkR2Lg/jM87MabjkDm8N5 EH+w== X-Gm-Message-State: AOAM530FgnCW2DUDXNFJOumBCmI+ZDQ9FIdB573tzxJ2wYnn3FLZL+8c JSrzQ7KTp4lWPHsQ3iWj/1kZ3TYRJWcYmA== X-Google-Smtp-Source: ABdhPJx86J2yiWZ4kKjAGEnb1EHUFO3H/CztpugBS7id9x9Nm/xShLmDEd5FoQHYhQnvh/S8U2oQxw== X-Received: by 2002:a37:e214:: with SMTP id g20mr2422065qki.41.1613621120357; Wed, 17 Feb 2021 20:05:20 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id z28sm3254268qkj.72.2021.02.17.20.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:19 -0800 (PST) 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/14] lib: introduce BITS_{FIRST,LAST} macro Date: Wed, 17 Feb 2021 20:05:02 -0800 Message-Id: <20210218040512.709186-5-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org BITMAP_{LAST,FIRST}_WORD_MASK() in linux/bitmap.h duplicates the functionality of GENMASK(). The scope of there macros is wider than just bitmap. This patch defines 4 new macros: BITS_FIRST(), BITS_LAST(), BITS_FIRST_MASK() and BITS_LAST_MASK() in linux/bits.h on top of GENMASK() and replaces BITMAP_{LAST,FIRST}_WORD_MASK() to avoid duplication and increase the scope of the macros. Signed-off-by: Yury Norov --- include/linux/bitmap.h | 27 ++++++++++++--------------- include/linux/bits.h | 6 ++++++ include/linux/cpumask.h | 8 ++++---- include/linux/netdev_features.h | 2 +- include/linux/nodemask.h | 2 +- lib/bitmap.c | 26 +++++++++++++------------- lib/find_bit.c | 4 ++-- lib/genalloc.c | 8 ++++---- 8 files changed, 43 insertions(+), 40 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 70a932470b2d..adf7bd9f0467 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -219,9 +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 @@ -257,7 +254,7 @@ static inline void bitmap_copy_clear_tail(unsigned long *dst, { bitmap_copy(dst, src, nbits); if (nbits % BITS_PER_LONG) - dst[nbits / BITS_PER_LONG] &= BITMAP_LAST_WORD_MASK(nbits); + dst[nbits / BITS_PER_LONG] &= BITS_FIRST_MASK(nbits - 1); } /* @@ -282,7 +279,7 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) - return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0; + return (*dst = *src1 & *src2 & BITS_FIRST(nbits - 1)) != 0; return __bitmap_and(dst, src1, src2, nbits); } @@ -308,7 +305,7 @@ static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) - return (*dst = *src1 & ~(*src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; + return (*dst = *src1 & ~(*src2) & BITS_FIRST(nbits - 1)) != 0; return __bitmap_andnot(dst, src1, src2, nbits); } @@ -332,7 +329,7 @@ static inline int bitmap_equal(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) - return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); + return !((*src1 ^ *src2) & BITS_FIRST(nbits - 1)); if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) return !memcmp(src1, src2, nbits / 8); @@ -356,14 +353,14 @@ static inline bool bitmap_or_equal(const unsigned long *src1, if (!small_const_nbits(nbits)) return __bitmap_or_equal(src1, src2, src3, nbits); - return !(((*src1 | *src2) ^ *src3) & BITMAP_LAST_WORD_MASK(nbits)); + return !(((*src1 | *src2) ^ *src3) & BITS_FIRST(nbits - 1)); } static inline int bitmap_intersects(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) - return ((*src1 & *src2) & BITMAP_LAST_WORD_MASK(nbits)) != 0; + return ((*src1 & *src2) & BITS_FIRST(nbits - 1)) != 0; else return __bitmap_intersects(src1, src2, nbits); } @@ -372,7 +369,7 @@ static inline int bitmap_subset(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) - return ! ((*src1 & ~(*src2)) & BITMAP_LAST_WORD_MASK(nbits)); + return !((*src1 & ~(*src2)) & BITS_FIRST(nbits - 1)); else return __bitmap_subset(src1, src2, nbits); } @@ -380,7 +377,7 @@ static inline int bitmap_subset(const unsigned long *src1, static inline bool bitmap_empty(const unsigned long *src, unsigned nbits) { if (small_const_nbits(nbits)) - return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); + return !(*src & BITS_FIRST(nbits - 1)); return find_first_bit(src, nbits) == nbits; } @@ -388,7 +385,7 @@ static inline bool bitmap_empty(const unsigned long *src, unsigned nbits) static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) { if (small_const_nbits(nbits)) - return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); + return !(~(*src) & BITS_FIRST(nbits - 1)); return find_first_zero_bit(src, nbits) == nbits; } @@ -396,7 +393,7 @@ static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) static __always_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)); + return hweight_long(*src & BITS_FIRST(nbits - 1)); return __bitmap_weight(src, nbits); } @@ -432,7 +429,7 @@ static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *s unsigned int shift, unsigned int nbits) { if (small_const_nbits(nbits)) - *dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> shift; + *dst = (*src & BITS_FIRST(nbits - 1)) >> shift; else __bitmap_shift_right(dst, src, shift, nbits); } @@ -441,7 +438,7 @@ static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *sr unsigned int shift, unsigned int nbits) { if (small_const_nbits(nbits)) - *dst = (*src << shift) & BITMAP_LAST_WORD_MASK(nbits); + *dst = (*src << shift) & BITS_FIRST(nbits - 1); else __bitmap_shift_left(dst, src, shift, nbits); } diff --git a/include/linux/bits.h b/include/linux/bits.h index 7f475d59a097..8c191c29506e 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -37,6 +37,12 @@ #define GENMASK(h, l) \ (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) +#define BITS_FIRST(nr) GENMASK((nr), 0) +#define BITS_LAST(nr) GENMASK(BITS_PER_LONG - 1, (nr)) + +#define BITS_FIRST_MASK(nr) BITS_FIRST((nr) % BITS_PER_LONG) +#define BITS_LAST_MASK(nr) BITS_LAST((nr) % BITS_PER_LONG) + #define __GENMASK_ULL(h, l) \ (((~ULL(0)) - (ULL(1) << (l)) + 1) & \ (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h)))) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 383684e30f12..edf8d15cfd81 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -899,7 +899,7 @@ static inline const struct cpumask *get_cpu_mask(unsigned int cpu) #if NR_CPUS <= BITS_PER_LONG #define CPU_BITS_ALL \ { \ - [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \ + [BITS_TO_LONGS(NR_CPUS)-1] = BITS_FIRST_MASK(NR_CPUS - 1) \ } #else /* NR_CPUS > BITS_PER_LONG */ @@ -907,7 +907,7 @@ static inline const struct cpumask *get_cpu_mask(unsigned int cpu) #define CPU_BITS_ALL \ { \ [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ - [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \ + [BITS_TO_LONGS(NR_CPUS)-1] = BITS_FIRST_MASK(NR_CPUS - 1) \ } #endif /* NR_CPUS > BITS_PER_LONG */ @@ -931,13 +931,13 @@ cpumap_print_to_pagebuf(bool list, char *buf, const struct cpumask *mask) #if NR_CPUS <= BITS_PER_LONG #define CPU_MASK_ALL \ (cpumask_t) { { \ - [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \ + [BITS_TO_LONGS(NR_CPUS)-1] = BITS_FIRST_MASK(NR_CPUS - 1) \ } } #else #define CPU_MASK_ALL \ (cpumask_t) { { \ [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ - [BITS_TO_LONGS(NR_CPUS)-1] = BITMAP_LAST_WORD_MASK(NR_CPUS) \ + [BITS_TO_LONGS(NR_CPUS)-1] = BITS_FIRST_MASK(NR_CPUS - 1) \ } } #endif /* NR_CPUS > BITS_PER_LONG */ diff --git a/include/linux/netdev_features.h b/include/linux/netdev_features.h index 3de38d6a0aea..4cef7fe02f09 100644 --- a/include/linux/netdev_features.h +++ b/include/linux/netdev_features.h @@ -173,7 +173,7 @@ enum { */ static inline int find_next_netdev_feature(u64 feature, unsigned long start) { - /* like BITMAP_LAST_WORD_MASK() for u64 + /* like BITS_FIRST_MASK() for u64 * this sets the most significant 64 - start to 0. */ feature &= ~0ULL >> (-start & ((sizeof(feature) * 8) - 1)); diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index ac398e143c9a..2df0787c9155 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -302,7 +302,7 @@ static inline int __first_unset_node(const nodemask_t *maskp) find_first_zero_bit(maskp->bits, MAX_NUMNODES)); } -#define NODE_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES) +#define NODE_MASK_LAST_WORD BITS_FIRST_MASK(MAX_NUMNODES - 1) #if MAX_NUMNODES <= BITS_PER_LONG diff --git a/lib/bitmap.c b/lib/bitmap.c index 75006c4036e9..2507fef664ad 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -52,7 +52,7 @@ int __bitmap_equal(const unsigned long *bitmap1, return 0; if (bits % BITS_PER_LONG) - if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + if ((bitmap1[k] ^ bitmap2[k]) & BITS_FIRST_MASK(bits - 1)) return 0; return 1; @@ -76,7 +76,7 @@ bool __bitmap_or_equal(const unsigned long *bitmap1, return true; tmp = (bitmap1[k] | bitmap2[k]) ^ bitmap3[k]; - return (tmp & BITMAP_LAST_WORD_MASK(bits)) == 0; + return (tmp & BITS_FIRST_MASK(bits - 1)) == 0; } void __bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int bits) @@ -103,7 +103,7 @@ void __bitmap_shift_right(unsigned long *dst, const unsigned long *src, { unsigned k, lim = BITS_TO_LONGS(nbits); unsigned off = shift/BITS_PER_LONG, rem = shift % BITS_PER_LONG; - unsigned long mask = BITMAP_LAST_WORD_MASK(nbits); + unsigned long mask = BITS_FIRST_MASK(nbits - 1); for (k = 0; off + k < lim; ++k) { unsigned long upper, lower; @@ -246,7 +246,7 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, result |= (dst[k] = bitmap1[k] & bitmap2[k]); if (bits % BITS_PER_LONG) result |= (dst[k] = bitmap1[k] & bitmap2[k] & - BITMAP_LAST_WORD_MASK(bits)); + BITS_FIRST_MASK(bits - 1)); return result != 0; } EXPORT_SYMBOL(__bitmap_and); @@ -284,7 +284,7 @@ int __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, result |= (dst[k] = bitmap1[k] & ~bitmap2[k]); if (bits % BITS_PER_LONG) result |= (dst[k] = bitmap1[k] & ~bitmap2[k] & - BITMAP_LAST_WORD_MASK(bits)); + BITS_FIRST_MASK(bits - 1)); return result != 0; } EXPORT_SYMBOL(__bitmap_andnot); @@ -310,7 +310,7 @@ int __bitmap_intersects(const unsigned long *bitmap1, return 1; if (bits % BITS_PER_LONG) - if ((bitmap1[k] & bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + if ((bitmap1[k] & bitmap2[k]) & BITS_FIRST_MASK(bits - 1)) return 1; return 0; } @@ -325,7 +325,7 @@ int __bitmap_subset(const unsigned long *bitmap1, return 0; if (bits % BITS_PER_LONG) - if ((bitmap1[k] & ~bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + if ((bitmap1[k] & ~bitmap2[k]) & BITS_FIRST_MASK(bits - 1)) return 0; return 1; } @@ -340,7 +340,7 @@ int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) w += hweight_long(bitmap[k]); if (bits % BITS_PER_LONG) - w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); + w += hweight_long(bitmap[k] & BITS_FIRST_MASK(bits - 1)); return w; } @@ -351,7 +351,7 @@ void __bitmap_set(unsigned long *map, unsigned int start, int len) unsigned long *p = map + BIT_WORD(start); const unsigned int size = start + len; int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); - unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); + unsigned long mask_to_set = BITS_LAST_MASK(start); while (len - bits_to_set >= 0) { *p |= mask_to_set; @@ -361,7 +361,7 @@ void __bitmap_set(unsigned long *map, unsigned int start, int len) p++; } if (len) { - mask_to_set &= BITMAP_LAST_WORD_MASK(size); + mask_to_set &= BITS_FIRST_MASK(size - 1); *p |= mask_to_set; } } @@ -372,7 +372,7 @@ void __bitmap_clear(unsigned long *map, unsigned int start, int len) unsigned long *p = map + BIT_WORD(start); const unsigned int size = start + len; int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); - unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); + unsigned long mask_to_clear = BITS_LAST_MASK(start); while (len - bits_to_clear >= 0) { *p &= ~mask_to_clear; @@ -382,7 +382,7 @@ void __bitmap_clear(unsigned long *map, unsigned int start, int len) p++; } if (len) { - mask_to_clear &= BITMAP_LAST_WORD_MASK(size); + mask_to_clear &= BITS_FIRST_MASK(size - 1); *p &= ~mask_to_clear; } } @@ -1282,7 +1282,7 @@ void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, unsigned int nbits /* Clear tail bits in last word beyond nbits. */ if (nbits % BITS_PER_LONG) - bitmap[(halfwords - 1) / 2] &= BITMAP_LAST_WORD_MASK(nbits); + bitmap[(halfwords - 1) / 2] &= BITS_FIRST_MASK(nbits - 1); } EXPORT_SYMBOL(bitmap_from_arr32); diff --git a/lib/find_bit.c b/lib/find_bit.c index f67f86fd2f62..8c2a71a18793 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -44,7 +44,7 @@ static unsigned long _find_next_bit(const unsigned long *addr1, tmp ^= invert; /* Handle 1st word. */ - mask = BITMAP_FIRST_WORD_MASK(start); + mask = BITS_LAST_MASK(start); if (le) mask = swab(mask); @@ -141,7 +141,7 @@ EXPORT_SYMBOL(find_first_zero_bit); unsigned long find_last_bit(const unsigned long *addr, unsigned long size) { if (size) { - unsigned long val = BITMAP_LAST_WORD_MASK(size); + unsigned long val = BITS_FIRST_MASK(size - 1); unsigned long idx = (size-1) / BITS_PER_LONG; do { diff --git a/lib/genalloc.c b/lib/genalloc.c index 5dcf9cdcbc46..0af7275517ff 100644 --- a/lib/genalloc.c +++ b/lib/genalloc.c @@ -87,7 +87,7 @@ bitmap_set_ll(unsigned long *map, unsigned long start, unsigned long nr) unsigned long *p = map + BIT_WORD(start); const unsigned long size = start + nr; int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); - unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); + unsigned long mask_to_set = BITS_LAST_MASK(start); while (nr >= bits_to_set) { if (set_bits_ll(p, mask_to_set)) @@ -98,7 +98,7 @@ bitmap_set_ll(unsigned long *map, unsigned long start, unsigned long nr) p++; } if (nr) { - mask_to_set &= BITMAP_LAST_WORD_MASK(size); + mask_to_set &= BITS_FIRST_MASK(size - 1); if (set_bits_ll(p, mask_to_set)) return nr; } @@ -123,7 +123,7 @@ bitmap_clear_ll(unsigned long *map, unsigned long start, unsigned long nr) unsigned long *p = map + BIT_WORD(start); const unsigned long size = start + nr; int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); - unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); + unsigned long mask_to_clear = BITS_LAST_MASK(start); while (nr >= bits_to_clear) { if (clear_bits_ll(p, mask_to_clear)) @@ -134,7 +134,7 @@ bitmap_clear_ll(unsigned long *map, unsigned long start, unsigned long nr) p++; } if (nr) { - mask_to_clear &= BITMAP_LAST_WORD_MASK(size); + mask_to_clear &= BITS_FIRST_MASK(size - 1); if (clear_bits_ll(p, mask_to_clear)) return nr; } From patchwork Thu Feb 18 04:05:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 D6D3AC4332E for ; Thu, 18 Feb 2021 04:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CD4364E76 for ; Thu, 18 Feb 2021 04:06:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbhBREGv (ORCPT ); Wed, 17 Feb 2021 23:06:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbhBREGo (ORCPT ); Wed, 17 Feb 2021 23:06:44 -0500 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEB80C0617A7; Wed, 17 Feb 2021 20:05:22 -0800 (PST) Received: by mail-qv1-xf34.google.com with SMTP id g3so378140qvl.2; Wed, 17 Feb 2021 20:05:22 -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=ikJ0eLK/6OkjCoMd1X7LK5WjQKKwDBA3WSJVKIrvN0Q=; b=hJg6KQKGJOnvHn0vwvN/UNsRZ03BJw7giIx2ZKPCaDoI43w6V/Bb7ASZ6QVyuy6LL7 wAy+CoCNsGnuJo4Aw+0i6YbUFzsWiCUGnhrnhrwwD5PMayJ+lSz+T3X0B36OjRd7CY0O 9+CFQeFlikpBuYVc3jEwRO0o9N2iueXh79+fZ9SAEnGgXlZmLWPB4gOpHMiFgPW1NtAa a1dfEZpY70RNMlJFBDQco1J/AaC97WbbTL60/wZJtjN2Q77NzDze/Xh0X+YAyXrkE5/b +Ot7oyJGO7xF4PZHE6F/mUFsN06aq1qVgq0hcb0g8NykkGqzccjRAg7tna9k50ssR513 bNNQ== 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=ikJ0eLK/6OkjCoMd1X7LK5WjQKKwDBA3WSJVKIrvN0Q=; b=JxDKxj+UB3sx7WjMDFaasnbFfgiXawSZOImPytJ7em3RWBegPPQJuWkueSXRl6lIaH Yffol1SfTKB2T/KM/LIxjKXm2wPBkqw7uMkJ+/D65Bdb9ivGO6ax8Fmr1YzjaVXFdBTh Qm94a+8+HQUJfYmpHj8U+Z9EGHGTewwyekyijgAOqS2Iw8CUWSmGX/pMytSrsMXjvaRm OsW6Yx50hxJ7v0dtGN8ROH10v/RkMWLw+Nvtg33zoh/jd5z+rqSvsPOH/jmwo2K/JezT o/9kHrt2e/dq7cpIDzkEORCt0bUa2iZ+D8rEL+D7qylBbtcwexxKiajZavGv8sdhL20P zw9g== X-Gm-Message-State: AOAM533PQUHUMLRpnGe76zIxk00vxpjDHD/mGFmnvHZqFth1wpLZ7X6T qRas0EynDECPguc6p+J0CESPpkcpliZgCw== X-Google-Smtp-Source: ABdhPJx9Tusg+e1+VHXXdGQGgvi3R8zz4RvA+JAGQDv/ycQz9J7otTemRUSc3W5l09mHkDorr8UDFQ== X-Received: by 2002:ad4:4631:: with SMTP id x17mr2504586qvv.6.1613621121538; Wed, 17 Feb 2021 20:05:21 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id j66sm3255440qkf.78.2021.02.17.20.05.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:21 -0800 (PST) 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/14] tools: sync BITS_MASK macros with the kernel Date: Wed, 17 Feb 2021 20:05:03 -0800 Message-Id: <20210218040512.709186-6-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Remove BITMAP_{FIRST,LAST}_WORD_MASK and introduce BITS_{FIRST,LAST}{,_MASK} as per kernel implementation. Signed-off-by: Yury Norov --- tools/include/linux/bitmap.h | 20 ++++++-------------- tools/include/linux/bits.h | 6 ++++++ tools/lib/bitmap.c | 6 +++--- tools/lib/find_bit.c | 2 +- tools/testing/radix-tree/bitmap.c | 4 ++-- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 7cbd23e56d48..b6e8430c8bc9 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -19,14 +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) @@ -47,13 +39,13 @@ static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) unsigned int len = (nlongs - 1) * sizeof(unsigned long); memset(dst, 0xff, len); } - dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); + dst[nlongs - 1] = BITS_FIRST(nbits - 1); } static inline int bitmap_empty(const unsigned long *src, unsigned nbits) { if (small_const_nbits(nbits)) - return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); + return !(*src & BITS_FIRST(nbits - 1)); return find_first_bit(src, nbits) == nbits; } @@ -61,7 +53,7 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits) static inline int bitmap_full(const unsigned long *src, unsigned int nbits) { if (small_const_nbits(nbits)) - return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); + return !(~(*src) & BITS_FIRST(nbits - 1)); return find_first_zero_bit(src, nbits) == nbits; } @@ -69,7 +61,7 @@ static inline int bitmap_full(const unsigned long *src, unsigned 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)); + return hweight_long(*src & BITS_FIRST(nbits - 1)); return __bitmap_weight(src, nbits); } @@ -155,7 +147,7 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) - return (*dst = *src1 & *src2 & BITMAP_LAST_WORD_MASK(nbits)) != 0; + return (*dst = *src1 & *src2 & BITS_FIRST(nbits - 1)) != 0; return __bitmap_and(dst, src1, src2, nbits); } @@ -171,7 +163,7 @@ static inline int bitmap_equal(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { if (small_const_nbits(nbits)) - return !((*src1 ^ *src2) & BITMAP_LAST_WORD_MASK(nbits)); + return !((*src1 ^ *src2) & BITS_FIRST(nbits - 1)); if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) return !memcmp(src1, src2, nbits / 8); diff --git a/tools/include/linux/bits.h b/tools/include/linux/bits.h index 7f475d59a097..8c191c29506e 100644 --- a/tools/include/linux/bits.h +++ b/tools/include/linux/bits.h @@ -37,6 +37,12 @@ #define GENMASK(h, l) \ (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) +#define BITS_FIRST(nr) GENMASK((nr), 0) +#define BITS_LAST(nr) GENMASK(BITS_PER_LONG - 1, (nr)) + +#define BITS_FIRST_MASK(nr) BITS_FIRST((nr) % BITS_PER_LONG) +#define BITS_LAST_MASK(nr) BITS_LAST((nr) % BITS_PER_LONG) + #define __GENMASK_ULL(h, l) \ (((~ULL(0)) - (ULL(1) << (l)) + 1) & \ (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h)))) diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c index f4e914712b6f..8cffad2d1f77 100644 --- a/tools/lib/bitmap.c +++ b/tools/lib/bitmap.c @@ -13,7 +13,7 @@ int __bitmap_weight(const unsigned long *bitmap, int bits) w += hweight_long(bitmap[k]); if (bits % BITS_PER_LONG) - w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits)); + w += hweight_long(bitmap[k] & BITS_FIRST_MASK(bits - 1)); return w; } @@ -68,7 +68,7 @@ int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, result |= (dst[k] = bitmap1[k] & bitmap2[k]); if (bits % BITS_PER_LONG) result |= (dst[k] = bitmap1[k] & bitmap2[k] & - BITMAP_LAST_WORD_MASK(bits)); + BITS_FIRST_MASK(bits - 1)); return result != 0; } @@ -81,7 +81,7 @@ int __bitmap_equal(const unsigned long *bitmap1, return 0; if (bits % BITS_PER_LONG) - if ((bitmap1[k] ^ bitmap2[k]) & BITMAP_LAST_WORD_MASK(bits)) + if ((bitmap1[k] ^ bitmap2[k]) & BITS_FIRST_MASK(bits - 1)) return 0; return 1; diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index ac37022e9486..49abb18549cc 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -43,7 +43,7 @@ static inline unsigned long _find_next_bit(const unsigned long *addr1, tmp ^= invert; /* Handle 1st word. */ - tmp &= BITMAP_FIRST_WORD_MASK(start); + tmp &= BITS_LAST_MASK(start); start = round_down(start, BITS_PER_LONG); while (!tmp) { diff --git a/tools/testing/radix-tree/bitmap.c b/tools/testing/radix-tree/bitmap.c index 66ec4a24a203..aedc15461f78 100644 --- a/tools/testing/radix-tree/bitmap.c +++ b/tools/testing/radix-tree/bitmap.c @@ -7,7 +7,7 @@ void bitmap_clear(unsigned long *map, unsigned int start, int len) unsigned long *p = map + BIT_WORD(start); const unsigned int size = start + len; int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); - unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start); + unsigned long mask_to_clear = BITS_LAST_MASK(start); while (len - bits_to_clear >= 0) { *p &= ~mask_to_clear; @@ -17,7 +17,7 @@ void bitmap_clear(unsigned long *map, unsigned int start, int len) p++; } if (len) { - mask_to_clear &= BITMAP_LAST_WORD_MASK(size); + mask_to_clear &= BITS_FIRST_MASK(size - 1); *p &= ~mask_to_clear; } } From patchwork Thu Feb 18 04:05:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 4E6D1C433E0 for ; Thu, 18 Feb 2021 04:07:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 03A026023B for ; Thu, 18 Feb 2021 04:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230310AbhBREG4 (ORCPT ); Wed, 17 Feb 2021 23:06:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230313AbhBREGo (ORCPT ); Wed, 17 Feb 2021 23:06:44 -0500 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 BF837C0617AA; Wed, 17 Feb 2021 20:05:23 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id o21so541972qtr.3; Wed, 17 Feb 2021 20:05:23 -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=6FLaYtqlcPj5mHz3wttzpDxqmTsU3JE46pi9R7LZnzQ=; b=WcaKUrkhzBFoblnjEi373y1rNZ+Iv84R7dXzYpvVZucFwksStCrd6i+xfoTRvzjJCq pZ1p7BEIF1oOl+8FXZnEcQO7Npv/GMkHu1QWg8/QJhaIxfjbElNQHBmj6gm877PsEv0T TDOoAofxpjcDqhfwMtM8gPlCe+I0JWxfCYi6ihiCdDFzArG+TPvOrCMJkU++TbXEfEiT 1zxvaAnq/cA5O1yr7F1afKon6lgZ8WfLkKYHoBMo80PWnN+I2029y+WVvqvqpDKWwwle UONBe+qp7YxJa2xfjoLbNO2oNbcUgQ20gwlyJuz4CnPLVlJWN0LUwcpBUJwAack17TPk qPbg== 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=6FLaYtqlcPj5mHz3wttzpDxqmTsU3JE46pi9R7LZnzQ=; b=ew+AURVtAl9Aa7vr81MgAd+yKHxWc7fG8+Wr42vyXuuVSXttMReVx5MNvBSja63ceL 2V1g4Z3CVpiY9fr0QIZLGAtCcq5dXAnlEVLh3BwdAkHotC+Pm20R2vrlAFFdD44NRM+8 mWZg3zAbQOSdheLNpAqd+4/dtrxLT5w9uTPrrlxVG7LN68RBx0Y2aQndJcQbfqAOMVcd 4SyBUAMHtY8e+1r//LtXjtxkvO1fKFiGhp3u+Bx+FKKDeWqT1ux0o0bklghSL4auwZEI wsYVAgNs6mqN+bQnh0WlNO8EpvJEytceCuUZ0Hz/rbmj7S86HamfIjK6uS6NyCyHLFAV mL7A== X-Gm-Message-State: AOAM533WAHPypmfat0Jl4+cfp+c44AgDhiYwy02au/6dWQ4vTp1+AzS3 MN5zvSvoVdE6bNRYHW/TK0rwMyAdWWzQXA== X-Google-Smtp-Source: ABdhPJzD9ex6BPIwZwBTxQRWM29pvG7PcO8nqZzvvxw3eMNa8TLjrRaZkC8xW/fyY/pkdE6kuXRemg== X-Received: by 2002:ac8:ac4:: with SMTP id g4mr1888414qti.88.1613621122627; Wed, 17 Feb 2021 20:05:22 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id g5sm3199230qki.90.2021.02.17.20.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:22 -0800 (PST) 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/14] bitsperlong.h: introduce SMALL_CONST() macro Date: Wed, 17 Feb 2021 20:05:04 -0800 Message-Id: <20210218040512.709186-7-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Many algorithms become simpler if they are passed with relatively small input values. One example is bitmap operations when the whole bitmap fits into one word. To implement such simplifications, linux/bitmap.h declares small_const_nbits() macro. Other subsystems may also benefit from optimizations of this sort, like find_bit API in the following patches. So it looks helpful to generalize the macro and extend it's visibility. Signed-off-by: Yury Norov --- include/asm-generic/bitsperlong.h | 2 ++ include/linux/bitmap.h | 33 ++++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/include/asm-generic/bitsperlong.h b/include/asm-generic/bitsperlong.h index 3905c1c93dc2..0eeb77544f1d 100644 --- a/include/asm-generic/bitsperlong.h +++ b/include/asm-generic/bitsperlong.h @@ -23,4 +23,6 @@ #define BITS_PER_LONG_LONG 64 #endif +#define SMALL_CONST(n) (__builtin_constant_p(n) && (unsigned long)(n) < BITS_PER_LONG) + #endif /* __ASM_GENERIC_BITS_PER_LONG */ diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index adf7bd9f0467..e89f1dace846 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -224,9 +224,6 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf, * 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); @@ -278,7 +275,7 @@ extern void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return (*dst = *src1 & *src2 & BITS_FIRST(nbits - 1)) != 0; return __bitmap_and(dst, src1, src2, nbits); } @@ -286,7 +283,7 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) *dst = *src1 | *src2; else __bitmap_or(dst, src1, src2, nbits); @@ -295,7 +292,7 @@ static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) *dst = *src1 ^ *src2; else __bitmap_xor(dst, src1, src2, nbits); @@ -304,7 +301,7 @@ static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return (*dst = *src1 & ~(*src2) & BITS_FIRST(nbits - 1)) != 0; return __bitmap_andnot(dst, src1, src2, nbits); } @@ -312,7 +309,7 @@ static inline int bitmap_andnot(unsigned long *dst, const unsigned long *src1, static inline void bitmap_complement(unsigned long *dst, const unsigned long *src, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) *dst = ~(*src); else __bitmap_complement(dst, src, nbits); @@ -328,7 +325,7 @@ static inline void bitmap_complement(unsigned long *dst, const unsigned long *sr static inline int bitmap_equal(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return !((*src1 ^ *src2) & BITS_FIRST(nbits - 1)); if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) @@ -350,7 +347,7 @@ static inline bool bitmap_or_equal(const unsigned long *src1, const unsigned long *src3, unsigned int nbits) { - if (!small_const_nbits(nbits)) + if (!SMALL_CONST(nbits - 1)) return __bitmap_or_equal(src1, src2, src3, nbits); return !(((*src1 | *src2) ^ *src3) & BITS_FIRST(nbits - 1)); @@ -359,7 +356,7 @@ static inline bool bitmap_or_equal(const unsigned long *src1, static inline int bitmap_intersects(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return ((*src1 & *src2) & BITS_FIRST(nbits - 1)) != 0; else return __bitmap_intersects(src1, src2, nbits); @@ -368,7 +365,7 @@ static inline int bitmap_intersects(const unsigned long *src1, static inline int bitmap_subset(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return !((*src1 & ~(*src2)) & BITS_FIRST(nbits - 1)); else return __bitmap_subset(src1, src2, nbits); @@ -376,7 +373,7 @@ static inline int bitmap_subset(const unsigned long *src1, static inline bool bitmap_empty(const unsigned long *src, unsigned nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return !(*src & BITS_FIRST(nbits - 1)); return find_first_bit(src, nbits) == nbits; @@ -384,7 +381,7 @@ static inline bool bitmap_empty(const unsigned long *src, unsigned nbits) static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return !(~(*src) & BITS_FIRST(nbits - 1)); return find_first_zero_bit(src, nbits) == nbits; @@ -392,7 +389,7 @@ static inline bool bitmap_full(const unsigned long *src, unsigned int nbits) static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return hweight_long(*src & BITS_FIRST(nbits - 1)); return __bitmap_weight(src, nbits); } @@ -428,7 +425,7 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start, static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src, unsigned int shift, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) *dst = (*src & BITS_FIRST(nbits - 1)) >> shift; else __bitmap_shift_right(dst, src, shift, nbits); @@ -437,7 +434,7 @@ static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *s static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *src, unsigned int shift, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) *dst = (*src << shift) & BITS_FIRST(nbits - 1); else __bitmap_shift_left(dst, src, shift, nbits); @@ -449,7 +446,7 @@ static inline void bitmap_replace(unsigned long *dst, const unsigned long *mask, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) *dst = (*old & ~(*mask)) | (*new & *mask); else __bitmap_replace(dst, old, new, mask, nbits); From patchwork Thu Feb 18 04:05:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 0842AC433E0 for ; Thu, 18 Feb 2021 04:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A9CC864E28 for ; Thu, 18 Feb 2021 04:08:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbhBREIK (ORCPT ); Wed, 17 Feb 2021 23:08:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230335AbhBREG4 (ORCPT ); Wed, 17 Feb 2021 23:06:56 -0500 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 B6714C061356; Wed, 17 Feb 2021 20:05:24 -0800 (PST) Received: by mail-qk1-x732.google.com with SMTP id r77so926856qka.12; Wed, 17 Feb 2021 20:05:24 -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=cjSIeqJixMTGqRQf4pKdu4MWSI5GGmFq1M6YrJB6ms0=; b=NwqiIYKiwQvjkCSg9zybdmkHUmSyFt2HOQn/UnvZHP1/cFo5L0xG2Qu2pDC776jxbP CuAKEnW4PiUEXH+BYQwj7akf/i9yRdU6TBvYU0hxuFK4B/0KRSHcI7+ost9IZ5DjIeQh vgbzSHWeKp99QlRbJROnOw7SYSI0RWLKVEwEPAQC3Ch8SJSn6WtwDRvHA0Pn6czqz2lX 3y6mYEVeSMqZHAnb1WK7uqgX4CsXsGJzryOu0kpByxDoE8jB554hRuKBlLerxp/K0upN SUGhK7kDp8YtmJEWeafHWGpDJT6gijvMS8TFMLYj9E8wWtCanPW5sEl9uw8zvv5thqdp ENQg== 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=cjSIeqJixMTGqRQf4pKdu4MWSI5GGmFq1M6YrJB6ms0=; b=pYHXUXx9mZgpgP4z8GiUzpbnYmTfjbN5thIkT+TFqlpJxLHPVwAjUO7OgaiO9GzB85 UB0wAoO1ZpMTsY3+z/kWEaPTsbdR7yjEP0r45ccJp9tFOLC6o8hC2rRqmgIqeWZfLNYu b1b1/K1HJrd9EBL0/r7V647wL7N0aogsE4yYRc46tDhQUfcFBdrxuLSL9X1u6AJpSOiR 5jy8XZt4UTpDI4lP2sp+eism6TwU1IgTZMKpQue5eshAkZVQPTX+bgEydIFDALsT06Iw ueOATGKWqEJWrZ/2m3yImhRQ9n+yo5uMB0iov7ZqayGYmlTh4AhtxsuPgGNzCIyuaXBc zh7A== X-Gm-Message-State: AOAM531WCLkApLPzTPFn0oJ3djUa6/1hwqMFVVZ2JMPXHPjHCd9bCCa8 7ZUmIYKGfbcnW/5KlAAA1AmuhJ0Jjuq+sg== X-Google-Smtp-Source: ABdhPJwWyhO8SiOvUL7zClLuBCnRg+OdrKdBQxcsMRMEOJ5MAi89x93TmlkkOhuwzoAKgXCkxlDjpQ== X-Received: by 2002:a05:620a:166a:: with SMTP id d10mr2364582qko.213.1613621123624; Wed, 17 Feb 2021 20:05:23 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id c7sm2637792qtc.82.2021.02.17.20.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:23 -0800 (PST) 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/14] tools: introduce SMALL_CONST() macro Date: Wed, 17 Feb 2021 20:05:05 -0800 Message-Id: <20210218040512.709186-8-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org Many algorithms become simpler if they are passed with relatively small input values. One example is bitmap operations when the whole bitmap fits into one word. To implement such simplifications, linux/bitmap.h declares small_const_nbits() macro. Other subsystems may also benefit from optimizations of this sort, like find_bit API in the following patches. So it looks helpful to generalize the macro and extend it's visibility. Signed-off-by: Yury Norov --- tools/include/asm-generic/bitsperlong.h | 2 ++ tools/include/linux/bitmap.h | 19 ++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/include/asm-generic/bitsperlong.h b/tools/include/asm-generic/bitsperlong.h index 8f2283052333..432d272baf27 100644 --- a/tools/include/asm-generic/bitsperlong.h +++ b/tools/include/asm-generic/bitsperlong.h @@ -18,4 +18,6 @@ #define BITS_PER_LONG_LONG 64 #endif +#define SMALL_CONST(n) (__builtin_constant_p(n) && (unsigned long)(n) < BITS_PER_LONG) + #endif /* __ASM_GENERIC_BITS_PER_LONG */ diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index b6e8430c8bc9..fdc0b64bbdbf 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h @@ -19,12 +19,9 @@ 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 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)) + if (SMALL_CONST(nbits - 1)) *dst = 0UL; else { int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); @@ -35,7 +32,7 @@ static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) { unsigned int nlongs = BITS_TO_LONGS(nbits); - if (!small_const_nbits(nbits)) { + if (!SMALL_CONST(nbits - 1)) { unsigned int len = (nlongs - 1) * sizeof(unsigned long); memset(dst, 0xff, len); } @@ -44,7 +41,7 @@ static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) static inline int bitmap_empty(const unsigned long *src, unsigned nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return !(*src & BITS_FIRST(nbits - 1)); return find_first_bit(src, nbits) == nbits; @@ -52,7 +49,7 @@ static inline int bitmap_empty(const unsigned long *src, unsigned nbits) static inline int bitmap_full(const unsigned long *src, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return !(~(*src) & BITS_FIRST(nbits - 1)); return find_first_zero_bit(src, nbits) == nbits; @@ -60,7 +57,7 @@ static inline int bitmap_full(const unsigned long *src, unsigned int nbits) static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return hweight_long(*src & BITS_FIRST(nbits - 1)); return __bitmap_weight(src, nbits); } @@ -68,7 +65,7 @@ static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) *dst = *src1 | *src2; else __bitmap_or(dst, src1, src2, nbits); @@ -146,7 +143,7 @@ size_t bitmap_scnprintf(unsigned long *bitmap, unsigned int nbits, static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return (*dst = *src1 & *src2 & BITS_FIRST(nbits - 1)) != 0; return __bitmap_and(dst, src1, src2, nbits); } @@ -162,7 +159,7 @@ static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, static inline int bitmap_equal(const unsigned long *src1, const unsigned long *src2, unsigned int nbits) { - if (small_const_nbits(nbits)) + if (SMALL_CONST(nbits - 1)) return !((*src1 ^ *src2) & BITS_FIRST(nbits - 1)); if (__builtin_constant_p(nbits & BITMAP_MEM_MASK) && IS_ALIGNED(nbits, BITMAP_MEM_ALIGNMENT)) From patchwork Thu Feb 18 04:05:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 9071AC433DB for ; Thu, 18 Feb 2021 04:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 478D064E4B for ; Thu, 18 Feb 2021 04:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230306AbhBREIQ (ORCPT ); Wed, 17 Feb 2021 23:08:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230336AbhBREG4 (ORCPT ); Wed, 17 Feb 2021 23:06:56 -0500 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C121AC06121D; Wed, 17 Feb 2021 20:05:25 -0800 (PST) Received: by mail-qv1-xf34.google.com with SMTP id 2so385549qvd.0; Wed, 17 Feb 2021 20:05:25 -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=12ov5Wc2VLYqBN6pji2I8kDJUvO1aq9EkiflVHQIASU=; b=gM1892Gp7EhVkJlC1YDQrEi+eVz/l3odoEPeC60+u3x0JmB7+bV23A9RxMC2b2Qa4n 2t9KQC2WEpA+40SQFez5eQycP5lpCkx+w6Fct1NfqkKWzPEANXdWiDoUvU0hBvS18i1/ Xdmn8EP/A9mrsSyldp1oB+3q8X7Xbq12KSIykPl7IcSNTKJvPdqzpbEyJrdD7U0fzbZC CvKuQ1mXZuMUGzFxEM3PKpiRtBYGsNNpUgp3ICRQ2QfyPxN+/yDVTrETekwD/rXSbBmq nDmTM+HCSpfbkOxzTdK/8a6CC0BJA8GEJ1+PrbiQPfPuktiUSULTAfdC8gb7DA3P+S6v G/Dw== 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=12ov5Wc2VLYqBN6pji2I8kDJUvO1aq9EkiflVHQIASU=; b=sgn+bRP5O0daGADuv9bFHVj4Al9D7BWzINiPsHbUQ5tm5llANbFW3gdJPTuXFcSah+ w2u6Bi4/1jtt6Toz6q3NXvemBx9f/xyulnoE22nMW6PhyXMkbMVkCleSbWp8uqFZwqhU uD0unuRA/bazJDIOvIK0kus0tQ9aH1mkklLOBxbgc6/ajMyi55A5pCm3cViqH/q2bEyJ 2tiRYTTdDJibvNi+Ncb7sRf1UmEGTJTvc+ibuJWfOJSYjueatRnWu9GvduBFbWD3VI90 DZd4S5XWPrybOjePbkStdbPdZDilTDHwNMEl95lhEI8DUdgwrNVyV7SGxAB4/rJ/JTPJ 01ig== X-Gm-Message-State: AOAM5320sfhLcoHaoIG3DoS/vZ7Qqf9VjyFpqi8ak7yVGGA6PmVdq+SH PIs2LCOY3Rr9paAWrHQb/90jp39PTbrFPA== X-Google-Smtp-Source: ABdhPJxrSRuP+gTwPyAKuBZNi9wigb9Ulmo6Vw2o4RPWDN6boR/FDUrfh2GsiQQ7m2PZ9eioTSr4zw== X-Received: by 2002:a0c:c345:: with SMTP id j5mr2423906qvi.13.1613621124700; Wed, 17 Feb 2021 20:05:24 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id u27sm3171707qku.82.2021.02.17.20.05.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:24 -0800 (PST) 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/14] lib/Kconfig: introduce FAST_PATH option Date: Wed, 17 Feb 2021 20:05:06 -0800 Message-Id: <20210218040512.709186-9-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org This series introduces fast paths for find_bit() routines. It is beneficial for typical systems, but those who limited in I-cache may be concerned about increasing the .text size of the Image. To address this concern, one can disable FAST_PATH option in the config and some save memory. The effect of this option on my arm64 next-20210217 build is: Before: Sections: Idx Name Size VMA LMA File off Algn 0 .head.text 00010000 ffff800010000000 ffff800010000000 00010000 2**16 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .text 0115e3a8 ffff800010010000 ffff800010010000 00020000 2**16 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .got.plt 00000018 ffff80001116e3a8 ffff80001116e3a8 0117e3a8 2**3 CONTENTS, ALLOC, LOAD, DATA 3 .rodata 007a72ca ffff800011170000 ffff800011170000 01180000 2**12 CONTENTS, ALLOC, LOAD, DATA ... After: Sections: Idx Name Size VMA LMA File off Algn 0 .head.text 00010000 ffff800010000000 ffff800010000000 00010000 2**16 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .text 011623a8 ffff800010010000 ffff800010010000 00020000 2**16 CONTENTS, ALLOC, LOAD, READONLY, CODE 2 .got.plt 00000018 ffff8000111723a8 ffff8000111723a8 011823a8 2**3 CONTENTS, ALLOC, LOAD, DATA 3 .rodata 007a772a ffff800011180000 ffff800011180000 01190000 2**12 CONTENTS, ALLOC, LOAD, DATA ... Notice that this is the cumulive effect on already existing fast paths controlled by SMALL_CONST() together with ones added by this series. Signed-off-by: Yury Norov --- include/asm-generic/bitsperlong.h | 4 ++++ lib/Kconfig | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/include/asm-generic/bitsperlong.h b/include/asm-generic/bitsperlong.h index 0eeb77544f1d..209e531074c1 100644 --- a/include/asm-generic/bitsperlong.h +++ b/include/asm-generic/bitsperlong.h @@ -23,6 +23,10 @@ #define BITS_PER_LONG_LONG 64 #endif +#ifdef CONFIG_FAST_PATH #define SMALL_CONST(n) (__builtin_constant_p(n) && (unsigned long)(n) < BITS_PER_LONG) +#else +#define SMALL_CONST(n) (0) +#endif #endif /* __ASM_GENERIC_BITS_PER_LONG */ diff --git a/lib/Kconfig b/lib/Kconfig index a38cc61256f1..7a1b9c8d2a32 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -39,6 +39,13 @@ config PACKING When in doubt, say N. +config FAST_PATH + bool "Enable fast path code generation" + default y + help + This option enables fast path optimization with the cost of increasing + the text section. + config BITREVERSE tristate From patchwork Thu Feb 18 04:05:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 9CAE4C4332D for ; Thu, 18 Feb 2021 04:08:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B81E64E28 for ; Thu, 18 Feb 2021 04:08:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbhBREI0 (ORCPT ); Wed, 17 Feb 2021 23:08:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbhBREG6 (ORCPT ); Wed, 17 Feb 2021 23:06:58 -0500 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDCC9C06121F; Wed, 17 Feb 2021 20:05:26 -0800 (PST) Received: by mail-qk1-x735.google.com with SMTP id v206so979133qkb.3; Wed, 17 Feb 2021 20:05:26 -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=HmPBP/xYFM2V4M5yRdhQkDM4FUGg/XThal+e+GFUzBk=; b=GiUpYytEN9GxwWe2Xq34GASeeJ5UvGfZWYN4nO5fcZvOYZPN0WIdauU8kQvU5aqCom jkXm2SCpfItKTfJy4+GJI5o+jQ5sNdOZCS/TIHlXnHvhivxCXlZoScAW2GuZ3g/L33KS vDn8EHTuetOHsbGaXh4V7fWkQIhz933CDGCEml8oQi9bylQKGbXaAqPw4LdxY6/0uJzw juyhn6pRpbqn9qLshtStkJXHwkrB6lTcfKIZJnnXkdGfcf6SQQfyHGOQF8/n+LsyTIzr OVjRzw7YjsbKBDdyX8qnPkGLW8qxLTgT4W9UGcgv18Kj1ZbJfYSMVOoB2dNz2tHqNr6N xBwQ== 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=HmPBP/xYFM2V4M5yRdhQkDM4FUGg/XThal+e+GFUzBk=; b=VOSbl0ZKLUQBFgCoSNm30en7oo0If2uesu2unfTIN/OBDpyo5c9fRhFt9l14a99TAi +qRPy+JvKzoUETCcGWEDPeT2PTiR6v6sUXPFlmvRWsd0dNyvc5DazGj4PCmCzWHwkrrg 64AE+N01wjdrrorkTkBbnS93zt9bVcUPko606EVLsv4tmwnYfj/JDeBm+Bweaca16usG 8c7NjSYXRjo3vvaaFQxZIe2PFN7C9+VVUUIM2NIwk1964UkSg1p0+0oOI1JPqX2CSm77 VgaSGa5/mEtXX2bOSm3Pv3CJPC/BNgr3ts/lr1tMws1ki4hz8pqwVKPw6FvqkuVREOBy 0S1g== X-Gm-Message-State: AOAM533nHUpYisLMwwFtho2tSy5k2WsCt2eu38WqLHWHi7SU1ZrsLMxy jcTFNyS8tTXGcuiPW7PUjWTHzTU/JT2hYQ== X-Google-Smtp-Source: ABdhPJxLd23qyCOn0PqBQ4+mkx5ZlWBk7ksEhnS/nxWAPtukfRMO3gp2sVT5/luuHBVP8Ds1DV5KLA== X-Received: by 2002:a05:620a:a4f:: with SMTP id j15mr2416698qka.419.1613621125795; Wed, 17 Feb 2021 20:05:25 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id h12sm3160746qko.29.2021.02.17.20.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:25 -0800 (PST) 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/14] lib: inline _find_next_bit() wrappers Date: Wed, 17 Feb 2021 20:05:07 -0800 Message-Id: <20210218040512.709186-10-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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 8c2a71a18793..2470ae390f3c 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 Feb 18 04:05:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 A8423C433DB for ; Thu, 18 Feb 2021 04:08:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FCE964E28 for ; Thu, 18 Feb 2021 04:08:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230508AbhBREIe (ORCPT ); Wed, 17 Feb 2021 23:08:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbhBREG6 (ORCPT ); Wed, 17 Feb 2021 23:06:58 -0500 Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAE2DC061222; Wed, 17 Feb 2021 20:05:27 -0800 (PST) Received: by mail-qv1-xf32.google.com with SMTP id e9so378083qvy.3; Wed, 17 Feb 2021 20:05:27 -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=bofFnMxTFz4PBXj6o6dHzaDYYxjiUjTajgeVigTmpD4=; b=NBJIBaXSDFVyI+C/svM/xqIgmxHPmZjZE1aKuUDMzOjji2K7OK5Vgxo+AgJRd/q9QR eAMBE+hmw47PMW/X5TLZKgicL2HtGfqzClbD0sRg3/j5/qe1TbSiO+VncIfZPWUR33P0 D23nQ0dkoR9oNDV8HsCw/agrGbn1qcENzbjzoCwZ4Gn4oybky4nNVxhDKbo4UZLSd0M8 zO1mOq99CdE9jJuPucbqkh/v0g5I9IdCTSi5WCNfXE8F/CdKz/sLsTnDw9NBIs1gWC7A 1Z2BYXFc3592T2I2SV5wR8GRvfgAu9eVJpxTcat0WAvAW4/P8P9fHq6MSZELcHDJ/g6H yRcQ== 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=bofFnMxTFz4PBXj6o6dHzaDYYxjiUjTajgeVigTmpD4=; b=MRt89EdlWA/5GVJu0PaRWUjjxgT6kLrWOmZMK47fEmG8chM8s2mK7MimfTD5PigEig QdayzkekebiXQy28Yw7hfOTJhLsFcpHL+zS17hiHiKQ+WTz0Z43ueo9Pdab8yGaAbACj E2eiDuK+Wda0TbeIc+c4wQfRjbk1rgKG9KUrYrL2zy3EXRUuRg8ztRLikvbJRMu5sqe0 JEgTZPkTeLLqZ1ZqONRRacofZ3JrXjIWiH9XHiDPPCFn5ltHtwSTRz3onRltTwgWzhfs m41nC7iuzEjepmKcK6eZVzQyE5WHxkyc8jkXJdlpSf8EcP0rC7bG5eNoePpx2TV9R2Z1 7fYQ== X-Gm-Message-State: AOAM533HW7EThXqKV+FCbqP4npaBZUhnkfkdl6I++n3nFLqePliZqPKV BFkO1UHzwSdmaADXOBsTFg1eWgq+ZPJUGw== X-Google-Smtp-Source: ABdhPJz2h7fTU4jSBiWg2IFpY7ylm7t0yR2zxr/gMwBXIGzUQNTqUKFIVSvhtge7rHDrt+RcnWY74g== X-Received: by 2002:a0c:e38c:: with SMTP id a12mr2596030qvl.38.1613621126777; Wed, 17 Feb 2021 20:05:26 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id n4sm2762840qtl.77.2021.02.17.20.05.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:26 -0800 (PST) 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/14] tools: sync find_next_bit implementation Date: Wed, 17 Feb 2021 20:05:08 -0800 Message-Id: <20210218040512.709186-11-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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 49abb18549cc..c3378b291205 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 &= BITS_LAST_MASK(start); + mask = BITS_LAST_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 Thu Feb 18 04:05:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 C9BC9C433E0 for ; Thu, 18 Feb 2021 04:08:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85C1B64E7A for ; Thu, 18 Feb 2021 04:08:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230510AbhBREIi (ORCPT ); Wed, 17 Feb 2021 23:08:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbhBREHF (ORCPT ); Wed, 17 Feb 2021 23:07:05 -0500 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D99E3C061224; Wed, 17 Feb 2021 20:05:28 -0800 (PST) Received: by mail-qk1-x736.google.com with SMTP id x14so992121qkm.2; Wed, 17 Feb 2021 20:05:28 -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=p/4S7LKqScJemznNw5zpAMo2LpQEMVSK1lx74u88L8E=; b=GYd46QJ+oJ/OGZaSr9nWwEUqzlbyRm/1o84ManClVrZwd4tv9PeTdMv8IQ5G1Z207z /oK0EkR88dgK67Pr3qCcpjUvAJgnOV3ouLgJaRaxXKIrmGyEy70rZkoiN6/YKWXUq3jO oQ9lFz2b80eQxsI07WYG/py9Bq+dqmAJnH46dJqGUlFRWs5oY9g3vgNR396xDpPNtk33 L5nu+Rs6iCubHXvcioXMj7D737P+EVZkD2F9xSJIpb/Rx9HCLix2IzR4EiWXVWwuedDm mWpJEeHfTDuB7Rdd09ZQxJWUVYLaATLiLw6+BcTp6TQrlauoV2ZRiQ7O5qEZuRkIcz4b /qGw== 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=p/4S7LKqScJemznNw5zpAMo2LpQEMVSK1lx74u88L8E=; b=Ttgjo5nE6pu/reEAf42qKl7V+vn5tpTmKK3CA1m3FDz1n9ceDBZCZ8+EYpbYKVDAiS RdcKvvi2dQ+onf9NrOgxP1Rzyf5MgH3pZ7dUxgE8i0kAiC/mD+S0WR8INGVlOWWKMfto J1YXcgSwF38/O3TzFkcXc5PMVYnORVnAX/k+u15sDQDsoScW5QoITO8u07XBxhr9P3DT ajvLp/aUKVLr+Aiiw1gpe4pQMv1PcteQF9Sba9hGlbqQiJTsf0ay6bdwsHp4HgZQCG2O IqbwiqgTKi7aIf7qOLWv2pjZbPu0Ff+pxThXpH9F6MFsjGaNBNPcsWTEzBMmxoAMQl7M 32pg== X-Gm-Message-State: AOAM531xLitWqWKntys3Wm1JzzS4RGWVT0na6DUtTIIbjbfgBfgvCcT2 YEb8Nq0587hJeyoY4EQRFDozIc3V3TmxWw== X-Google-Smtp-Source: ABdhPJwqLW9dD0u6WaV4WJMbZta3+pAWwUzqVQnTlK1xeZU70MAuaFTwanHg5zK34akToJSnUpB8WA== X-Received: by 2002:a37:4ecd:: with SMTP id c196mr2513316qkb.264.1613621127718; Wed, 17 Feb 2021 20:05:27 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id t19sm3230755qke.109.2021.02.17.20.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:27 -0800 (PST) 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/14] lib: add fast path for find_next_*_bit() Date: Wed, 17 Feb 2021 20:05:09 -0800 Message-Id: <20210218040512.709186-12-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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 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); On ARM64 if CONFIG_FAST_PATH is disabled it generates: 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 If CONFIG_FAST_PATH is enabled: 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. (And I suspect we can improve the GENMASK() for better code generation.) find_next_bit() itself is 41 instructions. 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..8bd7a33a889d 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(size - 1)) { + 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(size - 1)) { + 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(size - 1)) { + 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..18ebcf639d7f 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(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(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 Thu Feb 18 04:05:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 B7EB3C433E0 for ; Thu, 18 Feb 2021 04:09:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6BFBB6023B for ; Thu, 18 Feb 2021 04:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231135AbhBREJM (ORCPT ); Wed, 17 Feb 2021 23:09:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbhBREHa (ORCPT ); Wed, 17 Feb 2021 23:07:30 -0500 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 11260C061226; Wed, 17 Feb 2021 20:05:30 -0800 (PST) Received: by mail-qk1-x734.google.com with SMTP id t62so954818qke.7; Wed, 17 Feb 2021 20:05:30 -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=auV1FihgL+Hhe6KeCKrfxhfgLAMurMRXz5BY3NK/J34=; b=aTN8lBtMBfgtXr1E5UkK1ODJRv0vE/TNJGnP/PvBflL29hUH8Z6lg/2JkNiP62uxC7 JYRNq3ljbtFtYm2puoe4qidur9uf8FPGXl1EVnYkhVV+xLQYJJTsGp0vsnUxB8HbydCu MfHYa0+9dUmIV/Tf9fuDKu7dAsKv+8/ymRi+E+4lSJ+MwCj9vS6D4OmWG2QmnPmlQfHH dUHWtF2/qsU+uUafErQTFLj8iz2DgwgCzKHOmVv7C3mO7d4yl+TAFfiIAvbbFlHHMkVy RKojnHHs++zXLrCHrwoSvLus0MduZgIydlQYc/8jDNyk2yqX3LsEK36YRhkpwx0N0lRN aTbA== 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=auV1FihgL+Hhe6KeCKrfxhfgLAMurMRXz5BY3NK/J34=; b=a2JljKqCN7ZMpJpoxKDuCWDLocjz6V82H5bmOjRaWoF3l5122tB8XnAVIWgunmt51e BJLbJ7woCHG1OX4d3AmAoyn/SmthkEYwVEsPJg6JEuw3cghISu123JKb58KN7s6vkQU7 9ncsw2r06RWID0wMduHpqWC0zAEBWX1P8RAL3bkhZVxZ/O5qaWBGk99aVyI+8To6Yjwl lOHGw9WWcQMiFNhoT0/MMYASR6E37gglgfVNAWmYyMxf5QWoSfymvRCWKKE1ERPLwkDa yR/D/HJj0XzdmEJGjOOMUSgA/8bzdgW0EIAGDD50WEk7M7Q3NSfga8cSW1ETlaNrV1T1 mTaQ== X-Gm-Message-State: AOAM531EJvtqxe2dyu2njXlDRaf2mV5ymPVlyQpQ+6/Zo11LF+Nd6l12 x+6UNy+Kkdv15gSHBW8+dFiRUmBSlFuyiw== X-Google-Smtp-Source: ABdhPJylLFSAFCKQxD+ogvR0tRAyrg0nQlTyagQmOXjvcxoWOP3VHx9Swx8Wtz/fn9p2rbli9lTCcQ== X-Received: by 2002:a37:445:: with SMTP id 66mr2535679qke.345.1613621128947; Wed, 17 Feb 2021 20:05:28 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id o3sm3048179qke.132.2021.02.17.20.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:28 -0800 (PST) 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/14] lib: add fast path for find_first_*_bit() and find_last_bit() Date: Wed, 17 Feb 2021 20:05:10 -0800 Message-Id: <20210218040512.709186-13-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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 8bd7a33a889d..3633a37cec38 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(size - 1)) { + unsigned long val = *addr & BITS_FIRST(size - 1); + + 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(size - 1)) { + unsigned long val = *addr | ~BITS_FIRST(size - 1); + + 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(size - 1)) { + unsigned long val = *addr & BITS_FIRST(size - 1); + + 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 2470ae390f3c..e2c301d28568 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 = BITS_FIRST_MASK(size - 1); @@ -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 Thu Feb 18 04:05:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 ED375C433E6 for ; Thu, 18 Feb 2021 04:09:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A66FB64E76 for ; Thu, 18 Feb 2021 04:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbhBREIo (ORCPT ); Wed, 17 Feb 2021 23:08:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230095AbhBREHG (ORCPT ); Wed, 17 Feb 2021 23:07:06 -0500 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B55EC0611C1; Wed, 17 Feb 2021 20:05:31 -0800 (PST) Received: by mail-qv1-xf2f.google.com with SMTP id a1so347992qvd.13; Wed, 17 Feb 2021 20:05:31 -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=8wdFX9EW7ZSKDkfndJw3oSm6afvNog5P4ZYr8XpMLSA=; b=sTbbYPvfLf4cjPEXv6PIqMQqe/CsiDOdGZs5j+rg1s56RFyl+LCWx7sbg66yKBxX+Y 6ImgifZRxTEUI81XsSv18TlR2ouioDLstJRQUnFaUzwTGRDSkxslz0e6ckoqZl32EOc1 l7zAxVmKSEArvlYzPZjgMUV8q+rp4MwLhTiDygyASMsyw0RTWTSUV3Bp5dMo5t60p2GW qU51fMuGF4rYzgT8XuGdIJmCbCTSQ8N6c45FsBMooVv/b1vyovUJ/lVGarSDfHEwTAE2 hGDjcxdFpjp8v196FkPSB19DjGNe3dTnqeXzfH+bIJlkmHSQ9MmzS7suP72rhjB4nIxB Q97Q== 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=8wdFX9EW7ZSKDkfndJw3oSm6afvNog5P4ZYr8XpMLSA=; b=eV40MRhO39Gs+EXrXD/ax7HUc7gLbwey9bnjqJs/3ttx8WL/IHhaiaZWqAdCEQHJRA dEjVqXZhhK//mZNuvsSO+SE1yoU5gkuUlEkIxUgb5Ro9zpwvvNj5P3Z+50Dj45OanjMo iyq7JXuYA9I0U3k2vdC+I4N9wk3hYkxu0Y4ItAil7wihAg/SCjtdXR/xD/JHqlA1sW34 eIPnFsuHHc3e/oDzsu8E9EtEpSwvWQuJmwAw2obSHxCCIXQVfsSEJI5DS8av97qSrczv FbH6amgJb6WG/3vQ4eW+3GxkB7G2ouCPZFiKjvsKQZsyxKjTS5DKz/ebzI07sB60tUU8 3gGw== X-Gm-Message-State: AOAM530GWvjTTzB+1xTVuoLfhlzuONpEgrQUv6X+N+pfQSOkxAg405XK r5s/xFwjRo4P3nHUy8ZrvFfeudcJ1ZZFOw== X-Google-Smtp-Source: ABdhPJzJ8gZQ59fVjoYHAMW8DbKl62bBXcmMfhZ/uXUFBcsHKBFXqxqYSJL8PiO2/hoUwx8ib1FdzQ== X-Received: by 2002:a05:6214:d6d:: with SMTP id 13mr2663718qvs.60.1613621129975; Wed, 17 Feb 2021 20:05:29 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id b137sm3332443qkg.51.2021.02.17.20.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:29 -0800 (PST) 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 13/14] tools: sync lib/find_bit implementation Date: Wed, 17 Feb 2021 20:05:11 -0800 Message-Id: <20210218040512.709186-14-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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..382cd80c61aa 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(size - 1)) { + 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(size - 1)) { + 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(size - 1)) { + 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(size - 1)) { + unsigned long val = *addr & BITS_FIRST(size - 1); + + 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(size - 1)) { + unsigned long val = *addr | ~BITS_FIRST(size - 1); + + 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 c3378b291205..a77884ca30ec 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 Thu Feb 18 04:05:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12093031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=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 BFCAFC433E0 for ; Thu, 18 Feb 2021 04:09:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9845F64E28 for ; Thu, 18 Feb 2021 04:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbhBREJY (ORCPT ); Wed, 17 Feb 2021 23:09:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbhBREHG (ORCPT ); Wed, 17 Feb 2021 23:07:06 -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 39421C0611C3; Wed, 17 Feb 2021 20:05:32 -0800 (PST) Received: by mail-qt1-x835.google.com with SMTP id f17so525096qth.7; Wed, 17 Feb 2021 20:05:32 -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=84gBY6rinb7deZXraCF0UsTbJivw5Olo0gL8/eJ63tU=; b=KxfSS6niVzijRzEtdP/DC9eQUkwlu1PvxSxEgcuFub2GuTOz4WaJzl7H/fCoy3S4+a eY4RldJTLxIdrBcLG0vRW7OXyBIjEZFa7saILAydNPEBgUNEHizOdS7B/TEiEx0rbstR rev03iKVpZhbH2hPkQYiQIqUWyIcgRFiVWM1RG12hesTBatJevDd7loVlToiG+B1atGS rGcBdPLVhqF6B8ANXWe6OR4SLeGgwF4iP707XgAkmtbFwUetmpHypCVFnhwUR5kfALT5 tlH5Sd+YLHI0F27k+7ecClMw1Obo98OnA0M042LYX8TCbWfoaLW7/YKRMUA+KYUrLYwI MPnQ== 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=84gBY6rinb7deZXraCF0UsTbJivw5Olo0gL8/eJ63tU=; b=Wc8ZQJ0jPvOcl+LG0wzPl4ISJmS6kNHMtELuDmslnDuDzhK0ptsp5NEb/8fs1td6xN YfRTg2TnrtVgOdhd1VOZBSvwgHI4t6mUh3zIpddiAUqfCbaZuLZopBVA5kw2dFzvqvQ6 XrMb/gZ13i15ABOT61fGqgIFXGQ97BT+SIU81U8a/0wMaPcKjnM73wn8nZ73dHZrwKTI 0wahFeM94f0XCmSTCJBlvxCxvQhwskhxBXVNc7xGyZmUFlg26vA1Ltc9rVYl8QvkmdbX UCS1pq0rgXJ3VHkTcU0w6c0eVJV07fsASeRXDwqTabkQsXbtci8PRgudltgr2kSx41Hh dfkg== X-Gm-Message-State: AOAM531by5KdfynW+pi0UFePdp8Hb5qVH1GH1UU2vghBBpBjs4vkRBX4 bpNYXaRDsbXU/ODuUm6Be7v01vpI2RCHhg== X-Google-Smtp-Source: ABdhPJwZifiZxE3P8q/lcvCbxJp+cC2M2zwuZmUjKMFL5WEt9kpRarYcAFb6PR4VznGQdSPl6yydfw== X-Received: by 2002:ac8:5d44:: with SMTP id g4mr2660798qtx.93.1613621131027; Wed, 17 Feb 2021 20:05:31 -0800 (PST) Received: from localhost (d27-96-190-162.evv.wideopenwest.com. [96.27.162.190]) by smtp.gmail.com with ESMTPSA id b20sm2748495qto.45.2021.02.17.20.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 20:05:30 -0800 (PST) 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 14/14] MAINTAINERS: Add entry for the bitmap API Date: Wed, 17 Feb 2021 20:05:12 -0800 Message-Id: <20210218040512.709186-15-yury.norov@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210218040512.709186-1-yury.norov@gmail.com> References: <20210218040512.709186-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. I'm an author of current implementation of lib/find_bit and an active contributor to lib/bitmap. It was spotted that there's no maintainer for bitmap API. I'm willing to maintain it. Signed-off-by: Yury Norov Acked-by: Andy Shevchenko --- MAINTAINERS | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 7bdf12d3e0a8..9f8540a9dabf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3146,6 +3146,20 @@ F: Documentation/filesystems/bfs.rst F: fs/bfs/ F: include/uapi/linux/bfs_fs.h +BITMAP API +M: Yury Norov +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_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