Skip to contentSkip to conversation

adapt prefetch functions for MSVC

PATCH In review Tyler Retzlaff 2 participants 4 messages Mar 20, 2024 – Jun 14, 2024

lore
Share & tools
lore
#2 lore raw

PATCH 2/2 eal: adjust intrinsic type casts for CXX

In reply to Tyler Retzlaff

_mm_prefetch does not take a volatile qualified pointer, cast it away. Additionally the pointer type should be char * not void * so adjust the cast to match.

_mm_cldemote does not take a volatile qualified pointer, cast it away.

---
 lib/eal/x86/include/rte_prefetch.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/eal/x86/include/rte_prefetch.h +5 -5
index 715c61b..8a93777 100644
@@ -20,7 +20,7 @@
 static inline void rte_prefetch0(const volatile void *p)
 {
 #ifdef RTE_TOOLCHAIN_MSVC
-	_mm_prefetch((const void *)p, _MM_HINT_T0);
+	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_T0);
 #else
 	asm volatile ("prefetcht0 %[p]" : : [p] "m" (*(const volatile char *)p));
 #endif
@@ -29,7 +29,7 @@ static inline void rte_prefetch0(const volatile void *p)
 static inline void rte_prefetch1(const volatile void *p)
 {
 #ifdef RTE_TOOLCHAIN_MSVC
-	_mm_prefetch((const void *)p, _MM_HINT_T1);
+	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_T1);
 #else
 	asm volatile ("prefetcht1 %[p]" : : [p] "m" (*(const volatile char *)p));
 #endif
@@ -38,7 +38,7 @@ static inline void rte_prefetch1(const volatile void *p)
 static inline void rte_prefetch2(const volatile void *p)
 {
 #ifdef RTE_TOOLCHAIN_MSVC
-	_mm_prefetch((const void *)p, _MM_HINT_T2);
+	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_T2);
 #else
 	asm volatile ("prefetcht2 %[p]" : : [p] "m" (*(const volatile char *)p));
 #endif
@@ -47,7 +47,7 @@ static inline void rte_prefetch2(const volatile void *p)
 static inline void rte_prefetch_non_temporal(const volatile void *p)
 {
 #ifdef RTE_TOOLCHAIN_MSVC
-	_mm_prefetch((const void *)p, _MM_HINT_NTA);
+	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_NTA);
 #else
 	asm volatile ("prefetchnta %[p]" : : [p] "m" (*(const volatile char *)p));
 #endif
@@ -58,7 +58,7 @@ static inline void rte_prefetch_non_temporal(const volatile void *p)
 rte_cldemote(const volatile void *p)
 {
 #ifdef RTE_TOOLCHAIN_MSVC
-	_mm_cldemote(p);
+	_mm_cldemote((const void *)(uintptr_t)p);
 #else
 	/*
 	 * We use raw byte codes for now as only the newest compiler
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 eal: provide prefetch functions for MSVC

In reply to Tyler Retzlaff

MSVC does not have an equivalent of __builtin_prefetch that allows read or read-write parameter. Introduce conditional compile expansion of rte_prefetch[0-2] inline functions when building with MSVC.

---
 lib/eal/include/generic/rte_prefetch.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/eal/include/generic/rte_prefetch.h +12 -0
index f9fab5e..773b3b8 100644
@@ -71,7 +71,11 @@
 	 * GCC docs where these integer constants are described in more detail:
 	 *  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
 	 */
+#ifdef RTE_TOOLCHAIN_MSVC
+	rte_prefetch0(p);
+#else
 	__builtin_prefetch(p, 1, 3);
+#endif
 }
 
 /**
@@ -92,7 +96,11 @@
 	 * GCC docs where these integer constants are described in more detail:
 	 *  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
 	 */
+#ifdef RTE_TOOLCHAIN_MSVC
+	rte_prefetch1(p);
+#else
 	__builtin_prefetch(p, 1, 2);
+#endif
 }
 
 /**
@@ -113,7 +121,11 @@
 	 * GCC docs where these integer constants are described in more detail:
 	 *  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
 	 */
+#ifdef RTE_TOOLCHAIN_MSVC
+	rte_prefetch2(p);
+#else
 	__builtin_prefetch(p, 1, 1);
+#endif
 }
 
 /**
Signature · 1 line
1.8.3.1
#0 lore raw

cover adapt prefetch functions for MSVC

MSVC does not have intrinsics that allow prefetch specifying read/write so adjust conditional compilation to allow MSVC to use the non access type inline functions from rte_prefetch.h

While here fix issues with C++ build (which only appears on MSVC because it uses intrinsics and not inline assembly)

Tyler Retzlaff (2):
eal: provide prefetch functions for MSVC
eal: adjust intrinsic type casts for CXX

 lib/eal/include/generic/rte_prefetch.h | 12 ++++++++++++
 lib/eal/x86/include/rte_prefetch.h     | 10 +++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1
#3 lore raw
Quoted 8 lines · Tyler Retzlaff

MSVC does not have intrinsics that allow prefetch specifying read/write so adjust conditional compilation to allow MSVC to use the non access type inline functions from rte_prefetch.h

While here fix issues with C++ build (which only appears on MSVC because it uses intrinsics and not inline assembly)

Quoted 8 lines

Tyler Retzlaff (2):
eal: provide prefetch functions for MSVC
eal: adjust intrinsic type casts for CXX

 lib/eal/include/generic/rte_prefetch.h | 12 ++++++++++++
 lib/eal/x86/include/rte_prefetch.h     | 10 +++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)

Series applied, thanks.

Signature · 1 line
David Marchand