Skip to content

Commit b5f9d43

Browse files
authored
rust-lang/portable-simd#289: Strengthen warnings about relying on Mask layout
This makes it more clear that you can't rely on the layout of these, which seems worth doing given that the names vaguely suggest that you can (and the docs only clarify that you can't on Mask but not the maskNxM aliases).
1 parent 2e081db commit b5f9d43

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

crates/core_simd/src/masks.rs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ impl_element! { isize }
8383
///
8484
/// Masks represent boolean inclusion/exclusion on a per-lane basis.
8585
///
86-
/// The layout of this type is unspecified.
86+
/// The layout of this type is unspecified, and may change between platforms
87+
/// and/or Rust versions, and code should not assume that it is equivalent to
88+
/// `[T; LANES]`.
8789
#[repr(transparent)]
8890
pub struct Mask<T, const LANES: usize>(mask_impl::Mask<T, LANES>)
8991
where
@@ -521,57 +523,129 @@ where
521523
}
522524

523525
/// A mask for SIMD vectors with eight elements of 8 bits.
526+
///
527+
/// The layout of this type is unspecified, and may change between platforms
528+
/// and/or Rust versions, and code should not assume that it is equivalent to
529+
/// `[i8; 8]`.
524530
pub type mask8x8 = Mask<i8, 8>;
525531

526532
/// A mask for SIMD vectors with 16 elements of 8 bits.
533+
///
534+
/// The layout of this type is unspecified, and may change between platforms
535+
/// and/or Rust versions, and code should not assume that it is equivalent to
536+
/// `[i8; 16]`.
527537
pub type mask8x16 = Mask<i8, 16>;
528538

529539
/// A mask for SIMD vectors with 32 elements of 8 bits.
540+
///
541+
/// The layout of this type is unspecified, and may change between platforms
542+
/// and/or Rust versions, and code should not assume that it is equivalent to
543+
/// `[i8; 32]`.
530544
pub type mask8x32 = Mask<i8, 32>;
531545

532546
/// A mask for SIMD vectors with 64 elements of 8 bits.
547+
///
548+
/// The layout of this type is unspecified, and may change between platforms
549+
/// and/or Rust versions, and code should not assume that it is equivalent to
550+
/// `[i8; 64]`.
533551
pub type mask8x64 = Mask<i8, 64>;
534552

535553
/// A mask for SIMD vectors with four elements of 16 bits.
554+
///
555+
/// The layout of this type is unspecified, and may change between platforms
556+
/// and/or Rust versions, and code should not assume that it is equivalent to
557+
/// `[i16; 4]`.
536558
pub type mask16x4 = Mask<i16, 4>;
537559

538560
/// A mask for SIMD vectors with eight elements of 16 bits.
561+
///
562+
/// The layout of this type is unspecified, and may change between platforms
563+
/// and/or Rust versions, and code should not assume that it is equivalent to
564+
/// `[i16; 8]`.
539565
pub type mask16x8 = Mask<i16, 8>;
540566

541567
/// A mask for SIMD vectors with 16 elements of 16 bits.
568+
///
569+
/// The layout of this type is unspecified, and may change between platforms
570+
/// and/or Rust versions, and code should not assume that it is equivalent to
571+
/// `[i16; 16]`.
542572
pub type mask16x16 = Mask<i16, 16>;
543573

544574
/// A mask for SIMD vectors with 32 elements of 16 bits.
575+
///
576+
/// The layout of this type is unspecified, and may change between platforms
577+
/// and/or Rust versions, and code should not assume that it is equivalent to
578+
/// `[i16; 32]`.
545579
pub type mask16x32 = Mask<i16, 32>;
546580

547581
/// A mask for SIMD vectors with two elements of 32 bits.
582+
///
583+
/// The layout of this type is unspecified, and may change between platforms
584+
/// and/or Rust versions, and code should not assume that it is equivalent to
585+
/// `[i32; 2]`.
548586
pub type mask32x2 = Mask<i32, 2>;
549587

550588
/// A mask for SIMD vectors with four elements of 32 bits.
589+
///
590+
/// The layout of this type is unspecified, and may change between platforms
591+
/// and/or Rust versions, and code should not assume that it is equivalent to
592+
/// `[i32; 4]`.
551593
pub type mask32x4 = Mask<i32, 4>;
552594

553595
/// A mask for SIMD vectors with eight elements of 32 bits.
596+
///
597+
/// The layout of this type is unspecified, and may change between platforms
598+
/// and/or Rust versions, and code should not assume that it is equivalent to
599+
/// `[i32; 8]`.
554600
pub type mask32x8 = Mask<i32, 8>;
555601

556602
/// A mask for SIMD vectors with 16 elements of 32 bits.
603+
///
604+
/// The layout of this type is unspecified, and may change between platforms
605+
/// and/or Rust versions, and code should not assume that it is equivalent to
606+
/// `[i32; 16]`.
557607
pub type mask32x16 = Mask<i32, 16>;
558608

559609
/// A mask for SIMD vectors with two elements of 64 bits.
610+
///
611+
/// The layout of this type is unspecified, and may change between platforms
612+
/// and/or Rust versions, and code should not assume that it is equivalent to
613+
/// `[i64; 2]`.
560614
pub type mask64x2 = Mask<i64, 2>;
561615

562616
/// A mask for SIMD vectors with four elements of 64 bits.
617+
///
618+
/// The layout of this type is unspecified, and may change between platforms
619+
/// and/or Rust versions, and code should not assume that it is equivalent to
620+
/// `[i64; 4]`.
563621
pub type mask64x4 = Mask<i64, 4>;
564622

565623
/// A mask for SIMD vectors with eight elements of 64 bits.
624+
///
625+
/// The layout of this type is unspecified, and may change between platforms
626+
/// and/or Rust versions, and code should not assume that it is equivalent to
627+
/// `[i64; 8]`.
566628
pub type mask64x8 = Mask<i64, 8>;
567629

568630
/// A mask for SIMD vectors with two elements of pointer width.
631+
///
632+
/// The layout of this type is unspecified, and may change between platforms
633+
/// and/or Rust versions, and code should not assume that it is equivalent to
634+
/// `[isize; 2]`.
569635
pub type masksizex2 = Mask<isize, 2>;
570636

571637
/// A mask for SIMD vectors with four elements of pointer width.
638+
///
639+
/// The layout of this type is unspecified, and may change between platforms
640+
/// and/or Rust versions, and code should not assume that it is equivalent to
641+
/// `[isize; 4]`.
572642
pub type masksizex4 = Mask<isize, 4>;
573643

574644
/// A mask for SIMD vectors with eight elements of pointer width.
645+
///
646+
/// The layout of this type is unspecified, and may change between platforms
647+
/// and/or Rust versions, and code should not assume that it is equivalent to
648+
/// `[isize; 8]`.
575649
pub type masksizex8 = Mask<isize, 8>;
576650

577651
macro_rules! impl_from {

0 commit comments

Comments
 (0)