Fix riscv SIMD target detection
## Summary
- recognize __riscv before x86 / ARM SIMD probing in cglm's public headers;
- keep riscv64 on the existing generic non-SIMD path instead of inheriting host x86 SIMD state.#494
Open
carlosqwqqwq wants to merge 1 commit into
Open
Conversation
Owner
|
I think we must not undef compiler's macros. It can affect user code included after cgl. Is this because these are used in headers like vec4.h? Some paths use CGLM_INLINE
void
glm_vec4_add(vec4 a, vec4 b, vec4 dest) {
#if defined(__wasm__) && defined(__wasm_simd128__)
glmm_store(dest, wasm_f32x4_add(glmm_load(a), glmm_load(b)));
#elif defined( __SSE__ ) || defined( __SSE2__ )
glmm_store(dest, _mm_add_ps(glmm_load(a), glmm_load(b)));
#elif defined(CGLM_NEON_FP)
vst1q_f32(dest, vaddq_f32(vld1q_f32(a), vld1q_f32(b)));
#else
dest[0] = a[0] + b[0];
dest[1] = a[1] + b[1];
dest[2] = a[2] + b[2];
dest[3] = a[3] + b[3];
#endifMaybe converting these to use CGLM defined SIMD macros: could help better? |
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
cglm already has a conservative generic path that can serve as the baseline for
riscv64, but its current preprocessing can inherit host x86 SIMD builtins during simulated or cross-target validation. That leakage affects both backend selection and matrix alignment decisions, which makes a forcedriscv64build select x86-specific code paths even though no RISC-V SIMD backend exists yet.What changed
include/cglm/simd/intrin.hso__riscvis recognized before x86 or ARM probing.intrin.hto x86 targets only, instead of relying on raw host__SSE*__and__AVX__macros alone.include/cglm/common.h, clear host x86 SIMD builtins when the target is forced to__riscvso later headers and alignment logic do not inherit the wrong architecture state.README.mdto document thatriscv64currently uses cglm's generic non-SIMD path unless a dedicated RISC-V backend is added.Verification
cmake -S . -B build-native-min -G Ninja -DCGLM_SHARED=OFF -DCGLM_STATIC=ON -DCGLM_USE_TEST=OFF -DCMAKE_BUILD_TYPE=Releasecmake --build build-native-min --parallel 4riscv64smoke translation unit that includescglm/cglm.hand exercisesglm_mat4_mulv, with explicit assertions thatCGLM_SIMD_x86,CGLM_SSE_FP,CGLM_SSE2_FP,CGLM_AVX_FP,__SSE__, and__AVX__must not be present.cglm/cglm.hwith-D__riscv=1 -D__riscv_xlen=64and confirmed the result only reportsCGLM_ARCH_RISCV, with no x86 SIMD feature macros.cglm/cglm.hon the native x86_64 host and confirmed the existing x86 SIMD path still reportsCGLM_ARCH_X86,CGLM_SIMD_x86,CGLM_SSE_FP, andCGLM_SSE2_FP.riscv64CMake build successfully:cmake --build build-riscv-config --parallel 4build-riscv-config/build.ninjaand confirmed the generated compile flags do not include-msse*or-mavx*.riscv64cross-compilation and execution in Docker (ubuntu:24.04):cglm/cglm.hand exercisingglm_vec3_addandglm_mat4_mulvwith hostgcc;riscv64-linux-gnu-gcc;ELF64/Machine: RISC-Vviafileandreadelf -h;riscv64binary successfully withqemu-riscv64-static -L /usr/riscv64-linux-gnu.Notes
This is a conservative portability patch. It does not add RVV or any other RISC-V SIMD implementation. The goal is to make
riscv64select cglm's existing generic path correctly and to stop host x86 SIMD state from leaking into simulated or cross-target validation.