10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- // MARK: - Memory layout
13
+ // MARK: Memory layout
14
14
15
- /// A 128-bit signed integer type.
15
+ /// A 128-bit signed integer value type.
16
16
@available ( SwiftStdlib 6 . 0 , * )
17
17
@frozen
18
18
public struct Int128 : Sendable {
19
+ #if _pointerBitWidth(_64) || arch(arm64_32)
19
20
// On 64-bit platforms (including arm64_32 and any similar targets with
20
21
// 32b pointers but HW-backed 64b integers), the layout is simply that
21
22
// of `Builtin.Int128`.
22
- #if _pointerBitWidth(_64) || arch(arm64_32)
23
23
public var _value : Builtin . Int128
24
24
25
25
@available ( SwiftStdlib 6 . 0 , * )
@@ -45,25 +45,23 @@ public struct Int128: Sendable {
45
45
@_transparent
46
46
public init ( _low: UInt64 , _high: Int64 ) {
47
47
#if _endian(little)
48
- self = unsafeBitCast ( ( _low, _high) , to: Int128 . self)
48
+ self = unsafeBitCast ( ( _low, _high) , to: Self . self)
49
49
#else
50
- self = unsafeBitCast ( ( _high, _low) , to: Int128 . self)
50
+ self = unsafeBitCast ( ( _high, _low) , to: Self . self)
51
51
#endif
52
52
}
53
53
54
54
#else
55
55
// On 32-bit platforms, we don't want to use Builtin.Int128 for layout
56
56
// because it would be 16B aligned, which is excessive for such targets
57
57
// (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
59
59
// about endianness in this case.
60
60
#if _endian(little)
61
61
public var _low : UInt64
62
-
63
62
public var _high : Int64
64
63
#else
65
64
public var _high : Int64
66
-
67
65
public var _low : UInt64
68
66
#endif
69
67
@@ -94,6 +92,16 @@ public struct Int128: Sendable {
94
92
}
95
93
#endif
96
94
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.
97
105
@available ( SwiftStdlib 6 . 0 , * )
98
106
@_transparent
99
107
public init ( bitPattern: UInt128 ) {
@@ -102,7 +110,6 @@ public struct Int128: Sendable {
102
110
}
103
111
104
112
// MARK: - Constants
105
-
106
113
@available ( SwiftStdlib 6 . 0 , * )
107
114
extension Int128 {
108
115
@available ( SwiftStdlib 6 . 0 , * )
@@ -125,7 +132,6 @@ extension Int128 {
125
132
}
126
133
127
134
// MARK: - Conversions from other integers
128
-
129
135
@available ( SwiftStdlib 6 . 0 , * )
130
136
extension Int128 : ExpressibleByIntegerLiteral ,
131
137
_ExpressibleByBuiltinIntegerLiteral {
0 commit comments