Skip to content

Commit 154454e

Browse files
Use specialized [u]int64 -> FloatingPoint conversions even on 32b platforms. (#70541)
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 bbc5543 commit 154454e

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
@@ -1061,13 +1061,13 @@ extension ${Self} {
10611061
@inlinable // FIXME(inline-always)
10621062
@inline(__always)
10631063
public init<Source: BinaryInteger>(_ value: Source) {
1064-
if value.bitWidth <= ${word_bits} {
1064+
if value.bitWidth <= 64 {
10651065
if Source.isSigned {
1066-
let asInt = Int(truncatingIfNeeded: value)
1067-
_value = Builtin.sitofp_Int${word_bits}_FPIEEE${bits}(asInt._value)
1066+
let asInt = Int64(truncatingIfNeeded: value)
1067+
_value = Builtin.sitofp_Int64_FPIEEE${bits}(asInt._value)
10681068
} else {
1069-
let asUInt = UInt(truncatingIfNeeded: value)
1070-
_value = Builtin.uitofp_Int${word_bits}_FPIEEE${bits}(asUInt._value)
1069+
let asUInt = UInt64(truncatingIfNeeded: value)
1070+
_value = Builtin.uitofp_Int64_FPIEEE${bits}(asUInt._value)
10711071
}
10721072
} else {
10731073
// TODO: we can do much better than the generic _convert here for Float

0 commit comments

Comments
 (0)