[v3] eal, power: use UINT64_MAX and UINT32_MAX

Message ID 1615853611-7253-1-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v3] eal, power: use UINT64_MAX and UINT32_MAX |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/travis-robot success travis build: passed
ci/github-robot success github build: passed
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS

Commit Message

Tyler Retzlaff March 16, 2021, 12:13 a.m. UTC
  Use UINT64_MAX and UINT32_MAX instead of -1 or ~0 literal variations
of different explicit widths when creating masks and sentinel values.

some compilers generate a warning when applying a '-' to an unsigned
literal so avoid this by initializing with unsigned preprocessor
definitions where appropriate.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/librte_eal/common/eal_common_fbarray.c | 12 ++++++------
 lib/librte_eal/common/eal_common_log.c     |  2 +-
 lib/librte_power/rte_power_pmd_mgmt.c      |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)
  

Comments

Morten Brørup March 16, 2021, 11:06 a.m. UTC | #1
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tyler Retzlaff
> Sent: Tuesday, March 16, 2021 1:14 AM
> 
> Use UINT64_MAX and UINT32_MAX instead of -1 or ~0 literal variations
> of different explicit widths when creating masks and sentinel values.
> 
> some compilers generate a warning when applying a '-' to an unsigned
> literal so avoid this by initializing with unsigned preprocessor
> definitions where appropriate.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  lib/librte_eal/common/eal_common_fbarray.c | 12 ++++++------
>  lib/librte_eal/common/eal_common_log.c     |  2 +-
>  lib/librte_power/rte_power_pmd_mgmt.c      |  2 +-
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_fbarray.c
> b/lib/librte_eal/common/eal_common_fbarray.c
> index 592ec5859..3a28a5324 100644
> --- a/lib/librte_eal/common/eal_common_fbarray.c
> +++ b/lib/librte_eal/common/eal_common_fbarray.c
> @@ -138,7 +138,7 @@ find_next_n(const struct rte_fbarray *arr, unsigned
> int start, unsigned int n,
>  	 */
>  	last = MASK_LEN_TO_IDX(arr->len);
>  	last_mod = MASK_LEN_TO_MOD(arr->len);
> -	last_msk = ~(-1ULL << last_mod);
> +	last_msk = ~(UINT64_MAX << last_mod);
> 
>  	for (msk_idx = first; msk_idx < msk->n_masks; msk_idx++) {
>  		uint64_t cur_msk, lookahead_msk;
> @@ -398,8 +398,8 @@ find_prev_n(const struct rte_fbarray *arr, unsigned
> int start, unsigned int n,
>  	first_mod = MASK_LEN_TO_MOD(start);
>  	/* we're going backwards, so mask must start from the top */
>  	ignore_msk = first_mod == MASK_ALIGN - 1 ?
> -				-1ULL : /* prevent overflow */
> -				~(-1ULL << (first_mod + 1));
> +				UINT64_MAX : /* prevent overflow */
> +				~(UINT64_MAX << (first_mod + 1));
> 
>  	/* go backwards, include zero */
>  	msk_idx = first;
> @@ -513,7 +513,7 @@ find_prev_n(const struct rte_fbarray *arr, unsigned
> int start, unsigned int n,
>  				 * no runs in the space we've lookbehind-
> scanned
>  				 * as well, so skip that on next iteration.
>  				 */
> -				ignore_msk = -1ULL << need;
> +				ignore_msk = UINT64_MAX << need;
>  				msk_idx = lookbehind_idx;
>  				break;
>  			}
> @@ -560,8 +560,8 @@ find_prev(const struct rte_fbarray *arr, unsigned
> int start, bool used)
>  	first_mod = MASK_LEN_TO_MOD(start);
>  	/* we're going backwards, so mask must start from the top */
>  	ignore_msk = first_mod == MASK_ALIGN - 1 ?
> -				-1ULL : /* prevent overflow */
> -				~(-1ULL << (first_mod + 1));
> +				UINT64_MAX : /* prevent overflow */
> +				~(UINT64_MAX << (first_mod + 1));
> 
>  	/* go backwards, include zero */
>  	idx = first;
> diff --git a/lib/librte_eal/common/eal_common_log.c
> b/lib/librte_eal/common/eal_common_log.c
> index c5554badb..1b2745329 100644
> --- a/lib/librte_eal/common/eal_common_log.c
> +++ b/lib/librte_eal/common/eal_common_log.c
> @@ -30,7 +30,7 @@ static struct rte_logs {
>  	size_t dynamic_types_len;
>  	struct rte_log_dynamic_type *dynamic_types;
>  } rte_logs = {
> -	.type = ~0,
> +	.type = UINT32_MAX,
>  	.level = RTE_LOG_DEBUG,
>  };
> 
> diff --git a/lib/librte_power/rte_power_pmd_mgmt.c
> b/lib/librte_power/rte_power_pmd_mgmt.c
> index 454ef7091..db03cbf42 100644
> --- a/lib/librte_power/rte_power_pmd_mgmt.c
> +++ b/lib/librte_power/rte_power_pmd_mgmt.c
> @@ -111,7 +111,7 @@ clb_umwait(uint16_t port_id, uint16_t qidx, struct
> rte_mbuf **pkts __rte_unused,
>  				ret = rte_eth_get_monitor_addr(port_id, qidx,
>  						&pmc);
>  				if (ret == 0)
> -					rte_power_monitor(&pmc, -1ULL);
> +					rte_power_monitor(&pmc, UINT64_MAX);
>  			}
>  			q_conf->umwait_in_progress = false;
> 
> --
> 2.30.0.vfs.0.2
> 

Acked-by: Morten Brørup <mb@smartsharesystems.com>
  
Anatoly Burakov April 1, 2021, 11:22 a.m. UTC | #2
On 16-Mar-21 12:13 AM, Tyler Retzlaff wrote:
> Use UINT64_MAX and UINT32_MAX instead of -1 or ~0 literal variations
> of different explicit widths when creating masks and sentinel values.
> 
> some compilers generate a warning when applying a '-' to an unsigned
> literal so avoid this by initializing with unsigned preprocessor
> definitions where appropriate.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
Thomas Monjalon April 19, 2021, 9:43 a.m. UTC | #3
01/04/2021 13:22, Burakov, Anatoly:
> On 16-Mar-21 12:13 AM, Tyler Retzlaff wrote:
> > Use UINT64_MAX and UINT32_MAX instead of -1 or ~0 literal variations
> > of different explicit widths when creating masks and sentinel values.
> > 
> > some compilers generate a warning when applying a '-' to an unsigned
> > literal so avoid this by initializing with unsigned preprocessor
> > definitions where appropriate.
> > 
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Split in 2 patches (EAL and power) and applied, thanks.

There are other occurences to remove:
git grep -l -- '-1U'
	app/test-eventdev/test_perf_common.c
	app/test-eventdev/test_pipeline_common.c
	drivers/net/bnxt/tf_ulp/ulp_flow_db.c
	drivers/net/bnxt/tf_ulp/ulp_rte_parser.h
	drivers/net/mlx5/mlx5_rxtx_vec_neon.h

I think we should add a checkpatch test
to avoid inserting more occurences in future.
Tyler, please could you work on it?
  

Patch

diff --git a/lib/librte_eal/common/eal_common_fbarray.c b/lib/librte_eal/common/eal_common_fbarray.c
index 592ec5859..3a28a5324 100644
--- a/lib/librte_eal/common/eal_common_fbarray.c
+++ b/lib/librte_eal/common/eal_common_fbarray.c
@@ -138,7 +138,7 @@  find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
 	 */
 	last = MASK_LEN_TO_IDX(arr->len);
 	last_mod = MASK_LEN_TO_MOD(arr->len);
-	last_msk = ~(-1ULL << last_mod);
+	last_msk = ~(UINT64_MAX << last_mod);
 
 	for (msk_idx = first; msk_idx < msk->n_masks; msk_idx++) {
 		uint64_t cur_msk, lookahead_msk;
@@ -398,8 +398,8 @@  find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
 	first_mod = MASK_LEN_TO_MOD(start);
 	/* we're going backwards, so mask must start from the top */
 	ignore_msk = first_mod == MASK_ALIGN - 1 ?
-				-1ULL : /* prevent overflow */
-				~(-1ULL << (first_mod + 1));
+				UINT64_MAX : /* prevent overflow */
+				~(UINT64_MAX << (first_mod + 1));
 
 	/* go backwards, include zero */
 	msk_idx = first;
@@ -513,7 +513,7 @@  find_prev_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
 				 * no runs in the space we've lookbehind-scanned
 				 * as well, so skip that on next iteration.
 				 */
-				ignore_msk = -1ULL << need;
+				ignore_msk = UINT64_MAX << need;
 				msk_idx = lookbehind_idx;
 				break;
 			}
@@ -560,8 +560,8 @@  find_prev(const struct rte_fbarray *arr, unsigned int start, bool used)
 	first_mod = MASK_LEN_TO_MOD(start);
 	/* we're going backwards, so mask must start from the top */
 	ignore_msk = first_mod == MASK_ALIGN - 1 ?
-				-1ULL : /* prevent overflow */
-				~(-1ULL << (first_mod + 1));
+				UINT64_MAX : /* prevent overflow */
+				~(UINT64_MAX << (first_mod + 1));
 
 	/* go backwards, include zero */
 	idx = first;
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb..1b2745329 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -30,7 +30,7 @@  static struct rte_logs {
 	size_t dynamic_types_len;
 	struct rte_log_dynamic_type *dynamic_types;
 } rte_logs = {
-	.type = ~0,
+	.type = UINT32_MAX,
 	.level = RTE_LOG_DEBUG,
 };
 
diff --git a/lib/librte_power/rte_power_pmd_mgmt.c b/lib/librte_power/rte_power_pmd_mgmt.c
index 454ef7091..db03cbf42 100644
--- a/lib/librte_power/rte_power_pmd_mgmt.c
+++ b/lib/librte_power/rte_power_pmd_mgmt.c
@@ -111,7 +111,7 @@  clb_umwait(uint16_t port_id, uint16_t qidx, struct rte_mbuf **pkts __rte_unused,
 				ret = rte_eth_get_monitor_addr(port_id, qidx,
 						&pmc);
 				if (ret == 0)
-					rte_power_monitor(&pmc, -1ULL);
+					rte_power_monitor(&pmc, UINT64_MAX);
 			}
 			q_conf->umwait_in_progress = false;