@@ -33,8 +33,12 @@ prefix operator .!
33
33
/// conform to `SIMD`.
34
34
public protocol SIMDStorage {
35
35
/// The type of scalars in the vector space.
36
+ #if $Embedded
37
+ associatedtype Scalar : Hashable
38
+ #else
36
39
associatedtype Scalar : Codable , Hashable
37
-
40
+ #endif
41
+
38
42
/// The number of scalars, or elements, in the vector.
39
43
var scalarCount : Int { get }
40
44
@@ -71,6 +75,20 @@ public protocol SIMDScalar {
71
75
associatedtype SIMD64Storage : SIMDStorage where SIMD64Storage. Scalar == Self
72
76
}
73
77
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
+
74
92
/// A SIMD vector of a fixed number of elements.
75
93
public protocol SIMD < Scalar> :
76
94
SIMDStorage ,
@@ -84,6 +102,8 @@ public protocol SIMD<Scalar>:
84
102
where MaskStorage. Scalar: FixedWidthInteger & SignedInteger
85
103
}
86
104
105
+ #endif
106
+
87
107
extension SIMD {
88
108
/// The valid indices for subscripting the vector.
89
109
@_transparent
@@ -111,7 +131,9 @@ extension SIMD {
111
131
public func hash( into hasher: inout Hasher ) {
112
132
for i in indices { hasher. combine ( self [ i] ) }
113
133
}
114
-
134
+
135
+ #if !$Embedded
136
+
115
137
/// Encodes the scalars of this vector into the given encoder in an unkeyed
116
138
/// container.
117
139
///
@@ -125,7 +147,7 @@ extension SIMD {
125
147
try container. encode ( self [ i] )
126
148
}
127
149
}
128
-
150
+
129
151
/// Creates a new vector by decoding scalars from the given decoder.
130
152
///
131
153
/// This initializer throws an error if reading from the decoder fails, or
@@ -147,14 +169,16 @@ extension SIMD {
147
169
self [ i] = try container. decode ( Scalar . self)
148
170
}
149
171
}
150
-
172
+
151
173
/// A textual description of the vector.
152
174
public var description : String {
153
175
get {
154
176
return " \( Self . self) ( " + indices. map ( { " \( self [ $0] ) " } ) . joined ( separator: " , " ) + " ) "
155
177
}
156
178
}
157
-
179
+
180
+ #endif
181
+
158
182
/// A vector mask with the result of a pointwise equality comparison.
159
183
///
160
184
/// Equivalent to:
@@ -541,6 +565,7 @@ extension SIMD where Scalar: FixedWidthInteger {
541
565
542
566
/// Returns a vector with random values from within the specified range in
543
567
/// all lanes, using the given generator as a source for randomness.
568
+ @_unavailableInEmbedded
544
569
@inlinable
545
570
public static func random< T: RandomNumberGenerator > (
546
571
in range: Range < Scalar > ,
@@ -555,14 +580,16 @@ extension SIMD where Scalar: FixedWidthInteger {
555
580
556
581
/// Returns a vector with random values from within the specified range in
557
582
/// all lanes.
583
+ @_unavailableInEmbedded
558
584
@inlinable
559
585
public static func random( in range: Range < Scalar > ) -> Self {
560
586
var g = SystemRandomNumberGenerator ( )
561
587
return Self . random ( in: range, using: & g)
562
588
}
563
-
589
+
564
590
/// Returns a vector with random values from within the specified range in
565
591
/// all lanes, using the given generator as a source for randomness.
592
+ @_unavailableInEmbedded
566
593
@inlinable
567
594
public static func random< T: RandomNumberGenerator > (
568
595
in range: ClosedRange < Scalar > ,
@@ -577,11 +604,13 @@ extension SIMD where Scalar: FixedWidthInteger {
577
604
578
605
/// Returns a vector with random values from within the specified range in
579
606
/// all lanes.
607
+ @_unavailableInEmbedded
580
608
@inlinable
581
609
public static func random( in range: ClosedRange < Scalar > ) -> Self {
582
610
var g = SystemRandomNumberGenerator ( )
583
611
return Self . random ( in: range, using: & g)
584
612
}
613
+
585
614
}
586
615
587
616
extension SIMD where Scalar: FloatingPoint {
@@ -608,6 +637,7 @@ extension SIMD where Scalar: FloatingPoint {
608
637
}
609
638
}
610
639
640
+ @_unavailableInEmbedded
611
641
extension SIMD
612
642
where Scalar: BinaryFloatingPoint , Scalar. RawSignificand: FixedWidthInteger {
613
643
/// Returns a vector with random values from within the specified range in
@@ -695,6 +725,7 @@ public struct SIMDMask<Storage>: SIMD
695
725
}
696
726
}
697
727
728
+ @_unavailableInEmbedded
698
729
extension SIMDMask {
699
730
/// Returns a vector mask with `true` or `false` randomly assigned in each
700
731
/// lane, using the given generator as a source for randomness.
0 commit comments