Skip to content
Merged
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
4 changes: 0 additions & 4 deletions include/boost/safe_numbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#ifndef BOOST_SAFENUMBERS_HPP
#define BOOST_SAFENUMBERS_HPP

#define BOOST_SAFE_NUMBERS_DETAIL_INT128_ALLOW_SIGN_CONVERSION

#include <boost/safe_numbers/unsigned_integers.hpp>
#include <boost/safe_numbers/signed_integers.hpp>
#include <boost/safe_numbers/bounded_integers.hpp>
Expand All @@ -23,6 +21,4 @@
#include <boost/safe_numbers/cmath.hpp>
#include <boost/safe_numbers/functional.hpp>

#undef BOOST_SAFE_NUMBERS_DETAIL_INT128_ALLOW_SIGN_CONVERSION

#endif //BOOST_SAFENUMBERS_HPP
20 changes: 12 additions & 8 deletions include/boost/safe_numbers/detail/int128/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# define BOOST_CHARCONV_ENABLE_CUDA
#endif

#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_SYCL) && !defined(BOOST_CHARCONV_ENABLE_SYCL)
# define BOOST_CHARCONV_ENABLE_SYCL
#endif

#include <boost/safe_numbers/detail/int128/int128.hpp>
#include <boost/safe_numbers/detail/int128/literals.hpp>
#include <boost/charconv.hpp>
Expand Down Expand Up @@ -44,23 +48,23 @@ struct make_signed<int128::uint128_t> { using type = int128::int128_t; };
template <>
struct make_signed<int128::int128_t> { using type = int128::int128_t; };

#if defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA)
#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)

template <>
__host__ __device__ constexpr int128::uint128_t get_max_value<int128::uint128_t>()
BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int128::uint128_t get_max_value<int128::uint128_t>()
{
return std::numeric_limits<int128::uint128_t>::max();
}

template <>
__host__ __device__ constexpr int128::int128_t get_max_value<int128::int128_t>()
BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int128::int128_t get_max_value<int128::int128_t>()
{
return std::numeric_limits<int128::int128_t>::max();
}

#endif // __NVCC__
#endif

#if !(defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA))
#if !defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)

BOOST_SAFE_NUMBERS_DETAIL_INT128_INLINE_CONSTEXPR int128::uint128_t int128_pow10[39] =
{
Expand Down Expand Up @@ -109,7 +113,7 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_INLINE_CONSTEXPR int128::uint128_t int128_pow10

BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int num_digits(const int128::uint128_t& x) noexcept
{
#if defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA)
#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)

constexpr int128::uint128_t int128_pow10[39] =
{
Expand Down Expand Up @@ -187,7 +191,7 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE constexpr int num_digits(const int1

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
{
#if !(defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA))
#if !defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)

if (base == 10)
{
Expand All @@ -201,7 +205,7 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DEVICE BOOST_CHARCONV_CONSTEXPR to_chars_r

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
{
#if !(defined(__CUDACC__) && defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_ENABLE_CUDA))
#if !defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_GPU_SUPPORT)

if (base == 10)
{
Expand Down
27 changes: 14 additions & 13 deletions include/boost/safe_numbers/detail/int128/cstdlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,6 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_EXPORT BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DE
return i128div_t{0, 0};
}

#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_INT128)

const auto builtin_x {static_cast<detail::builtin_i128>(x)};
const auto builtin_y {static_cast<detail::builtin_i128>(y)};
return i128div_t{static_cast<int128_t>(builtin_x / builtin_y),
static_cast<int128_t>(builtin_x % builtin_y)};

#else

const auto abs_lhs {static_cast<uint128_t>(abs(x))};
const auto abs_rhs {static_cast<uint128_t>(abs(y))};

Expand All @@ -78,19 +69,29 @@ BOOST_SAFE_NUMBERS_DETAIL_INT128_EXPORT BOOST_SAFE_NUMBERS_DETAIL_INT128_HOST_DE
return {0, x};
}

const auto unsigned_res {div(abs_lhs, abs_rhs)};

const auto negative_quot {(x.high < 0) != (y.high < 0)};
const auto negative_rem {x.high < 0};

#if defined(BOOST_SAFE_NUMBERS_DETAIL_INT128_HAS_INT128)

if (abs_rhs.high != 0)
{
const auto builtin_x {static_cast<detail::builtin_i128>(x)};
const auto builtin_y {static_cast<detail::builtin_i128>(y)};
return i128div_t{static_cast<int128_t>(builtin_x / builtin_y),
static_cast<int128_t>(builtin_x % builtin_y)};
}

#endif

const auto unsigned_res {div(abs_lhs, abs_rhs)};

i128div_t res {static_cast<int128_t>(unsigned_res.quot), static_cast<int128_t>(unsigned_res.rem)};

res.quot = negative_quot ? -res.quot : res.quot;
res.rem = negative_rem ? -res.rem : res.rem;

return res;

#endif
}

} // namespace int128
Expand Down
Loading
Loading