From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 E07B5C2D0C9 for ; Thu, 12 Dec 2019 13:16:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BAE0221655 for ; Thu, 12 Dec 2019 13:16:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729405AbfLLNQl (ORCPT ); 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-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@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-- From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 D1A92C43603 for ; Thu, 12 Dec 2019 13:16:46 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5D5721655 for ; Thu, 12 Dec 2019 13:16:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5D5721655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 7B261882E1; Thu, 12 Dec 2019 13:16:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fv5pmwCN1Qdn; Thu, 12 Dec 2019 13:16:44 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 7A3F1882C5; Thu, 12 Dec 2019 13:16:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5A911C1D81; Thu, 12 Dec 2019 13:16:44 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 03335C0881 for ; Thu, 12 Dec 2019 13:16:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id E54F58706F for ; Thu, 12 Dec 2019 13:16:41 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nFKH9Zt5Cn5n for ; Thu, 12 Dec 2019 13:16:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 973D68706E for ; Thu, 12 Dec 2019 13:16:40 +0000 (UTC) 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 Date: Thu, 12 Dec 2019 14:16:27 +0100 In-Reply-To: <20191205223044.GA250573@google.com> References: <20191205223044.GA250573@google.com> User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Cc: linux-pci@vger.kernel.org, Michael Turquette , "J. Bruce Fields" , linux-nfs@vger.kernel.org, Edward Cree , linux-clk@vger.kernel.org, f.fainelli@gmail.com, Herbert Xu , Emilio =?ISO-8859-1?Q?L=F3pez?= , maz@kernel.org, phil@raspberrypi.org, Doug Ledford , Jason Gunthorpe , Chen-Yu Tsai , Chuck Lever , Martin Habets , wahrenst@gmx.net, Tom Lendacky , Jiri Pirko , Solarflare linux maintainers , Maxime Ripard , linux-rpi-kernel@lists.infradead.org, Anna Schumaker , Trond Myklebust , linux-arm-kernel@lists.infradead.org, Mirko Lindner , Mike Marciniszyn , mbrugger@suse.com, Stephen Boyd , netdev@vger.kernel.org, Yishai Hadas , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, jeremy.linton@arm.com, "David S. Miller" , Stephen Hemminger , linux-rdma@vger.kernel.org, iommu@lists.linux-foundation.org, Moni Shoua , Eric Biederman , james.quinlan@broadcom.com, Thomas Graf , Robin Murphy , David Woodhouse , Dennis Dalessandro X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============3734289617452540184==" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" --===============3734289617452540184== Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-vpJ9shRBsDfxzY4jD4N5" --=-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-- --===============3734289617452540184== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu --===============3734289617452540184==-- From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 391A8C00454 for ; Thu, 12 Dec 2019 13:16:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB0DC21655 for ; Thu, 12 Dec 2019 13:16:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="q61HNPZk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB0DC21655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: MIME-Version:References:In-Reply-To:Date:To:From:Subject:Message-ID:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+VN9MEiLCK/sK2JkBFjqFE7XMKaNCYrFzRfk7YIFUfE=; b=q61HNPZk4ScVyrxova5g0691v CUDPOUv7Rma5oMaE/P3jadp/lREqOx+bzpJ+aMiZ5Zs9Rhnf8byWkBTAWI5KN0RB77WZh5i9IkoIG jjaHIMV/qjPZMVDti0Ye6YWYap6fp2uB8AJof108H/7D7Je0i1Pt1e1lvshK8jey3N4S4LWQGUAN/ yVznSM1m5cJ7vnr3R5XBvqXQd2BNe0BSCx/2zY/9wOPb+4C53YZWkct303/fnCI575s94LrLgx2oc 2EvhJZojFagcaDDwExf9Tn31TTSqBklyNUdNU3Y9uOa8qlIj3rhqvazJAvMYlA2//xk4du3TfqdP1 qF8hVo5fw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ifOKi-0004yt-On; Thu, 12 Dec 2019 13:16:44 +0000 Received: from mx2.suse.de ([195.135.220.15] helo=mx1.suse.de) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ifOKe-0004xJ-Lf; Thu, 12 Dec 2019 13:16:42 +0000 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 Date: Thu, 12 Dec 2019 14:16:27 +0100 In-Reply-To: <20191205223044.GA250573@google.com> References: <20191205223044.GA250573@google.com> User-Agent: Evolution 3.34.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191212_051640_995416_4EFB3C34 X-CRM114-Status: GOOD ( 17.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, Michael Turquette , "J. Bruce Fields" , linux-nfs@vger.kernel.org, Edward Cree , linux-clk@vger.kernel.org, f.fainelli@gmail.com, Herbert Xu , Emilio =?ISO-8859-1?Q?L=F3pez?= , maz@kernel.org, Joerg Roedel , phil@raspberrypi.org, Doug Ledford , Jason Gunthorpe , Chen-Yu Tsai , Chuck Lever , Martin Habets , wahrenst@gmx.net, Tom Lendacky , Jiri Pirko , Solarflare linux maintainers , Maxime Ripard , linux-rpi-kernel@lists.infradead.org, Anna Schumaker , Trond Myklebust , linux-arm-kernel@lists.infradead.org, Mirko Lindner , Mike Marciniszyn , mbrugger@suse.com, Stephen Boyd , netdev@vger.kernel.org, Yishai Hadas , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, jeremy.linton@arm.com, "David S. Miller" , Stephen Hemminger , linux-rdma@vger.kernel.org, iommu@lists.linux-foundation.org, Moni Shoua , Eric Biederman , james.quinlan@broadcom.com, Thomas Graf , andrew.murray@arm.com, Robin Murphy , David Woodhouse , Dennis Dalessandro , Lu Baolu Content-Type: multipart/mixed; boundary="===============7176417081273859226==" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org --===============7176417081273859226== Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-vpJ9shRBsDfxzY4jD4N5" --=-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-- --===============7176417081273859226== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel --===============7176417081273859226==-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Message-ID: Subject: Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two() From: Nicolas Saenz Julienne Date: Thu, 12 Dec 2019 14:16:27 +0100 In-Reply-To: <20191205223044.GA250573@google.com> References: <20191205223044.GA250573@google.com> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============1584875826772588478==" Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, Michael Turquette , "J. Bruce Fields" , linux-nfs@vger.kernel.org, Edward Cree , linux-clk@vger.kernel.org, f.fainelli@gmail.com, Herbert Xu , Emilio =?ISO-8859-1?Q?L=F3pez?= , maz@kernel.org, Joerg Roedel , phil@raspberrypi.org, Doug Ledford , Jason Gunthorpe , Chen-Yu Tsai , Chuck Lever , Martin Habets , wahrenst@gmx.net, Tom Lendacky , Jiri Pirko , Solarflare linux maintainers , Maxime Ripard , linux-rpi-kernel@lists.infradead.org, Anna Schumaker , Trond Myklebust , linux-arm-kernel@lists.infradead.org, Mirko Lindner , Mike Marciniszyn , mbrugger@suse.com, Stephen Boyd , netdev@vger.kernel.org, Yishai Hadas , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, jeremy.linton@arm.com, "David S. Miller" , Stephen Hemminger , linux-rdma@vger.kernel.org, iommu@lists.linux-foundation.org, Moni Shoua , Eric Biederman , james.quinlan@broadcom.com, Thomas Graf , andrew.murray@arm.com, Robin Murphy , David Woodhouse , Dennis Dalessandro , Lu Baolu --===============1584875826772588478== Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-vpJ9shRBsDfxzY4jD4N5" --=-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-- --===============1584875826772588478== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec --===============1584875826772588478==--