1717#include "distance-sse2.h"
1818#include "distance-avx2.h"
1919#include "distance-avx512.h"
20+ #include "distance-rvv.h"
2021
2122const char * distance_backend_name = "CPU" ;
2223distance_function_t dispatch_distance_table [VECTOR_DISTANCE_MAX ][VECTOR_TYPE_MAX ] = {0 };
@@ -828,7 +829,14 @@ float bit1_distance_hamming_cpu (const void *v1, const void *v2, int n) {
828829 x86_cpuid (1 , 0 , & eax , & ebx , & ecx , & edx );
829830 return (edx & (1 << 26 )) != 0 ; // SSE2
830831 }
831-
832+ #elif defined(__riscv ) || defined(__riscv__ )
833+ #include <sys/auxv.h>
834+ #define ISA_V_HWCAP (1 << ('v' - 'a'))
835+
836+ bool cpu_supports_rvv (void ) {
837+ unsigned long hw_cap = getauxval (AT_HWCAP );
838+ return (hw_cap & ISA_V_HWCAP ) != 0 ;
839+ }
832840#else
833841 // For ARM (NEON is always present on aarch64, runtime detection rarely needed)
834842 #if defined(__aarch64__ ) || defined(__ARM_NEON ) || defined(__ARM_NEON__ )
@@ -844,7 +852,7 @@ float bit1_distance_hamming_cpu (const void *v1, const void *v2, int n) {
844852 #include <sys/auxv.h>
845853 #include <asm/hwcap.h>
846854 bool cpu_supports_neon (void ) {
847- #ifdef AT_HWCAP
855+ #if defined( AT_HWCAP ) && defined( HWCAP_NEON )
848856 return (getauxval (AT_HWCAP ) & HWCAP_NEON ) != 0 ;
849857 #else
850858 return false;
@@ -919,6 +927,10 @@ void init_distance_functions (bool force_cpu) {
919927 if (cpu_supports_neon ()) {
920928 init_distance_functions_neon ();
921929 }
930+ #elif defined(__riscv ) || defined(__riscv__ )
931+ if (cpu_supports_rvv ()) {
932+ init_distance_functions_rvv ();
933+ }
922934 #endif
923935}
924936
0 commit comments