Fix use-of-uninitialized-value in SVE accumulator operations#331
Merged
ashvardanian merged 1 commit intoashvardanian:main-devfrom Mar 31, 2026
Merged
Conversation
1 task
Use `_m` (merge) instead of `_x` (don't-care) for SVE multiply-accumulate operations on accumulator vectors. The `_x` variant leaves inactive lanes undefined, but the final `svaddv` with `svptrue` sums all lanes including those undefined ones, causing MemorySanitizer to report use-of-uninitialized-value when vector length is not a multiple of the SVE register width. The `_m` variant preserves the accumulator value for inactive lanes, keeping them at their initialized zero. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
e5c7bf0 to
fb679cb
Compare
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.
Summary
Use
_m(merge) instead of_x(don't-care) for SVE multiply-accumulate operations (svmla,svmls) on accumulator vectors inspatial.handdot.h.The
_xvariant leaves inactive lanes undefined when the predicate is false (i.e., for elements past the end of the input array). However, the final horizontal reductionsvaddvusessvptrue(all lanes active), which sums all lanes — including those with undefined values from_x. This causes MemorySanitizer to report use-of-uninitialized-value when the input vector length is not a multiple of the SVE register width.The
_m(merge) variant preserves the first operand (the accumulator) for inactive lanes, keeping them at their initialized zero value. This is correct because:svaddv(svptrue, ...)correctly sums all lanesAffected functions
spatial.h:
simsimd_l2sq_f32_sve,simsimd_cos_f32_sve,simsimd_l2sq_f64_sve,simsimd_cos_f64_sve,simsimd_l2sq_f16_sve,simsimd_cos_f16_sve,simsimd_l2sq_bf16_svedot.h:
simsimd_dot_f32_sve,simsimd_dot_f32c_sve,simsimd_vdot_f32c_sve,simsimd_dot_f64_sve,simsimd_dot_f64c_sve,simsimd_vdot_f64c_sve,simsimd_dot_f16_sve,simsimd_dot_f16c_sve,simsimd_vdot_f16c_sveReproduction
Detected as
MemorySanitizer: use-of-uninitialized-valueinsimsimd_cos_f32_sveduring ClickHouse CI stress tests on ARM with MSan.