Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4212075pxf; Tue, 16 Mar 2021 08:09:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0mMafPU3hO5OdKeuDbYuZ4j0MOhG3HEpmaWQGQY8w63LT53iNm1iXNMLX6mClwcsN08BW X-Received: by 2002:a17:906:b159:: with SMTP id bt25mr29884791ejb.364.1615907393115; Tue, 16 Mar 2021 08:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615907393; cv=none; d=google.com; s=arc-20160816; b=RLe2rP5JZBa3YQl+tVsNKGTvd92XhWI6Q854AjLvthrfdcpW2IxIU6hbukrtiCz8lz fnexC707OhFXBz/nXAMy+6O1xlTBi02hX7QcqjzdozHHngrpY6fpHwNKD92OB02XPZlH cS9b5KprReq0r/rAOYc7HCT8TRSUKTavQMFJbMgV+VgMjs1ZA8ZZE0cfTn45fEfPOyrE YRBuL19PHSrutZKbMpO2/yqfDuwc4KiGEsh2uKfYB0XGyn1VK7zB6jyZC08NQ4kWAARU CuSK5JdWMKl8js1L0Lw9HMhFK+7JsYm6DsjpJgSA0jpDOacKw9dAILoxSUOtovfxI/qa hXOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=CjLHqcRLXQ6dUznEJBtg7nu1kYjN9GGJK8Vh/4Q1wzA=; b=YXLgWYlWnC0x1VJjUHyqnanTYDJattmOeTpuqcDyOg4L626OIwt3xP+iPW724qfg5A HAclB/z+f7J+G8RBs3T6XAMST6dXBjTL23ftePkebdnBbpNArfrdWSLZWSZP5Ov4qu5+ kXLgv5A6eIfPm96P91tekx0rbl++s5Gvz8rYiJRXJvsMIKixHKafE8lKJVdcj8qZpDuk jR9EcjGIn7OJWx8ff/8vL3eVbN2+LUcNRvW2WxHejLhHDwPpSxe7Kex03eOL4XT6VZ+v m+ng5XVDiRxFxW2e9yho/gGAfkvrNuOtUVAzZgN4sBvMsKNAQTRmmNxPftIuT5Y+XQqT I/cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=OEJpKcLP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i25si13767804ejv.640.2021.03.16.08.09.30; Tue, 16 Mar 2021 08:09:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=OEJpKcLP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235025AbhCPIf7 (ORCPT + 99 others); Tue, 16 Mar 2021 04:35:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235056AbhCPIfj (ORCPT ); Tue, 16 Mar 2021 04:35:39 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96B11C061762 for ; Tue, 16 Mar 2021 01:35:38 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id mj10so70712466ejb.5 for ; Tue, 16 Mar 2021 01:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=CjLHqcRLXQ6dUznEJBtg7nu1kYjN9GGJK8Vh/4Q1wzA=; b=OEJpKcLPxwWKVbTLwSSr7+MNyb9zdWFY/fF18jofgn4mxQMADe2HQsPAkkHa86yGnc y41M7m8CU7Ge6P42bbOxRSyGne/uCklsiZ23yXnW+6QiZlZBOkJLJ8VK+WNVDDC1JJYd slfwgL6ElRonbWkeqSvLi8yBukPzwNQ35X5iU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=CjLHqcRLXQ6dUznEJBtg7nu1kYjN9GGJK8Vh/4Q1wzA=; b=D/Y0S6EZz66HFVHD8mTC7aGk6d/2kJTixiZ6aeXbSOYtfGfm4h4svf4PDOokEvjkGj f4yyT+O0W6y6UC4cTyOIKyQICT2F62z1Z2ErLzuTqCa1htf1ODlb0HBVshNjg1hug2GD 5oloMMIhBBMk/Gm/InLUHJzm1B9QripYF+TT3hzBaldEBRxw+n8ikRRuhJyBr0Q8lo2P S2GvD8B+NtSbLgG7eLKG8mUycMVdtShBHT+NnXg8XSQ0hyzNyLpGrFZQSaAv0CBHdwr1 JrD8xlud1Rm5j1o9CKHBQcwAJURfnlA7Ly0LnvV+AnV7+APvYde/SP2MWJiUW2Hvtd0P Vu7g== X-Gm-Message-State: AOAM5307da1SMZ1f+GrHfoA6SltfZZl0e3zRSaNev3GaM6XIpDjrNgxp miDCm0qjQy5KeuBmfPPOrILoPQ== X-Received: by 2002:a17:906:aada:: with SMTP id kt26mr27652274ejb.137.1615883737275; Tue, 16 Mar 2021 01:35:37 -0700 (PDT) Received: from [192.168.1.149] ([80.208.71.248]) by smtp.gmail.com with ESMTPSA id gj26sm8825176ejb.67.2021.03.16.01.35.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Mar 2021 01:35:36 -0700 (PDT) Subject: Re: [PATCH 04/13] lib: introduce BITS_{FIRST,LAST} macro To: Yury Norov , linux-kernel@vger.kernel.org Cc: 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 , Rich Felker , Stefano Brivio , Wei Yang , Wolfram Sang , Yoshinori Sato References: <20210316015424.1999082-1-yury.norov@gmail.com> <20210316015424.1999082-5-yury.norov@gmail.com> From: Rasmus Villemoes Message-ID: <8021faab-e592-9587-329b-817ae007b89a@rasmusvillemoes.dk> Date: Tue, 16 Mar 2021 09:35:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210316015424.1999082-5-yury.norov@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/03/2021 02.54, Yury Norov wrote: > BITMAP_{LAST,FIRST}_WORD_MASK() in linux/bitmap.h duplicates the > functionality of GENMASK(). The scope of BITMAP* macros is wider > than just bitmaps. 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. > > This change doesn't affect code generation. On ARM64: > scripts/bloat-o-meter vmlinux.before vmlinux > add/remove: 1/2 grow/shrink: 2/0 up/down: 17/-16 (1) > Function old new delta > ethtool_get_drvinfo 900 908 +8 > e843419@0cf2_0001309d_7f0 - 8 +8 > vermagic 48 49 +1 > e843419@0d45_000138bb_f68 8 - -8 > e843419@0cc9_00012bce_198c 8 - -8 [what on earth are those weird symbols?] > 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) I don't think it's a good idea to propagate the unusual closed-range semantics of GENMASK to those wrappers. Almost all C and kernel code uses the 'inclusive lower bound, exclusive upper bound', and I'd expect BITS_FIRST(5) to result in a word with five bits set, not six. So I think these changes as-is make the code much harder to read and understand. Regardless, please add some comments on the valid input ranges to the macros, whether that ends up being 0 <= nr < BITS_PER_LONG or 0 < nr <= BITS_PER_LONG or whatnot. It would also be much easier to review if you just redefined the BITMAP_LAST_WORD_MASK macros etc. in terms of these new things, so you wouldn't have to do a lot of mechanical changes at the same time as introducing the new ones - especially when those mechanical changes involve adding a "minus 1" everywhere. Rasmus