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

Improved basic operators for 32 and 64 bit types #677

Merged
merged 45 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0b59517
Remove repeated operations in decimal32 division
mborland Jun 21, 2024
32137ce
Remove repeated operations in decimal64 division
mborland Jun 21, 2024
7ef2010
Simplify 32 bit addition
mborland Jun 21, 2024
0dd9002
Simplify 64 bit addition
mborland Jun 21, 2024
da78a23
Slightly simplify 32 bit subtraction implementation
mborland Jun 21, 2024
6ca21c6
Fix potential overflow in decimal32 mixed type addition
mborland Jun 21, 2024
84581d9
Add additional typedefs
mborland Jun 21, 2024
a6101b9
Apply new sub impl to addition
mborland Jun 21, 2024
211a43d
Simplify 32 bit subtraction
mborland Jun 21, 2024
1c1b444
Fix and simplify decimal32_fast subtraction
mborland Jun 21, 2024
643450d
Add additional typedefs
mborland Jun 21, 2024
8482088
Simplify 64 bit operator-
mborland Jun 24, 2024
bb43e59
Further simplification to operator+
mborland Jun 24, 2024
76f7130
Simplify 64-bit sub impl
mborland Jun 24, 2024
e52ede3
Add decimal64_fast riemann zeta testing
mborland Jun 24, 2024
ead73a3
Fix linker error
mborland Jun 24, 2024
2a7dec6
Further changes to decimal64_fast operator+
mborland Jun 24, 2024
07ec0e5
Simplify decimal64_fast operators-
mborland Jun 24, 2024
b293a74
Add basic operator significand promotion function
mborland Jun 24, 2024
376aae9
Add a conditional significantly simpler mul_impl
mborland Jun 24, 2024
2ad339c
Improve decimal32_fast operator*
mborland Jun 24, 2024
85aedca
Improve decimal32 operator*
mborland Jun 24, 2024
f89b3d8
Add simplified 64 bit mul impl
mborland Jun 24, 2024
30e4acf
Simplify operators*
mborland Jun 24, 2024
61405c5
Fix normalization of 0s
mborland Jun 24, 2024
4624fc9
Fix decimal64_fast type errors
mborland Jun 24, 2024
5d6817c
Make exp a template type
mborland Jun 24, 2024
e2b7832
Disable FMAs for now since they need reworked
mborland Jun 24, 2024
f1d524d
Fix old clang conversion
mborland Jun 24, 2024
2688bdf
Remove workaround code path
mborland Jun 24, 2024
457cc1c
Simplify value of sign
mborland Jun 24, 2024
de73cbc
Fix narrowing conversions
mborland Jun 25, 2024
adc6657
Add typedefs to 128 bit types
mborland Jun 25, 2024
0730545
Fix more conversions
mborland Jun 25, 2024
cc5cff4
Fix conversions in decima128_fast
mborland Jun 25, 2024
d1b0087
Add template type for exponent
mborland Jun 25, 2024
016d1d8
Add single division to keep from digit counting a uint128
mborland Jun 25, 2024
a8f3259
Speed up mul_impl for decimal32 and add additional impl for dec32_fast
mborland Jun 25, 2024
3ca6e64
Change intermediate mul type for clang 6-12
mborland Jun 25, 2024
7255a0a
Additional old clang workaround
mborland Jun 25, 2024
2616fdd
Fix handling of signed 0
mborland Jun 25, 2024
b7163d8
Fix testing of signed 0s
mborland Jun 25, 2024
49631b1
Fix type of exp
mborland Jun 25, 2024
cdf9ffa
Further clang workarounds
mborland Jun 25, 2024
f6fa637
Change division type for old clangs
mborland Jun 26, 2024
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
9 changes: 6 additions & 3 deletions include/boost/decimal/decimal128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ BOOST_DECIMAL_CONSTEXPR_VARIABLE uint128 d128_big_combination_field_mask {UINT64

struct decimal128_components
{
using sig_type = uint128;
using significand_type = uint128;
using biased_exponent_type = std::int32_t;

uint128 sig {};
std::int32_t exp {};
significand_type sig {};
biased_exponent_type exp {};
bool sign {};

constexpr decimal128_components() = default;
Expand All @@ -150,6 +151,8 @@ BOOST_DECIMAL_EXPORT class decimal128 final
{
public:
using significand_type = detail::uint128;
using exponent_type = std::uint64_t;
using biased_exponent_type = std::int32_t;

private:
detail::uint128 bits_ {};
Expand Down
22 changes: 12 additions & 10 deletions include/boost/decimal/decimal128_fast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ BOOST_DECIMAL_CONSTEXPR_VARIABLE auto d128_fast_snan = std::numeric_limits<uint1

struct decimal128_fast_components
{
using sig_type = uint128;
using significand_type = uint128;
using biased_exponent_type = std::int_fast32_t;

uint128 sig;
std::int32_t exp;
significand_type sig;
biased_exponent_type exp;
bool sign;
};

Expand All @@ -45,6 +46,7 @@ class decimal128_fast final
public:
using significand_type = detail::uint128;
using exponent_type = std::uint_fast32_t;
using biased_exponent_type = std::int_fast32_t;

private:
// Instead of having to encode and decode at every operation
Expand All @@ -69,9 +71,9 @@ class decimal128_fast final
return exponent_;
}

constexpr auto biased_exponent() const noexcept -> std::int32_t
constexpr auto biased_exponent() const noexcept -> biased_exponent_type
{
return static_cast<std::int32_t>(exponent_) - detail::bias_v<decimal128>;
return static_cast<biased_exponent_type>(exponent_) - detail::bias_v<decimal128>;
}

template <typename Decimal, typename TargetType>
Expand Down Expand Up @@ -820,7 +822,7 @@ constexpr auto operator+(decimal128_fast lhs, Integer rhs) noexcept
auto lhs_components {detail::decimal128_fast_components{lhs.significand_, lhs.biased_exponent(), lhs.isneg()}};

auto sig_rhs {static_cast<detail::uint128>(detail::make_positive_unsigned(rhs))};
std::int32_t exp_rhs {0};
decimal128_fast::biased_exponent_type exp_rhs {0};
detail::normalize<decimal128>(sig_rhs, exp_rhs);
auto unsigned_sig_rhs = detail::make_positive_unsigned(sig_rhs);
auto rhs_components {detail::decimal128_fast_components{unsigned_sig_rhs, exp_rhs, (rhs < 0)}};
Expand Down Expand Up @@ -914,7 +916,7 @@ constexpr auto operator-(decimal128_fast lhs, Integer rhs) noexcept
auto lhs_components {detail::decimal128_fast_components{lhs.significand_, lhs.biased_exponent(), lhs.isneg()}};

auto sig_rhs {static_cast<detail::uint128>(detail::make_positive_unsigned(rhs))};
std::int32_t exp_rhs {0};
decimal128_fast::biased_exponent_type exp_rhs {0};
detail::normalize<decimal128>(sig_rhs, exp_rhs);
auto unsigned_sig_rhs {detail::make_positive_unsigned(sig_rhs)};
auto rhs_components {detail::decimal128_fast_components{unsigned_sig_rhs, exp_rhs, (rhs < 0)}};
Expand Down Expand Up @@ -946,7 +948,7 @@ constexpr auto operator-(Integer lhs, decimal128_fast rhs) noexcept
const bool abs_lhs_bigger {detail::make_positive_unsigned(lhs) > abs(rhs)};

auto sig_lhs {static_cast<detail::uint128>(detail::make_positive_unsigned(lhs))};
std::int32_t exp_lhs {0};
decimal128_fast::biased_exponent_type exp_lhs {0};
detail::normalize<decimal128>(sig_lhs, exp_lhs);
auto unsigned_sig_lhs {detail::make_positive_unsigned(sig_lhs)};
auto lhs_components {detail::decimal128_fast_components{unsigned_sig_lhs, exp_lhs, (lhs < 0)}};
Expand Down Expand Up @@ -992,7 +994,7 @@ constexpr auto operator*(decimal128_fast lhs, Integer rhs) noexcept
#endif

auto rhs_sig {static_cast<detail::uint128>(detail::make_positive_unsigned(rhs))};
std::int32_t rhs_exp {0};
decimal128_fast::biased_exponent_type rhs_exp {0};
detail::normalize<decimal128_fast>(rhs_sig, rhs_exp);

const auto result {detail::d128_fast_mul_impl<detail::decimal128_fast_components>(
Expand Down Expand Up @@ -1128,7 +1130,7 @@ constexpr auto operator/(decimal128_fast lhs, Integer rhs) noexcept
detail::decimal128_fast_components lhs_components {lhs.significand_, lhs.biased_exponent(), lhs.isneg()};

auto rhs_sig {detail::make_positive_unsigned(rhs)};
std::int32_t rhs_exp {};
decimal128_fast::biased_exponent_type rhs_exp {};
detail::decimal128_fast_components rhs_components {rhs_sig, rhs_exp, rhs < 0};
detail::decimal128_fast_components q_components {};

Expand Down
Loading
Loading