Skip to content

Add riscv fallback detection#261

Merged
wcawijngaards merged 1 commit into
NLnetLabs:mainfrom
carlosqwqqwq:riscv-simdzone
Jun 19, 2026
Merged

Add riscv fallback detection#261
wcawijngaards merged 1 commit into
NLnetLabs:mainfrom
carlosqwqqwq:riscv-simdzone

Conversation

@carlosqwqqwq

Copy link
Copy Markdown
Contributor

Why

simdzone currently ships x86_64-specific SIMD kernels for Westmere and Haswell, plus a generic fallback parser. That fallback is the right conservative baseline for riscv64 until a dedicated RISC-V SIMD backend exists. However, src/isadetection.h still checks raw x64 target macros directly, so forced-target validation on an x86_64 host can incorrectly enter the cpuid-based x64 detection path instead of the generic fallback path expected for riscv64.

What changed

  • Add an explicit __riscv branch to src/isadetection.h that returns DEFAULT, so RISC-V resolves to the existing fallback parser instead of inheriting x64 ISA detection.
  • Update CMakeLists.txt to emit a clear configure-time status message when the target processor matches riscv*, documenting that only the fallback kernel is built.
  • Update README.md to state that RISC-V and other non-x86_64 targets currently use the fallback kernel until a dedicated SIMD backend is added.

Verification

  • Ran the native CMake/Ninja build successfully:
    • cmake -S . -B build-native -G Ninja -DBUILD_TESTING=OFF -DBUILD_DOCUMENTATION=OFF
    • cmake --build build-native --parallel 4
  • Ran a real riscv64 cross build and install with dockcross/linux-riscv64:
    • cmake -S /repo -B /tmp/simdzone-build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=riscv64 -DCMAKE_C_COMPILER="$CC" -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY -DBUILD_TESTING=OFF
    • cmake --build /tmp/simdzone-build --parallel 4
    • cmake --install /tmp/simdzone-build --prefix /tmp/simdzone-install
  • Linked a minimal zone_parse_string consumer against the installed libzone.a:
    • "$CC" -std=c99 -O2 -static -I/tmp/simdzone-install/include simdzone_smoke.c /tmp/simdzone-install/lib/libzone.a -o /tmp/simdzone_smoke.riscv64
  • Verified the produced binary is a real RISC-V ELF:
    • file /tmp/simdzone_smoke.riscv64
    • readelf -h /tmp/simdzone_smoke.riscv64
  • Ran the binary under qemu-riscv64 successfully:
    • output: simdzone-ok count=1 ttl=3600 addr=192.0.2.1

Notes

This is a conservative portability patch. It does not add RVV or any dedicated RISC-V SIMD implementation. The goal is to make riscv64 route cleanly to simdzone's existing fallback kernel and to keep x86_64-specific ISA detection from leaking into RISC-V validation.

@wcawijngaards

Copy link
Copy Markdown
Member

The code looks good. Thank you for the additional platform checks.

@wcawijngaards wcawijngaards merged commit 8888c3b into NLnetLabs:main Jun 19, 2026
6 checks passed
wcawijngaards added a commit that referenced this pull request Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants