Repository navigation
Conversation
Tested on a Milk-V Jupiter (SpacemiT K1) and a StarFive VisionFive 2 (JH7110), both running Debian 13 with an AMD R9 290 (radeonsi): Half-Life 2 runs and renders correctly. - platform.h: add PLATFORM_RISCV64 and handle it next to ARM (PLATFORM_64BITS, DebuggerBreak, FPU control word, endianness, Plat_Rdtsc via clock_gettime). - SIMD: add common/sse2simde.h, which maps the SSE intrinsics to SIMDe (the counterpart of sse2neon.h on ARM); used by ssemath.h, vector4d.h and mathlib/sse.cpp. sse.cpp takes the non-asm paths. - mathlib.h: RoundFloatToInt/RoundFloatToUnsignedLong via lrintf/llrintf (round to nearest even, like cvtss2si on x86). - imesh.h: use the intrinsics paths instead of x86 MMX inline asm. - tslist.h: RISC-V has no 128-bit CAS instruction (no Zacas), so use __atomic_compare_exchange_n, provided (lock-based) by libatomic. - cpu.cpp, cpu_posix.cpp, processor_detect_linux.cpp, reliabletimer.cpp, pathmatch.cpp, saverestoretypes.h, steamtypes.h: no x86 cpuid/rdtsc/ int3 on riscv. - wscript: -fsigned-char for riscv (char is unsigned by default) and link libatomic (as LIB, so it is placed after the objects with --as-needed). - scripts/build-debian-riscv64.sh: native build on riscv64 Debian 13 (trixie), like the other build-*.sh scripts; also installs libsimde-dev. Co-Authored-By: Claude <noreply@anthropic.com>
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.
This adds support for 64-bit RISC-V Linux (RV64GC, so no vector extension needed). Half-Life 2 builds, runs and renders correctly on two RISC-V boards with an AMD GPU.
The approach follows the existing ARM support: wherever the code has an
__arm__/__aarch64__case, riscv64 takes the same non-x86 path. For SSE, SIMDe is used in the same way thatsse2neon.his used on ARM.How to build
On a riscv64 machine running Debian 13 (trixie):
This works like the other
scripts/build-*.shscripts. The only new dependency islibsimde-dev(SIMDe headers; on Fedorasimde-devel).Changes
public/tier0/platform.h: newPLATFORM_RISCV64, handled next to ARM forPLATFORM_64BITS,DebuggerBreak, the FPU control word (no-op), little-endian andPlat_Rdtsc(clock_gettime).common/sse2simde.h, the RISC-V counterpart ofsse2neon.h. It enables SIMDe's native aliases, so the existing_mm_*SSE code compiles unchanged. It is included fromssemath.h,vector4d.handmathlib/sse.cpp.sse.cpptakes the same non-inline-asm paths as ARM.public/mathlib/mathlib.h:RoundFloatToIntandRoundFloatToUnsignedLonguselrintf/llrintf(round to nearest even, likecvtss2sion x86).public/materialsystem/imesh.h: the intrinsics paths instead of the x86 MMX inline asm.public/tier0/tslist.h: the lock-free list needs a 128-bit CAS. RISC-V has no such instruction (no Zacas), so__atomic_compare_exchange_nis used, which libatomic provides (lock-based).tier0/cpu.cpp,tier0/cpu_posix.cpp,tier1/processor_detect_linux.cpp,tier1/reliabletimer.cpp,tier1/pathmatch.cpp,public/saverestoretypes.h,public/steam/steamtypes.h: no x86cpuid,rdtscorint3on riscv. The arch name isriscv64and the vendorRISC-V.wscript:-fsigned-charfor riscv (charis unsigned there, like on ARM, and the code assumes x86). It also linkslibatomic, asLIBrather than a link flag, so it comes after the objects with--as-needed.scripts/build-debian-riscv64.sh: native build script for Debian 13.Testing
Both boards run Debian 13 with an AMD Radeon R9 290 (radeonsi, desktop OpenGL) on PCIe and KDE Plasma. The test was a
timedemoon ad1_canals_01demo (5449 frames, 1280×720):build-debian-riscv64.sh)The x86_64 build was checked again with these changes: it still builds and runs.
Under Wayland, start the game with
SDL_VIDEODRIVER=x11until #493 is merged. That crash is not RISC-V specific.Not included
-marchflags: the defaultrv64gcworks on every RV64GC board. I also tried an RVV (vector) build on the Jupiter. It was not faster, because the game is limited by the main thread, so I left it out to keep this PR small.How this was made
I made this together with Claude Code, Anthropic's AI coding assistant. I guided it throughout and corrected it where needed, so that the change fits the existing project structure:
sse2neon.hscripts/build-*.sh, with no extra container or cross-compile toolingI tested the result myself on both boards listed above.