Skip to content

Conversation

ckormanyos
Copy link
Member

@ckormanyos ckormanyos commented Apr 15, 2025

In cpp_int/misc.hpp, there is a dependency on Boost.Integer.

But if and only if it is not standalone. Yet the standalone version does not need integer. I was wondering if it is possible to remove this dependency in the non-standalone mode? Thereby the behavior would be the same for constexpr_gcd in standalone as well as non-standalone mode.

Why? I got some pesky warnings coming in from Boost.Integer.

The header has also been refactored to treat having/not-having std::gcd in a uniform fashion with respect to compiler switches. The compiler switches were not the same in the two places earlier.

Cc: @jzmaddock and @mborland

#ifndef BOOST_MP_STANDALONE
#include <boost/integer/common_factor_rt.hpp>
#endif
#if (defined(__cpp_lib_gcd_lcm) && (__cpp_lib_gcd_lcm >= 201606L)) && (!defined(BOOST_HAS_INT128) || !defined(__STRICT_ANSI__))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we really need the && (!defined(BOOST_HAS_INT128) || !defined(__STRICT_ANSI__)) part? Ah wait... no std::gcd and std::lcm for __int128? I know we have our own gcd/lcm as a fall-back of last resort, but they're not actually very performant (I suspect anyway) compared to the full Boost versions. Or perhaps I'm wrong on that?

In any case we need to get these CI tests fixed up before we can do much of anything... :(

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.1%. Comparing base (0acb5b4) to head (83133b7).
Report is 9 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop    #676     +/-   ##
=========================================
+ Coverage     94.1%   94.1%   +0.1%     
=========================================
  Files          280     280             
  Lines        29067   29074      +7     
=========================================
+ Hits         27340   27347      +7     
  Misses        1727    1727             
Files with missing lines Coverage Δ
include/boost/multiprecision/cpp_int/misc.hpp 91.9% <ø> (+0.2%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0acb5b4...83133b7. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ckormanyos
Copy link
Member Author

ckormanyos commented Apr 15, 2025

... we have our own gcd/lcm as a fall-back of last resort, but they're not actually very performant (I suspect anyway) compared to the full Boost versions. Or perhaps I'm wrong on that?

Hmmm... That's a good one. I would be somewhat leary of incurring a performance loss for this. The real changes I implemented involve calculating the gcd() for integral types. These default to ::std::gcd() (when available).

I could work out some perf-tests before/after.

In any case we need to get these CI tests fixed up before we can do much of anything...

Well, it can go green and just did.

We can also drop this one any time, it is not a critical change. But I'll invest the hour of play-time for some perf-experiments...

Thanks John!

@ckormanyos
Copy link
Member Author

ckormanyos commented May 5, 2025

... we have our own gcd/lcm as a fall-back of last resort, but they're not actually very performant (I suspect anyway) compared to the full Boost versions. Or perhaps I'm wrong on that?

work out some perf-tests before/after.

Well, the performance numbers took a while, but here they are. Care was taken to measure the time of the GCD operations themselves insofar as possible (maybe with extra time only for move-ingh them into the vector storage). So I precomputed a bunch of random a and b, stored these in a vector and then timed the gcd(a, b) and stored these in c. This is the time shown below.

So it does, in fact, appear that the full Boost versions of GCD in Boost.Integer offer slightly superior performance. In light of this, I don't see any reason to pursue this PR any further. And I'll close it if that's the consensus?

Cc: @jzmaddock and @mborland

digits runs time (develop) [s] time (candidate) [s] ratio
128 16 * 0x200000 1.65 1.63 1.00
256 16 * 0x200000 2.20 2.27 1.03
512 16 * 0x200000 3.48 3.64 1.05
1024 16 * 0x200000 6.29 6.75 1.07
4096 16 * 0x200000 23.3 24.6 1.06

@ckormanyos
Copy link
Member Author

ckormanyos commented May 5, 2025

The header has also been refactored to treat having/not-having std::gcd in a uniform fashion with respect to compiler switches.

This part, however, might be a useful change.

Cc: @jzmaddock and @mborland

@ckormanyos ckormanyos changed the title Remove dependency on Boost.Integer Uniform logic has or not-has GCD/LCM May 5, 2025
@ckormanyos
Copy link
Member Author

Add the source codes used for performance measurements. It is a zip archive of the source files.
Test.zip

@ckormanyos
Copy link
Member Author

Hi @jzmaddock and @mborland I've never really follwed the Circle CI build that much.

For some reason, on trivial changes, the inspect job is failing. But I can't really see why. Do you guys know why it is failing?

@ckormanyos
Copy link
Member Author

OK I made a bit of a little mess. I'll need a few tries to clean this up... In progress

@jzmaddock
Copy link
Collaborator

For some reason, on trivial changes, the inspect job is failing. But I can't really see why. Do you guys know why it is failing?

No, but it's started failing on Math as well. I think something outside our control has changed, will try to take a look...

@jzmaddock
Copy link
Collaborator

See comment: boostorg/inspect@0ef7948#r156401450

@ckormanyos ckormanyos merged commit 9de48c7 into develop May 5, 2025
79 of 80 checks passed
@ckormanyos ckormanyos deleted the integer_dependency branch May 5, 2025 19:56
@ckormanyos
Copy link
Member Author

Merging in acceptance of upstream break in Inspect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants