Skip to content

Commit 8e11af4

Browse files
Make the naming of underlying builtin for FP + Vector match Integer. (#15430)
* Make the underlying builtins for FP + Vector match Integer. For stdlib integer types, these are named `_value` and `init(_ _value: Builtin.xxx)`. This patch adopts the same scheme for stdlib floating point and SDK overlay vector types, and removes a legacy init for integers that was only needed to support them. There should be no changes visible outside of the stdlib, and no functional change within the stdlib; the naming of some implementation details is simply more uniform now.
1 parent b8b3144 commit 8e11af4

File tree

6 files changed

+28
-40
lines changed

6 files changed

+28
-40
lines changed

stdlib/public/SDK/simd/simd.swift.gyb

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,20 @@ cardinal = { 2:'two', 3:'three', 4:'four'}
4343
@_alignment(${vecsize})
4444
public struct ${vectype} {
4545
46-
public var _vector: Builtin.${llvm_vectype}
46+
public var _value: Builtin.${llvm_vectype}
4747
4848
% for i in xrange(count):
4949
public var ${component[i]} : ${scalar} {
5050
@_transparent
5151
get {
52-
let elt = Builtin.${extractelement}(_vector,
52+
let elt = Builtin.${extractelement}(_value,
5353
(${i} as Int32)._value)
5454
55-
return ${scalar}(_bits: elt)
55+
return ${scalar}(elt)
5656
}
5757
@_transparent
5858
set {
59-
_vector = Builtin.${insertelement}(_vector,
59+
_value = Builtin.${insertelement}(_value,
6060
newValue._value,
6161
(${i} as Int32)._value)
6262
}
@@ -68,8 +68,8 @@ public struct ${vectype} {
6868
public init() { self.init(0) }
6969
7070
@_transparent
71-
public init(_bits: Builtin.${llvm_vectype}) {
72-
_vector = _bits
71+
public init(_ _value: Builtin.${llvm_vectype}) {
72+
self._value = _value
7373
}
7474
7575
/// Initialize a vector with the specified elements.
@@ -81,7 +81,7 @@ public struct ${vectype} {
8181
${component[i]}._value,
8282
(${i} as Int32)._value)
8383
% end
84-
_vector = v
84+
_value = v
8585
}
8686
8787
/// Initialize a vector with the specified elements.
@@ -113,15 +113,15 @@ public struct ${vectype} {
113113
get {
114114
_precondition(index >= 0, "Vector index out of range")
115115
_precondition(index < ${count}, "Vector index out of range")
116-
let elt = Builtin.${extractelement}(_vector,
116+
let elt = Builtin.${extractelement}(_value,
117117
Int32(index)._value)
118-
return ${scalar}(_bits: elt)
118+
return ${scalar}(elt)
119119
}
120120
@_transparent
121121
set(value) {
122122
_precondition(index >= 0, "Vector index out of range")
123123
_precondition(index < ${count}, "Vector index out of range")
124-
_vector = Builtin.${insertelement}(_vector,
124+
_value = Builtin.${insertelement}(_value,
125125
value._value,
126126
Int32(index)._value)
127127
}
@@ -183,15 +183,13 @@ extension ${vectype} {
183183
/// Vector (elementwise) sum of `lhs` and `rhs`.
184184
@_transparent
185185
public static func ${wrap}+(lhs: ${vectype}, rhs: ${vectype}) -> ${vectype} {
186-
return ${vectype}(_bits:
187-
Builtin.${prefix}add_${llvm_vectype}(lhs._vector, rhs._vector))
186+
return ${vectype}(Builtin.${prefix}add_${llvm_vectype}(lhs._value, rhs._value))
188187
}
189188
190189
/// Vector (elementwise) difference of `lhs` and `rhs`.
191190
@_transparent
192191
public static func ${wrap}-(lhs: ${vectype}, rhs: ${vectype}) -> ${vectype} {
193-
return ${vectype}(_bits:
194-
Builtin.${prefix}sub_${llvm_vectype}(lhs._vector, rhs._vector))
192+
return ${vectype}(Builtin.${prefix}sub_${llvm_vectype}(lhs._value, rhs._value))
195193
}
196194
197195
/// Negation of `rhs`.
@@ -204,8 +202,7 @@ extension ${vectype} {
204202
/// vector product).
205203
@_transparent
206204
public static func ${wrap}*(lhs: ${vectype}, rhs: ${vectype}) -> ${vectype} {
207-
return ${vectype}(_bits:
208-
Builtin.${prefix}mul_${llvm_vectype}(lhs._vector, rhs._vector))
205+
return ${vectype}(Builtin.${prefix}mul_${llvm_vectype}(lhs._value, rhs._value))
209206
}
210207
211208
/// Scalar-Vector product.
@@ -223,8 +220,7 @@ extension ${vectype} {
223220
/// Elementwise quotient of `lhs` and `rhs`.
224221
@_transparent
225222
public static func /(lhs: ${vectype}, rhs: ${vectype}) -> ${vectype} {
226-
return ${vectype}(_bits:
227-
Builtin.${divide}_${llvm_vectype}(lhs._vector, rhs._vector))
223+
return ${vectype}(Builtin.${divide}_${llvm_vectype}(lhs._value, rhs._value))
228224
}
229225
230226
/// Divide vector by scalar.

stdlib/public/core/BuiltinMath.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def TypedUnaryIntrinsicFunctions():
6767
@_inlineable // FIXME(sil-serialize-all)
6868
@_transparent
6969
public func _${ufunc}(_ x: ${T}) -> ${T} {
70-
return ${T}(_bits: Builtin.int_${ufunc}_FPIEEE${bits}(x._value))
70+
return ${T}(Builtin.int_${ufunc}_FPIEEE${bits}(x._value))
7171
}
7272
% if bits == 80:
7373
#endif

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public struct ${Self} {
7474
@_inlineable // FIXME(sil-serialize-all)
7575
@_transparent
7676
public // @testable
77-
init(_bits v: Builtin.FPIEEE${bits}) {
78-
self._value = v
77+
init(_ _value: Builtin.FPIEEE${bits}) {
78+
self._value = _value
7979
}
8080
}
8181

@@ -214,7 +214,7 @@ extension ${Self}: BinaryFloatingPoint {
214214
/// - Parameter bitPattern: The integer encoding of a `${Self}` instance.
215215
@_inlineable // FIXME(sil-serialize-all)
216216
public init(bitPattern: UInt${bits}) {
217-
self.init(_bits: Builtin.bitcast_Int${bits}_FPIEEE${bits}(bitPattern._value))
217+
self.init(Builtin.bitcast_Int${bits}_FPIEEE${bits}(bitPattern._value))
218218
}
219219

220220
/// The sign of the floating-point value.
@@ -1449,7 +1449,7 @@ extension ${Self} : _ExpressibleByBuiltinIntegerLiteral, ExpressibleByIntegerLit
14491449
@_transparent
14501450
public
14511451
init(_builtinIntegerLiteral value: Builtin.Int${builtinIntLiteralBits}){
1452-
self = ${Self}(_bits: Builtin.itofp_with_overflow_Int${builtinIntLiteralBits}_FPIEEE${bits}(value))
1452+
self = ${Self}(Builtin.itofp_with_overflow_Int${builtinIntLiteralBits}_FPIEEE${bits}(value))
14531453
}
14541454

14551455
/// Creates a new value from the given integer literal.
@@ -1468,7 +1468,7 @@ extension ${Self} : _ExpressibleByBuiltinIntegerLiteral, ExpressibleByIntegerLit
14681468
@_inlineable // FIXME(sil-serialize-all)
14691469
@_transparent
14701470
public init(integerLiteral value: Int64) {
1471-
self = ${Self}(_bits: Builtin.sitofp_Int64_FPIEEE${bits}(value._value))
1471+
self = ${Self}(Builtin.sitofp_Int64_FPIEEE${bits}(value._value))
14721472
}
14731473
}
14741474

@@ -1483,9 +1483,9 @@ extension ${Self} : _ExpressibleByBuiltinFloatLiteral {
14831483
public
14841484
init(_builtinFloatLiteral value: Builtin.FPIEEE${builtinFloatLiteralBits}) {
14851485
% if bits == builtinFloatLiteralBits:
1486-
self = ${Self}(_bits: value)
1486+
self = ${Self}(value)
14871487
% elif bits < builtinFloatLiteralBits:
1488-
self = ${Self}(_bits: Builtin.fptrunc_FPIEEE${builtinFloatLiteralBits}_FPIEEE${bits}(value))
1488+
self = ${Self}(Builtin.fptrunc_FPIEEE${builtinFloatLiteralBits}_FPIEEE${bits}(value))
14891489
% else:
14901490
// FIXME: This is actually losing precision <rdar://problem/14073102>.
14911491
self = ${Self}(Builtin.fpext_FPIEEE${builtinFloatLiteralBits}_FPIEEE${bits}(value))
@@ -1503,10 +1503,10 @@ extension ${Self} : _ExpressibleByBuiltinFloatLiteral {
15031503
public
15041504
init(_builtinFloatLiteral value: Builtin.FPIEEE${builtinFloatLiteralBits}) {
15051505
% if bits == builtinFloatLiteralBits:
1506-
self = ${Self}(_bits: value)
1506+
self = ${Self}(value)
15071507
% elif bits < builtinFloatLiteralBits:
15081508
// FIXME: This can result in double rounding errors (SR-7124).
1509-
self = ${Self}(_bits: Builtin.fptrunc_FPIEEE${builtinFloatLiteralBits}_FPIEEE${bits}(value))
1509+
self = ${Self}(Builtin.fptrunc_FPIEEE${builtinFloatLiteralBits}_FPIEEE${bits}(value))
15101510
% else:
15111511
// FIXME: This is actually losing precision <rdar://problem/14073102>.
15121512
self = ${Self}(Builtin.fpext_FPIEEE${builtinFloatLiteralBits}_FPIEEE${bits}(value))
@@ -1569,15 +1569,15 @@ extension ${Self} {
15691569
@_inlineable // FIXME(sil-serialize-all)
15701570
@_transparent
15711571
public var magnitude: ${Self} {
1572-
return ${Self}(_bits: Builtin.int_fabs_FPIEEE${bits}(_value))
1572+
return ${Self}(Builtin.int_fabs_FPIEEE${bits}(_value))
15731573
}
15741574
}
15751575

15761576
extension ${Self} {
15771577
@_inlineable // FIXME(sil-serialize-all)
15781578
@_transparent
15791579
public static prefix func - (x: ${Self}) -> ${Self} {
1580-
return ${Self}(_bits: Builtin.fneg_FPIEEE${bits}(x._value))
1580+
return ${Self}(Builtin.fneg_FPIEEE${bits}(x._value))
15811581
}
15821582
}
15831583

stdlib/public/core/Integers.swift.gyb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3290,14 +3290,6 @@ ${assignmentOperatorComment('%', True)}
32903290
self._value = _value
32913291
}
32923292

3293-
// FIXME(integers): in order to remove this, the simd.swift.gyb should be
3294-
// updated
3295-
@_inlineable // FIXME(sil-serialize-all)
3296-
@_transparent
3297-
public init(_bits: Builtin.Int${bits}) {
3298-
self._value = _bits
3299-
}
3300-
33013293
% for x in binaryBitwise:
33023294
${assignmentOperatorComment(x.operator, True)}
33033295
@_inlineable // FIXME(sil-serialize-all)

test/DebugInfo/vector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public struct float2 {
1414
get {
1515
let elt = Builtin.extractelement_Vec2xFPIEEE32_Int32(_vector,
1616
Int32(index)._value)
17-
return Float(_bits: elt)
17+
return Float(elt)
1818
}
1919
}
2020
}

test/stdlib/FloatingPoint.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension Float80 {
4949
Builtin.zextOrBitCast_Int64_Int80((64 as Int64)._value))
5050
result = Builtin.or_Int80(
5151
result, Builtin.zextOrBitCast_Int64_Int80(bitPattern.significand._value))
52-
self = Float80(_bits: Builtin.bitcast_Int80_FPIEEE80(result))
52+
self = Float80(Builtin.bitcast_Int80_FPIEEE80(result))
5353
}
5454
}
5555

0 commit comments

Comments
 (0)