Skip to content

Commit 78f4484

Browse files
committed
Improve 32/64 bit conditionals. Rearrange Bool/DoubleWord definitions
1 parent b2328b5 commit 78f4484

File tree

6 files changed

+76
-125
lines changed

6 files changed

+76
-125
lines changed

Sources/Atomics/AtomicBool.swift.gyb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@
1616
}%
1717
${autogenerated_warning()}
1818

19-
#if !ATOMICS_NATIVE_BUILTINS
19+
#if ATOMICS_NATIVE_BUILTINS
20+
import Builtin
21+
22+
extension Bool {
23+
@_alwaysEmitIntoClient
24+
@inline(__always)
25+
internal init(_ builtin: Builtin.Int1) {
26+
self = unsafeBitCast(builtin, to: Bool.self)
27+
}
28+
}
29+
#else
2030
import _AtomicsShims
2131
#endif
2232

@@ -189,7 +199,7 @@ extension Bool.AtomicRepresentation {
189199
% end
190200
}
191201

192-
% for construct in ["Atomic", "UnsafeAtomic", "ManagedAtomic"]:
202+
% for construct in ["Atomic", "UnsafeAtomic"]:
193203
% if construct == "Atomic":
194204
#if compiler(>=5.9) && $RawLayout
195205
% end

Sources/Atomics/DoubleWord.swift

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,60 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if !ATOMICS_NATIVE_BUILTINS
13+
#if ATOMICS_NATIVE_BUILTINS
14+
import Builtin
15+
16+
#if _pointerBitWidth(_32)
17+
@frozen
18+
@_alignment(8)
19+
public struct DoubleWord {
20+
@usableFromInline
21+
internal typealias _Builtin = Builtin.Int64
22+
23+
public var first: UInt
24+
public var second: UInt
25+
26+
@inlinable @inline(__always)
27+
public init(first: UInt, second: UInt) {
28+
self.first = first
29+
self.second = second
30+
}
31+
}
32+
#elseif _pointerBitWidth(_64)
33+
@frozen
34+
@_alignment(16)
35+
public struct DoubleWord {
36+
@usableFromInline
37+
internal typealias _Builtin = Builtin.Int128
38+
39+
public var first: UInt
40+
public var second: UInt
41+
42+
@inlinable @inline(__always)
43+
public init(first: UInt, second: UInt) {
44+
self.first = first
45+
self.second = second
46+
}
47+
}
48+
#else
49+
#error("Unsupported pointer bit width")
50+
#endif
51+
52+
extension DoubleWord {
53+
@_alwaysEmitIntoClient
54+
@inline(__always)
55+
internal init(_ builtin: _Builtin) {
56+
self = unsafeBitCast(builtin, to: DoubleWord.self)
57+
}
58+
59+
@_alwaysEmitIntoClient
60+
@inline(__always)
61+
internal var _value: _Builtin {
62+
unsafeBitCast(self, to: _Builtin.self)
63+
}
64+
}
65+
66+
#else // !ATOMICS_NATIVE_BUILTINS
1467
import _AtomicsShims
1568
public typealias DoubleWord = _AtomicsShims.DoubleWord
1669
#endif

Sources/Atomics/Primitives.native.swift.gyb

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,6 @@ ${autogenerated_warning()}
1818
#if ATOMICS_NATIVE_BUILTINS
1919
import Builtin
2020

21-
#if ${ptrBitWidth32}
22-
@frozen
23-
@_alignment(8)
24-
public struct DoubleWord {
25-
@usableFromInline
26-
internal typealias _Builtin = Builtin.Int64
27-
28-
public var first: UInt
29-
public var second: UInt
30-
31-
@inlinable @inline(__always)
32-
public init(first: UInt, second: UInt) {
33-
self.first = first
34-
self.second = second
35-
}
36-
}
37-
#else
38-
@frozen
39-
@_alignment(16)
40-
public struct DoubleWord {
41-
@usableFromInline
42-
internal typealias _Builtin = Builtin.Int128
43-
44-
public var first: UInt
45-
public var second: UInt
46-
47-
@inlinable @inline(__always)
48-
public init(first: UInt, second: UInt) {
49-
self.first = first
50-
self.second = second
51-
}
52-
}
53-
#endif
54-
55-
extension DoubleWord {
56-
@_alwaysEmitIntoClient
57-
@inline(__always)
58-
internal init(_ builtin: _Builtin) {
59-
self = unsafeBitCast(builtin, to: DoubleWord.self)
60-
}
61-
62-
@_alwaysEmitIntoClient
63-
@inline(__always)
64-
internal var _value: _Builtin {
65-
unsafeBitCast(self, to: _Builtin.self)
66-
}
67-
}
68-
69-
extension Bool {
70-
@_alwaysEmitIntoClient
71-
@inline(__always)
72-
internal init(_ builtin: Builtin.Int1) {
73-
self = unsafeBitCast(builtin, to: Bool.self)
74-
}
75-
}
76-
7721
@_alwaysEmitIntoClient
7822
@_transparent
7923
internal func _atomicMemoryFence(

Sources/Atomics/autogenerated/IntegerConformances.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ extension UInt.AtomicRepresentation: AtomicIntegerStorage {
20922092

20932093

20942094

2095-
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)
2095+
#if (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)))
20962096
extension DoubleWord: AtomicValue {
20972097
@frozen
20982098
public struct AtomicRepresentation {
@@ -2229,7 +2229,7 @@ extension DoubleWord.AtomicRepresentation: AtomicStorage {
22292229

22302230

22312231

2232-
#else /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
2232+
#else /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
22332233
extension DoubleWord: AtomicValue {
22342234
@frozen
22352235
public struct AtomicRepresentation {
@@ -2363,5 +2363,5 @@ extension DoubleWord.AtomicRepresentation: AtomicStorage {
23632363
}
23642364
}
23652365

2366-
#endif /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
2366+
#endif /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
23672367

Sources/Atomics/autogenerated/Primitives.native.swift

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,6 @@
2121
#if ATOMICS_NATIVE_BUILTINS
2222
import Builtin
2323

24-
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)
25-
@frozen
26-
@_alignment(8)
27-
public struct DoubleWord {
28-
@usableFromInline
29-
internal typealias _Builtin = Builtin.Int64
30-
31-
public var first: UInt
32-
public var second: UInt
33-
34-
@inlinable @inline(__always)
35-
public init(first: UInt, second: UInt) {
36-
self.first = first
37-
self.second = second
38-
}
39-
}
40-
#else
41-
@frozen
42-
@_alignment(16)
43-
public struct DoubleWord {
44-
@usableFromInline
45-
internal typealias _Builtin = Builtin.Int128
46-
47-
public var first: UInt
48-
public var second: UInt
49-
50-
@inlinable @inline(__always)
51-
public init(first: UInt, second: UInt) {
52-
self.first = first
53-
self.second = second
54-
}
55-
}
56-
#endif
57-
58-
extension DoubleWord {
59-
@_alwaysEmitIntoClient
60-
@inline(__always)
61-
internal init(_ builtin: _Builtin) {
62-
self = unsafeBitCast(builtin, to: DoubleWord.self)
63-
}
64-
65-
@_alwaysEmitIntoClient
66-
@inline(__always)
67-
internal var _value: _Builtin {
68-
unsafeBitCast(self, to: _Builtin.self)
69-
}
70-
}
71-
72-
extension Bool {
73-
@_alwaysEmitIntoClient
74-
@inline(__always)
75-
internal init(_ builtin: Builtin.Int1) {
76-
self = unsafeBitCast(builtin, to: Bool.self)
77-
}
78-
}
79-
8024
@_alwaysEmitIntoClient
8125
@_transparent
8226
internal func _atomicMemoryFence(
@@ -2150,7 +2094,7 @@ extension UnsafeMutablePointer where Pointee == Int64 {
21502094
}
21512095
}
21522096

2153-
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)
2097+
#if (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)))
21542098
extension UnsafeMutablePointer where Pointee == Int {
21552099
/// Atomically loads a word starting at this address with the specified
21562100
/// memory ordering.
@@ -2663,7 +2607,7 @@ extension UnsafeMutablePointer where Pointee == Int {
26632607
}
26642608
}
26652609

2666-
#else /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
2610+
#else /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
26672611
extension UnsafeMutablePointer where Pointee == Int {
26682612
/// Atomically loads a word starting at this address with the specified
26692613
/// memory ordering.
@@ -3175,8 +3119,8 @@ extension UnsafeMutablePointer where Pointee == Int {
31753119
}
31763120
}
31773121
}
3178-
#endif /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
3179-
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)
3122+
#endif /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
3123+
#if (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)))
31803124
extension UnsafeMutablePointer where Pointee == DoubleWord {
31813125
/// Atomically loads a word starting at this address with the specified
31823126
/// memory ordering.
@@ -3493,7 +3437,7 @@ extension UnsafeMutablePointer where Pointee == DoubleWord {
34933437

34943438
}
34953439

3496-
#else /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
3440+
#else /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
34973441
extension UnsafeMutablePointer where Pointee == DoubleWord {
34983442
/// Atomically loads a word starting at this address with the specified
34993443
/// memory ordering.
@@ -3809,5 +3753,5 @@ extension UnsafeMutablePointer where Pointee == DoubleWord {
38093753
}
38103754

38113755
}
3812-
#endif /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
3756+
#endif /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
38133757
#endif // ATOMICS_NATIVE_BUILTINS

Utilities/gyb_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def lowerFirst(str):
129129
def argLabel(label):
130130
return label + ": " if label != "_" else ""
131131

132-
ptrBitWidth32 = "arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)"
132+
ptrBitWidth32 = "(compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)))"
133133

134134
def bitwidth_variants(value64, value32):
135135
if value64 == value32:

0 commit comments

Comments
 (0)