eal/riscv/spinlock: add rte_cpuflag.h
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/5 config/riscv: detect V extension
From: Sun Yuechi <[email protected]>
This patch is derived from "config/riscv: detect presence of Zbc extension with modifications".
The RISC-V C api defines architecture extension test macros These let us detect whether the V extension is supported on the compiler and -march we're building with. The C api also defines V intrinsics we can use rather than inline assembly on newer versions of GCC (14.1.0+) and Clang (18.1.0+).
If the V extension and intrinsics are both present and we can detect the V extension at runtime, we define a flag, RTE_RISCV_FEATURE_V.
--- .mailmap | 1 + config/riscv/meson.build | 25 +++++++++++++++++++++++++ lib/eal/riscv/include/rte_vect.h | 4 ++++ 3 files changed, 30 insertions(+)
.mailmap +1 -0
@@ -1513,6 +1513,7 @@ Sunil Kumar Kori <[email protected]> <[email protected]> <[email protected]> Sunil Pai G <[email protected]> Sunil Uttarwar <[email protected]> Sun Jiajia <[email protected]> +Sun Yuechi <[email protected]> <[email protected]> Sunyang Wu <[email protected]> Surabhi Boob <[email protected]> Suyang Ju <[email protected]>
config/riscv/meson.build +25 -0
@@ -119,6 +119,31 @@ foreach flag: arch_config['machine_args'] endif endforeach +# check if we can do buildtime detection of extensions supported by the target +riscv_extension_macros = false +if (cc.get_define('__riscv_arch_test', args: machine_args) == '1') + message('Detected architecture extension test macros') + riscv_extension_macros = true +else + warning('RISC-V architecture extension test macros not available. Build-time detection of extensions not possible') +endif + +# detect extensions +# Requires intrinsics available in GCC 14.1.0+ and Clang 18.1.0+ +if (riscv_extension_macros and + (cc.get_define('__riscv_vector', args: machine_args) != '')) + if ((cc.get_id() == 'gcc' and cc.version().version_compare('>=14.1.0')) + or (cc.get_id() == 'clang' and cc.version().version_compare('>=18.1.0'))) + if (cc.compiles('''#include <riscv_vector.h> + int main(void) { size_t vl = __riscv_vsetvl_e32m1(1); }''', args: machine_args)) + message('Compiling with the V extension') + machine_args += ['-DRTE_RISCV_FEATURE_V'] + endif + else + warning('Detected V extension but cannot use because intrinsics are not available (present in GCC 14.1.0+ and Clang 18.1.0+)') + endif +endif + # apply flags foreach flag: dpdk_flags if flag.length() > 0
lib/eal/riscv/include/rte_vect.h +4 -0
@@ -11,6 +11,10 @@#include "generic/rte_vect.h" #include "rte_common.h" +#ifdef RTE_RISCV_FEATURE_V +#include <riscv_vector.h> +#endif +#ifdef __cplusplusextern "C" {#endif
Signature · 1 line
2.50.0
Re: [PATCH v2 1/5] config/riscv: detect V extension
Quoted 11 lines · On Tue, 1 Jul 2025, 20:21 , <[email protected]> wrote:
From: Sun Yuechi <[email protected]>
This patch is derived from "config/riscv: detect presence of Zbc extension with modifications".
The RISC-V C api defines architecture extension test macros These let us detect whether the V extension is supported on the compiler and -march we're building with. The C api also defines V intrinsics we can use rather than inline assembly on newer versions of GCC (14.1.0+) and Clang (18.1.0+).
Quoted 5 lines
If the V extension and intrinsics are both present and we can detect the V extension at runtime, we define a flag,
RTE_RISCV_FEATURE_V.Signed-off-by Sun Yuechi <[email protected]>
Quoted 80 lines
--- .mailmap | 1 + config/riscv/meson.build | 25 +++++++++++++++++++++++++ lib/eal/riscv/include/rte_vect.h | 4 ++++ 3 files changed, 30 insertions(+).mailmap +0
-0@@ -1513,6 +1513,7 @@ Sunil Kumar Kori <[email protected]> <[email protected]> <[email protected]>
Sunil Pai G <[email protected]>
Sunil Uttarwar <[email protected]> Sun Jiajia <[email protected]>.mailmap +1
-0+Sun Yuechi <[email protected]> <[email protected]> Sunyang Wu <[email protected]> Surabhi Boob <[email protected]> Suyang Ju <[email protected]>config/riscv/meson.build +1
-0@@ -119,6 +119,31 @@ foreach flag: arch_config['machine_args'] endif endforeach +# check if we can do buildtime detection of extensions supported by thetarget
config/riscv/meson.build +6
-0+riscv_extension_macros = false +if (cc.get_define('__riscv_arch_test', args: machine_args) == '1') + message('Detected architecture extension test macros') + riscv_extension_macros = true +else + warning('RISC-V architecture extension test macros not available.Build-time detection of extensions not possible')
config/riscv/meson.build +8
-0+endif + +# detect extensions +# Requires intrinsics available in GCC 14.1.0+ and Clang 18.1.0+ +if (riscv_extension_macros and + (cc.get_define('__riscv_vector', args: machine_args) != '')) + if ((cc.get_id() == 'gcc' and cc.version().version_compare('>=14.1.0')) + or (cc.get_id() == 'clang' andcc.version().version_compare('>=18.1.0')))
config/riscv/meson.build +2
-0+ if (cc.compiles('''#include <riscv_vector.h> + int main(void) { size_t vl = __riscv_vsetvl_e32m1(1); }''', args:
machine_args))config/riscv/meson.build +5
-0+ message('Compiling with the V extension') + machine_args += ['-DRTE_RISCV_FEATURE_V'] + endif + else + warning('Detected V extension but cannot use because intrinsics arenot available (present in GCC 14.1.0+ and Clang 18.1.0+)')
config/riscv/meson.build +3
-0+ endif +endif + # apply flags foreach flag: dpdk_flags if flag.length() > 0lib/eal/riscv/include/rte_vect.h +4
-1@@ -11,6 +11,10 @@#include "generic/rte_vect.h" #include "rte_common.h" +#ifdef RTE_RISCV_FEATURE_V +#include <riscv_vector.h> +#endif +#ifdef __cplusplusextern "C" {#endif --2.50.0
孙越池
Reviewed-by Stanisław KardachRe: Re: [PATCH v2 1/5] config/riscv: detect V extension
Hi,
Just checking if this patch might be merged soon, since there haven’t been any change requests for a while.
-----原始邮件-----
发件人:"Stanisław Kardach" <[email protected]>
发送时间:2025-08-12 17:21:53 (星期二)
收件人: [email protected]
抄送: [email protected], "Sun Yuechi" <[email protected]>, "Thomas Monjalon" <[email protected]>, "Bruce Richardson" <[email protected]> 主题: Re: [PATCH v2 1/5] config/riscv: detect V extension
On Tue, 1 Jul 2025, 20:21 , <[email protected]> wrote:
From: Sun Yuechi <[email protected]>
This patch is derived from "config/riscv: detect presence of Zbc extension with modifications".
The RISC-V C api defines architecture extension test macros These let us detect whether the V extension is supported on the compiler and -march we're building with. The C api also defines V intrinsics we can use rather than inline assembly on newer versions of GCC (14.1.0+) and Clang (18.1.0+).
If the V extension and intrinsics are both present and we can detect the V extension at runtime, we define a flag, RTE_RISCV_FEATURE_V.
--- .mailmap | 1 + config/riscv/meson.build | 25 +++++++++++++++++++++++++ lib/eal/riscv/include/rte_vect.h | 4 ++++ 3 files changed, 30 insertions(+)
.mailmap +1 -0
@@ -1513,6 +1513,7 @@ Sunil Kumar Kori <[email protected]> <[email protected]> <[email protected]> Sunil Pai G <[email protected]> Sunil Uttarwar <[email protected]> Sun Jiajia <[email protected]> +Sun Yuechi <[email protected]> <[email protected]> Sunyang Wu <[email protected]> Surabhi Boob <[email protected]> Suyang Ju <[email protected]>
config/riscv/meson.build +25 -0
@@ -119,6 +119,31 @@ foreach flag: arch_config['machine_args'] endif endforeach +# check if we can do buildtime detection of extensions supported by the target +riscv_extension_macros = false +if (cc.get_define('__riscv_arch_test', args: machine_args) == '1') + message('Detected architecture extension test macros') + riscv_extension_macros = true +else + warning('RISC-V architecture extension test macros not available. Build-time detection of extensions not possible') +endif + +# detect extensions +# Requires intrinsics available in GCC 14.1.0+ and Clang 18.1.0+ +if (riscv_extension_macros and + (cc.get_define('__riscv_vector', args: machine_args) != '')) + if ((cc.get_id() == 'gcc' and cc.version().version_compare('>=14.1.0')) + or (cc.get_id() == 'clang' and cc.version().version_compare('>=18.1.0'))) + if (cc.compiles('''#include <riscv_vector.h> + int main(void) { size_t vl = __riscv_vsetvl_e32m1(1); }''', args: machine_args)) + message('Compiling with the V extension') + machine_args += ['-DRTE_RISCV_FEATURE_V'] + endif + else + warning('Detected V extension but cannot use because intrinsics are not available (present in GCC 14.1.0+ and Clang 18.1.0+)') + endif +endif + # apply flags foreach flag: dpdk_flags if flag.length() > 0
lib/eal/riscv/include/rte_vect.h +4 -0
@@ -11,6 +11,10 @@#include "generic/rte_vect.h" #include "rte_common.h" +#ifdef RTE_RISCV_FEATURE_V +#include <riscv_vector.h> +#endif +#ifdef __cplusplusextern "C" {#endif
--
2.50.0
PATCH v2 2/5 eal/riscv/spinlock: add rte_cpuflag.h
In reply to a message not in the archiveFrom: Sun Yuechi <[email protected]>
Same as the x86 style, include "rte_cpuflags.h" in rte_spinlock.h so that files like lib/fib/dir24_8.c don’t need to include it.
--- lib/eal/riscv/include/rte_spinlock.h | 1 + 1 file changed, 1 insertion(+)
lib/eal/riscv/include/rte_spinlock.h +1 -0
@@ -14,6 +14,7 @@#include <rte_common.h> #include "generic/rte_spinlock.h" +#include "rte_cpuflags.h" #ifdef __cplusplusextern "C" {
Signature · 1 line
2.50.0
Quoted 7 lines · On Tue, 1 Jul 2025, 20:20 , <[email protected]> wrote:
From: Sun Yuechi <[email protected]>
Same as the x86 style, include "
rte_cpuflags.h" inrte_spinlock.hso that files likelib/fib/dir24_8.cdon’t need to include it.Signed-off-by Sun Yuechi <[email protected]>
Quoted 21 lines
--- lib/eal/riscv/include/rte_spinlock.h | 1 + 1 file changed, 1 insertion(+)lib/eal/riscv/include/rte_spinlock.h +1
-1@@ -14,6 +14,7 @@#include <rte_common.h> #include "generic/rte_spinlock.h" +#include "rte_cpuflags.h" #ifdef __cplusplusextern "C" { --2.50.0
01/07/2025 20:20, [email protected]:
Quoted 6 lines
From: Sun Yuechi <[email protected]>
Same as the x86 style, include "
rte_cpuflags.h" inrte_spinlock.hso that files likelib/fib/dir24_8.cdon’t need to include it.Signed-off-by Sun Yuechi <[email protected]>
I disagree.
I prefer removing useless includes like in x86 spinlock.
Okay, I initially thought this was common practice across all architectures, but it turns out only x86 added #include "rte_cpuflags.h" here. I’ve now moved it to lib/fib/dir24_8_rvv.h and updated v3.
> -----原始邮件-----
> 发件人: "Thomas Monjalon" <[email protected]>
> 发送时间: 2025-09-19 23:13:19 (星期五)
> 收件人: "Sun Yuechi" <[email protected]>
> 抄送: [email protected], "Stanislaw Kardach" <[email protected]>, [email protected]
> 主题: Re: [PATCH v2 2/5] eal/riscv/spinlock: add rte_cpuflag.h
>
> 01/07/2025 20:20, [email protected]:
> > From: Sun Yuechi <[email protected]>
> >
> > Same as the x86 style, include "rte_cpuflags.h" in rte_spinlock.h
> > so that files like lib/fib/dir24_8.c don’t need to include it.
> >
> > Signed-off-by: Sun Yuechi <[email protected]>
>
> I disagree.
> I prefer removing useless includes like in x86 spinlock.
> </[email protected]></[email protected]></[email protected]></[email protected]></[email protected]>
PATCH v2 3/5 lib/lpm: R-V V rte_lpm_lookupx4
In reply to a message not in the archiveFrom: Sun Yuechi <[email protected]>
Implement LPM lookupx4 function for RISC-V architecture using RISC-V Vector Extension instruction set
--- MAINTAINERS | 2 ++ lib/lpm/meson.build | 1 + lib/lpm/rte_lpm.h | 2 ++ lib/lpm/rte_lpm_rvv.h | 59 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 lib/lpm/rte_lpm_rvv.h
MAINTAINERS +2 -0
@@ -341,6 +341,8 @@ M: Stanislaw Kardach <[email protected]> F: config/riscv/ F: doc/guides/linux_gsg/cross_build_dpdk_for_riscv.rst F: lib/eal/riscv/ +M: sunyuechi <[email protected]> +F: lib/**/*rvv* Intel x86 M: Bruce Richardson <[email protected]>
lib/lpm/meson.build +1 -0
@@ -11,6 +11,7 @@ indirect_headers += files( 'rte_lpm_scalar.h', 'rte_lpm_sse.h', 'rte_lpm_sve.h', + 'rte_lpm_rvv.h', ) deps += ['hash'] deps += ['rcu']
lib/lpm/rte_lpm.h +2 -0
@@ -420,6 +420,8 @@ rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4],#include "rte_lpm_altivec.h" #elif defined(RTE_ARCH_X86 )#include "rte_lpm_sse.h" +#elif defined(RTE_ARCH_RISCV ) && defined(RTE_RISCV_FEATURE_V ) +#include "rte_lpm_rvv.h" #else #include "rte_lpm_scalar.h" #endif
lib/lpm/rte_lpm_rvv.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.50.0
Re: [PATCH v2 3/5] lib/lpm: R-V V rte_lpm_lookupx4
Quoted 7 lines · On Tue, 1 Jul 2025, 20:20 , <[email protected]> wrote:
From: Sun Yuechi <[email protected]>
Implement LPM lookupx4 function for RISC-V architecture using RISC-V Vector Extension instruction set
Signed-off-by Sun Yuechi <[email protected]>
Quoted 124 lines
--- MAINTAINERS | 2 ++ lib/lpm/meson.build | 1 + lib/lpm/rte_lpm.h | 2 ++ lib/lpm/rte_lpm_rvv.h | 59 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 lib/lpm/rte_lpm_rvv.hMAINTAINERS +2
-0@@ -341,6 +341,8 @@ M: Stanislaw Kardach <[email protected]> F: config/riscv/ F: doc/guides/linux_gsg/cross_build_dpdk_for_riscv.rst F: lib/eal/riscv/ +M: sunyuechi <[email protected]> +F: lib/**/*rvv* Intel x86 M: Bruce Richardson <[email protected]>lib/lpm/meson.build +1
-0@@ -11,6 +11,7 @@ indirect_headers += files( 'rte_lpm_scalar.h', 'rte_lpm_sse.h', 'rte_lpm_sve.h', + 'rte_lpm_rvv.h', ) deps += ['hash'] deps += ['rcu']lib/lpm/rte_lpm.h +2
-0@@ -420,6 +420,8 @@ rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4],#include "rte_lpm_altivec.h" #elif defined(RTE_ARCH_X86 )#include "rte_lpm_sse.h" +#elif defined(RTE_ARCH_RISCV ) && defined(RTE_RISCV_FEATURE_V ) +#include "rte_lpm_rvv.h" #else #include "rte_lpm_scalar.h" #endif
lib/lpm/rte_lpm_rvv.h new file +2
-0@@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS).
+ */lib/lpm/rte_lpm_rvv.h new file +15
-0+ +#ifndef _RTE_LPM_RVV_H_ +#define _RTE_LPM_RVV_H_ + +#include <rte_vect.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define RTE_LPM_LOOKUP_SUCCESS 0x01000000 +#define RTE_LPM_VALID_EXT_ENTRY_BITMASK 0x03000000 + +static inline void rte_lpm_lookupx4( + const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], uint32_tdefv)
lib/lpm/rte_lpm_rvv.h new file +14
-0+{ +size_t vl =4 ; + +const uint32_t *tbl24_p = (const uint32_t *)lpm->tbl24; +uint32_t tbl_entries[4 ] = { + tbl24_p[((uint32_t )ip[0 ]) >>8 ], + tbl24_p[((uint32_t )ip[1 ]) >>8 ], + tbl24_p[((uint32_t )ip[2 ]) >>8 ], + tbl24_p[((uint32_t )ip[3 ]) >>8 ], + }; +vuint32m1_t vtbl_entry =__riscv_vle32_v_u32m1 (tbl_entries, vl); + + vbool32_t mask = __riscv_vmseq_vx_u32m1_b32( + __riscv_vand_vx_u32m1(vtbl_entry,
RTE_LPM_VALID_EXT_ENTRY_BITMASK, vl),lib/lpm/rte_lpm_rvv.h new file +5
-0+ RTE_LPM_VALID_EXT_ENTRY_BITMASK, vl); + + vuint32m1_t vtbl8_index = __riscv_vsll_vx_u32m1( + __riscv_vadd_vv_u32m1( + __riscv_vsll_vx_u32m1(__riscv_vand_vx_u32m1(vtbl_entry,
0x00FFFFFF, vl), 8, vl),lib/lpm/rte_lpm_rvv.h new file +2
-0+ __riscv_vand_vx_u32m1( + __riscv_vle32_v_u32m1((const uint32_t *)&ip, vl),
0x000000FF, vl),lib/lpm/rte_lpm_rvv.h new file +5
-0+ vl), + 2, vl); + + vtbl_entry = __riscv_vluxei32_v_u32m1_mu( + mask, vtbl_entry, (const uint32_t *)(lpm->tbl8), vtbl8_index,vl);
lib/lpm/rte_lpm_rvv.h new file +2
-0+ + vuint32m1_t vnext_hop = __riscv_vand_vx_u32m1(vtbl_entry,
0x00FFFFFF, vl);lib/lpm/rte_lpm_rvv.h new file +2
-0+ mask = __riscv_vmseq_vx_u32m1_b32( + __riscv_vand_vx_u32m1(vtbl_entry, RTE_LPM_LOOKUP_SUCCESS, vl),0, vl);
lib/lpm/rte_lpm_rvv.h new file +11
-1+ + vnext_hop =__riscv_vmerge_vxm_u32m1 (vnext_hop, defv, mask, vl); + +__riscv_vse32_v_u32m1 (hop, vnext_hop, vl); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_LPM_RVV_H_ */ --2.50.0
PATCH v2 4/5 lib/fib: R-V V rte_fib_lookup_bulk
In reply to a message not in the archiveFrom: Sun Yuechi <[email protected]>
Implement rte_fib_lookup_bulk function for RISC-V architecture using RISC-V Vector Extension instruction set
--- lib/fib/dir24_8.c | 20 ++++++++++++++ lib/fib/dir24_8_rvv.c | 64 +++++++++++++++++++++++++++++++++++++++++++ lib/fib/dir24_8_rvv.h | 24 ++++++++++++++++ lib/fib/meson.build | 2 ++ 4 files changed, 110 insertions(+) create mode 100644 lib/fib/dir24_8_rvv.c create mode 100644 lib/fib/dir24_8_rvv.h
lib/fib/dir24_8.c +20 -0
@@ -20,6 +20,10 @@#include "dir24_8_avx512.h" +#elif defined(RTE_RISCV_FEATURE_V ) + +#include "dir24_8_rvv.h" +#endif /* CC_AVX512_SUPPORT */ #define DIR24_8_NAMESIZE 64
@@ -88,6 +92,22 @@ get_vector_fn(enum rte_fib_dir24_8_nh_sz nh_sz, bool be_addr)default : return NULL; } +#elif defined(RTE_RISCV_FEATURE_V) +RTE_SET_USED (be_addr); +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_RISCV_ISA_V ) <=0 ) +return NULL ; +switch (nh_sz) { +case RTE_FIB_DIR24_8_1B : +return rte_dir24_8_vec_lookup_bulk_1b; +case RTE_FIB_DIR24_8_2B : +return rte_dir24_8_vec_lookup_bulk_2b; +case RTE_FIB_DIR24_8_4B : +return rte_dir24_8_vec_lookup_bulk_4b; +case RTE_FIB_DIR24_8_8B : +return rte_dir24_8_vec_lookup_bulk_8b; +default : +return NULL ; + }#else RTE_SET_USED (nh_sz);RTE_SET_USED (be_addr);
lib/fib/dir24_8_rvv.c new file +64 -0
64 lines not on this page · raw message
lib/fib/dir24_8_rvv.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS). +*/ + +#ifndef _DIR248_RVV_H_ +#define _DIR248_RVV_H_ + +void +rte_dir24_8_vec_lookup_bulk_1b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_2b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_4b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_8b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +#endif /* _DIR248_RVV_H_ */
lib/fib/meson.build +2 -0
@@ -10,4 +10,6 @@ deps += ['net'] if dpdk_conf.has('RTE_ARCH_X86_64') sources_avx512 += files('dir24_8_avx512.c', 'trie_avx512.c') +elif dpdk_conf.has('RTE_ARCH_RISCV') + sources += files('dir24_8_rvv.c') endif
Signature · 1 line
2.50.0
Re: [PATCH v2 4/5] lib/fib: R-V V rte_fib_lookup_bulk
Quoted 7 lines · On Tue, 1 Jul 2025, 20:21 , <[email protected]> wrote:
From: Sun Yuechi <[email protected]>
Implement
rte_fib_lookup_bulkfunction for RISC-V architecture using RISC-V Vector Extension instruction setSigned-off-by Sun Yuechi <[email protected]>
From RISC-V perspective:
Quoted 180 lines
--- lib/fib/dir24_8.c | 20 ++++++++++++++ lib/fib/dir24_8_rvv.c | 64 +++++++++++++++++++++++++++++++++++++++++++ lib/fib/dir24_8_rvv.h | 24 ++++++++++++++++ lib/fib/meson.build | 2 ++ 4 files changed, 110 insertions(+) create mode 100644 lib/fib/dir24_8_rvv.c create mode 100644 lib/fib/dir24_8_rvv.hlib/fib/dir24_8.c +20
-0@@ -20,6 +20,10 @@#include "dir24_8_avx512.h" +#elif defined(RTE_RISCV_FEATURE_V ) + +#include "dir24_8_rvv.h" +#endif /* CC_AVX512_SUPPORT */ #define DIR24_8_NAMESIZE 64@@ -88,6 +92,22 @@ get_vector_fn(enum rte_fib_dir24_8_nh_sz nh_sz, bool be_addr)default : return NULL; } +#elif defined(RTE_RISCV_FEATURE_V) +RTE_SET_USED (be_addr); +if (rte_cpu_get_flag_enabled (RTE_CPUFLAG_RISCV_ISA_V ) <=0 ) +return NULL ; +switch (nh_sz) { +case RTE_FIB_DIR24_8_1B : +return rte_dir24_8_vec_lookup_bulk_1b; +case RTE_FIB_DIR24_8_2B : +return rte_dir24_8_vec_lookup_bulk_2b; +case RTE_FIB_DIR24_8_4B : +return rte_dir24_8_vec_lookup_bulk_4b; +case RTE_FIB_DIR24_8_8B : +return rte_dir24_8_vec_lookup_bulk_8b; +default : +return NULL ; + }#else RTE_SET_USED (nh_sz);RTE_SET_USED(be_addr);lib/fib/dir24_8_rvv.c new file +2
-0@@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS).
+ */lib/fib/dir24_8_rvv.c new file +26
-0+ +#if defined(RTE_RISCV_FEATURE_V ) + +#include <rte_vect.h> +#include <rte_fib.h> + +#include "dir24_8.h" +#include "dir24_8_rvv.h" + +#define DECLARE_VECTOR_FN (SFX ,NH_SZ ) \ +void \ +rte_dir24_8_vec_lookup_bulk_##SFX(void *p, \ + const uint32_t *ips, uint64_t *next_hops, unsigned int n) \ +{ \ + const uint8_t idx_bits = 3 - NH_SZ; \ + const uint32_t idx_mask = (1u << (3 - NH_SZ)) - 1u; \ + const uint64_t e_mask = ~0ULL >> (64 - (8u << NH_SZ)); \ + struct dir24_8_tbl *tbl = (struct dir24_8_tbl *)p; \ + const uint64_t *tbl24 = tbl->tbl24; \ + size_t vl; \ + for (unsigned int i = 0; i < n; i += vl) { \ + vl = __riscv_vsetvl_e32m4(n - i); \ + vuint32m4_t v_ips = __riscv_vle32_v_u32m4(&ips[i], vl); \ + vuint64m8_t vtbl_word = __riscv_vluxei32_v_u64m8(tbl24, \ + __riscv_vsll_vx_u32m4( \ + __riscv_vsrl_vx_u32m4(v_ips, idx_bits + 8,vl), 3, vl), vl); \
+vuint32m4_tv_tbl_index= __riscv_vsrl_vx_u32m4(v_ips, 8,
vl); \
+vuint32m4_tv_entry_idx=__riscv_vand_vx_u32m4(v_tbl_index, idx_mask, vl); \
+vuint32m4_tv_shift=__riscv_vsll_vx_u32m4(v_entry_idx, 3 + NH_SZ, vl); \lib/fib/dir24_8_rvv.c new file +5
-0+vuint64m8_t vtbl_entry =__riscv_vand_vx_u64m8 ( \ +__riscv_vsrl_vv_u64m8 (vtbl_word, \ +__riscv_vwcvtu_x_x_v_u64m8 (v_shift, vl), vl), e_mask, vl); \ + vbool8_t mask = __riscv_vmseq_vx_u64m8_b8( \ + __riscv_vand_vx_u64m8(vtbl_entry, 1, vl),1, vl); \
lib/fib/dir24_8_rvv.c new file +3
-0+if (__riscv_vcpop_m_b8 (mask, vl)) { \ +const uint64_t *tbl8 = tbl->tbl8; \ + v_tbl_index = __riscv_vadd_vv_u32m4_mu(mask,
v_tbl_index, \lib/fib/dir24_8_rvv.c new file +4
-0+__riscv_vsll_vx_u32m4 ( \ +__riscv_vnsrl_wx_u32m4 (vtbl_entry,1 , vl),8 , vl), \ + __riscv_vand_vx_u32m4(v_ips, 0xFF, vl), vl); \ + vtbl_word = __riscv_vluxei32_v_u64m8_mu(mask,
vtbl_word, tbl8, \lib/fib/dir24_8_rvv.c new file +2
-0+ __riscv_vsll_vx_u32m4( \ + __riscv_vsrl_vx_u32m4(v_tbl_index,
idx_bits, vl), 3, vl), \lib/fib/dir24_8_rvv.c new file +2
-0+ vl); \ + v_entry_idx = __riscv_vand_vx_u32m4(v_tbl_index,
idx_mask, vl); \lib/fib/dir24_8_rvv.c new file +8
-0+ v_shift = __riscv_vsll_vx_u32m4(v_entry_idx, 3 +NH_SZ , vl); \ + vtbl_entry =__riscv_vand_vx_u64m8 ( \ +__riscv_vsrl_vv_u64m8 (vtbl_word, \ +__riscv_vwcvtu_x_x_v_u64m8 (v_shift, vl), vl), e_mask, vl); \ + } \ + __riscv_vse64_v_u64m8(&next_hops[i], \ + __riscv_vsrl_vx_u64m8(vtbl_entry, 1, vl),vl); \
lib/fib/dir24_8_rvv.c new file +9
-0+ } \ +} + +DECLARE_VECTOR_FN(1b, 0) +DECLARE_VECTOR_FN(2b, 1) +DECLARE_VECTOR_FN(4b, 2) +DECLARE_VECTOR_FN (8b ,3 ) + +#endiflib/fib/dir24_8_rvv.h new file +2
-0@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2025 Institute of Software Chinese Academy of Sciences (ISCAS).
+ */lib/fib/dir24_8_rvv.h new file +21
-0+ +#ifndef _DIR248_RVV_H_ +#define _DIR248_RVV_H_ + +void +rte_dir24_8_vec_lookup_bulk_1b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_2b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_4b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +void +rte_dir24_8_vec_lookup_bulk_8b (void *p,const uint32_t *ips, +uint64_t *next_hops,const unsigned int n); + +#endif /* _DIR248_RVV_H_ */ lib/fib/meson.build +2
-1@@ -10,4 +10,6 @@ deps += ['net'] if dpdk_conf.has('RTE_ARCH_X86_64') sources_avx512 += files('dir24_8_avx512.c', 'trie_avx512.c') +elif dpdk_conf.has('RTE_ARCH_RISCV') + sources += files('dir24_8_rvv.c') endif --2.50.0
PATCH v2 5/5 riscv: override machine_args only when default
In reply to a message not in the archiveFrom: Sun Yuechi <[email protected]>
Support using -Dcpu_instruction_set=rv64gcv to enable V extension.
--- config/riscv/meson.build | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
config/riscv/meson.build +9 -7
@@ -111,13 +111,15 @@ arch_config = arch_config[arch_id] # Concatenate flags respecting priorities. dpdk_flags = flags_common + vendor_config['flags'] + arch_config.get('flags', []) -# apply supported machine args -machine_args = [] # Clear previous machine args -foreach flag: arch_config['machine_args'] - if cc.has_argument(flag) - machine_args += flag - endif -endforeach +if (cpu_instruction_set == 'rv64gc') + # apply supported machine args + machine_args = [] # Clear previous machine args + foreach flag: arch_config['machine_args'] + if cc.has_argument(flag) + machine_args += flag + endif + endforeach +endif # check if we can do buildtime detection of extensions supported by the target riscv_extension_macros = false
Signature · 1 line
2.50.0
Re: [PATCH v2 5/5] riscv: override machine_args only when default
Quoted 6 lines · On Tue, 1 Jul 2025, 20:21 , <[email protected]> wrote:
From: Sun Yuechi <[email protected]>
Support using -Dcpu_instruction_set=rv64gcv to enable V extension.
Signed-off-by Sun Yuechi <[email protected]>
Quoted 37 lines
--- config/riscv/meson.build | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)config/riscv/meson.build +9
-7@@ -111,13 +111,15 @@ arch_config = arch_config[arch_id] # Concatenate flags respecting priorities. dpdk_flags = flags_common + vendor_config['flags'] + arch_config.get('flags', []) -# apply supported machine args -machine_args = [] # Clear previous machine args -foreach flag: arch_config['machine_args'] - if cc.has_argument(flag) - machine_args += flag - endif -endforeach +if (cpu_instruction_set == 'rv64gc') + # apply supported machine args + machine_args = [] # Clear previous machine args + foreach flag: arch_config['machine_args'] + if cc.has_argument(flag) + machine_args += flag + endif + endforeach +endif # check if we can do buildtime detection of extensions supported by thetarget
riscv_extension_macros= false
--
2.50.0