[v2] hash: provide crc32 functions based on intrinsics

Message ID 1716336134-27366-2-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers
Series [v2] hash: provide crc32 functions based on intrinsics |

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-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-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-unit-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Tyler Retzlaff May 22, 2024, 12:02 a.m. UTC
  MSVC does not support inline asm so replace crc32 inline function
implementations with intrinsics compatible with all toolchains.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/hash/rte_crc_x86.h | 38 +++++++++++++-------------------------
 1 file changed, 13 insertions(+), 25 deletions(-)
  

Comments

Stephen Hemminger May 22, 2024, 2:21 a.m. UTC | #1
On Tue, 21 May 2024 17:02:14 -0700
Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:

> MSVC does not support inline asm so replace crc32 inline function
> implementations with intrinsics compatible with all toolchains.
> 
> Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> ---

always good to remove asm since in tends not to get optimized.

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  
Morten Brørup May 22, 2024, 8:36 a.m. UTC | #2
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Wednesday, 22 May 2024 04.21
> 
> On Tue, 21 May 2024 17:02:14 -0700
> Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
> 
> > MSVC does not support inline asm so replace crc32 inline function
> > implementations with intrinsics compatible with all toolchains.
> >
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > ---
> 
> always good to remove asm since in tends not to get optimized.
> 
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Acked-by: Morten Brørup <mb@smartsharesystems.com>
  
Thomas Monjalon May 26, 2024, 3:07 p.m. UTC | #3
22/05/2024 10:36, Morten Brørup:
> > From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> > Sent: Wednesday, 22 May 2024 04.21
> > 
> > On Tue, 21 May 2024 17:02:14 -0700
> > Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:
> > 
> > > MSVC does not support inline asm so replace crc32 inline function
> > > implementations with intrinsics compatible with all toolchains.
> > >
> > > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> > 
> > always good to remove asm since in tends not to get optimized.
> > 
> > Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> 
> Acked-by: Morten Brørup <mb@smartsharesystems.com>

Applied, thanks.
  

Patch

diff --git a/lib/hash/rte_crc_x86.h b/lib/hash/rte_crc_x86.h
index 3b865e2..eadfe42 100644
--- a/lib/hash/rte_crc_x86.h
+++ b/lib/hash/rte_crc_x86.h
@@ -5,35 +5,33 @@ 
 #ifndef _RTE_CRC_X86_H_
 #define _RTE_CRC_X86_H_
 
+#include <rte_vect.h>
+
 static inline uint32_t
 crc32c_sse42_u8(uint8_t data, uint32_t init_val)
 {
-	__asm__ volatile(
-			"crc32b %[data], %[init_val];"
-			: [init_val] "+r" (init_val)
-			: [data] "rm" (data));
-	return init_val;
+	return _mm_crc32_u8(init_val, data);
 }
 
 static inline uint32_t
 crc32c_sse42_u16(uint16_t data, uint32_t init_val)
 {
-	__asm__ volatile(
-			"crc32w %[data], %[init_val];"
-			: [init_val] "+r" (init_val)
-			: [data] "rm" (data));
-	return init_val;
+	return _mm_crc32_u16(init_val, data);
 }
 
 static inline uint32_t
 crc32c_sse42_u32(uint32_t data, uint32_t init_val)
 {
-	__asm__ volatile(
-			"crc32l %[data], %[init_val];"
-			: [init_val] "+r" (init_val)
-			: [data] "rm" (data));
-	return init_val;
+	return _mm_crc32_u32(init_val, data);
+}
+
+#ifdef RTE_ARCH_X86_64
+static inline uint32_t
+crc32c_sse42_u64(uint64_t data, uint64_t init_val)
+{
+	return _mm_crc32_u64(init_val, data);
 }
+#endif
 
 static inline uint32_t
 crc32c_sse42_u64_mimic(uint64_t data, uint64_t init_val)
@@ -49,16 +47,6 @@ 
 	return (uint32_t)init_val;
 }
 
-static inline uint32_t
-crc32c_sse42_u64(uint64_t data, uint64_t init_val)
-{
-	__asm__ volatile(
-			"crc32q %[data], %[init_val];"
-			: [init_val] "+r" (init_val)
-			: [data] "rm" (data));
-	return (uint32_t)init_val;
-}
-
 /*
  * Use single crc32 instruction to perform a hash on a byte value.
  * Fall back to software crc32 implementation in case SSE4.2 is