Skip to content

Commit bef8b61

Browse files
[6.0] SE-0425 implementation (#72783)
Implements [U]Int128 per SE-0425
1 parent d7a0f08 commit bef8b61

17 files changed

+2998
-58
lines changed

stdlib/public/Synchronization/AtomicIntegers.swift.gyb

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift Atomics open source project
44
//
5-
// Copyright (c) 2023 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2023-2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -14,15 +14,19 @@ import Builtin
1414

1515
% from SwiftAtomics import *
1616

17-
% for (intType, intStorage, builtinInt) in intTypes:
17+
% for U in ["", "U"]:
18+
% for bits in atomicBits:
19+
% intType = U + "Int" + bits
20+
% intStorage = "_Atomic" + bits + "BitStorage"
1821

1922
//===----------------------------------------------------------------------===//
2023
// ${intType} AtomicRepresentable conformance
2124
//===----------------------------------------------------------------------===//
2225

23-
% if intType == "Int64" or intType == "UInt64":
24-
#if (_pointerBitWidth(_32) && _hasAtomicBitWidth(_64)) || _pointerBitWidth(_64)
25-
% end
26+
% if bits != "":
27+
% # Assume that everyone has word-sized atomics, but check for the rest
28+
#if _hasAtomicBitWidth(_${bits})
29+
% end
2630

2731
@available(SwiftStdlib 6.0, *)
2832
extension ${intType}: AtomicRepresentable {
@@ -107,7 +111,7 @@ extension Atomic where Value == ${intType} {
107111
@_alwaysEmitIntoClient
108112
@_transparent
109113
public func ${lowerFirst(name)}(
110-
_ operand: ${intType}${" = 1" if "crement" in name else ""},
114+
_ operand: ${intType},
111115
ordering: AtomicUpdateOrdering
112116
) -> (oldValue: ${intType}, newValue: ${intType}) {
113117
let original = switch ordering {
@@ -128,7 +132,7 @@ extension Atomic where Value == ${intType} {
128132
#error("Unsupported platform")
129133
#endif
130134
% else:
131-
Builtin.atomicrmw_${atomicOperationName(intType, builtinName)}_${llvmOrder}_${builtinInt}(
135+
Builtin.atomicrmw_${atomicOperationName(intType, builtinName)}_${llvmOrder}_Int${bits}(
132136
rawAddress,
133137
operand._value
134138
)
@@ -231,8 +235,9 @@ extension Atomic where Value == ${intType} {
231235
}
232236
}
233237

234-
% if intType == "Int64" or intType == "UInt64":
235-
#endif
236-
% end
238+
% if bits != "":
239+
#endif // _hasAtomicBitWidth
240+
% end
237241

238242
% end
243+
% end

stdlib/public/core/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,13 @@ split_embedded_sources(
226226
EMBEDDED DurationProtocol.swift
227227
EMBEDDED FloatingPointRandom.swift
228228
EMBEDDED Instant.swift
229+
EMBEDDED Int128.swift
229230
NORMAL Mirror.swift
230231
NORMAL PlaygroundDisplay.swift
231232
NORMAL CommandLine.swift
232233
EMBEDDED SliceBuffer.swift
233234
NORMAL StaticBigInt.swift
235+
EMBEDDED UInt128.swift
234236
NORMAL UnfoldSequence.swift
235237
NORMAL UnsafeBufferPointerSlice.swift
236238
NORMAL VarArgs.swift
@@ -246,9 +248,9 @@ split_embedded_sources(
246248
NORMAL FloatingPointParsing.swift.gyb
247249
EMBEDDED FloatingPointTypes.swift.gyb
248250
EMBEDDED IntegerTypes.swift.gyb
251+
EMBEDDED LegacyInt128.swift.gyb
249252
EMBEDDED UnsafeBufferPointer.swift.gyb
250253
EMBEDDED UnsafeRawBufferPointer.swift.gyb
251-
EMBEDDED Int128.swift.gyb
252254
EMBEDDED Tuple.swift.gyb
253255
)
254256

0 commit comments

Comments
 (0)