Add riscv64 scalar-path support#250
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
RTM already has a portable scalar fallback, but it does not currently recognize
riscv64as an explicit architecture in its public detection headers or developer build entrypoints. In addition, intrinsic auto-detection inrtm/math.hrelies on host compiler SIMD macros directly, which can leak hostx86_64SSE state into simulated or cross-targetriscv64builds. This patch makes the scalar fallback explicit for RISC-V and hardens feature detection so it is gated by the selected architecture instead of raw host SIMD defines alone.What changed
includes/rtm/impl/detect_arch.hto recognize__riscvand defineRTM_ARCH_RISCV,RTM_ARCH_RISCV64, orRTM_ARCH_RISCV32as appropriate.includes/rtm/math.hso SSE/AVX intrinsic detection only runs when the selected architecture isx86orx64, preventing host SIMD leakage into RISC-V builds.make.pyto acceptriscv64as a CPU target, auto-detect nativeriscv64Linux hosts, and reject fake cross-compilation attempts that do not use a real RISC-V compiler/toolchain.README.mdanddocs/getting_started.mdto document thatriscv64currently uses RTM's generic scalar path and that cross-compilation should use CMake with a proper RISC-V toolchain file.Verification
git submodule update --init --recursiveso the test targets could configure normally.cmake -S . -B build-native -G Ninja -DCPU_INSTRUCTION_SET=x64 -DCMAKE_CXX_STANDARD=11cmake --build build-native --parallel 4build-native/tests/main_generic/rtm_unit_tests.exeAll tests passed (6579 assertions in 180 test cases)__riscv=1and__riscv_xlen=64and confirmed the scalar fallback is selected.RTM_ARCH_RISCV,RTM_ARCH_RISCV64, andRTM_NO_INTRINSICSare defined, with noRTM_SSE2_INTRINSICSorRTM_NEON_INTRINSICS.python make.py -cpu riscv64on a non-RISC-V Windows host and confirmed it now fails fast with an explicit message thatmake.pyonly supports native Linuxriscv64hosts and that cross-compilation should use a proper CMake toolchain.riscv64cross configure indockcross/linux-riscv64:cmake -S . -B build-riscv -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=riscv64 -DCMAKE_CXX_COMPILER=/usr/xcc/riscv64-unknown-linux-gnu/bin/riscv64-unknown-linux-gnu-g++ -DCMAKE_C_COMPILER=/usr/xcc/riscv64-unknown-linux-gnu/bin/riscv64-unknown-linux-gnu-gcc -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY -DCPU_INSTRUCTION_SET=riscv64 -DIS_CROSS_COMPILING=ONriscv64test targets successfully:cmake --build build-riscv --parallel 4tests/main_generic/rtm_unit_teststests/validate_includes/librtm_validate_includes.abuild-riscv/build.ninjacontains no-march=native,-mavx*,-msse*,arm_neon,arm_sve,/arch:AVX, or/arch:SSE.file build-riscv/tests/main_generic/rtm_unit_testsreadelf -h build-riscv/tests/main_generic/rtm_unit_testsriscv64unit test executable underqemu-riscv64:qemu-riscv64 -L /usr/xcc/riscv64-unknown-linux-gnu/riscv64-unknown-linux-gnu/sysroot -E LD_LIBRARY_PATH=/usr/xcc/riscv64-unknown-linux-gnu/riscv64-unknown-linux-gnu/sysroot/lib:/usr/xcc/riscv64-unknown-linux-gnu/riscv64-unknown-linux-gnu/lib build-riscv/tests/main_generic/rtm_unit_testsAll tests passed (6579 assertions in 180 test cases)Notes
This is a conservative portability patch. It does not add a RISC-V SIMD or RVV backend. The goal is to make
riscv64a first-class scalar target and to avoid inheriting hostx86_64intrinsic state during simulated or cross-target validation.