Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ else # linux
STRIP = strip --strip-unneeded $@
endif

# For RISC-V pass through the arch string directly to march
ifneq (,$(findstring rv64,$(ARCH)))
LDFLAGS += -march=$(ARCH)
CFLAGS += -march=$(ARCH)
endif

# Windows .def file generation
$(DEF_FILE):
ifeq ($(PLATFORM),windows)
Expand Down
16 changes: 14 additions & 2 deletions src/distance-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "distance-sse2.h"
#include "distance-avx2.h"
#include "distance-avx512.h"
#include "distance-rvv.h"

const char *distance_backend_name = "CPU";
distance_function_t dispatch_distance_table[VECTOR_DISTANCE_MAX][VECTOR_TYPE_MAX] = {0};
Expand Down Expand Up @@ -828,7 +829,14 @@ float bit1_distance_hamming_cpu (const void *v1, const void *v2, int n) {
x86_cpuid(1, 0, &eax, &ebx, &ecx, &edx);
return (edx & (1 << 26)) != 0; // SSE2
}

#elif defined(__riscv) || defined(__riscv__)
#include <sys/auxv.h>
#define ISA_V_HWCAP (1 << ('v' - 'a'))

bool cpu_supports_rvv (void) {
unsigned long hw_cap = getauxval(AT_HWCAP);
return (hw_cap & ISA_V_HWCAP) != 0;
}
#else
// For ARM (NEON is always present on aarch64, runtime detection rarely needed)
#if defined(__aarch64__) || defined(__ARM_NEON) || defined(__ARM_NEON__)
Expand All @@ -844,7 +852,7 @@ float bit1_distance_hamming_cpu (const void *v1, const void *v2, int n) {
#include <sys/auxv.h>
#include <asm/hwcap.h>
bool cpu_supports_neon (void) {
#ifdef AT_HWCAP
#if defined(AT_HWCAP) && defined(HWCAP_NEON)
return (getauxval(AT_HWCAP) & HWCAP_NEON) != 0;
#else
return false;
Expand Down Expand Up @@ -919,6 +927,10 @@ void init_distance_functions (bool force_cpu) {
if (cpu_supports_neon()) {
init_distance_functions_neon();
}
#elif defined(__riscv) || defined(__riscv__)
if (cpu_supports_rvv()) {
init_distance_functions_rvv();
}
#endif
}

Loading