Skip to content

Commit 9718639

Browse files
authored
rust-lang/portable-simd#276: Mention slice methods as_simd() and as_simd_mut()
This links to a practical suggestion for how to solve the issues brought up in this section.
1 parent fcc5ca0 commit 9718639

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

beginners-guide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,10 @@ Fortunately, most SIMD types have a fairly predictable size. `i32x4` is bit-equi
8282

8383
However, this is not the same as alignment. Computer architectures generally prefer aligned accesses, especially when moving data between memory and vector registers, and while some support specialized operations that can bend the rules to help with this, unaligned access is still typically slow, or even undefined behavior. In addition, different architectures can require different alignments when interacting with their native SIMD types. For this reason, any `#[repr(simd)]` type has a non-portable alignment. If it is necessary to directly interact with the alignment of these types, it should be via [`mem::align_of`].
8484

85+
When working with slices, data correctly aligned for SIMD can be acquired using the [`as_simd`] and [`as_simd_mut`] methods of the slice primitive.
86+
8587
[`mem::transmute`]: https://doc.rust-lang.org/core/mem/fn.transmute.html
8688
[`mem::align_of`]: https://doc.rust-lang.org/core/mem/fn.align_of.html
89+
[`as_simd`]: https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.as_simd
90+
[`as_simd_mut`]: https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.as_simd_mut
91+

0 commit comments

Comments
 (0)