1010//
1111//===----------------------------------------------------------------------===//
1212
13- // MARK: - Memory layout
13+ // MARK: Memory layout
1414
15- /// A 128-bit signed integer type.
15+ /// A 128-bit signed integer value type.
1616@available ( SwiftStdlib 6 . 0 , * )
1717@frozen
1818public struct Int128 : Sendable {
19+ #if _pointerBitWidth(_64) || arch(arm64_32)
1920 // On 64-bit platforms (including arm64_32 and any similar targets with
2021 // 32b pointers but HW-backed 64b integers), the layout is simply that
2122 // of `Builtin.Int128`.
22- #if _pointerBitWidth(_64) || arch(arm64_32)
2323 public var _value : Builtin . Int128
2424
2525 @available ( SwiftStdlib 6 . 0 , * )
@@ -45,25 +45,23 @@ public struct Int128: Sendable {
4545 @_transparent
4646 public init ( _low: UInt64 , _high: Int64 ) {
4747#if _endian(little)
48- self = unsafeBitCast ( ( _low, _high) , to: Int128 . self)
48+ self = unsafeBitCast ( ( _low, _high) , to: Self . self)
4949#else
50- self = unsafeBitCast ( ( _high, _low) , to: Int128 . self)
50+ self = unsafeBitCast ( ( _high, _low) , to: Self . self)
5151#endif
5252 }
5353
5454#else
5555 // On 32-bit platforms, we don't want to use Builtin.Int128 for layout
5656 // because it would be 16B aligned, which is excessive for such targets
5757 // (and generally incompatible with C's `_BitInt(128)`). Instead we lay
58- // out the type as two `UInt64 ` fields--note that we have to be careful
58+ // out the type as two `{U}Int64 ` fields--note that we have to be careful
5959 // about endianness in this case.
6060#if _endian(little)
6161 public var _low : UInt64
62-
6362 public var _high : Int64
6463#else
6564 public var _high : Int64
66-
6765 public var _low : UInt64
6866#endif
6967
@@ -94,6 +92,16 @@ public struct Int128: Sendable {
9492 }
9593#endif
9694
95+ /// Creates a new instance with the same memory representation as the given
96+ /// value.
97+ ///
98+ /// This initializer does not perform any range or overflow checking. The
99+ /// resulting instance may not have the same numeric value as
100+ /// `bitPattern`---it is only guaranteed to use the same pattern of bits in
101+ /// its binary representation.
102+ ///
103+ /// - Parameter bitPattern: A value to use as the source of the new instance's
104+ /// binary representation.
97105 @available ( SwiftStdlib 6 . 0 , * )
98106 @_transparent
99107 public init ( bitPattern: UInt128 ) {
@@ -102,7 +110,6 @@ public struct Int128: Sendable {
102110}
103111
104112// MARK: - Constants
105-
106113@available ( SwiftStdlib 6 . 0 , * )
107114extension Int128 {
108115 @available ( SwiftStdlib 6 . 0 , * )
@@ -125,7 +132,6 @@ extension Int128 {
125132}
126133
127134// MARK: - Conversions from other integers
128-
129135@available ( SwiftStdlib 6 . 0 , * )
130136extension Int128 : ExpressibleByIntegerLiteral ,
131137 _ExpressibleByBuiltinIntegerLiteral {
0 commit comments