Skip to content

Commit b8c308d

Browse files
authored
Merge pull request #74775 from benrimmington/int128-docs
[stdlib] Update documentation of {U}Int128 types
2 parents f0fa750 + 7d3b2ef commit b8c308d

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

stdlib/public/core/Int128.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
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
1818
public 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, *)
107114
extension 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, *)
130136
extension Int128: ExpressibleByIntegerLiteral,
131137
_ExpressibleByBuiltinIntegerLiteral {

stdlib/public/core/UInt128.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
// MARK: - Memory layout
13+
// MARK: Memory layout
1414

15-
/// A 128-bit unsigned integer type.
15+
/// A 128-bit unsigned integer value type.
1616
@available(SwiftStdlib 6.0, *)
1717
@frozen
1818
public struct UInt128: Sendable {
@@ -59,13 +59,12 @@ public struct UInt128: Sendable {
5959
// about endianness in this case.
6060
#if _endian(little)
6161
public var _low: UInt64
62-
6362
public var _high: UInt64
6463
#else
6564
public var _high: UInt64
66-
6765
public var _low: UInt64
6866
#endif
67+
6968
@available(SwiftStdlib 6.0, *)
7069
@_transparent
7170
public init(_low: UInt64, _high: UInt64) {
@@ -93,6 +92,16 @@ public struct UInt128: Sendable {
9392
}
9493
#endif
9594

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.
96105
@available(SwiftStdlib 6.0, *)
97106
@_transparent
98107
public init(bitPattern: Int128) {
@@ -541,4 +550,3 @@ extension UInt128: FixedWidthInteger, UnsignedInteger {
541550
return Self(_low: _high.byteSwapped, _high: _low.byteSwapped)
542551
}
543552
}
544-

0 commit comments

Comments
 (0)