Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions Sources/Atomics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,33 @@ See https://swift.org/LICENSE.txt for license information
#]]

add_library(Atomics
autogenerated/AtomicBool.swift
autogenerated/AtomicLazyReference.swift
autogenerated/HighLevelTypes.swift
autogenerated/IntegerConformances.swift
autogenerated/PointerConformances.swift
autogenerated/Primitives.native.swift
autogenerated/Primitives.shims.swift
AtomicInteger.swift
AtomicMemoryOrderings.swift
AtomicOptional.swift
AtomicOptionalRawRepresentable.swift
AtomicRawRepresentable.swift
AtomicStrongReference.swift
AtomicValue.swift
DoubleWord.swift
"Unmanaged extensions.swift")
"Types/UnsafeAtomicLazyReference.swift"
"Types/IntegerOperations.swift.gyb"
"Types/DoubleWord.swift"
"Types/ManagedAtomic.swift"
"Types/ManagedAtomicLazyReference.swift"
"Types/AtomicMemoryOrderings.swift"
"Types/UnsafeAtomic.swift"
"Types/autogenerated/IntegerOperations.swift"
"Unmanaged extensions.swift"
"Primitives/Primitives.shims.swift.gyb"
"Primitives/Primitives.native.swift.gyb"
"Primitives/autogenerated/Primitives.native.swift"
"Primitives/autogenerated/Primitives.shims.swift"
"Conformances/RawRepresentable.swift"
"Conformances/AtomicBool.swift.gyb"
"Conformances/PointerConformances.swift.gyb"
"Conformances/OptionalRawRepresentable.swift"
"Conformances/IntegerConformances.swift.gyb"
"Conformances/autogenerated/IntegerConformances.swift"
"Conformances/autogenerated/PointerConformances.swift"
"Conformances/autogenerated/AtomicBool.swift"
"Protocols/AtomicInteger.swift"
"Protocols/AtomicValue.swift"
"Protocols/AtomicReference.swift"
"Protocols/AtomicOptionalWrappable.swift"
"Protocols/AtomicStorage.swift")

set_target_properties(Atomics PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ extension ${construct} where Value == Bool {
ordering: ordering)
return original ${op} operand
}

% end
}
% end
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ extension UnsafeAtomic where Value == Bool {
ordering: ordering)
return original && operand
}

/// Perform an atomic logical OR operation and return the original value, applying
/// the specified memory ordering.
///
Expand All @@ -320,6 +321,7 @@ extension UnsafeAtomic where Value == Bool {
ordering: ordering)
return original || operand
}

/// Perform an atomic logical XOR operation and return the original value, applying
/// the specified memory ordering.
///
Expand All @@ -338,6 +340,7 @@ extension UnsafeAtomic where Value == Bool {
ordering: ordering)
return original != operand
}

}
extension ManagedAtomic where Value == Bool {
/// Perform an atomic logical AND operation and return the original value, applying
Expand Down Expand Up @@ -412,6 +415,7 @@ extension ManagedAtomic where Value == Bool {
ordering: ordering)
return original && operand
}

/// Perform an atomic logical OR operation and return the original value, applying
/// the specified memory ordering.
///
Expand All @@ -430,6 +434,7 @@ extension ManagedAtomic where Value == Bool {
ordering: ordering)
return original || operand
}

/// Perform an atomic logical XOR operation and return the original value, applying
/// the specified memory ordering.
///
Expand All @@ -448,4 +453,5 @@ extension ManagedAtomic where Value == Bool {
ordering: ordering)
return original != operand
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ extension UInt.AtomicRepresentation: AtomicIntegerStorage {



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



#else /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
#else /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
extension DoubleWord: AtomicValue {
@frozen
public struct AtomicRepresentation {
Expand Down Expand Up @@ -2363,5 +2363,5 @@ extension DoubleWord.AtomicRepresentation: AtomicStorage {
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,9 @@ ${autogenerated_warning()}
#if ATOMICS_NATIVE_BUILTINS
import Builtin

#if ${ptrBitWidth32}
@frozen
@_alignment(8)
public struct DoubleWord {
@usableFromInline
internal typealias _Builtin = Builtin.Int64

public var first: UInt
public var second: UInt

@inlinable @inline(__always)
public init(first: UInt, second: UInt) {
self.first = first
self.second = second
}
}
#else
@frozen
@_alignment(16)
public struct DoubleWord {
@usableFromInline
internal typealias _Builtin = Builtin.Int128

public var first: UInt
public var second: UInt

@inlinable @inline(__always)
public init(first: UInt, second: UInt) {
self.first = first
self.second = second
}
}
#endif

extension DoubleWord {
@_alwaysEmitIntoClient
@inline(__always)
internal init(_ builtin: _Builtin) {
self = unsafeBitCast(builtin, to: DoubleWord.self)
}

@_alwaysEmitIntoClient
@inline(__always)
internal var _value: _Builtin {
unsafeBitCast(self, to: _Builtin.self)
}
}

extension Bool {
@_alwaysEmitIntoClient
@inline(__always)
@_transparent
internal init(_ builtin: Builtin.Int1) {
self = unsafeBitCast(builtin, to: Bool.self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,9 @@
#if ATOMICS_NATIVE_BUILTINS
import Builtin

#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)
@frozen
@_alignment(8)
public struct DoubleWord {
@usableFromInline
internal typealias _Builtin = Builtin.Int64

public var first: UInt
public var second: UInt

@inlinable @inline(__always)
public init(first: UInt, second: UInt) {
self.first = first
self.second = second
}
}
#else
@frozen
@_alignment(16)
public struct DoubleWord {
@usableFromInline
internal typealias _Builtin = Builtin.Int128

public var first: UInt
public var second: UInt

@inlinable @inline(__always)
public init(first: UInt, second: UInt) {
self.first = first
self.second = second
}
}
#endif

extension DoubleWord {
@_alwaysEmitIntoClient
@inline(__always)
internal init(_ builtin: _Builtin) {
self = unsafeBitCast(builtin, to: DoubleWord.self)
}

@_alwaysEmitIntoClient
@inline(__always)
internal var _value: _Builtin {
unsafeBitCast(self, to: _Builtin.self)
}
}

extension Bool {
@_alwaysEmitIntoClient
@inline(__always)
@_transparent
internal init(_ builtin: Builtin.Int1) {
self = unsafeBitCast(builtin, to: Bool.self)
}
Expand Down Expand Up @@ -2150,7 +2102,7 @@ extension UnsafeMutablePointer where Pointee == Int64 {
}
}

#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)
#if (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)))
extension UnsafeMutablePointer where Pointee == Int {
/// Atomically loads a word starting at this address with the specified
/// memory ordering.
Expand Down Expand Up @@ -2663,7 +2615,7 @@ extension UnsafeMutablePointer where Pointee == Int {
}
}

#else /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
#else /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
extension UnsafeMutablePointer where Pointee == Int {
/// Atomically loads a word starting at this address with the specified
/// memory ordering.
Expand Down Expand Up @@ -3175,8 +3127,8 @@ extension UnsafeMutablePointer where Pointee == Int {
}
}
}
#endif /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
#if arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)
#endif /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
#if (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32)))
extension UnsafeMutablePointer where Pointee == DoubleWord {
/// Atomically loads a word starting at this address with the specified
/// memory ordering.
Expand Down Expand Up @@ -3493,7 +3445,7 @@ extension UnsafeMutablePointer where Pointee == DoubleWord {

}

#else /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
#else /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
extension UnsafeMutablePointer where Pointee == DoubleWord {
/// Atomically loads a word starting at this address with the specified
/// memory ordering.
Expand Down Expand Up @@ -3809,5 +3761,5 @@ extension UnsafeMutablePointer where Pointee == DoubleWord {
}

}
#endif /* arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32) */
#endif /* (compiler(>=5.9) && _pointerBitWidth(_32)) || (compiler(<5.9) && (arch(i386) || arch(arm) || arch(arm64_32) || arch(wasm32))) */
#endif // ATOMICS_NATIVE_BUILTINS
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
//
//===----------------------------------------------------------------------===//

/// A type that supports atomic operations through a separate atomic storage
/// representation.
public protocol AtomicValue {
/// The atomic storage representation for this value.
associatedtype AtomicRepresentation: AtomicStorage
/* where Self is a subtype of AtomicRepresentation.Value */
}

/// The storage representation for an atomic value, providing pointer-based
/// atomic operations. This is a low-level implementation detail of atomic
/// types; instead of directly handling conforming types, it is usually better
Expand Down
19 changes: 19 additions & 0 deletions Sources/Atomics/Protocols/AtomicValue.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

/// A type that supports atomic operations through a separate atomic storage
/// representation.
public protocol AtomicValue {
/// The atomic storage representation for this value.
associatedtype AtomicRepresentation: AtomicStorage
/* where Self is a subtype of AtomicRepresentation.Value */
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,60 @@
//
//===----------------------------------------------------------------------===//

#if !ATOMICS_NATIVE_BUILTINS
#if ATOMICS_NATIVE_BUILTINS
import Builtin

#if _pointerBitWidth(_32)
@frozen
@_alignment(8)
public struct DoubleWord {
@usableFromInline
internal typealias _Builtin = Builtin.Int64

public var first: UInt
public var second: UInt

@inlinable @inline(__always)
public init(first: UInt, second: UInt) {
self.first = first
self.second = second
}
}
#elseif _pointerBitWidth(_64)
@frozen
@_alignment(16)
public struct DoubleWord {
@usableFromInline
internal typealias _Builtin = Builtin.Int128

public var first: UInt
public var second: UInt

@inlinable @inline(__always)
public init(first: UInt, second: UInt) {
self.first = first
self.second = second
}
}
#else
#error("Unexpected pointer bit width")
#endif

extension DoubleWord {
@_alwaysEmitIntoClient
@_transparent
internal init(_ builtin: _Builtin) {
self = unsafeBitCast(builtin, to: DoubleWord.self)
}

@_alwaysEmitIntoClient
@_transparent
internal var _value: _Builtin {
unsafeBitCast(self, to: _Builtin.self)
}
}

#else // !ATOMICS_NATIVE_BUILTINS
import _AtomicsShims
public typealias DoubleWord = _AtomicsShims.DoubleWord
#endif
Expand Down
Loading