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

Add cmake check for deducing 32bit or 64bit RISCV #2330

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 34 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ if(CHECK_PIE_SUPPORTED)
endif()
endif()

include(CheckCSourceCompiles)

check_c_source_compiles("
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good.
Would you mind making one minor change, wrapping this in something like if (CMAKE_CXX_COMPILER_ARCHITECTURE_ID MATCHES "RISCV32|RISCV64|RISCV128" OR CMAKE_SYSTEM_PROCESSOR MATCHES "riscv32|riscv64|riscv128")) so we do not get extra output on non-RISCV platforms?

#if __riscv_xlen == 64
int main() { return 0; }
#else
#error Not RISCV-64
#endif
" IS_RISCV_XLEN_64)

check_c_source_compiles("
#if __riscv_xlen == 32
int main() { return 0; }
#else
#error Not RISCV-32
#endif
" IS_RISCV_XLEN_32)

if(IS_RISCV_XLEN_32)
set(RISCV_XLEN 32)
elseif(IS_RISCV_XLEN_64)
set(RISCV_XLEN 64)
else()
message(WARNING "Unable to determine RISC-V XLEN")
endif()

include(GNUInstallDirs)

if (NOT CMAKE_BUILD_TYPE)
Expand All @@ -72,7 +98,7 @@ set(HWY_CMAKE_ARM7 OFF CACHE BOOL "Set copts for Armv7 with NEON (requires vfpv4
# skipped. For GCC 13.1+, you can also build with -fexcess-precision=standard.
set(HWY_CMAKE_SSE2 OFF CACHE BOOL "Set SSE2 as baseline for 32-bit x86?")

# Currently this will compile the entire codebase with `-march=rv64gcv1p0`:
# Currently this will compile the entire codebase with `-march=rv<XLEN>gcv1p0`:
set(HWY_CMAKE_RVV ON CACHE BOOL "Set copts for RISCV with RVV?")

# Unconditionally adding -Werror risks breaking the build when new warnings
Expand Down Expand Up @@ -378,8 +404,13 @@ else()
# we add the gcv compiler flag, which then requires the CPU (now when using
# either compiler) to support V.
if(HWY_CMAKE_RVV)
list(APPEND HWY_FLAGS -march=rv64gcv1p0)
add_link_options(-march=rv64gcv1p0)
if(RISCV_XLEN EQUAL 64)
list(APPEND HWY_FLAGS -march=rv64gcv1p0)
add_link_options(-march=rv64gcv1p0)
elseif(RISCV_XLEN EQUAL 32)
list(APPEND HWY_FLAGS -march=rv32gcv1p0)
add_link_options(-march=rvgcv1p0)
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
list(APPEND HWY_FLAGS -menable-experimental-extensions)
endif()
Expand Down
Loading