Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Aug 7, 2024
1 parent 0e6d752 commit bd6409b
Show file tree
Hide file tree
Showing 26 changed files with 1,082 additions and 1,443 deletions.
351 changes: 217 additions & 134 deletions godbolt/wjr.hpp

Large diffs are not rendered by default.

46 changes: 38 additions & 8 deletions include/wjr/biginteger/biginteger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class default_biginteger_vector_storage {
auto &storage = other.m_storage;
storage.m_data = result.ptr;
storage.m_size = __fasts_negate_with<int32_t>(m_storage.m_size, size);
storage.m_capacity = result.count;
storage.m_capacity = static_cast<size_type>(result.count);
}

void take_storage(default_biginteger_vector_storage &other, _Alty &) noexcept {
Expand Down Expand Up @@ -207,6 +207,16 @@ class default_biginteger_vector_storage {
template <typename Storage>
class basic_biginteger;

template <typename Alloc>
using default_biginteger = basic_biginteger<default_biginteger_vector_storage<Alloc>>;

using biginteger = default_biginteger<memory_pool<uint64_t>>;

using stack_biginteger = default_biginteger<math_detail::weak_stack_alloc<uint64_t>>;

using default_biginteger_storage =
default_biginteger_vector_storage<memory_pool<uint64_t>>;

WJR_PURE WJR_INTRINSIC_CONSTEXPR biginteger_data
make_biginteger_data(span<const uint64_t> sp) noexcept {
return biginteger_data{const_cast<uint64_t *>(sp.data()),
Expand Down Expand Up @@ -258,6 +268,11 @@ from_chars_result<const char *> __from_chars_impl(const char *first, const char
basic_biginteger<S> *dst,
unsigned int base) noexcept;

extern template from_chars_result<const char *>
__from_chars_impl<default_biginteger_storage>(
const char *first, const char *last,
basic_biginteger<default_biginteger_storage> *dst, unsigned int base) noexcept;

/// @private
WJR_PURE inline int32_t __compare_impl(const biginteger_data *lhs,
const biginteger_data *rhs) noexcept;
Expand Down Expand Up @@ -304,6 +319,14 @@ template <bool xsign, typename S>
void __addsub_impl(basic_biginteger<S> *dst, const biginteger_data *lhs,
const biginteger_data *rhs) noexcept;

extern template void __addsub_impl<false, default_biginteger_storage>(
basic_biginteger<default_biginteger_storage> *dst, const biginteger_data *lhs,
const biginteger_data *rhs) noexcept;

extern template void __addsub_impl<true, default_biginteger_storage>(
basic_biginteger<default_biginteger_storage> *dst, const biginteger_data *lhs,
const biginteger_data *rhs) noexcept;

/// @private
template <typename S>
void __add_impl(basic_biginteger<S> *dst, const biginteger_data *lhs,
Expand Down Expand Up @@ -377,6 +400,11 @@ template <typename S>
void __mul_impl(basic_biginteger<S> *dst, const biginteger_data *lhs,
const biginteger_data *rhs) noexcept;

extern template void
__mul_impl<default_biginteger_storage>(basic_biginteger<default_biginteger_storage> *dst,
const biginteger_data *lhs,
const biginteger_data *rhs) noexcept;

/// @private
template <typename S, typename T, WJR_REQUIRES(is_nonbool_integral_v<T>)>
void __mul_impl(basic_biginteger<S> *dst, const biginteger_data *lhs, T rhs) noexcept {
Expand All @@ -400,6 +428,10 @@ void __mul_impl(basic_biginteger<S> *dst, const biginteger_data *lhs, T rhs) noe
template <typename S>
void __sqr_impl(basic_biginteger<S> *dst, const biginteger_data *src) noexcept;

extern template void
__sqr_impl<default_biginteger_storage>(basic_biginteger<default_biginteger_storage> *dst,
const biginteger_data *src) noexcept;

/// @private
template <typename S>
void __addsubmul_impl(basic_biginteger<S> *dst, const biginteger_data *lhs, uint64_t rhs,
Expand Down Expand Up @@ -446,6 +478,10 @@ template <typename S>
void __addsubmul_impl(basic_biginteger<S> *dst, const biginteger_data *lhs,
const biginteger_data *rhs, int32_t xmask) noexcept;

extern template void __addsubmul_impl<default_biginteger_storage>(
basic_biginteger<default_biginteger_storage> *dst, const biginteger_data *lhs,
const biginteger_data *rhs, int32_t xmask) noexcept;

/// @private
template <typename S>
void __addmul_impl(basic_biginteger<S> *dst, const biginteger_data *lhs,
Expand Down Expand Up @@ -1366,12 +1402,6 @@ class basic_biginteger {
vector_type m_vec;
};

template <typename Alloc>
using default_biginteger = basic_biginteger<default_biginteger_vector_storage<Alloc>>;

using biginteger = default_biginteger<memory_pool<uint64_t>>;
using stack_biginteger = default_biginteger<math_detail::weak_stack_alloc<uint64_t>>;

template <typename Storage>
void swap(basic_biginteger<Storage> &lhs, basic_biginteger<Storage> &rhs) noexcept {
lhs.swap(rhs);
Expand Down Expand Up @@ -1667,7 +1697,7 @@ void __addsub_impl(basic_biginteger<S> *dst, const biginteger_data *lhs,
int32_t dssize;

if (compare{}(lssize, 0)) {
const auto cf = addc_1(dp, lp, lusize, rhs);
const uint32_t cf = addc_1(dp, lp, lusize, rhs, 0u);
dssize = __fasts_conditional_negate<int32_t>(xsign, lusize + cf);
if (cf) {
dp[lusize] = 1;
Expand Down
Loading

0 comments on commit bd6409b

Please sign in to comment.