From ad5e7b20a99d8b88f83e979312b8c618fca7f79f Mon Sep 17 00:00:00 2001 From: Michael Schellenberger Costa Date: Thu, 9 Jan 2025 21:22:02 +0100 Subject: [PATCH 1/2] Implement `views::empty` (#3254) * Disable pair conversion of subrange with clang in C++17 * Fix namespace views * Implement `views::empty` This implements `std::ranges::views::empty`, see https://en.cppreference.com/w/cpp/ranges/empty_view --- .../include/cuda/std/__internal/namespaces.h | 2 +- .../include/cuda/std/__ranges/empty_view.h | 80 ++++++++++++++++++ .../include/cuda/std/__ranges/subrange.h | 7 +- libcudacxx/include/cuda/std/ranges | 1 + .../range.empty/borrowing.compile.pass.cpp | 30 +++++++ .../range.empty/empty_view.pass.cpp | 83 +++++++++++++++++++ .../range.empty/views.empty.pass.cpp | 56 +++++++++++++ .../ctor.pair_like_conv.pass.cpp | 3 +- libcudacxx/test/support/test_range.h | 4 +- 9 files changed, 259 insertions(+), 7 deletions(-) create mode 100644 libcudacxx/include/cuda/std/__ranges/empty_view.h create mode 100644 libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/borrowing.compile.pass.cpp create mode 100644 libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/empty_view.pass.cpp create mode 100644 libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/views.empty.pass.cpp diff --git a/libcudacxx/include/cuda/std/__internal/namespaces.h b/libcudacxx/include/cuda/std/__internal/namespaces.h index d909bd3fe71..b23eed5366d 100644 --- a/libcudacxx/include/cuda/std/__internal/namespaces.h +++ b/libcudacxx/include/cuda/std/__internal/namespaces.h @@ -75,7 +75,7 @@ # define _CUDA_VSTD_NOVERSION ::cuda::std # define _CUDA_VSTD ::cuda::std::_LIBCUDACXX_ABI_NAMESPACE # define _CUDA_VRANGES ::cuda::std::ranges::_LIBCUDACXX_ABI_NAMESPACE -# define _CUDA_VIEWS ::cuda::std::ranges::views::_LIBCUDACXX_CUDA_ABI_NAMESPACE +# define _CUDA_VIEWS ::cuda::std::ranges::views::_LIBCUDACXX_ABI_NAMESPACE # define _CUDA_VMR ::cuda::mr::_LIBCUDACXX_ABI_NAMESPACE # define _CUDA_VPTX ::cuda::ptx::_LIBCUDACXX_ABI_NAMESPACE # define _CUDA_VSTD_FS ::cuda::std::__fs::filesystem::_LIBCUDACXX_ABI_NAMESPACE diff --git a/libcudacxx/include/cuda/std/__ranges/empty_view.h b/libcudacxx/include/cuda/std/__ranges/empty_view.h new file mode 100644 index 00000000000..a1a90e7f197 --- /dev/null +++ b/libcudacxx/include/cuda/std/__ranges/empty_view.h @@ -0,0 +1,80 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES +// +//===----------------------------------------------------------------------===// +#ifndef _LIBCUDACXX___RANGES_EMPTY_VIEW_H +#define _LIBCUDACXX___RANGES_EMPTY_VIEW_H + +#include + +#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) +# pragma GCC system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) +# pragma clang system_header +#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) +# pragma system_header +#endif // no system header + +#include +#include +#include + +#if _CCCL_STD_VER >= 2017 && !_CCCL_COMPILER(MSVC2017) + +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES +_LIBCUDACXX_BEGIN_NAMESPACE_RANGES_ABI + +_CCCL_TEMPLATE(class _Tp) +_CCCL_REQUIRES(_CCCL_TRAIT(is_object, _Tp)) +class empty_view : public view_interface> +{ +public: + _LIBCUDACXX_HIDE_FROM_ABI static constexpr _Tp* begin() noexcept + { + return nullptr; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr _Tp* end() noexcept + { + return nullptr; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr _Tp* data() noexcept + { + return nullptr; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr size_t size() noexcept + { + return 0; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr bool empty() noexcept + { + return true; + } +}; + +_LIBCUDACXX_END_NAMESPACE_RANGES_ABI + +template +_CCCL_INLINE_VAR constexpr bool enable_borrowed_range> = true; + +_LIBCUDACXX_END_NAMESPACE_RANGES + +_LIBCUDACXX_BEGIN_NAMESPACE_VIEWS + +# if _CCCL_COMPILER(MSVC) +template +_CCCL_INLINE_VAR constexpr empty_view<_Tp> empty{}; +# else // ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv +template +_CCCL_GLOBAL_CONSTANT empty_view<_Tp> empty{}; +# endif // !_CCCL_COMPILER_MSVC + +_LIBCUDACXX_END_NAMESPACE_VIEWS + +#endif // _CCCL_STD_VER >= 2017 && !_CCCL_COMPILER_MSVC_2017 + +#endif // _LIBCUDACXX___RANGES_EMPTY_VIEW_H diff --git a/libcudacxx/include/cuda/std/__ranges/subrange.h b/libcudacxx/include/cuda/std/__ranges/subrange.h index b1b2d9c81d0..28da5c75774 100644 --- a/libcudacxx/include/cuda/std/__ranges/subrange.h +++ b/libcudacxx/include/cuda/std/__ranges/subrange.h @@ -244,7 +244,7 @@ class _CCCL_TYPE_VISIBILITY_DEFAULT subrange : public view_interface = default; # else // ^^^ !_CCCL_NO_CONCEPTS ^^^ / vvv _CCCL_NO_CONCEPTS vvv @@ -294,14 +294,15 @@ class _CCCL_TYPE_VISIBILITY_DEFAULT subrange : public view_interface=, 9)) + // This often ICEs all of clang and old gcc when it encounteres a rvalue subrange in a pipe +# if !defined(_CCCL_NO_CONCEPTS) _CCCL_TEMPLATE(class _Pair) _CCCL_REQUIRES(__pair_like<_Pair> _CCCL_AND __subrange_to_pair<_Iter, _Sent, _Kind, _Pair>) _LIBCUDACXX_HIDE_FROM_ABI constexpr operator _Pair() const { return _Pair(__begin_, __end_); } -# endif // (!_CCCL_COMPILER(GCC) || _CCCL_COMPILER(GCC, >=, 9)) +# endif // !_CCCL_NO_CONCEPTS _CCCL_TEMPLATE(class _It = _Iter) _CCCL_REQUIRES(copyable<_It>) diff --git a/libcudacxx/include/cuda/std/ranges b/libcudacxx/include/cuda/std/ranges index a9678d6a43a..03f1438f456 100644 --- a/libcudacxx/include/cuda/std/ranges +++ b/libcudacxx/include/cuda/std/ranges @@ -30,6 +30,7 @@ _CCCL_DIAG_SUPPRESS_MSVC(4848) #include #include #include +#include #include #include #include diff --git a/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/borrowing.compile.pass.cpp b/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/borrowing.compile.pass.cpp new file mode 100644 index 00000000000..14a44c21886 --- /dev/null +++ b/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/borrowing.compile.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// UNSUPPORTED: msvc-19.16 + +// template +// inline constexpr bool enable_borrowed_range> = true; + +#include + +#include "test_range.h" + +static_assert(cuda::std::ranges::borrowed_range>); +static_assert(cuda::std::ranges::borrowed_range>); +static_assert(cuda::std::ranges::borrowed_range>); +#if _LIBCUDACXX_HAS_RANGES +static_assert(cuda::std::ranges::borrowed_range>); +#endif + +int main(int, char**) +{ + return 0; +} diff --git a/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/empty_view.pass.cpp b/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/empty_view.pass.cpp new file mode 100644 index 00000000000..68c8149e15f --- /dev/null +++ b/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/empty_view.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// UNSUPPORTED: msvc-19.16 + +// template +// class empty_view; + +#include +#include + +#include "test_macros.h" + +template +__host__ __device__ constexpr void testType() +{ + static_assert(cuda::std::ranges::range>); + static_assert(cuda::std::ranges::range>); + static_assert(cuda::std::ranges::view>); + + cuda::std::ranges::empty_view empty{}; + + assert(empty.begin() == nullptr); + assert(empty.end() == nullptr); + assert(empty.data() == nullptr); + assert(empty.size() == 0); + assert(empty.empty() == true); + + assert(cuda::std::ranges::begin(empty) == nullptr); + assert(cuda::std::ranges::end(empty) == nullptr); + assert(cuda::std::ranges::data(empty) == nullptr); + assert(cuda::std::ranges::size(empty) == 0); + assert(cuda::std::ranges::empty(empty) == true); +} + +struct Empty +{}; +struct BigType +{ + char buff[8]; +}; + +#if TEST_STD_VER >= 2020 +template +concept ValidEmptyView = requires { typename cuda::std::ranges::empty_view; }; +#else // ^^^ C++20 ^^^ / vvv C++17 vvv +template +constexpr bool ValidEmptyView = false; + +template +constexpr bool ValidEmptyView>> = true; +#endif // TEST_STD_VER <= 2017 + +__host__ __device__ constexpr bool test() +{ + // Not objects: + static_assert(!ValidEmptyView); + static_assert(!ValidEmptyView); + + testType(); + testType(); + testType(); + testType(); + testType(); + testType(); + + return true; +} + +int main(int, char**) +{ + test(); + static_assert(test()); + + return 0; +} diff --git a/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/views.empty.pass.cpp b/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/views.empty.pass.cpp new file mode 100644 index 00000000000..68a5e132a54 --- /dev/null +++ b/libcudacxx/test/libcudacxx/std/ranges/range.adaptors/range.empty/views.empty.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 +// UNSUPPORTED: msvc-19.16 + +// template +// inline constexpr empty_view<_Tp> empty{}; + +#include +#include + +#include "test_macros.h" + +template +__host__ __device__ constexpr void testType() +{ + ASSERT_SAME_TYPE(decltype(cuda::std::views::empty), const cuda::std::ranges::empty_view); + ASSERT_SAME_TYPE(decltype((cuda::std::views::empty) ), const cuda::std::ranges::empty_view&); + + auto v = cuda::std::views::empty; + assert(cuda::std::ranges::empty(v)); +} + +struct Empty +{}; +struct BigType +{ + char buff[8]; +}; + +__host__ __device__ constexpr bool test() +{ + testType(); + testType(); + testType(); + testType(); + testType(); + testType(); + + return true; +} + +int main(int, char**) +{ + test(); + static_assert(test()); + + return 0; +} diff --git a/libcudacxx/test/libcudacxx/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp b/libcudacxx/test/libcudacxx/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp index 251a1ccfce6..d59863e6c0d 100644 --- a/libcudacxx/test/libcudacxx/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/ranges/range.utility/range.subrange/ctor.pair_like_conv.pass.cpp @@ -7,9 +7,8 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14 +// UNSUPPORTED: c++03, c++11, c++14, c++17 // UNSUPPORTED: msvc-19.16 -// UNSUPPORTED: gcc-7, gcc-8 // class cuda::std::ranges::subrange; diff --git a/libcudacxx/test/support/test_range.h b/libcudacxx/test/support/test_range.h index 692843da5e2..83e8a25c425 100644 --- a/libcudacxx/test/support/test_range.h +++ b/libcudacxx/test/support/test_range.h @@ -105,11 +105,13 @@ _CCCL_INLINE_VAR constexpr bool enable_borrowed_range = true; static_assert(!cuda::std::ranges::view, ""); static_assert(cuda::std::ranges::borrowed_range, ""); -#if _LIBCUDACXX_HAS_RANGES +#if _CCCL_STD_VER >= 2017 && !_CCCL_COMPILER(MSVC2017) using BorrowedView = cuda::std::ranges::empty_view; static_assert(cuda::std::ranges::view, ""); static_assert(cuda::std::ranges::borrowed_range, ""); +#endif // _CCCL_STD_VER >= 2017 && !_CCCL_COMPILER(MSVC2017) +#if _LIBCUDACXX_HAS_RANGES using NonBorrowedView = cuda::std::ranges::single_view; static_assert(cuda::std::ranges::view, ""); static_assert(!cuda::std::ranges::borrowed_range, ""); From 1503b25db06b7be04a4ed04c1061d392c28c8aba Mon Sep 17 00:00:00 2001 From: David Bayer <48736217+davebayer@users.noreply.github.com> Date: Thu, 9 Jan 2025 21:23:22 +0100 Subject: [PATCH 2/2] Refactor `limits` and `climits` (#3221) * implement builtins for huge val, nan and nans * change `INFINITY` and `NAN` implementation for NVRTC --- libcudacxx/include/cuda/std/__cccl/builtin.h | 42 + .../include/cuda/std/__cuda/climits_prelude.h | 105 -- .../msvc_win32.h} | 25 +- .../cuda/std/__memory/allocator_traits.h | 2 + .../cuda/std/__memory/temporary_buffer.h | 3 +- libcudacxx/include/cuda/std/climits | 65 +- .../cuda/std/detail/libcxx/include/climits | 64 - .../cuda/std/detail/libcxx/include/cmath | 5 +- .../cuda/std/detail/libcxx/include/limits | 1120 ----------------- libcudacxx/include/cuda/std/limits | 546 +++++++- .../test/internal_headers/CMakeLists.txt | 5 + .../numeric.limits.members/lowest.pass.cpp | 1 + .../numeric.limits.members/max.pass.cpp | 1 + .../numeric.limits.members/min.pass.cpp | 1 + .../numerics/bit/bit.cast/bit_cast.pass.cpp | 4 +- .../numerics/bit/bit.endian/endian.pass.cpp | 1 + .../std/numerics/bit/invocable.pass.cpp | 1 + .../pairs.pair/trivial_copy_move.pass.cpp | 1 + 18 files changed, 678 insertions(+), 1314 deletions(-) delete mode 100644 libcudacxx/include/cuda/std/__cuda/climits_prelude.h rename libcudacxx/include/cuda/std/{detail/libcxx/include/support/win32/limits_msvc_win32.h => __limits/msvc_win32.h} (71%) delete mode 100644 libcudacxx/include/cuda/std/detail/libcxx/include/climits delete mode 100644 libcudacxx/include/cuda/std/detail/libcxx/include/limits diff --git a/libcudacxx/include/cuda/std/__cccl/builtin.h b/libcudacxx/include/cuda/std/__cccl/builtin.h index b19f7de4371..3a5fda2f0f5 100644 --- a/libcudacxx/include/cuda/std/__cccl/builtin.h +++ b/libcudacxx/include/cuda/std/__cccl/builtin.h @@ -288,6 +288,48 @@ # define _CCCL_BUILTIN_LINE() __LINE__ #endif // _CCCL_CUDACC_BELOW(11, 3) +#if _CCCL_CHECK_BUILTIN(builtin_huge_valf) || _CCCL_COMPILER(MSVC) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_HUGE_VALF() __builtin_huge_valf() +#endif // _CCCL_CHECK_BUILTIN(builtin_huge_valf) + +#if _CCCL_CHECK_BUILTIN(builtin_huge_val) || _CCCL_COMPILER(MSVC) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_HUGE_VAL() __builtin_huge_val() +#endif // _CCCL_CHECK_BUILTIN(builtin_huge_val) + +#if _CCCL_CHECK_BUILTIN(builtin_huge_vall) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_HUGE_VALL() __builtin_huge_vall() +#elif _CCCL_COMPILER(MSVC) +# define _CCCL_BUILTIN_HUGE_VALL() static_cast(__builtin_huge_val()) +#endif // _CCCL_CHECK_BUILTIN(builtin_huge_vall) + +#if _CCCL_CHECK_BUILTIN(builtin_nanf) || _CCCL_COMPILER(MSVC) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_NANF(...) __builtin_nanf(__VA_ARGS__) +#endif // _CCCL_CHECK_BUILTIN(builtin_nanf) + +#if _CCCL_CHECK_BUILTIN(builtin_nan) || _CCCL_COMPILER(MSVC) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_NAN(...) __builtin_nan(__VA_ARGS__) +#endif // _CCCL_CHECK_BUILTIN(builtin_nan) + +#if _CCCL_CHECK_BUILTIN(builtin_nanl) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_NANL(...) __builtin_nanl(__VA_ARGS__) +#elif _CCCL_COMPILER(MSVC) +# define _CCCL_BUILTIN_NANL(...) static_cast(__builtin_nan(__VA_ARGS__)) +#endif // _CCCL_CHECK_BUILTIN(builtin_nanl) + +#if _CCCL_CHECK_BUILTIN(builtin_nansf) || _CCCL_COMPILER(MSVC) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_NANSF(...) __builtin_nansf(__VA_ARGS__) +#endif // _CCCL_CHECK_BUILTIN(builtin_nansf) + +#if _CCCL_CHECK_BUILTIN(builtin_nans) || _CCCL_COMPILER(MSVC) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_NANS(...) __builtin_nans(__VA_ARGS__) +#endif // _CCCL_CHECK_BUILTIN(builtin_nans) + +#if _CCCL_CHECK_BUILTIN(builtin_nansl) || _CCCL_COMPILER(GCC, <, 10) +# define _CCCL_BUILTIN_NANSL(...) __builtin_nansl(__VA_ARGS__) +#elif _CCCL_COMPILER(MSVC) +# define _CCCL_BUILTIN_NANSL(...) static_cast(__builtin_nans(__VA_ARGS__)) +#endif // _CCCL_CHECK_BUILTIN(builtin_nansl) + #if _CCCL_CHECK_BUILTIN(builtin_log) || _CCCL_COMPILER(GCC) # define _CCCL_BUILTIN_LOGF(...) __builtin_logf(__VA_ARGS__) # define _CCCL_BUILTIN_LOG(...) __builtin_log(__VA_ARGS__) diff --git a/libcudacxx/include/cuda/std/__cuda/climits_prelude.h b/libcudacxx/include/cuda/std/__cuda/climits_prelude.h deleted file mode 100644 index e788eaa29ea..00000000000 --- a/libcudacxx/include/cuda/std/__cuda/climits_prelude.h +++ /dev/null @@ -1,105 +0,0 @@ -// -*- C++ -*- -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H -#define _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H - -#include - -#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) -# pragma GCC system_header -#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) -# pragma clang system_header -#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) -# pragma system_header -#endif // no system header - -#if !_CCCL_COMPILER(NVRTC) -# include -# include - -# include -#else // ^^^ !_CCCL_COMPILER(NVRTC) ^^^ / vvv _CCCL_COMPILER(NVRTC) vvv -# define CHAR_BIT 8 - -# define SCHAR_MIN (-128) -# define SCHAR_MAX 127 -# define UCHAR_MAX 255 -# define __CHAR_UNSIGNED__ ('\xff' > 0) // CURSED -# if __CHAR_UNSIGNED__ -# define CHAR_MIN 0 -# define CHAR_MAX UCHAR_MAX -# else -# define CHAR_MIN SCHAR_MIN -# define CHAR_MAX SCHAR_MAX -# endif -# define SHRT_MIN (-SHRT_MAX - 1) -# define SHRT_MAX 0x7fff -# define USHRT_MAX 0xffff -# define INT_MIN (-INT_MAX - 1) -# define INT_MAX 0x7fffffff -# define UINT_MAX 0xffffffff -# define LONG_MIN (-LONG_MAX - 1) -# ifdef __LP64__ -# define LONG_MAX LLONG_MAX -# define ULONG_MAX ULLONG_MAX -# else -# define LONG_MAX INT_MAX -# define ULONG_MAX UINT_MAX -# endif -# define LLONG_MIN (-LLONG_MAX - 1) -# define LLONG_MAX 0x7fffffffffffffffLL -# define ULLONG_MAX 0xffffffffffffffffUL - -# define __FLT_RADIX__ 2 -# define __FLT_MANT_DIG__ 24 -# define __FLT_DIG__ 6 -# define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F -# define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F -# define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F -# define __FLT_MIN_EXP__ (-125) -# define __FLT_MIN_10_EXP__ (-37) -# define __FLT_MAX_EXP__ 128 -# define __FLT_MAX_10_EXP__ 38 -# define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F -# define __DBL_MANT_DIG__ 53 -# define __DBL_DIG__ 15 -# define __DBL_MIN__ 2.22507385850720138309023271733240406e-308 -# define __DBL_MAX__ 1.79769313486231570814527423731704357e+308 -# define __DBL_EPSILON__ 2.22044604925031308084726333618164062e-16 -# define __DBL_MIN_EXP__ (-1021) -# define __DBL_MIN_10_EXP__ (-307) -# define __DBL_MAX_EXP__ 1024 -# define __DBL_MAX_10_EXP__ 308 -# define __DBL_DENORM_MIN__ 4.94065645841246544176568792868221372e-324 - -template -static _CCCL_DEVICE _CCCL_FORCEINLINE _To __cowchild_cast(_From __from) -{ - static_assert(sizeof(_From) == sizeof(_To), ""); - union __cast - { - _From __from; - _To __to; - }; - __cast __c; - __c.__from = __from; - return __c.__to; -} - -# define __builtin_huge_valf() __cowchild_cast(0x7f800000) -# define __builtin_nanf(__dummy) __cowchild_cast(0x7fc00000) -# define __builtin_nansf(__dummy) __cowchild_cast(0x7fa00000) -# define __builtin_huge_val() __cowchild_cast(0x7ff0000000000000) -# define __builtin_nan(__dummy) __cowchild_cast(0x7ff8000000000000) -# define __builtin_nans(__dummy) __cowchild_cast(0x7ff4000000000000) -#endif // _CCCL_COMPILER(NVRTC) - -#endif // _LIBCUDACXX___CUDA_CLIMITS_PRELUDE_H diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/support/win32/limits_msvc_win32.h b/libcudacxx/include/cuda/std/__limits/msvc_win32.h similarity index 71% rename from libcudacxx/include/cuda/std/detail/libcxx/include/support/win32/limits_msvc_win32.h rename to libcudacxx/include/cuda/std/__limits/msvc_win32.h index 1b4eeedba0b..d00c76895bc 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/support/win32/limits_msvc_win32.h +++ b/libcudacxx/include/cuda/std/__limits/msvc_win32.h @@ -1,14 +1,16 @@ // -*- C++ -*- -//===------------------ support/win32/limits_msvc_win32.h -----------------===// +//===----------------------------------------------------------------------===// // -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// Part of libcu++, the C++ Standard Library for your entire system, +// under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. // //===----------------------------------------------------------------------===// -#ifndef _LIBCUDACXX_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H -#define _LIBCUDACXX_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H +#ifndef _LIBCUDACXX___LIMITS_MSVC_WIN32_H +#define _LIBCUDACXX___LIMITS_MSVC_WIN32_H #if defined(__MINGW32__) # error "This header complements the Microsoft C Runtime library, and should not be included otherwise." @@ -19,8 +21,6 @@ #include // limit constants #include // CHAR_BIT -#include // HUGE_VAL -#include // internal MSVC header providing the needed functionality #define __CHAR_BIT__ CHAR_BIT @@ -63,15 +63,4 @@ // predefined by MinGW GCC #define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L -// __builtin replacements/workarounds -#if _MSC_VER < 1934 -# define __builtin_huge_vall() _LInf._Long_double -# define __builtin_nanl(__dummmy) _LNan._Long_double -# define __builtin_nansl(__dummy) _LSnan._Long_double -#else -# define __builtin_huge_vall() __builtin_huge_val() -# define __builtin_nanl(__v) __builtin_nan(__v) -# define __builtin_nansl(__v) __builtin_nans(__v) -#endif - -#endif // _LIBCUDACXX_SUPPORT_WIN32_LIMITS_MSVC_WIN32_H +#endif // _LIBCUDACXX___LIMITS_MSVC_WIN32_H diff --git a/libcudacxx/include/cuda/std/__memory/allocator_traits.h b/libcudacxx/include/cuda/std/__memory/allocator_traits.h index b553056ad99..035731687a3 100644 --- a/libcudacxx/include/cuda/std/__memory/allocator_traits.h +++ b/libcudacxx/include/cuda/std/__memory/allocator_traits.h @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/libcudacxx/include/cuda/std/__memory/temporary_buffer.h b/libcudacxx/include/cuda/std/__memory/temporary_buffer.h index 2aa33cad869..232003ab1ed 100644 --- a/libcudacxx/include/cuda/std/__memory/temporary_buffer.h +++ b/libcudacxx/include/cuda/std/__memory/temporary_buffer.h @@ -26,10 +26,11 @@ #include #include #include +#include #include #include #include -#include +#include _LIBCUDACXX_BEGIN_NAMESPACE_STD diff --git a/libcudacxx/include/cuda/std/climits b/libcudacxx/include/cuda/std/climits index 2860fc56468..a605f2dc597 100644 --- a/libcudacxx/include/cuda/std/climits +++ b/libcudacxx/include/cuda/std/climits @@ -23,7 +23,70 @@ _CCCL_PUSH_MACROS -#include +#if !_CCCL_COMPILER(NVRTC) +# include +#else // ^^^ !_CCCL_COMPILER(NVRTC) ^^^ / vvv _CCCL_COMPILER(NVRTC) vvv +# define CHAR_BIT 8 + +# define SCHAR_MIN (-128) +# define SCHAR_MAX 127 +# define UCHAR_MAX 255 +# define __CHAR_UNSIGNED__ ('\xff' > 0) // CURSED +# if __CHAR_UNSIGNED__ +# define CHAR_MIN 0 +# define CHAR_MAX UCHAR_MAX +# else +# define CHAR_MIN SCHAR_MIN +# define CHAR_MAX SCHAR_MAX +# endif +# define SHRT_MIN (-SHRT_MAX - 1) +# define SHRT_MAX 0x7fff +# define USHRT_MAX 0xffff +# define INT_MIN (-INT_MAX - 1) +# define INT_MAX 0x7fffffff +# define UINT_MAX 0xffffffff +# define LONG_MIN (-LONG_MAX - 1) +# ifdef __LP64__ +# define LONG_MAX LLONG_MAX +# define ULONG_MAX ULLONG_MAX +# else +# define LONG_MAX INT_MAX +# define ULONG_MAX UINT_MAX +# endif +# define LLONG_MIN (-LLONG_MAX - 1) +# define LLONG_MAX 0x7fffffffffffffffLL +# define ULLONG_MAX 0xffffffffffffffffUL + +# define __FLT_RADIX__ 2 +# define __FLT_MANT_DIG__ 24 +# define __FLT_DIG__ 6 +# define __FLT_MIN__ 1.17549435082228750796873653722224568e-38F +# define __FLT_MAX__ 3.40282346638528859811704183484516925e+38F +# define __FLT_EPSILON__ 1.19209289550781250000000000000000000e-7F +# define __FLT_MIN_EXP__ (-125) +# define __FLT_MIN_10_EXP__ (-37) +# define __FLT_MAX_EXP__ 128 +# define __FLT_MAX_10_EXP__ 38 +# define __FLT_DENORM_MIN__ 1.40129846432481707092372958328991613e-45F +# define __DBL_MANT_DIG__ 53 +# define __DBL_DIG__ 15 +# define __DBL_MIN__ 2.22507385850720138309023271733240406e-308 +# define __DBL_MAX__ 1.79769313486231570814527423731704357e+308 +# define __DBL_EPSILON__ 2.22044604925031308084726333618164062e-16 +# define __DBL_MIN_EXP__ (-1021) +# define __DBL_MIN_10_EXP__ (-307) +# define __DBL_MAX_EXP__ 1024 +# define __DBL_MAX_10_EXP__ 308 +# define __DBL_DENORM_MIN__ 4.94065645841246544176568792868221372e-324 +#endif // _CCCL_COMPILER(NVRTC) + +#if _CCCL_COMPILER(MSVC) +# include +#endif // _CCCL_COMPILER(MSVC) + +#ifndef __CHAR_BIT__ +# define __CHAR_BIT__ 8 +#endif // !__CHAR_BIT__ _CCCL_POP_MACROS diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/climits b/libcudacxx/include/cuda/std/detail/libcxx/include/climits deleted file mode 100644 index a80cd27db50..00000000000 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/climits +++ /dev/null @@ -1,64 +0,0 @@ -// -*- C++ -*- -//===--------------------------- climits ----------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCUDACXX_CLIMITS -#define _LIBCUDACXX_CLIMITS - -/* - climits synopsis - -Macros: - - CHAR_BIT - SCHAR_MIN - SCHAR_MAX - UCHAR_MAX - CHAR_MIN - CHAR_MAX - MB_LEN_MAX - SHRT_MIN - SHRT_MAX - USHRT_MAX - INT_MIN - INT_MAX - UINT_MAX - LONG_MIN - LONG_MAX - ULONG_MAX - LLONG_MIN // C99 - LLONG_MAX // C99 - ULLONG_MAX // C99 - -*/ - -#include - -#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) -# pragma GCC system_header -#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) -# pragma clang system_header -#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) -# pragma system_header -#endif // no system header - -#include - -_CCCL_PUSH_MACROS - -#if _CCCL_COMPILER(MSVC) -# include -#endif // _CCCL_COMPILER(MSVC) - -#ifndef __CHAR_BIT__ -# define __CHAR_BIT__ 8 -#endif // !__CHAR_BIT__ - -_CCCL_POP_MACROS - -#endif // _LIBCUDACXX_CLIMITS diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/cmath b/libcudacxx/include/cuda/std/detail/libcxx/include/cmath index a3ef375cb10..6d5618b7d78 100644 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/cmath +++ b/libcudacxx/include/cuda/std/detail/libcxx/include/cmath @@ -338,9 +338,8 @@ long double truncl(long double x); #endif // _LIBCUDACXX_HAS_NVBF16 #if _CCCL_COMPILER(NVRTC) -# include -# define INFINITY __builtin_huge_val() -# define NAN __builtin_nan() +# define INFINITY _CUDA_VSTD::numeric_limits::infinity() +# define NAN _CUDA_VSTD::numeric_limits::quiet_NaN() #endif // _CCCL_COMPILER(NVRTC) _CCCL_PUSH_MACROS diff --git a/libcudacxx/include/cuda/std/detail/libcxx/include/limits b/libcudacxx/include/cuda/std/detail/libcxx/include/limits deleted file mode 100644 index 95980e41dc9..00000000000 --- a/libcudacxx/include/cuda/std/detail/libcxx/include/limits +++ /dev/null @@ -1,1120 +0,0 @@ -// -*- C++ -*- -//===---------------------------- limits ----------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef _LIBCUDACXX_LIMITS -#define _LIBCUDACXX_LIMITS - -/* - limits synopsis - -namespace std -{ - -template -class numeric_limits -{ -public: - static constexpr bool is_specialized = false; - static constexpr T min() noexcept; - static constexpr T max() noexcept; - static constexpr T lowest() noexcept; - - static constexpr int digits = 0; - static constexpr int digits10 = 0; - static constexpr int max_digits10 = 0; - static constexpr bool is_signed = false; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = 0; - static constexpr T epsilon() noexcept; - static constexpr T round_error() noexcept; - - static constexpr int min_exponent = 0; - static constexpr int min_exponent10 = 0; - static constexpr int max_exponent = 0; - static constexpr int max_exponent10 = 0; - - static constexpr bool has_infinity = false; - static constexpr bool has_quiet_NaN = false; - static constexpr bool has_signaling_NaN = false; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - static constexpr T infinity() noexcept; - static constexpr T quiet_NaN() noexcept; - static constexpr T signaling_NaN() noexcept; - static constexpr T denorm_min() noexcept; - - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_toward_zero; -}; - -enum float_round_style -{ - round_indeterminate = -1, - round_toward_zero = 0, - round_to_nearest = 1, - round_toward_infinity = 2, - round_toward_neg_infinity = 3 -}; - -enum float_denorm_style -{ - denorm_indeterminate = -1, - denorm_absent = 0, - denorm_present = 1 -}; - -template<> class numeric_limits; - -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; // C++20 -template<> class numeric_limits; -template<> class numeric_limits; - -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; - -template<> class numeric_limits; -template<> class numeric_limits; -template<> class numeric_limits; - -} // std - -*/ - -#include - -#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) -# pragma GCC system_header -#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) -# pragma clang system_header -#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) -# pragma system_header -#endif // no system header - -#include -#include -#include - -_CCCL_PUSH_MACROS - -#if _CCCL_COMPILER(MSVC) -# include -#endif // _CCCL_COMPILER(MSVC) - -_LIBCUDACXX_BEGIN_NAMESPACE_STD - -enum float_round_style -{ - round_indeterminate = -1, - round_toward_zero = 0, - round_to_nearest = 1, - round_toward_infinity = 2, - round_toward_neg_infinity = 3 -}; - -enum float_denorm_style -{ - denorm_indeterminate = -1, - denorm_absent = 0, - denorm_present = 1 -}; - -template ::value> -class __cccl_numeric_limits -{ -protected: - typedef _Tp type; - - static constexpr bool is_specialized = false; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return type(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return type(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return type(); - } - - static constexpr int digits = 0; - static constexpr int digits10 = 0; - static constexpr int max_digits10 = 0; - static constexpr bool is_signed = false; - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = 0; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return type(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return type(); - } - - static constexpr int min_exponent = 0; - static constexpr int min_exponent10 = 0; - static constexpr int max_exponent = 0; - static constexpr int max_exponent10 = 0; - - static constexpr bool has_infinity = false; - static constexpr bool has_quiet_NaN = false; - static constexpr bool has_signaling_NaN = false; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return type(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return type(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return type(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return type(); - } - - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = false; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_toward_zero; -}; - -_CCCL_DIAG_PUSH -_CCCL_DIAG_SUPPRESS_MSVC(4309) -template -struct __cccl_compute_min -{ - static constexpr _Tp value = static_cast<_Tp>(_Tp(1) << __digits); -}; -_CCCL_DIAG_POP - -template -struct __cccl_compute_min<_Tp, __digits, false> -{ - static constexpr _Tp value = _Tp(0); -}; - -template -class __cccl_numeric_limits<_Tp, true> -{ -protected: - typedef _Tp type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = type(-1) < type(0); - static constexpr int digits = static_cast(sizeof(type) * __CHAR_BIT__ - is_signed); - static constexpr int digits10 = digits * 3 / 10; - static constexpr int max_digits10 = 0; - static constexpr type __min = __cccl_compute_min::value; - static constexpr type __max = is_signed ? type(type(~0) ^ __min) : type(~0); - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __min; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __max; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return min(); - } - - static constexpr bool is_integer = true; - static constexpr bool is_exact = true; - static constexpr int radix = 2; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return type(0); - } - - static constexpr int min_exponent = 0; - static constexpr int min_exponent10 = 0; - static constexpr int max_exponent = 0; - static constexpr int max_exponent10 = 0; - - static constexpr bool has_infinity = false; - static constexpr bool has_quiet_NaN = false; - static constexpr bool has_signaling_NaN = false; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return type(0); - } - - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = !_CUDA_VSTD::is_signed<_Tp>::value; - -#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || defined(__wasm__) - static constexpr bool traps = true; -#else - static constexpr bool traps = false; -#endif - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_toward_zero; -}; - -template <> -class __cccl_numeric_limits -{ -protected: - typedef bool type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = false; - static constexpr int digits = 1; - static constexpr int digits10 = 0; - static constexpr int max_digits10 = 0; - static constexpr type __min = false; - static constexpr type __max = true; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __min; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __max; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return min(); - } - - static constexpr bool is_integer = true; - static constexpr bool is_exact = true; - static constexpr int radix = 2; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return type(0); - } - - static constexpr int min_exponent = 0; - static constexpr int min_exponent10 = 0; - static constexpr int max_exponent = 0; - static constexpr int max_exponent10 = 0; - - static constexpr bool has_infinity = false; - static constexpr bool has_quiet_NaN = false; - static constexpr bool has_signaling_NaN = false; - static constexpr float_denorm_style has_denorm = denorm_absent; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return type(0); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return type(0); - } - - static constexpr bool is_iec559 = false; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_toward_zero; -}; - -template <> -class __cccl_numeric_limits -{ -protected: - typedef float type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = true; - static constexpr int digits = __FLT_MANT_DIG__; - static constexpr int digits10 = __FLT_DIG__; - static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __FLT_MIN__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __FLT_MAX__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return -max(); - } - - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = __FLT_RADIX__; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return __FLT_EPSILON__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return 0.5F; - } - - static constexpr int min_exponent = __FLT_MIN_EXP__; - static constexpr int min_exponent10 = __FLT_MIN_10_EXP__; - static constexpr int max_exponent = __FLT_MAX_EXP__; - static constexpr int max_exponent10 = __FLT_MAX_10_EXP__; - - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_present; - static constexpr bool has_denorm_loss = false; -#if _CCCL_COMPILER(NVRTC) - _LIBCUDACXX_HIDE_FROM_ABI static type infinity() noexcept - { - return __builtin_huge_valf(); - } - _LIBCUDACXX_HIDE_FROM_ABI static type quiet_NaN() noexcept - { - return __builtin_nanf(""); - } - _LIBCUDACXX_HIDE_FROM_ABI static type signaling_NaN() noexcept - { - return __builtin_nansf(""); - } -#else // ^^^ _CCCL_COMPILER(NVRTC) ^^^ // vvv !_CCCL_COMPILER(NVRTC) vvv - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return __builtin_huge_valf(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return __builtin_nanf(""); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return __builtin_nansf(""); - } -#endif // !_CCCL_COMPILER(NVRTC) - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return __FLT_DENORM_MIN__; - } - - static constexpr bool is_iec559 = true; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; -}; - -template <> -class __cccl_numeric_limits -{ -protected: - typedef double type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = true; - static constexpr int digits = __DBL_MANT_DIG__; - static constexpr int digits10 = __DBL_DIG__; - static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __DBL_MIN__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __DBL_MAX__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return -max(); - } - - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = __FLT_RADIX__; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return __DBL_EPSILON__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return 0.5; - } - - static constexpr int min_exponent = __DBL_MIN_EXP__; - static constexpr int min_exponent10 = __DBL_MIN_10_EXP__; - static constexpr int max_exponent = __DBL_MAX_EXP__; - static constexpr int max_exponent10 = __DBL_MAX_10_EXP__; - - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_present; - static constexpr bool has_denorm_loss = false; -#if _CCCL_COMPILER(NVRTC) - _LIBCUDACXX_HIDE_FROM_ABI static type infinity() noexcept - { - return __builtin_huge_val(); - } - _LIBCUDACXX_HIDE_FROM_ABI static type quiet_NaN() noexcept - { - return __builtin_nan(""); - } - _LIBCUDACXX_HIDE_FROM_ABI static type signaling_NaN() noexcept - { - return __builtin_nans(""); - } -#else // ^^^ _CCCL_COMPILER(NVRTC) ^^^ // vvv !_CCCL_COMPILER(NVRTC) vvv - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return __builtin_huge_val(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return __builtin_nan(""); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return __builtin_nans(""); - } -#endif // !_CCCL_COMPILER(NVRTC) - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return __DBL_DENORM_MIN__; - } - - static constexpr bool is_iec559 = true; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; -}; - -template <> -class __cccl_numeric_limits -{ -#ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE - -protected: - typedef long double type; - - static constexpr bool is_specialized = true; - - static constexpr bool is_signed = true; - static constexpr int digits = __LDBL_MANT_DIG__; - static constexpr int digits10 = __LDBL_DIG__; - static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __LDBL_MIN__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __LDBL_MAX__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return -max(); - } - - static constexpr bool is_integer = false; - static constexpr bool is_exact = false; - static constexpr int radix = __FLT_RADIX__; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return __LDBL_EPSILON__; - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return 0.5L; - } - - static constexpr int min_exponent = __LDBL_MIN_EXP__; - static constexpr int min_exponent10 = __LDBL_MIN_10_EXP__; - static constexpr int max_exponent = __LDBL_MAX_EXP__; - static constexpr int max_exponent10 = __LDBL_MAX_10_EXP__; - - static constexpr bool has_infinity = true; - static constexpr bool has_quiet_NaN = true; - static constexpr bool has_signaling_NaN = true; - static constexpr float_denorm_style has_denorm = denorm_present; - static constexpr bool has_denorm_loss = false; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return __builtin_huge_vall(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return __builtin_nanl(""); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return __builtin_nansl(""); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return __LDBL_DENORM_MIN__; - } - - static constexpr bool is_iec559 = true; - static constexpr bool is_bounded = true; - static constexpr bool is_modulo = false; - - static constexpr bool traps = false; - static constexpr bool tinyness_before = false; - static constexpr float_round_style round_style = round_to_nearest; -#endif -}; - -template -class _CCCL_TYPE_VISIBILITY_DEFAULT numeric_limits : private __cccl_numeric_limits> -{ - typedef __cccl_numeric_limits> __base; - typedef typename __base::type type; - -public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __base::min(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __base::max(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return __base::lowest(); - } - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return __base::epsilon(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return __base::round_error(); - } - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return __base::infinity(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return __base::quiet_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return __base::signaling_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return __base::denorm_min(); - } - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; -}; - -template -constexpr bool numeric_limits<_Tp>::is_specialized; -template -constexpr int numeric_limits<_Tp>::digits; -template -constexpr int numeric_limits<_Tp>::digits10; -template -constexpr int numeric_limits<_Tp>::max_digits10; -template -constexpr bool numeric_limits<_Tp>::is_signed; -template -constexpr bool numeric_limits<_Tp>::is_integer; -template -constexpr bool numeric_limits<_Tp>::is_exact; -template -constexpr int numeric_limits<_Tp>::radix; -template -constexpr int numeric_limits<_Tp>::min_exponent; -template -constexpr int numeric_limits<_Tp>::min_exponent10; -template -constexpr int numeric_limits<_Tp>::max_exponent; -template -constexpr int numeric_limits<_Tp>::max_exponent10; -template -constexpr bool numeric_limits<_Tp>::has_infinity; -template -constexpr bool numeric_limits<_Tp>::has_quiet_NaN; -template -constexpr bool numeric_limits<_Tp>::has_signaling_NaN; -template -constexpr float_denorm_style numeric_limits<_Tp>::has_denorm; -template -constexpr bool numeric_limits<_Tp>::has_denorm_loss; -template -constexpr bool numeric_limits<_Tp>::is_iec559; -template -constexpr bool numeric_limits<_Tp>::is_bounded; -template -constexpr bool numeric_limits<_Tp>::is_modulo; -template -constexpr bool numeric_limits<_Tp>::traps; -template -constexpr bool numeric_limits<_Tp>::tinyness_before; -template -constexpr float_round_style numeric_limits<_Tp>::round_style; - -template -class _CCCL_TYPE_VISIBILITY_DEFAULT numeric_limits : private numeric_limits<_Tp> -{ - typedef numeric_limits<_Tp> __base; - typedef _Tp type; - -public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __base::min(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __base::max(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return __base::lowest(); - } - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return __base::epsilon(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return __base::round_error(); - } - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return __base::infinity(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return __base::quiet_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return __base::signaling_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return __base::denorm_min(); - } - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; -}; - -template -constexpr bool numeric_limits::is_specialized; -template -constexpr int numeric_limits::digits; -template -constexpr int numeric_limits::digits10; -template -constexpr int numeric_limits::max_digits10; -template -constexpr bool numeric_limits::is_signed; -template -constexpr bool numeric_limits::is_integer; -template -constexpr bool numeric_limits::is_exact; -template -constexpr int numeric_limits::radix; -template -constexpr int numeric_limits::min_exponent; -template -constexpr int numeric_limits::min_exponent10; -template -constexpr int numeric_limits::max_exponent; -template -constexpr int numeric_limits::max_exponent10; -template -constexpr bool numeric_limits::has_infinity; -template -constexpr bool numeric_limits::has_quiet_NaN; -template -constexpr bool numeric_limits::has_signaling_NaN; -template -constexpr float_denorm_style numeric_limits::has_denorm; -template -constexpr bool numeric_limits::has_denorm_loss; -template -constexpr bool numeric_limits::is_iec559; -template -constexpr bool numeric_limits::is_bounded; -template -constexpr bool numeric_limits::is_modulo; -template -constexpr bool numeric_limits::traps; -template -constexpr bool numeric_limits::tinyness_before; -template -constexpr float_round_style numeric_limits::round_style; - -template -class _CCCL_TYPE_VISIBILITY_DEFAULT numeric_limits : private numeric_limits<_Tp> -{ - typedef numeric_limits<_Tp> __base; - typedef _Tp type; - -public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __base::min(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __base::max(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return __base::lowest(); - } - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return __base::epsilon(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return __base::round_error(); - } - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return __base::infinity(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return __base::quiet_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return __base::signaling_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return __base::denorm_min(); - } - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; -}; - -template -constexpr bool numeric_limits::is_specialized; -template -constexpr int numeric_limits::digits; -template -constexpr int numeric_limits::digits10; -template -constexpr int numeric_limits::max_digits10; -template -constexpr bool numeric_limits::is_signed; -template -constexpr bool numeric_limits::is_integer; -template -constexpr bool numeric_limits::is_exact; -template -constexpr int numeric_limits::radix; -template -constexpr int numeric_limits::min_exponent; -template -constexpr int numeric_limits::min_exponent10; -template -constexpr int numeric_limits::max_exponent; -template -constexpr int numeric_limits::max_exponent10; -template -constexpr bool numeric_limits::has_infinity; -template -constexpr bool numeric_limits::has_quiet_NaN; -template -constexpr bool numeric_limits::has_signaling_NaN; -template -constexpr float_denorm_style numeric_limits::has_denorm; -template -constexpr bool numeric_limits::has_denorm_loss; -template -constexpr bool numeric_limits::is_iec559; -template -constexpr bool numeric_limits::is_bounded; -template -constexpr bool numeric_limits::is_modulo; -template -constexpr bool numeric_limits::traps; -template -constexpr bool numeric_limits::tinyness_before; -template -constexpr float_round_style numeric_limits::round_style; - -template -class _CCCL_TYPE_VISIBILITY_DEFAULT numeric_limits : private numeric_limits<_Tp> -{ - typedef numeric_limits<_Tp> __base; - typedef _Tp type; - -public: - static constexpr bool is_specialized = __base::is_specialized; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept - { - return __base::min(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept - { - return __base::max(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept - { - return __base::lowest(); - } - - static constexpr int digits = __base::digits; - static constexpr int digits10 = __base::digits10; - static constexpr int max_digits10 = __base::max_digits10; - static constexpr bool is_signed = __base::is_signed; - static constexpr bool is_integer = __base::is_integer; - static constexpr bool is_exact = __base::is_exact; - static constexpr int radix = __base::radix; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept - { - return __base::epsilon(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept - { - return __base::round_error(); - } - - static constexpr int min_exponent = __base::min_exponent; - static constexpr int min_exponent10 = __base::min_exponent10; - static constexpr int max_exponent = __base::max_exponent; - static constexpr int max_exponent10 = __base::max_exponent10; - - static constexpr bool has_infinity = __base::has_infinity; - static constexpr bool has_quiet_NaN = __base::has_quiet_NaN; - static constexpr bool has_signaling_NaN = __base::has_signaling_NaN; - static constexpr float_denorm_style has_denorm = __base::has_denorm; - static constexpr bool has_denorm_loss = __base::has_denorm_loss; - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept - { - return __base::infinity(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept - { - return __base::quiet_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept - { - return __base::signaling_NaN(); - } - _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept - { - return __base::denorm_min(); - } - - static constexpr bool is_iec559 = __base::is_iec559; - static constexpr bool is_bounded = __base::is_bounded; - static constexpr bool is_modulo = __base::is_modulo; - - static constexpr bool traps = __base::traps; - static constexpr bool tinyness_before = __base::tinyness_before; - static constexpr float_round_style round_style = __base::round_style; -}; - -template -constexpr bool numeric_limits::is_specialized; -template -constexpr int numeric_limits::digits; -template -constexpr int numeric_limits::digits10; -template -constexpr int numeric_limits::max_digits10; -template -constexpr bool numeric_limits::is_signed; -template -constexpr bool numeric_limits::is_integer; -template -constexpr bool numeric_limits::is_exact; -template -constexpr int numeric_limits::radix; -template -constexpr int numeric_limits::min_exponent; -template -constexpr int numeric_limits::min_exponent10; -template -constexpr int numeric_limits::max_exponent; -template -constexpr int numeric_limits::max_exponent10; -template -constexpr bool numeric_limits::has_infinity; -template -constexpr bool numeric_limits::has_quiet_NaN; -template -constexpr bool numeric_limits::has_signaling_NaN; -template -constexpr float_denorm_style numeric_limits::has_denorm; -template -constexpr bool numeric_limits::has_denorm_loss; -template -constexpr bool numeric_limits::is_iec559; -template -constexpr bool numeric_limits::is_bounded; -template -constexpr bool numeric_limits::is_modulo; -template -constexpr bool numeric_limits::traps; -template -constexpr bool numeric_limits::tinyness_before; -template -constexpr float_round_style numeric_limits::round_style; - -_LIBCUDACXX_END_NAMESPACE_STD - -_CCCL_POP_MACROS - -#endif // _LIBCUDACXX_LIMITS diff --git a/libcudacxx/include/cuda/std/limits b/libcudacxx/include/cuda/std/limits index e1c5981cd3e..98c63813b7b 100644 --- a/libcudacxx/include/cuda/std/limits +++ b/libcudacxx/include/cuda/std/limits @@ -21,9 +21,553 @@ # pragma system_header #endif // no system header +#include +#include +#include +#include + _CCCL_PUSH_MACROS -#include +_LIBCUDACXX_BEGIN_NAMESPACE_STD + +enum float_round_style +{ + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3 +}; + +enum float_denorm_style +{ + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 +}; + +template ::value> +class __numeric_limits_impl +{ +public: + using type = _Tp; + + static constexpr bool is_specialized = false; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept + { + return type(); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept + { + return type(); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept + { + return type(); + } + + static constexpr int digits = 0; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + static constexpr bool is_signed = false; + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = 0; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept + { + return type(); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept + { + return type(); + } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept + { + return type(); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept + { + return type(); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept + { + return type(); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept + { + return type(); + } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = false; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; +}; + +// MSVC warns about overflowing left shift +_CCCL_DIAG_PUSH +_CCCL_DIAG_SUPPRESS_MSVC(4309) +template +struct __int_min +{ + static constexpr _Tp value = static_cast<_Tp>(_Tp(1) << __digits); +}; +_CCCL_DIAG_POP + +template +struct __int_min<_Tp, __digits, false> +{ + static constexpr _Tp value = _Tp(0); +}; + +template +class __numeric_limits_impl<_Tp, true> +{ +public: + using type = _Tp; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = type(-1) < type(0); + static constexpr int digits = static_cast(sizeof(type) * __CHAR_BIT__ - is_signed); + static constexpr int digits10 = digits * 3 / 10; + static constexpr int max_digits10 = 0; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept + { + return __int_min::value; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept + { + return is_signed ? type(type(~0) ^ min()) : type(~0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept + { + return min(); + } + + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept + { + return type(0); + } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept + { + return type(0); + } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = !is_signed; + +#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || defined(__wasm__) + static constexpr bool traps = true; +#else + static constexpr bool traps = false; +#endif + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; +}; + +template <> +class __numeric_limits_impl +{ +public: + using type = bool; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = false; + static constexpr int digits = 1; + static constexpr int digits10 = 0; + static constexpr int max_digits10 = 0; + + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept + { + return false; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept + { + return true; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept + { + return min(); + } + + static constexpr bool is_integer = true; + static constexpr bool is_exact = true; + static constexpr int radix = 2; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept + { + return type(0); + } + + static constexpr int min_exponent = 0; + static constexpr int min_exponent10 = 0; + static constexpr int max_exponent = 0; + static constexpr int max_exponent10 = 0; + + static constexpr bool has_infinity = false; + static constexpr bool has_quiet_NaN = false; + static constexpr bool has_signaling_NaN = false; + static constexpr float_denorm_style has_denorm = denorm_absent; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept + { + return type(0); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept + { + return type(0); + } + + static constexpr bool is_iec559 = false; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_toward_zero; +}; + +template <> +class __numeric_limits_impl +{ +public: + using type = float; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = true; + static constexpr int digits = __FLT_MANT_DIG__; + static constexpr int digits10 = __FLT_DIG__; + static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept + { + return __FLT_MIN__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept + { + return __FLT_MAX__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept + { + return -max(); + } + + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = __FLT_RADIX__; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept + { + return __FLT_EPSILON__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept + { + return 0.5F; + } + + static constexpr int min_exponent = __FLT_MIN_EXP__; + static constexpr int min_exponent10 = __FLT_MIN_10_EXP__; + static constexpr int max_exponent = __FLT_MAX_EXP__; + static constexpr int max_exponent10 = __FLT_MAX_10_EXP__; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = false; + +#if defined(_CCCL_BUILTIN_HUGE_VALF) + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept + { + return _CCCL_BUILTIN_HUGE_VALF(); + } +#else // ^^^ _CCCL_BUILTIN_HUGE_VALF ^^^ // vvv !_CCCL_BUILTIN_HUGE_VALF vvv + _LIBCUDACXX_HIDE_FROM_ABI static _LIBCUDACXX_CONSTEXPR_BIT_CAST type infinity() noexcept + { + return _CUDA_VSTD::bit_cast(0x7f800000); + } +#endif // !_CCCL_BUILTIN_HUGE_VALF +#if defined(_CCCL_BUILTIN_NANF) + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept + { + return _CCCL_BUILTIN_NANF(""); + } +#else // ^^^ _CCCL_BUILTIN_NANF ^^^ // vvv !_CCCL_BUILTIN_NANF vvv + _LIBCUDACXX_HIDE_FROM_ABI static _LIBCUDACXX_CONSTEXPR_BIT_CAST type quiet_NaN() noexcept + { + return _CUDA_VSTD::bit_cast(0x7fc00000); + } +#endif // !_CCCL_BUILTIN_NANF +#if defined(_CCCL_BUILTIN_NANSF) + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept + { + return _CCCL_BUILTIN_NANSF(""); + } +#else // ^^^ _CCCL_BUILTIN_NANSF ^^^ // vvv !_CCCL_BUILTIN_NANSF vvv + _LIBCUDACXX_HIDE_FROM_ABI static _LIBCUDACXX_CONSTEXPR_BIT_CAST type signaling_NaN() noexcept + { + return _CUDA_VSTD::bit_cast(0x7fa00000); + } +#endif // !_CCCL_BUILTIN_NANSF + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept + { + return __FLT_DENORM_MIN__; + } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; +}; + +template <> +class __numeric_limits_impl +{ +public: + using type = double; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = true; + static constexpr int digits = __DBL_MANT_DIG__; + static constexpr int digits10 = __DBL_DIG__; + static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept + { + return __DBL_MIN__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept + { + return __DBL_MAX__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept + { + return -max(); + } + + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = __FLT_RADIX__; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept + { + return __DBL_EPSILON__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept + { + return 0.5; + } + + static constexpr int min_exponent = __DBL_MIN_EXP__; + static constexpr int min_exponent10 = __DBL_MIN_10_EXP__; + static constexpr int max_exponent = __DBL_MAX_EXP__; + static constexpr int max_exponent10 = __DBL_MAX_10_EXP__; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = false; + +#if defined(_CCCL_BUILTIN_HUGE_VAL) + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept + { + return _CCCL_BUILTIN_HUGE_VAL(); + } +#else // ^^^ _CCCL_BUILTIN_HUGE_VAL ^^^ // vvv !_CCCL_BUILTIN_HUGE_VAL vvv + _LIBCUDACXX_HIDE_FROM_ABI static _LIBCUDACXX_CONSTEXPR_BIT_CAST type infinity() noexcept + { + return _CUDA_VSTD::bit_cast(0x7ff0000000000000); + } +#endif // !_CCCL_BUILTIN_HUGE_VAL +#if defined(_CCCL_BUILTIN_NAN) + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept + { + return _CCCL_BUILTIN_NAN(""); + } +#else // ^^^ _CCCL_BUILTIN_NAN ^^^ // vvv !_CCCL_BUILTIN_NAN vvv + _LIBCUDACXX_HIDE_FROM_ABI static _LIBCUDACXX_CONSTEXPR_BIT_CAST type quiet_NaN() noexcept + { + return std::bit_cast(0x7ff8000000000000); + } +#endif // !_CCCL_BUILTIN_NAN +#if defined(_CCCL_BUILTIN_NANS) + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept + { + return _CCCL_BUILTIN_NANS(""); + } +#else // ^^^ _CCCL_BUILTIN_NANS ^^^ // vvv !_CCCL_BUILTIN_NANS vvv + _LIBCUDACXX_HIDE_FROM_ABI static _LIBCUDACXX_CONSTEXPR_BIT_CAST type signaling_NaN() noexcept + { + return _CUDA_VSTD::bit_cast(0x7ff4000000000000); + } +#endif // !_CCCL_BUILTIN_NANS + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept + { + return __DBL_DENORM_MIN__; + } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; +}; + +template <> +class __numeric_limits_impl +{ +#ifndef _LIBCUDACXX_HAS_NO_LONG_DOUBLE + +public: + using type = long double; + + static constexpr bool is_specialized = true; + + static constexpr bool is_signed = true; + static constexpr int digits = __LDBL_MANT_DIG__; + static constexpr int digits10 = __LDBL_DIG__; + static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type min() noexcept + { + return __LDBL_MIN__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type max() noexcept + { + return __LDBL_MAX__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type lowest() noexcept + { + return -max(); + } + + static constexpr bool is_integer = false; + static constexpr bool is_exact = false; + static constexpr int radix = __FLT_RADIX__; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type epsilon() noexcept + { + return __LDBL_EPSILON__; + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type round_error() noexcept + { + return 0.5L; + } + + static constexpr int min_exponent = __LDBL_MIN_EXP__; + static constexpr int min_exponent10 = __LDBL_MIN_10_EXP__; + static constexpr int max_exponent = __LDBL_MAX_EXP__; + static constexpr int max_exponent10 = __LDBL_MAX_10_EXP__; + + static constexpr bool has_infinity = true; + static constexpr bool has_quiet_NaN = true; + static constexpr bool has_signaling_NaN = true; + static constexpr float_denorm_style has_denorm = denorm_present; + static constexpr bool has_denorm_loss = false; + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type infinity() noexcept + { + return _CCCL_BUILTIN_HUGE_VALL(); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type quiet_NaN() noexcept + { + return _CCCL_BUILTIN_NANL(""); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type signaling_NaN() noexcept + { + return _CCCL_BUILTIN_NANSL(""); + } + _LIBCUDACXX_HIDE_FROM_ABI static constexpr type denorm_min() noexcept + { + return __LDBL_DENORM_MIN__; + } + + static constexpr bool is_iec559 = true; + static constexpr bool is_bounded = true; + static constexpr bool is_modulo = false; + + static constexpr bool traps = false; + static constexpr bool tinyness_before = false; + static constexpr float_round_style round_style = round_to_nearest; +#endif // !_LIBCUDACXX_HAS_NO_LONG_DOUBLE +}; + +template +class numeric_limits : public __numeric_limits_impl<_Tp> +{}; + +template +class numeric_limits : public numeric_limits<_Tp> +{}; + +template +class numeric_limits : public numeric_limits<_Tp> +{}; + +template +class numeric_limits : public numeric_limits<_Tp> +{}; + +_LIBCUDACXX_END_NAMESPACE_STD _CCCL_POP_MACROS diff --git a/libcudacxx/test/internal_headers/CMakeLists.txt b/libcudacxx/test/internal_headers/CMakeLists.txt index cbb4ccce057..0129b5540ad 100644 --- a/libcudacxx/test/internal_headers/CMakeLists.txt +++ b/libcudacxx/test/internal_headers/CMakeLists.txt @@ -26,6 +26,11 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" AND NOT "${CMAKE_CXX_STANDARD}" M list(FILTER internal_headers EXCLUDE REGEX "mdspan") endif() +# Exclude __limits/msvc_win32.h on non-MSVC compilers +if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + list(FILTER internal_headers EXCLUDE REGEX "__limits/msvc_win32.h") +endif() + # generated cuda::ptx headers are not standalone list(FILTER internal_headers EXCLUDE REGEX "__ptx/instructions/generated") diff --git a/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/lowest.pass.cpp b/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/lowest.pass.cpp index 0c3bcb22229..6fec93e4a3d 100644 --- a/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/lowest.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/lowest.pass.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "test_macros.h" diff --git a/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/max.pass.cpp b/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/max.pass.cpp index 4e7a65d40b0..67c94051729 100644 --- a/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/max.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/max.pass.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "test_macros.h" diff --git a/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/min.pass.cpp b/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/min.pass.cpp index c377645f698..53d196d2a51 100644 --- a/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/min.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/language.support/support.limits/limits/numeric.limits.members/min.pass.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "test_macros.h" diff --git a/libcudacxx/test/libcudacxx/std/numerics/bit/bit.cast/bit_cast.pass.cpp b/libcudacxx/test/libcudacxx/std/numerics/bit/bit.cast/bit_cast.pass.cpp index 8aeef5fcff4..b4c5f35683a 100644 --- a/libcudacxx/test/libcudacxx/std/numerics/bit/bit.cast/bit_cast.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/numerics/bit/bit.cast/bit_cast.pass.cpp @@ -263,7 +263,9 @@ __host__ __device__ bool tests() #if !defined(TEST_COMPILER_NVRTC) && !defined(TEST_COMPILER_CLANG_CUDA) cuda::std::nanf(""), #endif // !TEST_COMPILER_NVRTC && !TEST_COMPILER_CLANG_CUDA - __builtin_nanf("0x55550001"), // NaN with a payload +#if defined(_CCCL_BUILTIN_NANF) + _CCCL_BUILTIN_NANF("0x55550001"), // NaN with a payload +#endif // _CCCL_BUILTIN_NANF cuda::std::numeric_limits::signaling_NaN(), cuda::std::numeric_limits::quiet_NaN(), cuda::std::numeric_limits::infinity()}) diff --git a/libcudacxx/test/libcudacxx/std/numerics/bit/bit.endian/endian.pass.cpp b/libcudacxx/test/libcudacxx/std/numerics/bit/bit.endian/endian.pass.cpp index 073a54568cf..8f8d721fee7 100644 --- a/libcudacxx/test/libcudacxx/std/numerics/bit/bit.endian/endian.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/numerics/bit/bit.endian/endian.pass.cpp @@ -15,6 +15,7 @@ // #include #include #include +#include #include "test_macros.h" diff --git a/libcudacxx/test/libcudacxx/std/numerics/bit/invocable.pass.cpp b/libcudacxx/test/libcudacxx/std/numerics/bit/invocable.pass.cpp index 369263bedc1..f2a32e5af68 100644 --- a/libcudacxx/test/libcudacxx/std/numerics/bit/invocable.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/numerics/bit/invocable.pass.cpp @@ -11,6 +11,7 @@ #include #include +#include #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_MSC_VER) && _MSVC_LANG >= 201703L) # define CPP17_PERFORM_INVOCABLE_TEST diff --git a/libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp b/libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp index 0b225097a33..7c15a194d65 100644 --- a/libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp +++ b/libcudacxx/test/libcudacxx/std/utilities/utility/pairs/pairs.pair/trivial_copy_move.pass.cpp @@ -16,6 +16,7 @@ // pair(pair&&) = default; #include +#include #include #include "test_macros.h"