Skip to content

Replace __cpuid_check for AVX512 with compiler builtin cpu features#655

Open
r-devulap wants to merge 3 commits intomainfrom
fix-avx512-runtimecheck
Open

Replace __cpuid_check for AVX512 with compiler builtin cpu features#655
r-devulap wants to merge 3 commits intomainfrom
fix-avx512-runtimecheck

Conversation

@r-devulap
Copy link
Copy Markdown

@r-devulap r-devulap commented Apr 6, 2026

Fixes #629.

This pull request simplifies AVX-512 feature detection logic in the jvector_simd_check.c file by replacing manual CPUID bit checks with built-in compiler functions (available only on gcc and llvm compilers). The earlier code was missing XSAVE support at runtime. On VMs where 512‑bit register state saving is disabled, this can result in #UD faults when executing AVX‑512 instructions.

CPU feature detection improvements:

  1. Replaced manual CPUID register checks for AVX-512 features with calls to __builtin_cpu_supports for each required feature, improving code readability and portability.
    Added a call to __builtin_cpu_init() to ensure proper initialization before feature checks.
  2. . Rename check_compatibility to check_avx512_compatibility.
  3. Add a test to verify output of the runtime check by validating it with /proc/cpuinfo.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Before you submit for review:

  • Does your PR follow guidelines from CONTRIBUTIONS.md?
  • Did you summarize what this PR does clearly and concisely?
  • Did you include performance data for changes which may be performance impacting?
  • Did you include useful docs for any user-facing changes or features?
  • Did you include useful javadocs for developer oriented changes, explaining new concepts or key changes?
  • Did you trigger and review regression testing results against the base branch via Run Bench Main?
  • Did you adhere to the code formatting guidelines (TBD)
  • Did you group your changes for easy review, providing meaningful descriptions for each commit?
  • Did you ensure that all files contain the correct copyright header?

If you did not complete any of these, then please explain below.

Replaces manual CPUID bit parsing in jvector_simd_check.c with
__builtin_cpu_supports and adds __builtin_cpu_init(). This corrects
missing XSAVE runtime checks, preventing #UD exceptions on systems where
512‑bit register state saves are disabled.
@r-devulap r-devulap force-pushed the fix-avx512-runtimecheck branch from c2bcf57 to 0f19393 Compare April 7, 2026 04:37
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.

Missing OS level XSAVE check in AVX-512 runtime checks

1 participant