Skip to content

Commit afaa974

Browse files
committed
stdlib: excise the FP16 support routines on x64
Bump the minimum supported CPU to ~Nahelem so that we can take advantage of the F16C/CVT16 extensions to support half floating point rounding. This should avoid the need to replicate the compiler-rt functionality in the runtime and the associated problems with linking compiler-rt builtins on non-Windows targets when performing static linking.
1 parent a0dd2fd commit afaa974

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,12 @@ importer::addCommonInvocationArguments(
778778
// Enable double wide atomic intrinsics on every x86_64 target.
779779
// (This is the default on Darwin, but not so on other platforms.)
780780
invocationArgStrs.push_back("-mcx16");
781+
// Enable the FC16/CVT16 extensions which provide half prevision floating
782+
// point support on x86_64. This bumps the minimum requirement of the CPU
783+
// to ~Haswell, however, Windows 10 (at least as of 1709) requires
784+
// ~Broadwell. At this point, the complexity of supporting an older release
785+
// no longer is justified.
786+
invocationArgStrs.push_back("-mf16c");
781787
}
782788

783789
if (!importerOpts.Optimization.empty()) {

stdlib/cmake/modules/AddSwiftStdlib.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,18 @@ function(_add_target_variant_c_compile_flags)
288288
endif()
289289
endif()
290290

291+
# Avoid the need for the FP16 truncation and extension routines from
292+
# compiler-rt by assuming that we have hardware capable of performing
293+
# half-precision floating point conversions. This was announced circa 2007,
294+
# and is standard with ~Nahelem (~2013).
295+
if(CFLAGS_ARCH STREQUAL x86_64)
296+
if(SWIFT_COMPILER_IS_MSVC_LIKE)
297+
list(APPEND result /clang:-mf16c)
298+
else()
299+
list(APPEND result -mf16c)
300+
endif()
301+
endif()
302+
291303
if(CFLAGS_ENABLE_ASSERTIONS)
292304
list(APPEND result "-UNDEBUG")
293305
else()

stdlib/public/runtime/Float16Support.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929

3030
// Android NDK <r21 do not provide `__aeabi_d2h` in the compiler runtime,
3131
// provide shims in that case.
32-
#if (defined(__ANDROID__) && defined(__ARM_ARCH_7A__) && defined(__ARM_EABI__)) || \
33-
((defined(__i386__) || defined(__i686__) || defined(__x86_64__)) && !defined(__APPLE__) && !defined(__linux__))
32+
#if (defined(__ANDROID__) && defined(__ARM_ARCH_7A__) && defined(__ARM_EABI__))
3433

3534
#include "swift/shims/Visibility.h"
3635

@@ -156,4 +155,4 @@ SWIFT_RUNTIME_EXPORT unsigned short __aeabi_d2h(double d) {
156155
}
157156
#endif
158157

159-
#endif // defined(__x86_64__) && !defined(__APPLE__)
158+
#endif // defined(__ANDROID__) && defined(__ARM_ARCH_7A__) && defined(__ARM_EABI__)

0 commit comments

Comments
 (0)