Skip to content

Commit 8e18576

Browse files
authored
Merge pull request #102 from lorentey/fix-alignment-issues
Fix alignment issues with double-wide atomics on i386
2 parents bb83f84 + f10f031 commit 8e18576

19 files changed

+1731
-3176
lines changed

Package.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ let package = Package(
4444
dependencies: ["_AtomicsShims"],
4545
exclude: [
4646
"CMakeLists.txt",
47-
"AtomicBool.swift.gyb",
48-
"AtomicLazyReference.swift.gyb",
49-
"HighLevelTypes.swift.gyb",
50-
"IntegerConformances.swift.gyb",
51-
"PointerConformances.swift.gyb",
52-
"Primitives.native.swift.gyb",
53-
"Primitives.shims.swift.gyb",
47+
"Conformances/AtomicBool.swift.gyb",
48+
"Conformances/IntegerConformances.swift.gyb",
49+
"Conformances/PointerConformances.swift.gyb",
50+
"Primitives/Primitives.native.swift.gyb",
51+
"Primitives/Primitives.shims.swift.gyb",
52+
"Types/IntegerOperations.swift.gyb",
5453
],
5554
cSettings: _cSettings,
5655
swiftSettings: _swiftSettings
@@ -87,7 +86,8 @@ let package = Package(
8786
"Basics/BasicAtomicUInt8Tests.swift.gyb",
8887
"Basics/BasicAtomicUIntTests.swift.gyb",
8988
"Basics/BasicAtomicUnmanagedTests.swift.gyb",
90-
]
89+
],
90+
swiftSettings: _swiftSettings
9191
),
9292
]
9393
)

[email protected]

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ let package = Package(
3838
dependencies: ["_AtomicsShims"],
3939
exclude: [
4040
"CMakeLists.txt",
41-
"AtomicBool.swift.gyb",
42-
"AtomicLazyReference.swift.gyb",
43-
"HighLevelTypes.swift.gyb",
44-
"IntegerConformances.swift.gyb",
45-
"PointerConformances.swift.gyb",
46-
"Primitives.native.swift.gyb",
47-
"Primitives.shims.swift.gyb",
41+
"Conformances/AtomicBool.swift.gyb",
42+
"Conformances/IntegerConformances.swift.gyb",
43+
"Conformances/PointerConformances.swift.gyb",
44+
"Primitives/Primitives.native.swift.gyb",
45+
"Primitives/Primitives.shims.swift.gyb",
46+
"Types/IntegerOperations.swift.gyb",
4847
],
4948
cSettings: _cSettings,
5049
swiftSettings: _swiftSettings
@@ -81,7 +80,8 @@ let package = Package(
8180
"Basics/BasicAtomicUInt8Tests.swift.gyb",
8281
"Basics/BasicAtomicUIntTests.swift.gyb",
8382
"Basics/BasicAtomicUnmanagedTests.swift.gyb",
84-
]
83+
],
84+
swiftSettings: _swiftSettings
8585
),
8686
]
8787
)

[email protected]

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ let package = Package(
3838
dependencies: ["_AtomicsShims"],
3939
exclude: [
4040
"CMakeLists.txt",
41-
"AtomicBool.swift.gyb",
42-
"AtomicLazyReference.swift.gyb",
43-
"HighLevelTypes.swift.gyb",
44-
"IntegerConformances.swift.gyb",
45-
"PointerConformances.swift.gyb",
46-
"Primitives.native.swift.gyb",
47-
"Primitives.shims.swift.gyb",
41+
"Conformances/AtomicBool.swift.gyb",
42+
"Conformances/IntegerConformances.swift.gyb",
43+
"Conformances/PointerConformances.swift.gyb",
44+
"Primitives/Primitives.native.swift.gyb",
45+
"Primitives/Primitives.shims.swift.gyb",
46+
"Types/IntegerOperations.swift.gyb",
4847
],
4948
cSettings: _cSettings,
5049
swiftSettings: _swiftSettings
@@ -81,7 +80,8 @@ let package = Package(
8180
"Basics/BasicAtomicUInt8Tests.swift.gyb",
8281
"Basics/BasicAtomicUIntTests.swift.gyb",
8382
"Basics/BasicAtomicUnmanagedTests.swift.gyb",
84-
]
83+
],
84+
swiftSettings: _swiftSettings
8585
),
8686
]
8787
)

[email protected]

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ let package = Package(
3838
dependencies: ["_AtomicsShims"],
3939
exclude: [
4040
"CMakeLists.txt",
41-
"AtomicBool.swift.gyb",
42-
"AtomicLazyReference.swift.gyb",
43-
"HighLevelTypes.swift.gyb",
44-
"IntegerConformances.swift.gyb",
45-
"PointerConformances.swift.gyb",
46-
"Primitives.native.swift.gyb",
47-
"Primitives.shims.swift.gyb",
41+
"Conformances/AtomicBool.swift.gyb",
42+
"Conformances/IntegerConformances.swift.gyb",
43+
"Conformances/PointerConformances.swift.gyb",
44+
"Primitives/Primitives.native.swift.gyb",
45+
"Primitives/Primitives.shims.swift.gyb",
46+
"Types/IntegerOperations.swift.gyb",
4847
],
4948
cSettings: _cSettings,
5049
swiftSettings: _swiftSettings
@@ -81,7 +80,8 @@ let package = Package(
8180
"Basics/BasicAtomicUInt8Tests.swift.gyb",
8281
"Basics/BasicAtomicUIntTests.swift.gyb",
8382
"Basics/BasicAtomicUnmanagedTests.swift.gyb",
84-
]
83+
],
84+
swiftSettings: _swiftSettings
8585
),
8686
]
8787
)

Sources/Atomics/Conformances/AtomicBool.swift.gyb

Lines changed: 47 additions & 40 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+
@_transparent
25+
internal init(_ builtin: Builtin.Int1) {
26+
self = unsafeBitCast(builtin, to: Bool.self)
27+
}
28+
}
29+
#else
2030
import _AtomicsShims
2131
#endif
2232

@@ -25,46 +35,42 @@ extension Bool: AtomicValue {
2535
public struct AtomicRepresentation {
2636
public typealias Value = Bool
2737

28-
#if ATOMICS_NATIVE_BUILTINS
29-
@usableFromInline
30-
internal typealias _Storage = Int8
31-
#else
3238
@usableFromInline
3339
internal typealias _Storage = _AtomicInt8Storage
34-
#endif
3540

3641
@usableFromInline
3742
internal var _storage: _Storage
3843

39-
@inline(__always) @_alwaysEmitIntoClient
44+
@_transparent @_alwaysEmitIntoClient
4045
public init(_ value: Bool) {
41-
#if ATOMICS_NATIVE_BUILTINS
42-
_storage = value._atomicValue
43-
#else
44-
_storage = _sa_prepare_Int8(value._atomicValue)
45-
#endif
46+
_storage = value._atomicRepresentation
4647
}
4748

48-
@inline(__always) @_alwaysEmitIntoClient
49+
@_transparent @_alwaysEmitIntoClient
4950
public func dispose() -> Value {
50-
#if ATOMICS_NATIVE_BUILTINS
51-
return _storage._atomicBoolValue
52-
#else
53-
return _sa_dispose_Int8(_storage)._atomicBoolValue
54-
#endif
51+
return _storage._decodeBool
5552
}
5653
}
5754

58-
@_alwaysEmitIntoClient @inline(__always)
59-
internal var _atomicValue: Int8 {
60-
self ? 1 : 0
55+
@_transparent @_alwaysEmitIntoClient
56+
internal var _atomicRepresentation: _AtomicInt8Storage {
57+
let v: Int8 = (self ? 1 : 0)
58+
#if ATOMICS_NATIVE_BUILTINS
59+
return .init(v._value)
60+
#else
61+
return _sa_prepare_Int8(v)
62+
#endif
6163
}
6264
}
6365

64-
extension Int8 {
65-
@_alwaysEmitIntoClient @inline(__always)
66-
internal var _atomicBoolValue: Bool {
67-
(self & 1) != 0
66+
extension _AtomicInt8Storage {
67+
@_transparent @_alwaysEmitIntoClient
68+
internal var _decodeBool: Bool {
69+
#if ATOMICS_NATIVE_BUILTINS
70+
return (Int8(self._value) & 1) != 0
71+
#else
72+
return (_sa_dispose_Int8(self) & 1) != 0
73+
#endif
6874
}
6975
}
7076

@@ -86,7 +92,7 @@ extension Bool.AtomicRepresentation: AtomicStorage {
8692
at pointer: UnsafeMutablePointer<Bool.AtomicRepresentation>,
8793
ordering: AtomicLoadOrdering
8894
) -> Bool {
89-
pointer._extract._atomicLoad(ordering: ordering)._atomicBoolValue
95+
pointer._extract._atomicLoad(ordering: ordering)._decodeBool
9096
}
9197

9298
@_semantics("atomics.requires_constant_orderings")
@@ -96,7 +102,8 @@ extension Bool.AtomicRepresentation: AtomicStorage {
96102
at pointer: UnsafeMutablePointer<Bool.AtomicRepresentation>,
97103
ordering: AtomicStoreOrdering
98104
) {
99-
pointer._extract._atomicStore(desired._atomicValue, ordering: ordering)
105+
pointer._extract._atomicStore(
106+
desired._atomicRepresentation, ordering: ordering)
100107
}
101108

102109
@_semantics("atomics.requires_constant_orderings")
@@ -107,8 +114,8 @@ extension Bool.AtomicRepresentation: AtomicStorage {
107114
ordering: AtomicUpdateOrdering
108115
) -> Bool {
109116
pointer._extract._atomicExchange(
110-
desired._atomicValue, ordering: ordering
111-
)._atomicBoolValue
117+
desired._atomicRepresentation, ordering: ordering
118+
)._decodeBool
112119
}
113120

114121
@_semantics("atomics.requires_constant_orderings")
@@ -120,10 +127,10 @@ extension Bool.AtomicRepresentation: AtomicStorage {
120127
ordering: AtomicUpdateOrdering
121128
) -> (exchanged: Bool, original: Bool) {
122129
let r = pointer._extract._atomicCompareExchange(
123-
expected: expected._atomicValue,
124-
desired: desired._atomicValue,
130+
expected: expected._atomicRepresentation,
131+
desired: desired._atomicRepresentation,
125132
ordering: ordering)
126-
return (r.exchanged, r.original._atomicBoolValue)
133+
return (r.exchanged, r.original._decodeBool)
127134
}
128135

129136
@_semantics("atomics.requires_constant_orderings")
@@ -136,11 +143,11 @@ extension Bool.AtomicRepresentation: AtomicStorage {
136143
failureOrdering: AtomicLoadOrdering
137144
) -> (exchanged: Bool, original: Bool) {
138145
let r = pointer._extract._atomicCompareExchange(
139-
expected: expected._atomicValue,
140-
desired: desired._atomicValue,
146+
expected: expected._atomicRepresentation,
147+
desired: desired._atomicRepresentation,
141148
successOrdering: successOrdering,
142149
failureOrdering: failureOrdering)
143-
return (r.exchanged, r.original._atomicBoolValue)
150+
return (r.exchanged, r.original._decodeBool)
144151
}
145152

146153
@_semantics("atomics.requires_constant_orderings")
@@ -153,11 +160,11 @@ extension Bool.AtomicRepresentation: AtomicStorage {
153160
failureOrdering: AtomicLoadOrdering
154161
) -> (exchanged: Bool, original: Bool) {
155162
let r = pointer._extract._atomicWeakCompareExchange(
156-
expected: expected._atomicValue,
157-
desired: desired._atomicValue,
163+
expected: expected._atomicRepresentation,
164+
desired: desired._atomicRepresentation,
158165
successOrdering: successOrdering,
159166
failureOrdering: failureOrdering)
160-
return (r.exchanged, r.original._atomicBoolValue)
167+
return (r.exchanged, r.original._decodeBool)
161168
}
162169
}
163170

@@ -183,8 +190,8 @@ extension Bool.AtomicRepresentation {
183190
ordering: AtomicUpdateOrdering
184191
) -> Value {
185192
pointer._extract._atomicLoadThen${iname}(
186-
${argLabel(label)}operand._atomicValue, ordering: ordering
187-
)._atomicBoolValue
193+
${argLabel(label)}operand._atomicRepresentation, ordering: ordering
194+
)._decodeBool
188195
}
189196
% end
190197
}

0 commit comments

Comments
 (0)