DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
To: <dev@dpdk.org>
Cc: "Mattias Rönnblom" <hofors@lysator.liu.se>,
	"Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
Subject: [RFC 1/1] eal/x86: replace inline assembly prefetch with cc builtins
Date: Sun, 23 Feb 2025 13:52:15 +0100	[thread overview]
Message-ID: <20250223125215.358925-2-mattias.ronnblom@ericsson.com> (raw)
In-Reply-To: <20250223125215.358925-1-mattias.ronnblom@ericsson.com>

Implement the 32- and 64-bit x86 rte_prefetch<n>() functions and
rte_prefetch_non_temporal() using compiler builtins, rather than
inline assembly.

This change frees the compiler to do certain optimizations that
otherwise wouldn't be possible.

Signed-off-by: Mattias Rönnblom <mattias.ronnblom@ericsson.com>
---
 lib/eal/x86/include/rte_prefetch.h | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/lib/eal/x86/include/rte_prefetch.h b/lib/eal/x86/include/rte_prefetch.h
index 34a609cc65..329b1a81f7 100644
--- a/lib/eal/x86/include/rte_prefetch.h
+++ b/lib/eal/x86/include/rte_prefetch.h
@@ -22,7 +22,11 @@ static inline void rte_prefetch0(const volatile void *p)
 #ifdef RTE_TOOLCHAIN_MSVC
 	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_T0);
 #else
-	asm volatile ("prefetcht0 %[p]" : : [p] "m" (*(const volatile char *)p));
+	/* 0 indicates intention to read, 3 sets target cache level to L1. See
+	 * GCC docs where these integer constants are described in more detail:
+	 *  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
+	 */
+	__builtin_prefetch((const void *)(uintptr_t)p, 0, 3);
 #endif
 }
 
@@ -31,7 +35,11 @@ static inline void rte_prefetch1(const volatile void *p)
 #ifdef RTE_TOOLCHAIN_MSVC
 	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_T1);
 #else
-	asm volatile ("prefetcht1 %[p]" : : [p] "m" (*(const volatile char *)p));
+	/* 0 indicates intention to read, 2 sets target cache level to L2. See
+	 * GCC docs where these integer constants are described in more detail:
+	 *  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
+	 */
+	__builtin_prefetch((const void *)(uintptr_t)p, 0, 2);
 #endif
 }
 
@@ -40,7 +48,11 @@ static inline void rte_prefetch2(const volatile void *p)
 #ifdef RTE_TOOLCHAIN_MSVC
 	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_T2);
 #else
-	asm volatile ("prefetcht2 %[p]" : : [p] "m" (*(const volatile char *)p));
+	/* 0 indicates intention to read, 1 sets target cache level to L3. See
+	 * GCC docs where these integer constants are described in more detail:
+	 *  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
+	 */
+	__builtin_prefetch((const void *)(uintptr_t)p, 0, 1);
 #endif
 }
 
@@ -49,7 +61,11 @@ static inline void rte_prefetch_non_temporal(const volatile void *p)
 #ifdef RTE_TOOLCHAIN_MSVC
 	_mm_prefetch((const char *)(uintptr_t)p, _MM_HINT_NTA);
 #else
-	asm volatile ("prefetchnta %[p]" : : [p] "m" (*(const volatile char *)p));
+	/* 0 indicates intention to read, 1 sets target cache level to L3. See
+	 * GCC docs where these integer constants are described in more detail:
+	 *  https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
+	 */
+	__builtin_prefetch((const void *)(uintptr_t)p, 0, 0);
 #endif
 }
 
-- 
2.43.0


      reply	other threads:[~2025-02-23 13:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-23 12:52 [RFC 0/1] " Mattias Rönnblom
2025-02-23 12:52 ` Mattias Rönnblom [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250223125215.358925-2-mattias.ronnblom@ericsson.com \
    --to=mattias.ronnblom@ericsson.com \
    --cc=dev@dpdk.org \
    --cc=hofors@lysator.liu.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).