2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -25,8 +25,8 @@ public // @testable
25
25
func _stdlib_atomicCompareExchangeStrongPtr(
26
26
object target: UnsafeMutablePointer < UnsafeRawPointer ? > ,
27
27
expected: UnsafeMutablePointer < UnsafeRawPointer ? > ,
28
- desired: UnsafeRawPointer ? ) -> Bool {
29
-
28
+ desired: UnsafeRawPointer ?
29
+ ) -> Bool {
30
30
// We use Builtin.Word here because Builtin.RawPointer can't be nil.
31
31
let ( oldValue, won) = Builtin . cmpxchg_seqcst_seqcst_Word (
32
32
target. _rawValue,
@@ -36,7 +36,6 @@ func _stdlib_atomicCompareExchangeStrongPtr(
36
36
return Bool ( won)
37
37
}
38
38
39
- % for optional in [ '', '? '] :
40
39
/// Atomic compare and exchange of `UnsafeMutablePointer<T>` with sequentially
41
40
/// consistent memory ordering. Precise semantics are defined in C++11 or C11.
42
41
///
@@ -67,9 +66,53 @@ func _stdlib_atomicCompareExchangeStrongPtr(
67
66
@_transparent
68
67
public // @testable
69
68
func _stdlib_atomicCompareExchangeStrongPtr< T> (
70
- object target: UnsafeMutablePointer < UnsafeMutablePointer < T > ${ optional} > ,
71
- expected: UnsafeMutablePointer < UnsafeMutablePointer < T > ${ optional} > ,
72
- desired: UnsafeMutablePoin ter < T > ${ optional}
69
+ object target: UnsafeMutablePointer < UnsafeMutablePointer < T > > ,
70
+ expected: UnsafeMutablePointer < UnsafeMutablePointer < T > > ,
71
+ desired: UnsafeMutablePointer < T >
72
+ ) -> Bool {
73
+ let rawTarget = UnsafeMutableRawPointer ( target) . assumingMemoryBound (
74
+ to: Optional< UnsafeRawPointer> . self )
75
+ let rawExpected = UnsafeMutableRawPointer ( expected) . assumingMemoryBound (
76
+ to: Optional< UnsafeRawPointer> . self )
77
+ return _stdlib_atomicCompareExchangeStrongPtr (
78
+ object: rawTarget,
79
+ expected: rawExpected,
80
+ desired: UnsafeRawPointer ( desired) )
81
+ }
82
+
83
+ /// Atomic compare and exchange of `UnsafeMutablePointer<T>` with sequentially
84
+ /// consistent memory ordering. Precise semantics are defined in C++11 or C11.
85
+ ///
86
+ /// - Warning: This operation is extremely tricky to use correctly because of
87
+ /// writeback semantics.
88
+ ///
89
+ /// It is best to use it directly on an
90
+ /// `UnsafeMutablePointer<UnsafeMutablePointer<T>>` that is known to point
91
+ /// directly to the memory where the value is stored.
92
+ ///
93
+ /// In a call like this:
94
+ ///
95
+ /// _stdlib_atomicCompareExchangeStrongPtr(&foo.property1.property2, ...)
96
+ ///
97
+ /// you need to manually make sure that:
98
+ ///
99
+ /// - all properties in the chain are physical (to make sure that no writeback
100
+ /// happens; the compare-and-exchange instruction should operate on the
101
+ /// shared memory); and
102
+ ///
103
+ /// - the shared memory that you are accessing is located inside a heap
104
+ /// allocation (a class instance property, a `_BridgingBuffer`, a pointer to
105
+ /// an `Array` element etc.)
106
+ ///
107
+ /// If the conditions above are not met, the code will still compile, but the
108
+ /// compare-and-exchange instruction will operate on the writeback buffer, and
109
+ /// you will get a *race* while doing writeback into shared memory.
110
+ @_transparent
111
+ public // @testable
112
+ func _stdlib_atomicCompareExchangeStrongPtr< T> (
113
+ object target: UnsafeMutablePointer < UnsafeMutablePointer < T > ? > ,
114
+ expected: UnsafeMutablePointer < UnsafeMutablePointer < T > ? > ,
115
+ desired: UnsafeMutablePointer < T > ?
73
116
) -> Bool {
74
117
let rawTarget = UnsafeMutableRawPointer ( target) . assumingMemoryBound (
75
118
to: Optional< UnsafeRawPointer> . self )
@@ -80,14 +123,14 @@ func _stdlib_atomicCompareExchangeStrongPtr<T>(
80
123
expected: rawExpected,
81
124
desired: UnsafeRawPointer ( desired) )
82
125
}
83
- % end # optional
84
126
85
127
@_transparent
86
128
@discardableResult
87
129
public // @testable
88
130
func _stdlib_atomicInitializeARCRef(
89
131
object target: UnsafeMutablePointer < AnyObject ? > ,
90
- desired: AnyObject ) -> Bool {
132
+ desired: AnyObject
133
+ ) -> Bool {
91
134
var expected : UnsafeRawPointer ?
92
135
let desiredPtr = Unmanaged . passRetained ( desired) . toOpaque ( )
93
136
let rawTarget = UnsafeMutableRawPointer ( target) . assumingMemoryBound (
@@ -121,9 +164,39 @@ func _stdlib_atomicLoadARCRef(
121
164
/// A 32 byte buffer.
122
165
internal struct _Buffer32 {
123
166
internal init ( ) { }
124
- % for i in range ( 32 ) :
125
- internal var _x ${ i} : UInt8 = 0
126
- % end
167
+
168
+ internal var _x0 : UInt8 = 0
169
+ internal var _x1 : UInt8 = 0
170
+ internal var _x2 : UInt8 = 0
171
+ internal var _x3 : UInt8 = 0
172
+ internal var _x4 : UInt8 = 0
173
+ internal var _x5 : UInt8 = 0
174
+ internal var _x6 : UInt8 = 0
175
+ internal var _x7 : UInt8 = 0
176
+ internal var _x8 : UInt8 = 0
177
+ internal var _x9 : UInt8 = 0
178
+ internal var _x10 : UInt8 = 0
179
+ internal var _x11 : UInt8 = 0
180
+ internal var _x12 : UInt8 = 0
181
+ internal var _x13 : UInt8 = 0
182
+ internal var _x14 : UInt8 = 0
183
+ internal var _x15 : UInt8 = 0
184
+ internal var _x16 : UInt8 = 0
185
+ internal var _x17 : UInt8 = 0
186
+ internal var _x18 : UInt8 = 0
187
+ internal var _x19 : UInt8 = 0
188
+ internal var _x20 : UInt8 = 0
189
+ internal var _x21 : UInt8 = 0
190
+ internal var _x22 : UInt8 = 0
191
+ internal var _x23 : UInt8 = 0
192
+ internal var _x24 : UInt8 = 0
193
+ internal var _x25 : UInt8 = 0
194
+ internal var _x26 : UInt8 = 0
195
+ internal var _x27 : UInt8 = 0
196
+ internal var _x28 : UInt8 = 0
197
+ internal var _x29 : UInt8 = 0
198
+ internal var _x30 : UInt8 = 0
199
+ internal var _x31 : UInt8 = 0
127
200
128
201
internal mutating func withBytes< Result> (
129
202
_ body: ( UnsafeMutablePointer < UInt8 > ) throws -> Result
@@ -137,9 +210,79 @@ internal struct _Buffer32 {
137
210
/// A 72 byte buffer.
138
211
internal struct _Buffer72 {
139
212
internal init ( ) { }
140
- % for i in range ( 72 ) :
141
- internal var _x ${ i} : UInt8 = 0
142
- % end
213
+
214
+ internal var _x0 : UInt8 = 0
215
+ internal var _x1 : UInt8 = 0
216
+ internal var _x2 : UInt8 = 0
217
+ internal var _x3 : UInt8 = 0
218
+ internal var _x4 : UInt8 = 0
219
+ internal var _x5 : UInt8 = 0
220
+ internal var _x6 : UInt8 = 0
221
+ internal var _x7 : UInt8 = 0
222
+ internal var _x8 : UInt8 = 0
223
+ internal var _x9 : UInt8 = 0
224
+ internal var _x10 : UInt8 = 0
225
+ internal var _x11 : UInt8 = 0
226
+ internal var _x12 : UInt8 = 0
227
+ internal var _x13 : UInt8 = 0
228
+ internal var _x14 : UInt8 = 0
229
+ internal var _x15 : UInt8 = 0
230
+ internal var _x16 : UInt8 = 0
231
+ internal var _x17 : UInt8 = 0
232
+ internal var _x18 : UInt8 = 0
233
+ internal var _x19 : UInt8 = 0
234
+ internal var _x20 : UInt8 = 0
235
+ internal var _x21 : UInt8 = 0
236
+ internal var _x22 : UInt8 = 0
237
+ internal var _x23 : UInt8 = 0
238
+ internal var _x24 : UInt8 = 0
239
+ internal var _x25 : UInt8 = 0
240
+ internal var _x26 : UInt8 = 0
241
+ internal var _x27 : UInt8 = 0
242
+ internal var _x28 : UInt8 = 0
243
+ internal var _x29 : UInt8 = 0
244
+ internal var _x30 : UInt8 = 0
245
+ internal var _x31 : UInt8 = 0
246
+ internal var _x32 : UInt8 = 0
247
+ internal var _x33 : UInt8 = 0
248
+ internal var _x34 : UInt8 = 0
249
+ internal var _x35 : UInt8 = 0
250
+ internal var _x36 : UInt8 = 0
251
+ internal var _x37 : UInt8 = 0
252
+ internal var _x38 : UInt8 = 0
253
+ internal var _x39 : UInt8 = 0
254
+ internal var _x40 : UInt8 = 0
255
+ internal var _x41 : UInt8 = 0
256
+ internal var _x42 : UInt8 = 0
257
+ internal var _x43 : UInt8 = 0
258
+ internal var _x44 : UInt8 = 0
259
+ internal var _x45 : UInt8 = 0
260
+ internal var _x46 : UInt8 = 0
261
+ internal var _x47 : UInt8 = 0
262
+ internal var _x48 : UInt8 = 0
263
+ internal var _x49 : UInt8 = 0
264
+ internal var _x50 : UInt8 = 0
265
+ internal var _x51 : UInt8 = 0
266
+ internal var _x52 : UInt8 = 0
267
+ internal var _x53 : UInt8 = 0
268
+ internal var _x54 : UInt8 = 0
269
+ internal var _x55 : UInt8 = 0
270
+ internal var _x56 : UInt8 = 0
271
+ internal var _x57 : UInt8 = 0
272
+ internal var _x58 : UInt8 = 0
273
+ internal var _x59 : UInt8 = 0
274
+ internal var _x60 : UInt8 = 0
275
+ internal var _x61 : UInt8 = 0
276
+ internal var _x62 : UInt8 = 0
277
+ internal var _x63 : UInt8 = 0
278
+ internal var _x64 : UInt8 = 0
279
+ internal var _x65 : UInt8 = 0
280
+ internal var _x66 : UInt8 = 0
281
+ internal var _x67 : UInt8 = 0
282
+ internal var _x68 : UInt8 = 0
283
+ internal var _x69 : UInt8 = 0
284
+ internal var _x70 : UInt8 = 0
285
+ internal var _x71 : UInt8 = 0
143
286
144
287
internal mutating func withBytes< Result> (
145
288
_ body: ( UnsafeMutablePointer < UInt8 > ) throws -> Result
@@ -150,39 +293,75 @@ internal struct _Buffer72 {
150
293
}
151
294
}
152
295
153
- % for bits in [ 32 , 64 , 80 ] :
296
+ // Returns a UInt64, but that value is the length of the string, so it's
297
+ // guaranteed to fit into an Int. This is part of the ABI, so we can't
298
+ // trivially change it to Int. Callers can safely convert the result
299
+ // to any integer type without checks, however.
300
+ @_silgen_name ( " swift_float32ToString " )
301
+ internal func _float32ToStringImpl(
302
+ _ buffer: UnsafeMutablePointer < UTF8 . CodeUnit > ,
303
+ _ bufferLength: UInt , _ value: Float32 ,
304
+ _ debug: Bool
305
+ ) -> UInt64
154
306
155
- % if bits == 80 :
156
- #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
157
- % end
307
+ internal func _float32 ToString(
308
+ _ value: Float32 , debug: Bool
309
+ ) -> ( buffer: _Buffer32 , length: Int ) {
310
+ _internalInvariant ( MemoryLayout< _Buffer32> . size == 32 )
311
+ var buffer = _Buffer32 ( )
312
+ let length = buffer. withBytes { ( bufferPtr) in Int (
313
+ truncatingIfNeeded: _float32ToStringImpl ( bufferPtr, 32 , value, debug)
314
+ ) }
315
+ return ( buffer, length)
316
+ }
158
317
159
318
// Returns a UInt64, but that value is the length of the string, so it's
160
319
// guaranteed to fit into an Int. This is part of the ABI, so we can't
161
320
// trivially change it to Int. Callers can safely convert the result
162
321
// to any integer type without checks, however.
163
- @_silgen_name ( " swift_float${bits}ToString " )
164
- internal func _float$ { bits } ToStringImpl (
322
+ @_silgen_name ( " swift_float64ToString " )
323
+ internal func _float64ToStringImpl (
165
324
_ buffer: UnsafeMutablePointer < UTF8 . CodeUnit > ,
166
- _ bufferLength: UInt , _ value: Float $ { bits } ,
325
+ _ bufferLength: UInt , _ value: Float64 ,
167
326
_ debug: Bool
168
327
) -> UInt64
169
328
170
- internal func _float$ { bits } ToString (
171
- _ value: Float$ { bits } , debug: Bool
329
+ internal func _float 64 ToString (
330
+ _ value: Float64 , debug: Bool
172
331
) -> ( buffer: _Buffer32 , length: Int ) {
173
332
_internalInvariant ( MemoryLayout< _Buffer32> . size == 32 )
174
333
var buffer = _Buffer32 ( )
175
334
let length = buffer. withBytes { ( bufferPtr) in Int (
176
- truncatingIfNeeded: _float $ { bits } ToStringImpl ( bufferPtr, 32 , value, debug)
335
+ truncatingIfNeeded: _float64ToStringImpl ( bufferPtr, 32 , value, debug)
177
336
) }
178
337
return ( buffer, length)
179
338
}
180
339
181
- % if bits == 80 :
182
- #endif
183
- % end
184
340
185
- % end
341
+ #if !(os(Windows) || os(Android)) && (arch(i386) || arch(x86_64))
342
+
343
+ // Returns a UInt64, but that value is the length of the string, so it's
344
+ // guaranteed to fit into an Int. This is part of the ABI, so we can't
345
+ // trivially change it to Int. Callers can safely convert the result
346
+ // to any integer type without checks, however.
347
+ @_silgen_name ( " swift_float80ToString " )
348
+ internal func _float80ToStringImpl(
349
+ _ buffer: UnsafeMutablePointer < UTF8 . CodeUnit > ,
350
+ _ bufferLength: UInt , _ value: Float80 ,
351
+ _ debug: Bool
352
+ ) -> UInt64
353
+
354
+ internal func _float80 ToString(
355
+ _ value: Float80 , debug: Bool
356
+ ) -> ( buffer: _Buffer32 , length: Int ) {
357
+ _internalInvariant ( MemoryLayout< _Buffer32> . size == 32 )
358
+ var buffer = _Buffer32 ( )
359
+ let length = buffer. withBytes { ( bufferPtr) in Int (
360
+ truncatingIfNeeded: _float80ToStringImpl ( bufferPtr, 32 , value, debug)
361
+ ) }
362
+ return ( buffer, length)
363
+ }
364
+ #endif
186
365
187
366
// Returns a UInt64, but that value is the length of the string, so it's
188
367
// guaranteed to fit into an Int. This is part of the ABI, so we can't
@@ -394,7 +573,3 @@ internal class __SwiftNativeNSSet {
394
573
}
395
574
396
575
#endif
397
-
398
- // ${'Local Variables'}:
399
- // eval: (read-only-mode 1)
400
- // End:
0 commit comments