Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add support for riscv64 architecture #1333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(CMAKE_REQUIRED_FLAGS ${CMAKE_C_FLAGS})

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DIS_RISCV64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIS_RISCV64")
set(DISABLE_SIMD ON)
endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "riscv64")

if(NOT HAVE_SSE AND NOT HAVE_NEON AND NOT DISABLE_SIMD)
message(FATAL_ERROR "no SIMD instructions found")
endif(NOT HAVE_SSE AND NOT HAVE_NEON AND NOT DISABLE_SIMD)
Expand Down
13 changes: 12 additions & 1 deletion lib/src/common/arch_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <stdio.h>
#include <sys/auxv.h>
#define USER_HWCAP_NEON (1 << 12)
#elif IS_RISCV64
// No SIMD implementation
#else
#include <cpuid.h>
#define X86_CPUID_BASIC_LEAF 1
Expand All @@ -38,7 +40,7 @@

#define MAX_CMD_LEN (64)

#ifndef IS_ARM
#if !defined(IS_ARM) && !defined(IS_RISCV64)
static __inline int __get_cpuid_count_redef(unsigned int __leaf,
unsigned int __subleaf,
unsigned int* __eax,
Expand Down Expand Up @@ -105,11 +107,20 @@ const char* arm_get_isa()
}
#endif

#ifdef IS_RISCV64
const char* riscv_get_isa()
{
return "generic";
}
#endif

int main(int argc, char* argv[])
{
char cmd[MAX_CMD_LEN];
#ifdef IS_ARM
snprintf(cmd, MAX_CMD_LEN, "%s-%s", argv[0], arm_get_isa());
#elif IS_RISCV64
snprintf(cmd, MAX_CMD_LEN, "%s-%s", argv[0], riscv_get_isa());
#else
snprintf(cmd, MAX_CMD_LEN, "%s-%s", argv[0], x86_get_isa());
#endif
Expand Down