[2/2] eal: add rte ffs32 and rte ffs64 inline functions

Message ID 1710969879-23701-3-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series provide rte_ffs32, rte_ffs64 and __rte_x86_movdiri for MSVC |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-arm64-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 March 20, 2024, 9:24 p.m. UTC
  provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in
intrinsics.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
  

Comments

David Marchand June 14, 2024, 2:49 p.m. UTC | #1
On Wed, Mar 20, 2024 at 10:25 PM Tyler Retzlaff
<roretzla@linux.microsoft.com> wrote:
>
> provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in
> intrinsics.
>
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>

Please add a unit test and an entry in the release notes.

> ---
>  lib/eal/include/rte_bitops.h | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
> index 449565e..e157a45 100644
> --- a/lib/eal/include/rte_bitops.h
> +++ b/lib/eal/include/rte_bitops.h
> @@ -405,6 +405,28 @@
>         return (unsigned int)__popcnt64(v);
>  }
>
> +static inline unsigned int
> +rte_ffs32(uint32_t v)
> +{
> +       unsigned long rv;
> +
> +       if (0 == _BitScanForward(&rv, v))

_BitScanForward(&rv, v) == 0 please.
  

Patch

diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h
index 449565e..e157a45 100644
--- a/lib/eal/include/rte_bitops.h
+++ b/lib/eal/include/rte_bitops.h
@@ -405,6 +405,28 @@ 
 	return (unsigned int)__popcnt64(v);
 }
 
+static inline unsigned int
+rte_ffs32(uint32_t v)
+{
+	unsigned long rv;
+
+	if (0 == _BitScanForward(&rv, v))
+		return 0;
+
+	return (unsigned int)rv + 1;
+}
+
+static inline unsigned int
+rte_ffs64(uint64_t v)
+{
+	unsigned long rv;
+
+	if (0 == _BitScanForward64(&rv, v))
+		return 0;
+
+	return (unsigned int)rv + 1;
+}
+
 #else
 
 /**
@@ -491,6 +513,18 @@ 
 	return (unsigned int)__builtin_popcountll(v);
 }
 
+static inline unsigned int
+rte_ffs32(uint32_t v)
+{
+	return (unsigned int)__builtin_ffs(v);
+}
+
+static inline unsigned int
+rte_ffs64(uint64_t v)
+{
+	return (unsigned int)__builtin_ffsll(v);
+}
+
 #endif
 
 /**