mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
When building for Windows x86, we have a few conspiring issues to contend with. `__builtin_sqrtf` is treated by clang as a `__builtin_` prefixed libm call. On windows, there is no libm, with the role being taken up by ucrt. However, on 32-bit x86 targets, ucrt does not provide an implementation of `sqrtf` instead defining it inline as a wrapper which widens the argument to a double precision and invokes `sqrt`, the result of which is narrowed to the result. This function is locally defined and expected to be inlined and no out-of-line definition is provided by ucrt that can be referenced. Adjusting the shims to use the intrinsics would be the next option (thanks @stephentyrone!) which would work. However, when building the standard library, we need to combine the system headers which results in the use of the MSVCRT headers for `xmmintrin.h` rather than clang. As a result, we cannot directly use the intrinsics. Opt to instead open-code the intrinsic path by using the compiler builtin for sqrt. This both yields the optimal implementation and avoids providing an additional entry point in the runtime. It also has code size benefits. A special thanks to @stephentyrone for all the discussion and help with this!
5.4 KiB
5.4 KiB