[v3,7/7] hash: use abstracted bit count functions

Message ID 1699400300-22545-8-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series use abstracted bit count functions |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS

Commit Message

Tyler Retzlaff Nov. 7, 2023, 11:38 p.m. UTC
  Use rte_popcount64 instead of __builtin_popcountl where the argument
type passed to the intrinsic was 64-bits.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/hash/rte_cuckoo_hash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Morten Brørup Nov. 8, 2023, 8:47 a.m. UTC | #1
> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com]
> Sent: Wednesday, 8 November 2023 00.38
> 
> Use rte_popcount64 instead of __builtin_popcountl where the argument
> type passed to the intrinsic was 64-bits.

Can someone please explain why our CI test system accepted passing a 64-bit value to __builtin_popcountl(unsigned long) when building for 32-bit architectures, where an unsigned long is 32 bit? The 32 most significant bits were blindly truncated here.

It looks like this patch also fixes a bug (which should have been caught by the CI system) for 32-bit architectures.

> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---
>  lib/hash/rte_cuckoo_hash.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
> index 19ee53a..ccdc3b9 100644
> --- a/lib/hash/rte_cuckoo_hash.c
> +++ b/lib/hash/rte_cuckoo_hash.c
> @@ -2357,7 +2357,7 @@ struct rte_hash *
>  	__rte_hash_lookup_bulk(h, keys, num_keys, positions, hit_mask,
> data);
> 
>  	/* Return number of hits */
> -	return __builtin_popcountl(*hit_mask);
> +	return rte_popcount64(*hit_mask);
>  }
> 
> 
> @@ -2474,7 +2474,7 @@ struct rte_hash *
>  			positions, hit_mask, data);
> 
>  	/* Return number of hits */
> -	return __builtin_popcountl(*hit_mask);
> +	return rte_popcount64(*hit_mask);
>  }
> 
>  int32_t
> --
> 1.8.3.1
  

Patch

diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c
index 19ee53a..ccdc3b9 100644
--- a/lib/hash/rte_cuckoo_hash.c
+++ b/lib/hash/rte_cuckoo_hash.c
@@ -2357,7 +2357,7 @@  struct rte_hash *
 	__rte_hash_lookup_bulk(h, keys, num_keys, positions, hit_mask, data);
 
 	/* Return number of hits */
-	return __builtin_popcountl(*hit_mask);
+	return rte_popcount64(*hit_mask);
 }
 
 
@@ -2474,7 +2474,7 @@  struct rte_hash *
 			positions, hit_mask, data);
 
 	/* Return number of hits */
-	return __builtin_popcountl(*hit_mask);
+	return rte_popcount64(*hit_mask);
 }
 
 int32_t