All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Leon Romanovsky <leon@kernel.org>,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: andrew.murray@arm.com, maz@kernel.org,
	linux-kernel@vger.kernel.org,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Hanjun Guo <guohanjun@huawei.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Tariq Toukan <tariqt@mellanox.com>,
	Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Shawn Lin <shawn.lin@rock-chips.com>,
	Heiko Stuebner <heiko@sntech.de>, Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	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,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
	devicetree@vger.kernel.org, linux-rockchip@lists.infradead.org,
	iommu@lists.linux-foundation.org
Subject: Re: [PATCH v3 1/7] linux/log2.h: Add roundup/rounddown_pow_two64() family of functions
Date: Wed, 27 Nov 2019 18:06:18 +0000	[thread overview]
Message-ID: <6e0b9079-9efd-2884-26d1-3db2d622079d@arm.com> (raw)
In-Reply-To: <20191126125137.GA10331@unreal>

On 26/11/2019 12:51 pm, Leon Romanovsky wrote:
> On Tue, Nov 26, 2019 at 10:19:39AM +0100, Nicolas Saenz Julienne wrote:
>> Some users need to make sure their rounding function accepts and returns
>> 64bit long variables regardless of the architecture. Sadly
>> roundup/rounddown_pow_two() takes and returns unsigned longs. Create a
>> new generic 64bit variant of the function and cleanup rougue custom
>> implementations.
> 
> Is it possible to create general roundup/rounddown_pow_two() which will
> work correctly for any type of variables, instead of creating special
> variant for every type?

In fact, that is sort of the case already - roundup_pow_of_two() itself 
wraps ilog2() such that the constant case *is* type-independent. And 
since ilog2() handles non-constant values anyway, might it be reasonable 
to just take the strongly-typed __roundup_pow_of_two() helper out of the 
loop as below?

Robin

----->8-----
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 83a4a3ca3e8a..e825f8a6e8b5 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -172,11 +172,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
   */
  #define roundup_pow_of_two(n)			\
  (						\
-	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 1 :			\
-		(1UL << (ilog2((n) - 1) + 1))	\
-				   ) :		\
-	__roundup_pow_of_two(n)			\
+	(__builtin_constant_p(n) && (n == 1)) ?	\
+	1 : (1UL << (ilog2((n) - 1) + 1))	\
   )

  /**

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Leon Romanovsky <leon@kernel.org>,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: andrew.murray@arm.com, maz@kernel.org,
	linux-kernel@vger.kernel.org,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Hanjun Guo <guohanjun@huawei.com>,
	Sudeep Holla <sudeep.holla@arm.com>,
	Tariq Toukan <tariqt@mellanox.com>,
	Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Shawn Lin <shawn.lin@rock-chips.com>,
	Heiko Stuebner <heiko@sntech.de>, Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	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,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH v3 1/7] linux/log2.h: Add roundup/rounddown_pow_two64() family of functions
Date: Wed, 27 Nov 2019 18:06:18 +0000	[thread overview]
Message-ID: <6e0b9079-9efd-2884-26d1-3db2d622079d@arm.com> (raw)
In-Reply-To: <20191126125137.GA10331@unreal>

On 26/11/2019 12:51 pm, Leon Romanovsky wrote:
> On Tue, Nov 26, 2019 at 10:19:39AM +0100, Nicolas Saenz Julienne wrote:
>> Some users need to make sure their rounding function accepts and returns
>> 64bit long variables regardless of the architecture. Sadly
>> roundup/rounddown_pow_two() takes and returns unsigned longs. Create a
>> new generic 64bit variant of the function and cleanup rougue custom
>> implementations.
> 
> Is it possible to create general roundup/rounddown_pow_two() which will
> work correctly for any type of variables, instead of creating special
> variant for every type?

In fact, that is sort of the case already - roundup_pow_of_two() itself 
wraps ilog2() such that the constant case *is* type-independent. And 
since ilog2() handles non-constant values anyway, might it be reasonable 
to just take the strongly-typed __roundup_pow_of_two() helper out of the 
loop as below?

Robin

----->8-----
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 83a4a3ca3e8a..e825f8a6e8b5 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -172,11 +172,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
   */
  #define roundup_pow_of_two(n)			\
  (						\
-	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 1 :			\
-		(1UL << (ilog2((n) - 1) + 1))	\
-				   ) :		\
-	__roundup_pow_of_two(n)			\
+	(__builtin_constant_p(n) && (n == 1)) ?	\
+	1 : (1UL << (ilog2((n) - 1) + 1))	\
   )

  /**

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Leon Romanovsky <leon@kernel.org>,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: Heiko Stuebner <heiko@sntech.de>,
	linux-pci@vger.kernel.org, Shawn Lin <shawn.lin@rock-chips.com>,
	Hanjun Guo <guohanjun@huawei.com>,
	Frank Rowand <frowand.list@gmail.com>,
	Christoph Hellwig <hch@lst.de>,
	f.fainelli@gmail.com, linux-rockchip@lists.infradead.org,
	linux-rdma@vger.kernel.org, maz@kernel.org, phil@raspberrypi.org,
	linux-acpi@vger.kernel.org, Len Brown <lenb@kernel.org>,
	devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-arm-kernel@lists.infradead.org, mbrugger@suse.com,
	netdev@vger.kernel.org, "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org, jeremy.linton@arm.com,
	iommu@lists.linux-foundation.org,
	Rob Herring <robh+dt@kernel.org>,
	wahrenst@gmx.net, james.quinlan@broadcom.com,
	Sudeep Holla <sudeep.holla@arm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Tariq Toukan <tariqt@mellanox.com>
Subject: Re: [PATCH v3 1/7] linux/log2.h: Add roundup/rounddown_pow_two64() family of functions
Date: Wed, 27 Nov 2019 18:06:18 +0000	[thread overview]
Message-ID: <6e0b9079-9efd-2884-26d1-3db2d622079d@arm.com> (raw)
In-Reply-To: <20191126125137.GA10331@unreal>

On 26/11/2019 12:51 pm, Leon Romanovsky wrote:
> On Tue, Nov 26, 2019 at 10:19:39AM +0100, Nicolas Saenz Julienne wrote:
>> Some users need to make sure their rounding function accepts and returns
>> 64bit long variables regardless of the architecture. Sadly
>> roundup/rounddown_pow_two() takes and returns unsigned longs. Create a
>> new generic 64bit variant of the function and cleanup rougue custom
>> implementations.
> 
> Is it possible to create general roundup/rounddown_pow_two() which will
> work correctly for any type of variables, instead of creating special
> variant for every type?

In fact, that is sort of the case already - roundup_pow_of_two() itself 
wraps ilog2() such that the constant case *is* type-independent. And 
since ilog2() handles non-constant values anyway, might it be reasonable 
to just take the strongly-typed __roundup_pow_of_two() helper out of the 
loop as below?

Robin

----->8-----
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 83a4a3ca3e8a..e825f8a6e8b5 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -172,11 +172,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
   */
  #define roundup_pow_of_two(n)			\
  (						\
-	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 1 :			\
-		(1UL << (ilog2((n) - 1) + 1))	\
-				   ) :		\
-	__roundup_pow_of_two(n)			\
+	(__builtin_constant_p(n) && (n == 1)) ?	\
+	1 : (1UL << (ilog2((n) - 1) + 1))	\
   )

  /**
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

WARNING: multiple messages have this Message-ID (diff)
From: Robin Murphy <robin.murphy@arm.com>
To: Leon Romanovsky <leon@kernel.org>,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Cc: Heiko Stuebner <heiko@sntech.de>,
	linux-pci@vger.kernel.org, Shawn Lin <shawn.lin@rock-chips.com>,
	Hanjun Guo <guohanjun@huawei.com>,
	Frank Rowand <frowand.list@gmail.com>,
	Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	f.fainelli@gmail.com, linux-rockchip@lists.infradead.org,
	linux-rdma@vger.kernel.org, maz@kernel.org, phil@raspberrypi.org,
	linux-acpi@vger.kernel.org, Len Brown <lenb@kernel.org>,
	devicetree@vger.kernel.org,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	linux-rpi-kernel@lists.infradead.org,
	Bjorn Helgaas <bhelgaas@google.com>,
	linux-arm-kernel@lists.infradead.org, mbrugger@suse.com,
	netdev@vger.kernel.org, "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org, jeremy.linton@arm.com,
	iommu@lists.linux-foundation.org,
	Rob Herring <robh+dt@kernel.org>,
	wahrenst@gmx.net, james.quinlan@broadcom.com,
	Sudeep Holla <sudeep.holla@arm.com>,
	andrew.murray@arm.com, "David S. Miller" <davem@davemloft.net>,
	Tariq Toukan <tariqt@mellanox.com>
Subject: Re: [PATCH v3 1/7] linux/log2.h: Add roundup/rounddown_pow_two64() family of functions
Date: Wed, 27 Nov 2019 18:06:18 +0000	[thread overview]
Message-ID: <6e0b9079-9efd-2884-26d1-3db2d622079d@arm.com> (raw)
In-Reply-To: <20191126125137.GA10331@unreal>

On 26/11/2019 12:51 pm, Leon Romanovsky wrote:
> On Tue, Nov 26, 2019 at 10:19:39AM +0100, Nicolas Saenz Julienne wrote:
>> Some users need to make sure their rounding function accepts and returns
>> 64bit long variables regardless of the architecture. Sadly
>> roundup/rounddown_pow_two() takes and returns unsigned longs. Create a
>> new generic 64bit variant of the function and cleanup rougue custom
>> implementations.
> 
> Is it possible to create general roundup/rounddown_pow_two() which will
> work correctly for any type of variables, instead of creating special
> variant for every type?

In fact, that is sort of the case already - roundup_pow_of_two() itself 
wraps ilog2() such that the constant case *is* type-independent. And 
since ilog2() handles non-constant values anyway, might it be reasonable 
to just take the strongly-typed __roundup_pow_of_two() helper out of the 
loop as below?

Robin

----->8-----
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 83a4a3ca3e8a..e825f8a6e8b5 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -172,11 +172,8 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
   */
  #define roundup_pow_of_two(n)			\
  (						\
-	__builtin_constant_p(n) ? (		\
-		(n == 1) ? 1 :			\
-		(1UL << (ilog2((n) - 1) + 1))	\
-				   ) :		\
-	__roundup_pow_of_two(n)			\
+	(__builtin_constant_p(n) && (n == 1)) ?	\
+	1 : (1UL << (ilog2((n) - 1) + 1))	\
   )

  /**

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-11-27 18:06 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-26  9:19 [PATCH v3 0/7] Raspberry Pi 4 PCIe support Nicolas Saenz Julienne
2019-11-26  9:19 ` Nicolas Saenz Julienne
2019-11-26  9:19 ` Nicolas Saenz Julienne
2019-11-26  9:19 ` [PATCH v3 1/7] linux/log2.h: Add roundup/rounddown_pow_two64() family of functions Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-11-26 12:51   ` Leon Romanovsky
2019-11-26 12:51     ` Leon Romanovsky
2019-11-26 12:51     ` Leon Romanovsky
2019-11-26 12:51     ` Leon Romanovsky
2019-11-27 18:06     ` Robin Murphy [this message]
2019-11-27 18:06       ` Robin Murphy
2019-11-27 18:06       ` Robin Murphy
2019-11-27 18:06       ` Robin Murphy
2019-11-27 18:24       ` Nicolas Saenz Julienne
2019-11-27 18:24         ` Nicolas Saenz Julienne
2019-11-27 18:24         ` Nicolas Saenz Julienne
2019-11-27 18:24         ` Nicolas Saenz Julienne
2019-11-27 19:06         ` Robin Murphy
2019-11-27 19:06           ` Robin Murphy
2019-11-27 19:06           ` Robin Murphy
2019-11-27 19:06           ` Robin Murphy
2019-11-27 19:12           ` Leon Romanovsky
2019-11-27 19:12             ` Leon Romanovsky
2019-11-27 19:12             ` Leon Romanovsky
2019-11-27 19:12             ` Leon Romanovsky
2019-11-27 19:16           ` Nicolas Saenz Julienne
2019-11-27 19:16             ` Nicolas Saenz Julienne
2019-11-27 19:16             ` Nicolas Saenz Julienne
2019-11-27 19:16             ` Nicolas Saenz Julienne
2019-11-27 17:36   ` Nicolas Saenz Julienne
2019-11-27 17:36     ` Nicolas Saenz Julienne
2019-11-27 17:36     ` Nicolas Saenz Julienne
2019-11-26  9:19 ` [PATCH v3 2/7] dt-bindings: PCI: Add bindings for brcmstb's PCIe device Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-12-02 16:39   ` Rob Herring
2019-12-02 16:39     ` Rob Herring
2019-11-26  9:19 ` [PATCH v3 3/7] ARM: dts: bcm2711: Enable PCIe controller Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-11-26  9:37   ` Phil Elwell
2019-11-26  9:37     ` Phil Elwell
2019-11-26  9:43     ` Nicolas Saenz Julienne
2019-11-26  9:43       ` Nicolas Saenz Julienne
2019-11-26  9:19 ` [PATCH v3 4/7] PCI: brcmstb: add Broadcom STB PCIe host controller driver Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-12-02 15:01   ` Andrew Murray
2019-12-02 15:01     ` Andrew Murray
2019-12-02 15:49     ` Jim Quinlan
2019-12-02 15:49       ` Jim Quinlan
2019-12-03 16:31   ` Jeremy Linton
2019-12-03 16:31     ` Jeremy Linton
2019-12-03 16:48     ` Robin Murphy
2019-12-03 16:48       ` Robin Murphy
2019-12-03 17:23     ` Nicolas Saenz Julienne
2019-12-03 17:23       ` Nicolas Saenz Julienne
2019-11-26  9:19 ` [PATCH v3 5/7] PCI: brcmstb: add MSI capability Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-11-29 15:46   ` Andrew Murray
2019-11-29 15:46     ` Andrew Murray
2019-12-02  9:59     ` Nicolas Saenz Julienne
2019-12-02  9:59       ` Nicolas Saenz Julienne
2019-12-02 12:20       ` Andrew Murray
2019-12-02 12:20         ` Andrew Murray
2019-12-02 12:22         ` Nicolas Saenz Julienne
2019-12-02 12:22           ` Nicolas Saenz Julienne
2019-11-26  9:19 ` [PATCH v3 6/7] MAINTAINERS: Add brcmstb PCIe controller Nicolas Saenz Julienne
2019-11-26  9:19 ` [PATCH v3 7/7] arm64: defconfig: Enable Broadcom's STB " Nicolas Saenz Julienne
2019-11-26  9:19   ` Nicolas Saenz Julienne
2019-11-26 21:50 ` [PATCH v3 0/7] Raspberry Pi 4 PCIe support Bjorn Helgaas
2019-11-26 21:50   ` Bjorn Helgaas
2019-11-26 21:50   ` Bjorn Helgaas
2019-11-27 17:28   ` Nicolas Saenz Julienne
2019-11-27 17:28     ` Nicolas Saenz Julienne
2019-11-27 17:28     ` Nicolas Saenz Julienne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e0b9079-9efd-2884-26d1-3db2d622079d@arm.com \
    --to=robin.murphy@arm.com \
    --cc=andrew.murray@arm.com \
    --cc=bhelgaas@google.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=guohanjun@huawei.com \
    --cc=hch@lst.de \
    --cc=heiko@sntech.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=james.quinlan@broadcom.com \
    --cc=jeremy.linton@arm.com \
    --cc=lenb@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=m.szyprowski@samsung.com \
    --cc=maz@kernel.org \
    --cc=mbrugger@suse.com \
    --cc=netdev@vger.kernel.org \
    --cc=nsaenzjulienne@suse.de \
    --cc=phil@raspberrypi.org \
    --cc=rjw@rjwysocki.net \
    --cc=robh+dt@kernel.org \
    --cc=shawn.lin@rock-chips.com \
    --cc=sudeep.holla@arm.com \
    --cc=tariqt@mellanox.com \
    --cc=wahrenst@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.