From 89f2b634df9fe9aa2b08f00a739aa6cc11418dbd Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Tue, 2 Sep 2025 13:06:25 -0400 Subject: [PATCH] guarding from benchmark + rvv --- .github/workflows/rvv-1024-clang-18.yml | 29 +++++++++++++++++++++ .github/workflows/rvv-128-clang-17.yml | 29 +++++++++++++++++++++ .github/workflows/rvv-256-gcc-14.yml | 29 +++++++++++++++++++++ benchmark/from/CMakeLists.txt | 5 ++-- cmake/toolchains-ci/riscv64-linux-gnu.cmake | 4 +++ include/simdjson/portability.h | 16 ++++++++++++ 6 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/rvv-1024-clang-18.yml create mode 100644 .github/workflows/rvv-128-clang-17.yml create mode 100644 .github/workflows/rvv-256-gcc-14.yml create mode 100644 cmake/toolchains-ci/riscv64-linux-gnu.cmake diff --git a/.github/workflows/rvv-1024-clang-18.yml b/.github/workflows/rvv-1024-clang-18.yml new file mode 100644 index 000000000..4ba16d02b --- /dev/null +++ b/.github/workflows/rvv-1024-clang-18.yml @@ -0,0 +1,29 @@ +name: Ubuntu rvv VLEN=1024 (clang 18) + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Install packages + run: | + sudo apt-get update -q -y + sudo apt-get install -y cmake make g++-riscv64-linux-gnu qemu-user-static clang-18 + - name: Build + run: | + CXX=clang++-18 CXXFLAGS="--target=riscv64-linux-gnu -march=rv64gcv_zvbb" \ + cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -B build + cmake --build build/ -j$(nproc) + - name: Test VLEN=1024 + run: | + export QEMU_LD_PREFIX="/usr/riscv64-linux-gnu" + export QEMU_CPU="rv64,v=on,zvbb=on,vlen=1024,rvv_ta_all_1s=on,rvv_ma_all_1s=on" + ctest --timeout 1800 --output-on-failure --test-dir build -j $(nproc) diff --git a/.github/workflows/rvv-128-clang-17.yml b/.github/workflows/rvv-128-clang-17.yml new file mode 100644 index 000000000..65c6b794e --- /dev/null +++ b/.github/workflows/rvv-128-clang-17.yml @@ -0,0 +1,29 @@ +name: Ubuntu rvv VLEN=128 (clang 17) + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Install packages + run: | + sudo apt-get update -q -y + sudo apt-get install -y cmake make g++-riscv64-linux-gnu qemu-user-static clang-17 + - name: Build + run: | + CXX=clang++-17 CXXFLAGS="--target=riscv64-linux-gnu -march=rv64gcv" \ + cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -B build + cmake --build build/ -j$(nproc) + - name: Test VLEN=128 + run: | + export QEMU_LD_PREFIX="/usr/riscv64-linux-gnu" + export QEMU_CPU="rv64,v=on,vlen=128,rvv_ta_all_1s=on,rvv_ma_all_1s=on" + ctest --timeout 1800 --output-on-failure --test-dir build -j $(nproc) diff --git a/.github/workflows/rvv-256-gcc-14.yml b/.github/workflows/rvv-256-gcc-14.yml new file mode 100644 index 000000000..f21730a2e --- /dev/null +++ b/.github/workflows/rvv-256-gcc-14.yml @@ -0,0 +1,29 @@ +name: Ubuntu rvv VLEN=256 (gcc 14) + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + build: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - name: Install packages + run: | + sudo apt-get update -q -y + sudo apt-get install -y cmake make g++-14-riscv64-linux-gnu qemu-user-static + - name: Build + run: | + CXX=riscv64-linux-gnu-g++-14 CXXFLAGS=-march=rv64gcv \ + cmake --toolchain=cmake/toolchains-ci/riscv64-linux-gnu.cmake -DCMAKE_BUILD_TYPE=Release -B build + cmake --build build/ -j$(nproc) + - name: Test VLEN=256 + run: | + export QEMU_LD_PREFIX="/usr/riscv64-linux-gnu" + export QEMU_CPU="rv64,v=on,zvbb=on,vlen=256,rvv_ta_all_1s=on,rvv_ma_all_1s=on" + ctest --timeout 1800 --output-on-failure --test-dir build -j $(nproc) diff --git a/benchmark/from/CMakeLists.txt b/benchmark/from/CMakeLists.txt index 67e25524d..cccf31d81 100644 --- a/benchmark/from/CMakeLists.txt +++ b/benchmark/from/CMakeLists.txt @@ -2,8 +2,9 @@ add_executable(from_benchmark from_benchmark.cpp) # Compile for C++20. -target_compile_features(from_benchmark PRIVATE cxx_std_20) - +if(CMAKE_CXX_STANDARD LESS 20) + target_compile_features(from_benchmark PRIVATE cxx_std_20) +endif() # Check if -march=native is supported include(CheckCXXCompilerFlag) check_cxx_compiler_flag("-march=native" SIMDJSON_SUPPORTS_MARCH_NATIVE) diff --git a/cmake/toolchains-ci/riscv64-linux-gnu.cmake b/cmake/toolchains-ci/riscv64-linux-gnu.cmake new file mode 100644 index 000000000..ed58a2dba --- /dev/null +++ b/cmake/toolchains-ci/riscv64-linux-gnu.cmake @@ -0,0 +1,4 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR riscv64) + +set(CMAKE_CROSSCOMPILING_EMULATOR "qemu-riscv64-static") diff --git a/include/simdjson/portability.h b/include/simdjson/portability.h index ca0e8dfa0..cfe1c1357 100644 --- a/include/simdjson/portability.h +++ b/include/simdjson/portability.h @@ -45,6 +45,22 @@ using std::size_t; #define SIMDJSON_IS_ARM64 1 #elif defined(__riscv) && __riscv_xlen == 64 #define SIMDJSON_IS_RISCV64 1 + #if __riscv_v_intrinsic >= 11000 + #define SIMDJSON_HAS_RVV_INTRINSICS 1 + #endif + + #define SIMDJSON_HAS_ZVBB_INTRINSICS \ + 0 // there is currently no way to detect this + + #if SIMDJSON_HAS_RVV_INTRINSICS && __riscv_vector && \ + __riscv_v_min_vlen >= 128 && __riscv_v_elen >= 64 + // RISC-V V extension + #define SIMDJSON_IS_RVV 1 + #if SIMDJSON_HAS_ZVBB_INTRINSICS && __riscv_zvbb >= 1000000 + // RISC-V Vector Basic Bit-manipulation + #define SIMDJSON_IS_ZVBB 1 + #endif + #endif #elif defined(__loongarch_lp64) #define SIMDJSON_IS_LOONGARCH64 1 #elif defined(__PPC64__) || defined(_M_PPC64)