DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
@ 2026-05-18 16:33 Stephen Hemminger
  2026-05-18 16:56 ` Bruce Richardson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stephen Hemminger @ 2026-05-18 16:33 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, stable, Jack Bond-Preston, Gavin Hu,
	Honnappa Nagarahalli, Pablo de Lara

Newer GCC warns when a non-boolean constant is an operand of &&, which
trips whenever RTE_IS_POWER_OF_2 is used in a static_assert with a
power-of-two literal. Make the zero check explicit.

Fixes: 7c872b96983a ("hash: validate hash bucket entries while compiling")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/include/rte_bitops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
index aa6ac73abb..d2719ecd5e 100644
--- a/lib/eal/include/rte_bitops.h
+++ b/lib/eal/include/rte_bitops.h
@@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)
 /**
  * Macro to return 1 if n is a power of 2, 0 otherwise
  */
-#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
+#define RTE_IS_POWER_OF_2(n) ((n) != 0 && !(((n) - 1) & (n)))
 
 /**
  * Returns true if n is a power of 2
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
  2026-05-18 16:33 [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2 Stephen Hemminger
@ 2026-05-18 16:56 ` Bruce Richardson
  2026-05-18 17:10   ` Stephen Hemminger
  2026-05-19  9:26 ` Jack Bond-Preston
  2026-05-19 13:49 ` [PATCH v2] " Stephen Hemminger
  2 siblings, 1 reply; 5+ messages in thread
From: Bruce Richardson @ 2026-05-18 16:56 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: dev, stable, Jack Bond-Preston, Gavin Hu, Honnappa Nagarahalli,
	Pablo de Lara

On Mon, May 18, 2026 at 09:33:31AM -0700, Stephen Hemminger wrote:
> Newer GCC warns when a non-boolean constant is an operand of &&, which
> trips whenever RTE_IS_POWER_OF_2 is used in a static_assert with a
> power-of-two literal. Make the zero check explicit.
> 
> Fixes: 7c872b96983a ("hash: validate hash bucket entries while compiling")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>

One further suggestion below, since you are changing this.
> ---
>  lib/eal/include/rte_bitops.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
> index aa6ac73abb..d2719ecd5e 100644
> --- a/lib/eal/include/rte_bitops.h
> +++ b/lib/eal/include/rte_bitops.h
> @@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)
>  /**
>   * Macro to return 1 if n is a power of 2, 0 otherwise
>   */
> -#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
> +#define RTE_IS_POWER_OF_2(n) ((n) != 0 && !(((n) - 1) & (n)))
>  

I'd also suggest changing the second part of the && to match, changing the
"!" for explicit "== 0":

#define RTE_IS_POWER_OF_2(n) ((n) != 0 && (((n) - 1) & (n)) == 0)

>  /**
>   * Returns true if n is a power of 2
> -- 
> 2.53.0
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
  2026-05-18 16:56 ` Bruce Richardson
@ 2026-05-18 17:10   ` Stephen Hemminger
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2026-05-18 17:10 UTC (permalink / raw)
  To: Bruce Richardson
  Cc: dev, stable, Jack Bond-Preston, Gavin Hu, Honnappa Nagarahalli,
	Pablo de Lara

On Mon, 18 May 2026 17:56:08 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:

> I'd also suggest changing the second part of the && to match, changing the
> "!" for explicit "== 0":
> 
> #define RTE_IS_POWER_OF_2(n) ((n) != 0 && (((n) - 1) & (n)) == 0)

Was heading for the smallest possible part

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
  2026-05-18 16:33 [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2 Stephen Hemminger
  2026-05-18 16:56 ` Bruce Richardson
@ 2026-05-19  9:26 ` Jack Bond-Preston
  2026-05-19 13:49 ` [PATCH v2] " Stephen Hemminger
  2 siblings, 0 replies; 5+ messages in thread
From: Jack Bond-Preston @ 2026-05-19  9:26 UTC (permalink / raw)
  To: Stephen Hemminger, dev
  Cc: stable, Gavin Hu, Honnappa Nagarahalli, Pablo de Lara

On 18/05/2026 17:33, Stephen Hemminger wrote:
> Newer GCC warns when a non-boolean constant is an operand of &&, which
> trips whenever RTE_IS_POWER_OF_2 is used in a static_assert with a
> power-of-two literal. Make the zero check explicit.
> 
> Fixes: 7c872b96983a ("hash: validate hash bucket entries while compiling")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>   lib/eal/include/rte_bitops.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
> index aa6ac73abb..d2719ecd5e 100644
> --- a/lib/eal/include/rte_bitops.h
> +++ b/lib/eal/include/rte_bitops.h
> @@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)
>   /**
>    * Macro to return 1 if n is a power of 2, 0 otherwise
>    */
> -#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
> +#define RTE_IS_POWER_OF_2(n) ((n) != 0 && !(((n) - 1) & (n)))
>   
>   /**
>    * Returns true if n is a power of 2

Acked-by: Jack Bond-Preston <jack.bond-preston@foss.arm.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2
  2026-05-18 16:33 [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2 Stephen Hemminger
  2026-05-18 16:56 ` Bruce Richardson
  2026-05-19  9:26 ` Jack Bond-Preston
@ 2026-05-19 13:49 ` Stephen Hemminger
  2 siblings, 0 replies; 5+ messages in thread
From: Stephen Hemminger @ 2026-05-19 13:49 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, stable, Bruce Richardson, Jack Bond-Preston,
	Pablo de Lara, Gavin Hu, Honnappa Nagarahalli

Newer GCC warns when a non-boolean constant is an operand of &&, which
trips whenever RTE_IS_POWER_OF_2 is used in a static_assert with a
power-of-two literal. Make the zero check explicit.

Fixes: 7c872b96983a ("hash: validate hash bucket entries while compiling")
Cc: stable@dpdk.org

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Jack Bond-Preston <jack.bond-preston@foss.arm.com>
---
v2 - use suggestion to make both sides comparisons

Note: AI incorrectly complains about multiple evaluations in this macro
      but that has always been the case, and has to be macro
      for use with static assert.

 lib/eal/include/rte_bitops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
index aa6ac73abb..b170447714 100644
--- a/lib/eal/include/rte_bitops.h
+++ b/lib/eal/include/rte_bitops.h
@@ -1299,7 +1299,7 @@ rte_fls_u64(uint64_t x)
 /**
  * Macro to return 1 if n is a power of 2, 0 otherwise
  */
-#define RTE_IS_POWER_OF_2(n) ((n) && !(((n) - 1) & (n)))
+#define RTE_IS_POWER_OF_2(n) ((n) != 0 && (((n) - 1) & (n)) == 0)
 
 /**
  * Returns true if n is a power of 2
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-05-19 13:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-18 16:33 [PATCH] eal: silence -Wconstant-logical-operand in RTE_IS_POWER_OF_2 Stephen Hemminger
2026-05-18 16:56 ` Bruce Richardson
2026-05-18 17:10   ` Stephen Hemminger
2026-05-19  9:26 ` Jack Bond-Preston
2026-05-19 13:49 ` [PATCH v2] " Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox