Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp805832ybl; Thu, 12 Dec 2019 05:17:33 -0800 (PST) X-Google-Smtp-Source: APXvYqyJ5p8HPA3slvORkGbzoei8Ps+VHeloXLMLcG4dH9kzdmcuSfIwAYMN+vEfQl80BRcHf5Vi X-Received: by 2002:a9d:6f85:: with SMTP id h5mr8192788otq.19.1576156653833; Thu, 12 Dec 2019 05:17:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576156653; cv=none; d=google.com; s=arc-20160816; b=GyER30R9zhaxoCuUL+fVWPE4gOQEzYV49gYWM2np56w8eL+kW6Xd9/iiU7dNWS71SM mzY238O2WM5o+vFy7SOE/gXYnUuVeKOPxl7p8wrfz6RchvbSqbgpfUq2VcNn0mUlNzJy PW2/sStQM5jhh6pvs+DPpOEp9+W07m7XLaRDKt6ued+JVhwdpNT2LTg8GogbbYXhfDI0 Pz0NjjodRIGt9k0ebMCNG4YGGmUVmodhOKGZztWcDhWe2JGXI2ZEWxlGBK63sjeBXWSh bEoc/AJwp94sAg+0z0oUFtk3VD6ViOEz/po9EQwmRq7ob7QwuMH1G/5inSebbijBw7Aq kAjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:date:cc:to:from:subject:message-id; bh=SsxtEKcsEtwYYabRVbxfmW0Q2RjEMuczAsQjTOU2V08=; b=fIx5ZNie4j/uOTXIXYA+tbB+4cZoxg2nuFBzMF30lOmuayieb9PEk3qp3prZ71F3CR b+RF5A1udysQF1OPpnW5HcdBUMEHZn7aYnz3Uqu/6h+KF6eF23GX+8KjUhKkqVG7q0vv mbTer/4HSlqItY1tN3OKU4Lp8DSlCGC8g+yOh2AAvl5sqGUtMl19xwuK1WYK02WtXRiN n4Zh9aykjJ3owJ3tUfeug5Ls1Yv9tNulP5TVpm5NARyCOj/QhgsF+gtwuae+jD4b8/0k zPMoDmlRmrx+OYQ/nN/TLMxlUW9yUXfOTuzK5oFBiW2oBoRoHf8SkAHn3QSKffH1E7Zv cNig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8si2990096oto.259.2019.12.12.05.17.14; Thu, 12 Dec 2019 05:17:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729345AbfLLNQl (ORCPT + 99 others); Thu, 12 Dec 2019 08:16:41 -0500 Received: from mx2.suse.de ([195.135.220.15]:48780 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729338AbfLLNQl (ORCPT ); Thu, 12 Dec 2019 08:16:41 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9BC24AD07; Thu, 12 Dec 2019 13:16:36 +0000 (UTC) Message-ID: Subject: Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two() From: Nicolas Saenz Julienne To: Bjorn Helgaas Cc: andrew.murray@arm.com, maz@kernel.org, linux-kernel@vger.kernel.org, Michael Turquette , Stephen Boyd , Emilio =?ISO-8859-1?Q?L=F3pez?= , Maxime Ripard , Chen-Yu Tsai , Mike Marciniszyn , Dennis Dalessandro , Yishai Hadas , Moni Shoua , David Woodhouse , Lu Baolu , Joerg Roedel , Tom Lendacky , Mirko Lindner , Stephen Hemminger , Jiri Pirko , Solarflare linux maintainers , Edward Cree , Martin Habets , Eric Biederman , Thomas Graf , Herbert Xu , james.quinlan@broadcom.com, mbrugger@suse.com, f.fainelli@gmail.com, phil@raspberrypi.org, wahrenst@gmx.net, jeremy.linton@arm.com, linux-pci@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, Robin Murphy , Doug Ledford , Jason Gunthorpe , "David S. Miller" , Trond Myklebust , Anna Schumaker , "J. Bruce Fields" , Chuck Lever , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rdma@vger.kernel.org, iommu@lists.linux-foundation.org, netdev@vger.kernel.org, kexec@lists.infradead.org, linux-nfs@vger.kernel.org Date: Thu, 12 Dec 2019 14:16:27 +0100 In-Reply-To: <20191205223044.GA250573@google.com> References: <20191205223044.GA250573@google.com> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-vpJ9shRBsDfxzY4jD4N5" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org --=-vpJ9shRBsDfxzY4jD4N5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 2019-12-05 at 16:30 -0600, Bjorn Helgaas wrote: > You got the "n" on "down" in the subject, but still missing "of" ;) Yes, sorry about that, I tend to re-read what I meant to say instead of wha= t it's actually written. > On Tue, Dec 03, 2019 at 12:47:40PM +0100, Nicolas Saenz Julienne wrote: > > Some users need to make sure their rounding function accepts and return= s > > 64bit long variables regardless of the architecture. Sadly > > roundup/rounddown_pow_two() takes and returns unsigned longs. It turns > > out ilog2() already handles 32/64bit calculations properly, and being > > the building block to the round functions we can rework them as a > > wrapper around it. >=20 > Missing "of" in the function names here. > s/a wrapper/wrappers/ Noted > IIUC the point of this is that roundup_pow_of_two() returned > "unsigned long", which can be either 32 or 64 bits (worth pointing > out, I think), and many callers need something that returns > "unsigned long long" (always 64 bits). I'll update the commit message to be a more explicit. > It's a nice simplification to remove the "__" variants. Just as a > casual reader of this commit message, I'd like to know why we had both > the roundup and the __roundup versions in the first place, and why we > no longer need both. So, the commit that introduced it (312a0c170945b) meant to use the '__' var= iant as a helper, but, due to the fact this is a header file, some found it and = made use of it. I went over some if the commits introducing '__' usages and none= of them seem to acknowledge its use as opposed to the macro version. I think i= t's fair to say it's a case of cargo-culting. > > -#define roundup_pow_of_two(n) \ > > -( \ > > - __builtin_constant_p(n) ? ( \ > > - (n =3D=3D 1) ? 1 : \ > > - (1UL << (ilog2((n) - 1) + 1)) \ > > - ) : \ > > - __roundup_pow_of_two(n) \ > > - ) > > +#define roundup_pow_of_two(n) \ > > +( \ > > + (__builtin_constant_p(n) && ((n) =3D=3D 1)) ? \ > > + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ > > +) >=20 > Should the resulting type of this expression always be a ULL, even > when n=3D=3D1, i.e., should it be this? >=20 > 1ULL : (1ULL << (ilog2((n) - 1) + 1)) \ >=20 > Or maybe there's no case where that makes a difference? It should be 1ULL on either case. Regards, Nicolas --=-vpJ9shRBsDfxzY4jD4N5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEErOkkGDHCg2EbPcGjlfZmHno8x/4FAl3yPasACgkQlfZmHno8 x/4qrgf9GTaIX4ZRG0TCYwOuyJCzR/7cg3GMSsuHo8bknRFfBKmZUwtS0JmNNrn7 f1Av7IZ0OAbAWPJQkzOXw4OxNhVxq0ItdXAktetVKaF6U5Dz/5tWkkwHLFdhSepV FcS4qxWo8nOugcgYRzN6kDaihMFUqbAIioU7n1HGLRGN2s9vaJM1rNmOrGMPovU3 BbGTs4/7BMM3FmqoGwWUKX5FPFNamYrxAaaOknMUVa16iI7MN7hYH5scWUUK56ER 57y4jC6vGu17Cku4HBlynsoZpm6z6SvHDoXIMZCbUKbJogsiQo+b1+cZTWLVGi2P qQGX/jHjIhYWNVa2Le9F3qgxxmf0uA== =hg1F -----END PGP SIGNATURE----- --=-vpJ9shRBsDfxzY4jD4N5--