Skip to content

neon vst1_* intrinsics copy many more bytes than they should. #1220

Closed

Description

@HEnquist

This was introduces in this commit:
907cfb2

For example:

pub unsafe fn vst1q_f64(ptr: *mut f64, a: float64x2_t) {

pub unsafe fn vst1q_f64(ptr: *mut f64, a: float64x2_t) {
    copy_nonoverlapping(
        &a as *const float64x2_t as *const f64,
        ptr as *mut f64,
        size_of::<float64x2_t>(),
    )
}

The docs for copy_nonoverlapping says "Copies count * size_of::() bytes from src to dst"
The example above will get called with type T = f64 (with size 8 bytes), and count = size_of::<float64x2_t> = 16. So it will end up copying 8*16=128 bytes. That's quite a bit more than the 16 bytes it should have been.
The result is that it writes garbage to memory locations it should not touch.

https://doc.rust-lang.org/core/ptr/fn.copy_nonoverlapping.html

Activity

  1. hkratz commented on Sep 21, 2021

    @hkratz
    Contributor

    There is no instance of copy_nonoverlapping() remaining in the armv7/aarch64 intrinsics, so that all should be fixed in master, see e.g.

    pub unsafe fn vst1q_f64(ptr: *mut f64, a: float64x2_t) {
    write_unaligned(ptr.cast(), a);
    }

    But the stdarch submodule should be updated in the main Rust repo asap.

  2. HEnquist commented on Sep 21, 2021

    @HEnquist
    Author

    Ah thanks, the submodule thing threw me off. Let's keep this open then until the changes have made it into the main Rust repo.

  3. added a commit that references this issue on Sep 21, 2021
  4. added a commit that references this issue on Sep 27, 2021
  5. pthariensflame commented on Sep 27, 2021

    @pthariensflame
    Contributor

    Seems like rust-lang/rust#89145 is now merged!

  6. HEnquist commented on Sep 28, 2021

    @HEnquist
    Author

    This works fine now in the latest nightly. Closing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions