Skip to content

Commit e68d13a

Browse files
authored
Merge pull request #235 from cppalliance/int128
Update vendor copy of int128
2 parents 7c96b07 + 50251dd commit e68d13a

116 files changed

Lines changed: 1456 additions & 2727 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/boost/safe_numbers.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#ifndef BOOST_SAFENUMBERS_HPP
66
#define BOOST_SAFENUMBERS_HPP
77

8-
#define BOOST_SAFE_NUMBERS_DETAIL_INT128_ALLOW_SIGN_CONVERSION
9-
108
#include <boost/safe_numbers/unsigned_integers.hpp>
119
#include <boost/safe_numbers/signed_integers.hpp>
1210
#include <boost/safe_numbers/bounded_integers.hpp>
@@ -23,6 +21,4 @@
2321
#include <boost/safe_numbers/cmath.hpp>
2422
#include <boost/safe_numbers/functional.hpp>
2523

26-
#undef BOOST_SAFE_NUMBERS_DETAIL_INT128_ALLOW_SIGN_CONVERSION
27-
2824
#endif //BOOST_SAFENUMBERS_HPP

include/boost/safe_numbers/detail/int128/charconv.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
# define BOOST_CHARCONV_ENABLE_CUDA
1717
#endif
1818

19+
#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_SYCL) && !defined(BOOST_CHARCONV_ENABLE_SYCL)
20+
# define BOOST_CHARCONV_ENABLE_SYCL
21+
#endif
22+
1923
#include <boost/safe_numbers/detail/int128/int128.hpp>
2024
#include <boost/safe_numbers/detail/int128/literals.hpp>
2125
#include <boost/charconv.hpp>
@@ -44,23 +48,23 @@ struct make_signed<int128::uint128_t> { using type = int128::int128_t; };
4448
template <>
4549
struct make_signed<int128::int128_t> { using type = int128::int128_t; };
4650

47-
#if defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA)
51+
#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)
4852

4953
template <>
50-
__host__ __device__ constexpr int128::uint128_t get_max_value<int128::uint128_t>()
54+
BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int128::uint128_t get_max_value<int128::uint128_t>()
5155
{
5256
return std::numeric_limits<int128::uint128_t>::max();
5357
}
5458

5559
template <>
56-
__host__ __device__ constexpr int128::int128_t get_max_value<int128::int128_t>()
60+
BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int128::int128_t get_max_value<int128::int128_t>()
5761
{
5862
return std::numeric_limits<int128::int128_t>::max();
5963
}
6064

61-
#endif // __NVCC__
65+
#endif
6266

63-
#if !(defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA))
67+
#if !defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)
6468

6569
BOOST_SAFE_NUMBERS_DETAIL_INT128_INLINE_CONSTEXPR int128::uint128_t int128_pow10[39] =
6670
{
@@ -109,7 +113,7 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_INLINE_CONSTEXPR int128::uint128_t int128_pow10
109113

110114
BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int num_digits(const int128::uint128_t& x) noexcept
111115
{
112-
#if defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA)
116+
#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)
113117

114118
constexpr int128::uint128_t int128_pow10[39] =
115119
{
@@ -187,7 +191,7 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int num_digits(const int1
187191

188192
BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, const int128::uint128_t value, const int base = 10) noexcept
189193
{
190-
#if !(defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA))
194+
#if !defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)
191195

192196
if (base == 10)
193197
{
@@ -201,7 +205,7 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE BOOST_CHARCONV_CONSTEXPR to_chars_r
201205

202206
BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, const int128::int128_t value, const int base = 10) noexcept
203207
{
204-
#if !(defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA))
208+
#if !defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)
205209

206210
if (base == 10)
207211
{

include/boost/safe_numbers/detail/int128/cstdlib.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_EXPORT BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DE
6161
return i128div_t{0, 0};
6262
}
6363

64-
#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_INT128)
65-
66-
const auto builtin_x {static_cast<detail::builtin_i128>(x)};
67-
const auto builtin_y {static_cast<detail::builtin_i128>(y)};
68-
return i128div_t{static_cast<int128_t>(builtin_x / builtin_y),
69-
static_cast<int128_t>(builtin_x % builtin_y)};
70-
71-
#else
72-
7364
const auto abs_lhs {static_cast<uint128_t>(abs(x))};
7465
const auto abs_rhs {static_cast<uint128_t>(abs(y))};
7566

@@ -78,19 +69,29 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_EXPORT BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DE
7869
return {0, x};
7970
}
8071

81-
const auto unsigned_res {div(abs_lhs, abs_rhs)};
82-
8372
const auto negative_quot {(x.high < 0) != (y.high < 0)};
8473
const auto negative_rem {x.high < 0};
8574

75+
#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_INT128)
76+
77+
if (abs_rhs.high != 0)
78+
{
79+
const auto builtin_x {static_cast<detail::builtin_i128>(x)};
80+
const auto builtin_y {static_cast<detail::builtin_i128>(y)};
81+
return i128div_t{static_cast<int128_t>(builtin_x / builtin_y),
82+
static_cast<int128_t>(builtin_x % builtin_y)};
83+
}
84+
85+
#endif
86+
87+
const auto unsigned_res {div(abs_lhs, abs_rhs)};
88+
8689
i128div_t res {static_cast<int128_t>(unsigned_res.quot), static_cast<int128_t>(unsigned_res.rem)};
8790

8891
res.quot = negative_quot ? -res.quot : res.quot;
8992
res.rem = negative_rem ? -res.rem : res.rem;
9093

9194
return res;
92-
93-
#endif
9495
}
9596

9697
} // namespace int128

0 commit comments

Comments
 (0)