Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor limits and climits #3221

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<long double>(__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)
davebayer marked this conversation as resolved.
Show resolved Hide resolved
# define _CCCL_BUILTIN_NANL(...) __builtin_nanl(__VA_ARGS__)
#elif _CCCL_COMPILER(MSVC)
# define _CCCL_BUILTIN_NANL(...) static_cast<long double>(__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<long double>(__builtin_nans(__VA_ARGS__))
#endif // _CCCL_CHECK_BUILTIN(builtin_nansl)
miscco marked this conversation as resolved.
Show resolved Hide resolved

#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__)
Expand Down
105 changes: 0 additions & 105 deletions libcudacxx/include/cuda/std/__cuda/climits_prelude.h

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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."
Expand All @@ -19,8 +21,6 @@

#include <float.h> // limit constants
#include <limits.h> // CHAR_BIT
#include <math.h> // HUGE_VAL
#include <ymath.h> // internal MSVC header providing the needed functionality

#define __CHAR_BIT__ CHAR_BIT

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions libcudacxx/include/cuda/std/__memory/allocator_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <cuda/std/__type_traits/is_copy_constructible.h>
#include <cuda/std/__type_traits/is_empty.h>
#include <cuda/std/__type_traits/is_move_constructible.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/__type_traits/is_trivially_move_constructible.h>
#include <cuda/std/__type_traits/make_unsigned.h>
#include <cuda/std/__type_traits/remove_reference.h>
#include <cuda/std/__type_traits/void_t.h>
Expand Down
3 changes: 2 additions & 1 deletion libcudacxx/include/cuda/std/__memory/temporary_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
#include <cuda/std/__iterator/iterator_traits.h>
#include <cuda/std/__memory/addressof.h>
#include <cuda/std/__new_>
#include <cuda/std/__type_traits/alignment_of.h>
#include <cuda/std/__utility/move.h>
#include <cuda/std/__utility/pair.h>
#include <cuda/std/cstddef>
#include <cuda/std/detail/libcxx/include/limits>
#include <cuda/std/limits>

_LIBCUDACXX_BEGIN_NAMESPACE_STD

Expand Down
69 changes: 68 additions & 1 deletion libcudacxx/include/cuda/std/climits
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,74 @@

_CCCL_PUSH_MACROS

#include <cuda/std/detail/libcxx/include/climits>
#if !_CCCL_COMPILER(NVRTC)
# include <climits>
#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 <cuda/std/__limits/msvc_win32.h>
#endif // _CCCL_COMPILER(MSVC)

// ICC defines __CHAR_BIT__ by default
// accept that, but assert it is what we expect
#ifdef __CHAR_BIT__
static_assert(__CHAR_BIT__ == 8, "");
#else
# define __CHAR_BIT__ 8
#endif

_CCCL_POP_MACROS

Expand Down
68 changes: 0 additions & 68 deletions libcudacxx/include/cuda/std/detail/libcxx/include/climits

This file was deleted.

5 changes: 2 additions & 3 deletions libcudacxx/include/cuda/std/detail/libcxx/include/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,8 @@ long double truncl(long double x);
#endif // _LIBCUDACXX_HAS_NVBF16

#if _CCCL_COMPILER(NVRTC)
# include <cuda/std/climits>
# define INFINITY __builtin_huge_val()
# define NAN __builtin_nan()
# define INFINITY _CUDA_VSTD::numeric_limits<float>::infinity()
# define NAN _CUDA_VSTD::numeric_limits<float>::quiet_NaN()
#endif // _CCCL_COMPILER(NVRTC)

_CCCL_PUSH_MACROS
Expand Down
Loading