# From/Into arrays for core::arch SIMD types?

**URL:** <https://internals.rust-lang.org/t/from-into-arrays-for-core-arch-simd-types/22555>\
**Category:** libs\
**Created:** [March 14, 2025, 12:43pm UTC](https://internals.rust-lang.org/t/from-into-arrays-for-core-arch-simd-types/22555 "2025-03-14T12:43:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [March 14, 2025, 12:43pm UTC](https://internals.rust-lang.org/t/from-into-arrays-for-core-arch-simd-types/22555/1 "2025-03-14T12:43:23Z")

</div>

Currently it's cumbersome to get data in or out of non-portable SIMD types like `__m128` or `float32x4_t`.

- The load/store intrinsics require raw pointers like `*const f32`, which needs a combo of `.as_ptr().cast()`.
- Having a `*mut f32` pointer to load into requires creating an array first, which needs extra lines of code, and requires initializing it. Trying to explicitly avoid init (as opposed to hoping the raw pointer won't prevent the compiler from optimizing out the init), requires `[MaybeUninit<f32>; 4]`, which adds even more ceremony.
- The code is forced to pick a specific load/store intrinsic, but that doesn't actually matter! Behind the scenes they are implemented using `core::ptr::read_unaligned` or `mem::transmute`, and the optimizer does whatever it wants with them.
- In practice, everyone uses `mem::transmute` instead. However, this is a powerful function, and it raises doubt whether this is the correct thing to do, or maybe something hacky that may be UB.

Is there anything stopping `core::arch` SIMD types from implementing `From<[f32; 4]>` etc? If this needs to be unsafe, how about an inherent `unsafe fn into_array`/`from_array`?

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [March 14, 2025, 5:50pm UTC](https://internals.rust-lang.org/t/from-into-arrays-for-core-arch-simd-types/22555/2 "2025-03-14T17:50:15Z")

</div>

Hmm, [https://doc.rust-lang.org/std/simd/struct.Simd.html#impl-From\<Simd\<u16,+8\>\>-for-\_\_m128i](https://doc.rust-lang.org/std/simd/struct.Simd.html#impl-From%3CSimd%3Cu16,+8%3E%3E-for-__m128i) exists, so on nightly you can do this as `Simd::from_array(...).into()`.

> [@kornel](#):
>
> The code is forced to pick a specific load/store intrinsic

TBH this feels expected for arch simd. I agree it's not _nice_, but nothing about using arch simd intrinsics is nice 😛

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [September 5, 2026, 5:50pm UTC](https://internals.rust-lang.org/t/from-into-arrays-for-core-arch-simd-types/22555/3 "2026-09-05T17:50:38Z")

</div>

Closed on September 5, 2026, 5:50pm UTC

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
