aarch64/arm: use read_unaligned for vld1 lane and dup loads - #2213
Draft
rootkiller6788 wants to merge 1 commit into
Draft
aarch64/arm: use read_unaligned for vld1 lane and dup loads#2213rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
The vld1 (load single element) and ld1r (load and replicate) instructions do not require the source pointer to be aligned. However, the lane-load and dup-load intrinsics dereferenced the pointer directly, which inserts an alignment requirement and is UB for unaligned pointers. Replace the aligned dereference with ptr.read_unaligned() for the vld1*_lane* and vld1*_dup* intrinsics, and update the generator spec so the generated code stays in sync. Fixes rust-lang#2198
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
The
vld1(load single element) andld1r(load-and-replicate) instructions do not require the source pointer to be aligned. However, the NEON lane-load (vld1*_lane*) and dup-load (vld1*_dup*) intrinsics dereferenced the pointer directly (*ptr), which makes the compiler assume the pointer is aligned to the element's size. For unaligned pointers this is undefined behavior (and trips debug alignment checks).This replaces the aligned dereference with
ptr.read_unaligned()across all affected intrinsics, and updates the generator spec so the generated code remains in sync.Changes
crates/stdarch-gen-arm/spec/neon/arm_shared.spec.yml: emitptr.read_unaligned()instead of*ptrfor the lane-load and dup-loadcomposeexpressions.crates/core_arch/src/arm_shared/neon/generated.rs: update thevld1*_lane*andvld1*_dup*intrinsic bodies.crates/core_arch/src/aarch64/neon/mod.rs: fix the hand-writtenvld1_lane_f64/vld1q_lane_f64.Fixes #2198