Add RISC-V scalar compatibility shim#38
Open
carlosqwqqwq wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
simdcompcurrently supports x86/x64 through SSE/AVX and ARM through the in-treeneon128.hshim, but it has no clean portability path forriscv64. The core 128-bit kernels are already shared across architectures; the real blocker is that the build and headers still assume either x86 intrinsics or ARM NEON. As a result, ariscv64target cannot select a conservative non-x86 compatibility layer even though the project's wider AVX2/AVX-512 files are already isolated behind x86-only feature macros.What changed
include/riscv128.h, a small self-contained scalar implementation of the subset of SSE2/SSSE3/SSE4.1 intrinsics thatsimdcompactually uses.include/portability.hso__riscvselects that shim instead of falling through to<x86intrin.h>, and exposed the minimal SSE feature macros required by the existing 128-bit source paths.<emmintrin.h>or<smmintrin.h>.CMakeLists.txtto recognizeriscv*targets, skip-march=nativethere, and inject__riscv=1/__riscv_xlen=64for simulated target validation when a real RISC-V cross toolchain is not present.README.mdto document that RISC-V currently uses a conservative scalar compatibility backend rather than RVV acceleration.Verification
cmake -S . -B build-native -G Ninja -DSIMDCOMP_BUILD_TESTS=OFF -DSIMDCOMP_BUILD_EXAMPLES=OFF -DSIMDCOMP_BUILD_BENCHMARKS=OFFcmake --build build-native --parallel 4cmake -S . -B build-native-tests -G Ninja -DSIMDCOMP_BUILD_TESTS=ON -DSIMDCOMP_BUILD_EXAMPLES=OFF -DSIMDCOMP_BUILD_BENCHMARKS=OFFcmake --build build-native-tests --parallel 4ctest --test-dir build-native-tests --output-on-failureriscv64CMake configure/build successfully:cmake -S . -B build-riscv-sim -G Ninja -DSIMDCOMP_BUILD_TESTS=OFF -DSIMDCOMP_BUILD_EXAMPLES=OFF -DSIMDCOMP_BUILD_BENCHMARKS=OFF -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=riscv64 -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY -DSIMDCOMP_NATIVE=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ONcmake --build build-riscv-sim --parallel 4riscv64configure step reportsRISC-V target detected; using scalar 128-bit compatibility shim.build-riscv-sim/build.ninjaandbuild-riscv-sim/compile_commands.json:-D__riscv=1 -D__riscv_xlen=64-march=native,-msse*,-mavx*,-march=arm*,-mfpu, or-mrvvinclude/portability.hwith forced__riscvmacros and confirmed it resolves throughinclude/riscv128.h, while exposing__SSE2__,__SSSE3__,__SSE4_1__, and__SSE4_2__but not__AVX2__or__AVX512F__.__riscvsmoke compiles successfully for:src/simdbitpacking.csrc/simdintegratedbitpacking.csrc/simdcomputil.csrc/simdpackedsearch.csrc/simdpackedselect.criscv64cross-build and runtime path indockcross/linux-riscv64:CMAKE_C_COMPILER="$CC",CMAKE_SYSTEM_NAME=Linux,CMAKE_SYSTEM_PROCESSOR=riscv64,CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY,SIMDCOMP_BUILD_TESTS=ON,SIMDCOMP_BUILD_EXAMPLES=ON,SIMDCOMP_BUILD_BENCHMARKS=OFF, andSIMDCOMP_NATIVE=OFF;example,unit, andunit_charssuccessfully with/usr/xcc/riscv64-unknown-linux-gnu/bin/riscv64-unknown-linux-gnu-gcc.filereportsELF 64-bit LSB executable, UCB RISC-V, RVC, double-float ABIforexample;readelf -hreportsMachine: RISC-V.riscv64build does not rely on host ISA tuning flags:build.ninjacontains no-march=native,-msse*,-mavx*,-mfpu=neon, orarm_neon.libsimdcomp.astill containsavxbitpacking.c.oandavx512bitpacking.c.omembers, butriscv64-unknown-linux-gnu-nmfinds noavxsymbols in the archive.qemu-riscv64successfully:examplecompleted the compression/decompression demos and printedCode works!;unitcompleted and printedAll tests OK!;unit_charscompleted and printedCode looks good.Notes
This is a conservative portability patch. It does not add RVV or any dedicated RISC-V vector optimization backend. The goal is to let
riscv64build and validate cleanly against the existing 128-bit kernel API without leaking x86-specific headers or-march=nativeassumptions into the RISC-V path. Validation now includes a realriscv64cross-build andqemu-riscv64execution of the example and unit-test binaries, but it still does not include RVV coverage or real RISC-V hardware testing.