Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3983546pxf; Tue, 16 Mar 2021 02:47:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSJvsCnFoKFT5jWMv5tRfj8VJQjX0Y6BdWVU2HFsDEx0XXPlx4qz5t2Q4qwpxAZXXjPRhf X-Received: by 2002:aa7:d7da:: with SMTP id e26mr35411368eds.269.1615888076049; Tue, 16 Mar 2021 02:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615888076; cv=none; d=google.com; s=arc-20160816; b=BnD+5r3lOKuGSy4Mw2VcQ27E5hOTMg67BNF9jKJ0XknRIsmo7Hx4JE53EN01vqMQS7 QeWa2hz46PcA43SEsFv1Z4WqhuFpImO0jtSEia5iKKVKmSFmI28QV+IrI0BmTYJPwAa9 3PeIxNYI8gX/ivRCZRo/4Xbvw0JnyqTHupvd5eoV+ieO7vbNtyRqjdd+QqqtwcBaxmSv 8giSposVJ43WUO6Xb6aHOm7zyDq7pOFRnQOuVpZF2tDOGYJNp1dkg3G8r8njD509B9UF 8LYHBzIf9+iYWFfyNXxQI4+7+pp1h0/bVlOQvItjX0tBC/NcsAnYfx+y9/zCY8F3jKZa qyfQ== 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=Vr+DDhX4zCUcoDYqyVxp3WEAsa/2/5gUa+nZx6tBWmE=; b=iaM5T2egCkiS+qBwN8EF6HPzPICm1SppbfkxY70nK4WokaRpyuHNehV6LuYL2xWPXE 2r79myKkqEbNXQuFI4CtDO/reWgalo6d574T1/PdwgY9MjrQges233nKAsXUmpqjWcbX e5vNz4o4p5yHFPcoBj076b+Ts+U+oRcat1uHwIyZmBPnG7C+quV7ZDU9E1iLmpyD9G0y pkV8w4yK9iL5hNtumoABNaMq++srxIgP/sLQ7gzNcODiWIGfyn3+Tw9rOkORitPO1Rrv oPul/a0dgnw63pjBjRnwAS8fV210FH69XPaV62BHY69RdEdfcBwI6d3islySvvOt/rGL Ghbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=Nq34Egdh; 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 q14si13443056edw.414.2021.03.16.02.47.34; Tue, 16 Mar 2021 02:47:56 -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=Nq34Egdh; 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 S233039AbhCPI5X (ORCPT + 99 others); Tue, 16 Mar 2021 04:57:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230385AbhCPI4x (ORCPT ); Tue, 16 Mar 2021 04:56:53 -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 6DEB6C06174A for ; Tue, 16 Mar 2021 01:56:52 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id jt13so70847931ejb.0 for ; Tue, 16 Mar 2021 01:56:52 -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=Vr+DDhX4zCUcoDYqyVxp3WEAsa/2/5gUa+nZx6tBWmE=; b=Nq34Egdh9YX3VVX62IcMgmxwB/4u6FR0wjqNsrSRjEpOBYIu8LhRgW60T8wqxDOHZz gO2EaShHGJTkpCB6y6ajMK57915siiFZyV/1tRAsFH6VsfE+u1HGx2e2+zVumH98rY1D AHHRkwEXJZKMZjZVIContITRe4Bb8aCXYcHKU= 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=Vr+DDhX4zCUcoDYqyVxp3WEAsa/2/5gUa+nZx6tBWmE=; b=D1Qt3u1+bgxiEUVDulopcopfcJsFGM4nOUE7s0mUdoKeX4i555J99orWCP3TsfG2o8 ur34Krc/4WXvm/yODzfz4ZFLBkWnS99duaSziQzdIdWzBYasBNVbLO9qQ497SBHpXv5y N59zM47thnl0RS7/dCpdUJIQccXjEwYrDRyQf6JBom9wDV/9+a/RYom9lU5ZubR5fisH 8D0JnOsvQR1gmPNiPZ1bbubThkwYrSZuzGlu9QA4s9Zs7l55A7D6ftEK6P0MtvCHFSaz CU2aM3OHPxRQ6jP9125bdC6MJnMJjPGW8qRKaN/DmfwMymPaX8GCvzxBfhc9AO/VzTs4 lKOQ== X-Gm-Message-State: AOAM532ruCoyqk05gEIXN17BJqiVYyit+1yJKje+vDPUyKJefV04rH1C k02xkyqd4NChMTjOTh3auRUuxg== X-Received: by 2002:a17:907:628a:: with SMTP id nd10mr25564420ejc.326.1615885011190; Tue, 16 Mar 2021 01:56:51 -0700 (PDT) Received: from [192.168.1.149] ([80.208.71.248]) by smtp.gmail.com with ESMTPSA id q25sm5857563edt.51.2021.03.16.01.56.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Mar 2021 01:56:50 -0700 (PDT) Subject: Re: [PATCH 06/13] lib: extend the scope of small_const_nbits() 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-7-yury.norov@gmail.com> From: Rasmus Villemoes Message-ID: Date: Tue, 16 Mar 2021 09:56:49 +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-7-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: > find_bit would also benefit from small_const_nbits() optimizations. > > Signed-off-by: Yury Norov > --- > include/asm-generic/bitsperlong.h | 9 +++++++++ > include/linux/bitmap.h | 3 --- > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/include/asm-generic/bitsperlong.h b/include/asm-generic/bitsperlong.h > index 3905c1c93dc2..96032f4f908f 100644 > --- a/include/asm-generic/bitsperlong.h > +++ b/include/asm-generic/bitsperlong.h > @@ -23,4 +23,13 @@ > #define BITS_PER_LONG_LONG 64 > #endif > > +#define SMALL_CONST(n) (__builtin_constant_p(n) && (unsigned long)(n) < BITS_PER_LONG) > + > +/* > + * The valid number of bits for a bitmap to be small enough, or in other words, > + * fit into a single machine word is 1 to BITS_PER_LONG inclusively. 0 is not a > + * valid number for size, and most probably a sing of error. > + */ > +#define small_const_nbits(n) SMALL_CONST((n) - 1) > + I still don't see the point of introducing SMALL_CONST and still don't like the much-too-generic-name - especially since AFAICT you don't actually use it anywhere outside the definition of small_const_nbits()? > #endif /* __ASM_GENERIC_BITS_PER_LONG */ > diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h > index adf7bd9f0467..bc13a890ecc1 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. > */ You added another comment near its new definition, but the left-behind comment in bitmap.h is now somewhat confusing, no? I suggest expanding your new comment a bit so it's clear why we're interested in whether a bitmap is known at compile-time to consist of exactly one word: /* small_const_nbits(n) is true precisely when it is known at compile-time that BITMAP_SIZE(n) is 1, i.e. 1 <= n <= BITS_PER_LONG. This allows various bit/bitmap APIs to provide a fast inline implementation. Bitmaps of size 0 are very rare, and a compile-time-known-size 0 is most likely a sign of error. They will be handled correctly by the bit/bitmap APIs, but using the out-of-line functions, so that the inline implementations can unconditionally dereference the pointer(s). */ > -#define small_const_nbits(nbits) \ > - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0) > - > static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) > { > unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); > Rasmus