14
14
//
15
15
//===----------------------------------------------------------------------===//
16
16
17
- % {
18
- # The sizes to generate code for.
19
- sizes = [ 2 , 4 , 8 , 16 ]
20
- } %
21
-
22
- % for N in sizes:
23
-
24
- internal struct _FixedArray ${ N} < T> {
17
+ internal struct _FixedArray16 < T> {
25
18
// ABI TODO: This makes assumptions about tuple layout in the ABI, namely that
26
19
// they are laid out contiguously and individually addressable (i.e. strided).
27
20
//
28
21
internal var storage : (
29
- // A ${N}-wide tuple of type T
30
- % for i in range( 0 , N- 1 ) :
31
- T,
32
- % end
33
- T
22
+ // A 16-wide tuple of type T
23
+ T , T , T , T , T , T , T , T ,
24
+ T , T , T , T , T , T , T , T
34
25
)
35
26
36
27
var _count : Int8
37
28
}
38
29
39
- extension _FixedArray $ { N } {
30
+ extension _FixedArray16 {
40
31
internal static var capacity : Int {
41
- @inline ( __always) get { return $ { N } }
32
+ @inline ( __always) get { return 16 }
42
33
}
43
34
44
35
internal var capacity : Int {
45
- @inline ( __always) get { return $ { N } }
36
+ @inline ( __always) get { return 16 }
46
37
}
47
38
48
39
internal var count : Int {
@@ -51,7 +42,7 @@ extension _FixedArray${N} {
51
42
}
52
43
}
53
44
54
- extension _FixedArray $ { N } : Rando mAccessCollection, MutableCollection {
45
+ extension _FixedArray16 : RandomAccessCollection , MutableCollection {
55
46
internal typealias Index = Int
56
47
57
48
internal var startIndex : Index {
@@ -70,7 +61,7 @@ extension _FixedArray${N} : RandomAccessCollection, MutableCollection {
70
61
let res : T = withUnsafeBytes ( of: storage) {
71
62
( rawPtr : UnsafeRawBufferPointer ) -> T in
72
63
let stride = MemoryLayout< T> . stride
73
- _internalInvariant ( rawPtr. count == $ { N } * stride, " layout mismatch? " )
64
+ _internalInvariant ( rawPtr. count == 16 * stride, " layout mismatch? " )
74
65
let bufPtr = UnsafeBufferPointer (
75
66
start: rawPtr. baseAddress!. assumingMemoryBound ( to: T . self) ,
76
67
count: count)
@@ -98,23 +89,21 @@ extension _FixedArray${N} : RandomAccessCollection, MutableCollection {
98
89
}
99
90
}
100
91
101
- extension _FixedArray $ { N } {
92
+ extension _FixedArray16 {
102
93
internal mutating func append( _ newElement: T ) {
103
94
_internalInvariant ( count < capacity)
104
95
_count += 1
105
96
self [ count- 1 ] = newElement
106
97
}
107
98
}
108
99
109
- extension _FixedArray $ { N } where T : ExpressibleByIntegerLiteral {
100
+ extension _FixedArray16 where T : ExpressibleByIntegerLiteral {
110
101
@inline ( __always)
111
102
internal init ( count: Int ) {
112
- _internalInvariant ( count >= 0 && count <= _FixedArray$ { N } . capacity)
103
+ _internalInvariant ( count >= 0 && count <= _FixedArray16 . capacity)
113
104
self . storage = (
114
- % for i in range( 0 , N- 1 ) :
115
- 0 ,
116
- % end
117
- 0
105
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
106
+ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
118
107
)
119
108
self . _count = Int8 ( truncatingIfNeeded: count)
120
109
}
@@ -126,17 +115,17 @@ extension _FixedArray${N} where T : ExpressibleByIntegerLiteral {
126
115
127
116
@inline ( __always)
128
117
internal init ( allZeros: ( ) ) {
129
- self . init ( count: $ { N } )
118
+ self . init ( count: 16 )
130
119
}
131
120
}
132
121
133
- extension _FixedArray $ { N } {
122
+ extension _FixedArray16 {
134
123
internal mutating func withUnsafeMutableBufferPointer< R> (
135
124
_ body: ( UnsafeMutableBufferPointer < Element > ) throws -> R
136
125
) rethrows -> R {
137
126
let count = self . count // for exclusive access
138
127
return try withUnsafeMutableBytes ( of: & storage) { rawBuffer in
139
- _internalInvariant ( rawBuffer. count == $ { N } * MemoryLayout< T> . stride,
128
+ _internalInvariant ( rawBuffer. count == 16 * MemoryLayout< T> . stride,
140
129
" layout mismatch? " )
141
130
let buffer = UnsafeMutableBufferPointer < Element > (
142
131
start: rawBuffer. baseAddress. _unsafelyUnwrappedUnchecked
@@ -151,7 +140,7 @@ extension _FixedArray${N} {
151
140
) rethrows -> R {
152
141
let count = self . count // for exclusive access
153
142
return try withUnsafeBytes ( of: & storage) { rawBuffer in
154
- _internalInvariant ( rawBuffer. count == $ { N } * MemoryLayout< T> . stride,
143
+ _internalInvariant ( rawBuffer. count == 16 * MemoryLayout< T> . stride,
155
144
" layout mismatch? " )
156
145
let buffer = UnsafeBufferPointer < Element > (
157
146
start: rawBuffer. baseAddress. _unsafelyUnwrappedUnchecked
@@ -161,9 +150,3 @@ extension _FixedArray${N} {
161
150
}
162
151
}
163
152
}
164
-
165
- % end
166
-
167
- // ${'Local Variables'}:
168
- // eval: (read-only-mode 1)
169
- // End:
0 commit comments