Skip to content

Commit 298ab20

Browse files
committed
[stdlib][nfc] Prefer to put the _pointerBitWidth(_64) case first, as that is far more common
1 parent b82ce9c commit 298ab20

File tree

6 files changed

+41
-42
lines changed

6 files changed

+41
-42
lines changed

stdlib/public/core/AtomicInt.swift.gyb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ internal func _swift_stdlib_atomicCompareExchangeStrongInt(
6565
object target: UnsafeMutablePointer<Int>,
6666
expected: UnsafeMutablePointer<Int>,
6767
desired: Int) -> Bool {
68-
#if _pointerBitWidth(_32)
69-
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int32(
70-
target._rawValue, expected.pointee._value, desired._value)
71-
#elseif _pointerBitWidth(_64)
68+
#if _pointerBitWidth(_64)
7269
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int64(
7370
target._rawValue, expected.pointee._value, desired._value)
71+
#elseif _pointerBitWidth(_32)
72+
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int32(
73+
target._rawValue, expected.pointee._value, desired._value)
7474
#else
7575
#error("Unknown platform")
7676
#endif
@@ -84,12 +84,12 @@ internal func _swift_stdlib_atomicCompareExchangeStrongInt(
8484
public // Existing uses outside stdlib
8585
func _swift_stdlib_atomicLoadInt(
8686
object target: UnsafeMutablePointer<Int>) -> Int {
87-
#if _pointerBitWidth(_32)
88-
let value = Builtin.atomicload_seqcst_Int32(target._rawValue)
89-
return Int(value)
90-
#elseif _pointerBitWidth(_64)
87+
#if _pointerBitWidth(_64)
9188
let value = Builtin.atomicload_seqcst_Int64(target._rawValue)
9289
return Int(value)
90+
#elseif _pointerBitWidth(_32)
91+
let value = Builtin.atomicload_seqcst_Int32(target._rawValue)
92+
return Int(value)
9393
#else
9494
#error("Unknown platform")
9595
#endif
@@ -99,10 +99,10 @@ func _swift_stdlib_atomicLoadInt(
9999
internal func _swift_stdlib_atomicStoreInt(
100100
object target: UnsafeMutablePointer<Int>,
101101
desired: Int) {
102-
#if _pointerBitWidth(_32)
103-
Builtin.atomicstore_seqcst_Int32(target._rawValue, desired._value)
104-
#elseif _pointerBitWidth(_64)
102+
#if _pointerBitWidth(_64)
105103
Builtin.atomicstore_seqcst_Int64(target._rawValue, desired._value)
104+
#elseif _pointerBitWidth(_32)
105+
Builtin.atomicstore_seqcst_Int32(target._rawValue, desired._value)
106106
#else
107107
#error("Unknown platform")
108108
#endif
@@ -117,14 +117,14 @@ func _swift_stdlib_atomicFetch${operation}Int(
117117
object target: UnsafeMutablePointer<Int>,
118118
operand: Int) -> Int {
119119
let rawTarget = UnsafeMutableRawPointer(target)
120-
#if _pointerBitWidth(_32)
121-
let value = _swift_stdlib_atomicFetch${operation}Int32(
122-
object: rawTarget.assumingMemoryBound(to: Int32.self),
123-
operand: Int32(operand))
124-
#elseif _pointerBitWidth(_64)
120+
#if _pointerBitWidth(_64)
125121
let value = _swift_stdlib_atomicFetch${operation}Int64(
126122
object: rawTarget.assumingMemoryBound(to: Int64.self),
127123
operand: Int64(operand))
124+
#elseif _pointerBitWidth(_32)
125+
let value = _swift_stdlib_atomicFetch${operation}Int32(
126+
object: rawTarget.assumingMemoryBound(to: Int32.self),
127+
operand: Int32(operand))
128128
#else
129129
#error("Unknown platform")
130130
#endif

stdlib/public/core/Builtin.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,18 @@ internal var _objectPointerLowSpareBitShift: UInt {
406406
}
407407
}
408408

409-
#if _pointerBitWidth(_32)
410409
@inlinable
411410
internal var _objectPointerIsObjCBit: UInt {
412-
@inline(__always) get { return 0x0000_0002 }
413-
}
414-
#elseif _pointerBitWidth(_64)
415-
@inlinable
416-
internal var _objectPointerIsObjCBit: UInt {
417-
@inline(__always) get { return 0x4000_0000_0000_0000 }
418-
}
411+
@inline(__always) get {
412+
#if _pointerBitWidth(_64)
413+
return 0x4000_0000_0000_0000
414+
#elseif _pointerBitWidth(_32)
415+
return 0x0000_0002
419416
#else
420417
#error("Unknown platform")
421418
#endif
419+
}
420+
}
422421

423422
/// Extract the raw bits of `x`.
424423
@inlinable

stdlib/public/core/DictionaryVariant.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ extension Dictionary {
4646
@inlinable
4747
@inline(__always)
4848
init(dummy: Void) {
49-
#if _pointerBitWidth(_32)
50-
self.init(native: _NativeDictionary())
51-
#elseif _pointerBitWidth(_64)
49+
#if _pointerBitWidth(_64)
5250
self.object = _BridgeStorage(taggedPayload: 0)
51+
#elseif _pointerBitWidth(_32)
52+
self.init(native: _NativeDictionary())
5353
#else
5454
#error("Unknown platform")
5555
#endif

stdlib/public/core/Hasher.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ extension Hasher {
160160

161161
@inline(__always)
162162
internal mutating func combine(_ value: UInt) {
163-
#if _pointerBitWidth(_32)
164-
combine(UInt32(truncatingIfNeeded: value))
165-
#elseif _pointerBitWidth(_64)
163+
#if _pointerBitWidth(_64)
166164
combine(UInt64(truncatingIfNeeded: value))
165+
#elseif _pointerBitWidth(_32)
166+
combine(UInt32(truncatingIfNeeded: value))
167167
#else
168168
#error("Unknown platform")
169169
#endif
@@ -425,15 +425,15 @@ public struct Hasher {
425425
@usableFromInline
426426
internal static func _hash(seed: Int, _ value: UInt) -> Int {
427427
var state = _State(seed: seed)
428-
#if _pointerBitWidth(_32)
428+
#if _pointerBitWidth(_64)
429+
_internalInvariant(UInt.bitWidth == UInt64.bitWidth)
430+
state.compress(UInt64(truncatingIfNeeded: value))
431+
let tbc = _TailBuffer(tail: 0, byteCount: 8)
432+
#elseif _pointerBitWidth(_32)
429433
_internalInvariant(UInt.bitWidth < UInt64.bitWidth)
430434
let tbc = _TailBuffer(
431435
tail: UInt64(truncatingIfNeeded: value),
432436
byteCount: UInt.bitWidth &>> 3)
433-
#elseif _pointerBitWidth(_64)
434-
_internalInvariant(UInt.bitWidth == UInt64.bitWidth)
435-
state.compress(UInt64(truncatingIfNeeded: value))
436-
let tbc = _TailBuffer(tail: 0, byteCount: 8)
437437
#else
438438
#error("Unknown platform")
439439
#endif

stdlib/public/core/SetVariant.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ extension Set {
3636
@inlinable
3737
@inline(__always)
3838
init(dummy: ()) {
39-
#if _pointerBitWidth(_32)
40-
self.init(native: _NativeSet())
41-
#elseif _pointerBitWidth(_64)
39+
#if _pointerBitWidth(_64)
4240
self.object = _BridgeStorage(taggedPayload: 0)
41+
#elseif _pointerBitWidth(_32)
42+
self.init(native: _NativeSet())
4343
#else
4444
#error("Unknown platform")
4545
#endif

stdlib/public/core/StringGuts.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ extension _StringGuts {
179179
#else
180180
@usableFromInline @inline(never) @_effects(releasenone)
181181
internal func _invariantCheck() {
182-
#if _pointerBitWidth(_32)
183-
_internalInvariant(MemoryLayout<String>.size == 12, """
182+
#if _pointerBitWidth(_64)
183+
_internalInvariant(MemoryLayout<String>.size == 16, """
184184
the runtime is depending on this, update Reflection.mm and \
185185
this if you change it
186186
""")
187-
#elseif _pointerBitWidth(_64)
188-
_internalInvariant(MemoryLayout<String>.size == 16, """
187+
#elseif _pointerBitWidth(_32)
188+
_internalInvariant(MemoryLayout<String>.size == 12, """
189189
the runtime is depending on this, update Reflection.mm and \
190190
this if you change it
191191
""")

0 commit comments

Comments
 (0)