Skip to content

Commit 5342ef1

Browse files
Use specialized [u]int64 -> FloatingPoint conversions even on 32b platforms. (#70542)
This means that we'll end up going int32 -> int64 -> float/double sometiems, but LLVM knows how to optimize away the intermediate conversion so we end up with just a normal 32b->float conversion as desired, and we get much, much better performance on oddball platforms like arm64_32.
1 parent dc8e9fe commit 5342ef1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

stdlib/public/core/FloatingPointTypes.swift.gyb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,13 @@ extension ${Self} {
10551055
@inlinable // FIXME(inline-always)
10561056
@inline(__always)
10571057
public init<Source: BinaryInteger>(_ value: Source) {
1058-
if value.bitWidth <= ${word_bits} {
1058+
if value.bitWidth <= 64 {
10591059
if Source.isSigned {
1060-
let asInt = Int(truncatingIfNeeded: value)
1061-
_value = Builtin.sitofp_Int${word_bits}_FPIEEE${bits}(asInt._value)
1060+
let asInt = Int64(truncatingIfNeeded: value)
1061+
_value = Builtin.sitofp_Int64_FPIEEE${bits}(asInt._value)
10621062
} else {
1063-
let asUInt = UInt(truncatingIfNeeded: value)
1064-
_value = Builtin.uitofp_Int${word_bits}_FPIEEE${bits}(asUInt._value)
1063+
let asUInt = UInt64(truncatingIfNeeded: value)
1064+
_value = Builtin.uitofp_Int64_FPIEEE${bits}(asUInt._value)
10651065
}
10661066
} else {
10671067
// TODO: we can do much better than the generic _convert here for Float

0 commit comments

Comments
 (0)