@@ -33,8 +33,12 @@ prefix operator .!
3333/// conform to `SIMD`.
3434public protocol SIMDStorage {
3535 /// The type of scalars in the vector space.
36+ #if $Embedded
37+ associatedtype Scalar : Hashable
38+ #else
3639 associatedtype Scalar : Codable , Hashable
37-
40+ #endif
41+
3842 /// The number of scalars, or elements, in the vector.
3943 var scalarCount : Int { get }
4044
@@ -71,6 +75,20 @@ public protocol SIMDScalar {
7175 associatedtype SIMD64Storage : SIMDStorage where SIMD64Storage. Scalar == Self
7276}
7377
78+ #if $Embedded
79+ /// A SIMD vector of a fixed number of elements.
80+ public protocol SIMD < Scalar> :
81+ SIMDStorage ,
82+ Hashable ,
83+ ExpressibleByArrayLiteral
84+ {
85+ /// The mask type resulting from pointwise comparisons of this vector type.
86+ associatedtype MaskStorage : SIMD
87+ where MaskStorage. Scalar: FixedWidthInteger & SignedInteger
88+ }
89+
90+ #else
91+
7492/// A SIMD vector of a fixed number of elements.
7593public protocol SIMD < Scalar> :
7694 SIMDStorage ,
@@ -84,6 +102,8 @@ public protocol SIMD<Scalar>:
84102 where MaskStorage. Scalar: FixedWidthInteger & SignedInteger
85103}
86104
105+ #endif
106+
87107extension SIMD {
88108 /// The valid indices for subscripting the vector.
89109 @_transparent
@@ -111,7 +131,9 @@ extension SIMD {
111131 public func hash( into hasher: inout Hasher ) {
112132 for i in indices { hasher. combine ( self [ i] ) }
113133 }
114-
134+
135+ #if !$Embedded
136+
115137 /// Encodes the scalars of this vector into the given encoder in an unkeyed
116138 /// container.
117139 ///
@@ -125,7 +147,7 @@ extension SIMD {
125147 try container. encode ( self [ i] )
126148 }
127149 }
128-
150+
129151 /// Creates a new vector by decoding scalars from the given decoder.
130152 ///
131153 /// This initializer throws an error if reading from the decoder fails, or
@@ -147,14 +169,16 @@ extension SIMD {
147169 self [ i] = try container. decode ( Scalar . self)
148170 }
149171 }
150-
172+
151173 /// A textual description of the vector.
152174 public var description : String {
153175 get {
154176 return " \( Self . self) ( " + indices. map ( { " \( self [ $0] ) " } ) . joined ( separator: " , " ) + " ) "
155177 }
156178 }
157-
179+
180+ #endif
181+
158182 /// A vector mask with the result of a pointwise equality comparison.
159183 ///
160184 /// Equivalent to:
@@ -541,6 +565,7 @@ extension SIMD where Scalar: FixedWidthInteger {
541565
542566 /// Returns a vector with random values from within the specified range in
543567 /// all lanes, using the given generator as a source for randomness.
568+ @_unavailableInEmbedded
544569 @inlinable
545570 public static func random< T: RandomNumberGenerator > (
546571 in range: Range < Scalar > ,
@@ -555,14 +580,16 @@ extension SIMD where Scalar: FixedWidthInteger {
555580
556581 /// Returns a vector with random values from within the specified range in
557582 /// all lanes.
583+ @_unavailableInEmbedded
558584 @inlinable
559585 public static func random( in range: Range < Scalar > ) -> Self {
560586 var g = SystemRandomNumberGenerator ( )
561587 return Self . random ( in: range, using: & g)
562588 }
563-
589+
564590 /// Returns a vector with random values from within the specified range in
565591 /// all lanes, using the given generator as a source for randomness.
592+ @_unavailableInEmbedded
566593 @inlinable
567594 public static func random< T: RandomNumberGenerator > (
568595 in range: ClosedRange < Scalar > ,
@@ -577,11 +604,13 @@ extension SIMD where Scalar: FixedWidthInteger {
577604
578605 /// Returns a vector with random values from within the specified range in
579606 /// all lanes.
607+ @_unavailableInEmbedded
580608 @inlinable
581609 public static func random( in range: ClosedRange < Scalar > ) -> Self {
582610 var g = SystemRandomNumberGenerator ( )
583611 return Self . random ( in: range, using: & g)
584612 }
613+
585614}
586615
587616extension SIMD where Scalar: FloatingPoint {
@@ -608,6 +637,7 @@ extension SIMD where Scalar: FloatingPoint {
608637 }
609638}
610639
640+ @_unavailableInEmbedded
611641extension SIMD
612642where Scalar: BinaryFloatingPoint , Scalar. RawSignificand: FixedWidthInteger {
613643 /// Returns a vector with random values from within the specified range in
@@ -695,6 +725,7 @@ public struct SIMDMask<Storage>: SIMD
695725 }
696726}
697727
728+ @_unavailableInEmbedded
698729extension SIMDMask {
699730 /// Returns a vector mask with `true` or `false` randomly assigned in each
700731 /// lane, using the given generator as a source for randomness.
0 commit comments