[libcxx] Fix setup of MSVC specific intrinsics in Ryu code

This fixes warnings about implicitly declared `_umul128` and
`__shiftright128` when building for x86_64 with clang-cl.

Use `_MSC_VER` instead of `_LIBCPP_COMPILER_MSVC` for enabling MSVC
specific code; `_MSC_VER` is defined both in clang-cl and MSVC,
while `_LIBCPP_COMPILER_MSVC` only is defined if building with the
actual MSVC compiler.

Include `ryu.h` at the head of `d2s_intrinsics.h`, as it uses
the `_LIBCPP_64_BIT` define, which is defined in `ryu.h`.

Now the Ryu files build without warnings with clang-cl for i386,
x86_64, arm and aarch64.

Differential Revision: https://reviews.llvm.org/D119647
This commit is contained in:
Martin Storsjö 2022-02-12 22:00:46 +02:00
parent 1234011b80
commit 7b89360d3a
2 changed files with 7 additions and 5 deletions

View File

@ -44,6 +44,8 @@
#include "__config"
#include "include/ryu/ryu.h"
_LIBCPP_BEGIN_NAMESPACE_STD
#if defined(_M_X64) && defined(_MSC_VER)

View File

@ -56,9 +56,9 @@
#include "include/ryu/d2s.h"
#include "include/ryu/d2fixed.h"
#if defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
#include <intrin0.h> // for _umul128() and __shiftright128()
#endif // defined(_M_X64) && defined(_LIBCPP_COMPILER_MSVC)
#if defined(_MSC_VER)
#include <intrin.h> // for _umul128(), __shiftright128(), _BitScanForward{,64}
#endif // defined(_MSC_VER)
#if defined(_WIN64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__aarch64__)
#define _LIBCPP_64_BIT
@ -68,7 +68,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
// https://github.com/ulfjack/ryu/tree/59661c3/ryu
#if !defined(_LIBCPP_COMPILER_MSVC)
#if !defined(_MSC_VER)
_LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward64(unsigned long* __index, unsigned long long __mask) {
if (__mask == 0) {
return false;
@ -84,7 +84,7 @@ _LIBCPP_HIDE_FROM_ABI inline unsigned char _BitScanForward(unsigned long* __inde
*__index = __builtin_ctz(__mask);
return true;
}
#endif // _LIBCPP_COMPILER_MSVC
#endif // !_MSC_VER
template <class _Floating>
[[nodiscard]] to_chars_result _Floating_to_chars_ryu(