[PATCH] eal/riscv: implement prefetch using __builtin_prefetch

dangshiwei 1138222970gg at gmail.com
Tue Mar 10 14:35:24 CET 2026


RISC-V currently has no-op implementations of the rte_prefetch*
functions. Use __builtin_prefetch() to allow the compiler to emit
Zicbop prefetch instructions when the target supports them (GCC
13.1+, Clang 17.0.1+ with -march=rv*_zicbop).

The Zicbop extension has no cache-level hints, so rte_prefetch1()
and rte_prefetch2() fall back to rte_prefetch0(). The volatile
qualifier is stripped via uintptr_t cast to satisfy
__builtin_prefetch()'s const void * parameter without triggering
-Wdiscarded-qualifiers.

This replaces the abandoned v1 series by Daniel Gregory
(Message-ID: 20240530171948.19763-1-daniel.gregory at bytedance.com)
addressing reviewer feedback from Kardach and Hemminger.

Signed-off-by: dangshiwei <1138222970gg at gmail.com>
---
 lib/eal/riscv/include/rte_prefetch.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/eal/riscv/include/rte_prefetch.h b/lib/eal/riscv/include/rte_prefetch.h
index 42146491ea..37b4787387 100644
--- a/lib/eal/riscv/include/rte_prefetch.h
+++ b/lib/eal/riscv/include/rte_prefetch.h
@@ -18,22 +18,24 @@ extern "C" {
 
 static inline void rte_prefetch0(const volatile void *p)
 {
-	RTE_SET_USED(p);
+	__builtin_prefetch((const void *)(uintptr_t)p);
 }
 
 static inline void rte_prefetch1(const volatile void *p)
 {
-	RTE_SET_USED(p);
+	/* Zicbop has no cache-level hints, fallback to rte_prefetch0 */
+	rte_prefetch0(p);
 }
 
 static inline void rte_prefetch2(const volatile void *p)
 {
-	RTE_SET_USED(p);
+	/* Zicbop has no cache-level hints, fallback to rte_prefetch0 */
+	rte_prefetch0(p);
 }
 
 static inline void rte_prefetch_non_temporal(const volatile void *p)
 {
-	/* non-temporal version not available, fallback to rte_prefetch0 */
+	/* Zicbop has no non-temporal hint, fallback to rte_prefetch0 */
 	rte_prefetch0(p);
 }
 
-- 
2.43.0



More information about the dev mailing list