[1/2] bitset: discontinue the use of GCC builtin

Message ID 20241016135411.827850-1-mattias.ronnblom@ericsson.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [1/2] bitset: discontinue the use of GCC builtin |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Mattias Rönnblom Oct. 16, 2024, 1:54 p.m. UTC
Replace the use of __builtin_ffsll() with rte_bsf64() to be MSVC
compatible.

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Suggested-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/include/rte_bitset.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
  

Comments

David Marchand Oct. 16, 2024, 3:19 p.m. UTC | #1
On Wed, Oct 16, 2024 at 4:03 PM Mattias Rönnblom
<mattias.ronnblom@ericsson.com> wrote:
>
> Replace the use of __builtin_ffsll() with rte_bsf64() to be MSVC
> compatible.
>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
> Suggested-by: David Marchand <david.marchand@redhat.com>

Thank you, lgtm.
  
David Marchand Oct. 16, 2024, 8:55 p.m. UTC | #2
On Wed, Oct 16, 2024 at 4:03 PM Mattias Rönnblom
<mattias.ronnblom@ericsson.com> wrote:
>
> Replace the use of __builtin_ffsll() with rte_bsf64() to be MSVC
> compatible.
>
> Suggested-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>

Series applied, thanks.
  

Patch

diff --git a/lib/eal/include/rte_bitset.h b/lib/eal/include/rte_bitset.h
index 74c643a72a..27b7a2e34d 100644
--- a/lib/eal/include/rte_bitset.h
+++ b/lib/eal/include/rte_bitset.h
@@ -601,7 +601,6 @@  __rte_bitset_find_nowrap(const uint64_t *bitset, size_t __rte_unused size, size_
 
 	while (word_idx <= __RTE_BITSET_WORD_IDX(end_bit - 1)) {
 		uint64_t word;
-		int word_ffs;
 
 		word = bitset[word_idx];
 		if (find_clear)
@@ -609,16 +608,14 @@  __rte_bitset_find_nowrap(const uint64_t *bitset, size_t __rte_unused size, size_
 
 		word >>= offset;
 
-		word_ffs = __builtin_ffsll(word);
-
-		if (word_ffs != 0) {
-			ssize_t ffs = start_bit + word_ffs - 1;
+		if (word != 0) {
+			size_t ffs = start_bit + rte_bsf64(word);
 
 			/*
 			 * Check if set bit were among the last,
 			 * unused bits, in the last word.
 			 */
-			if (unlikely(ffs >= (ssize_t)end_bit))
+			if (unlikely(ffs >= end_bit))
 				return -1;
 
 			return ffs;