Fix tagged pointer small integer bounds for 32/64-bit platforms#8554
Fix tagged pointer small integer bounds for 32/64-bit platforms#8554
Conversation
|
@copilot revert your fix to |
|
@copilot also, revert your massive changes to indentation. It makes the diff very hard to read. |
Reverted. Set methods now only write to small integers when the mpz is already small. Once an mpz becomes large, it stays large. Fixed in d3572a9. |
src/util/mpz.h
Outdated
| } | ||
|
|
||
| void set(int v) { | ||
| m_value = static_cast<uintptr_t>(static_cast<intptr_t>(v)) << 1; |
There was a problem hiding this comment.
@copilot you removed the memory leak fix that was here.
Once a value becomes large, it should stay large forever (and not leak memory like this).
There was a problem hiding this comment.
@copilot Oh, I see it is only called if is_small() holds. Add an assertion then.
There was a problem hiding this comment.
Added assertion to set() method to ensure it's only called when is_small() holds. Fixed in 46bc45d.
src/util/mpz.h
Outdated
| if (a.value() == INT_MIN) { | ||
| int64_t val = a.value64(); | ||
| cell = reserve; | ||
| if (val == mpz::SMALL_INT_MIN) { |
src/util/mpz.cpp
Outdated
| template<bool SYNCH> | ||
| void mpz_manager<SYNCH>::gcd(mpz const & a, mpz const & b, mpz & c) { | ||
| static_assert(sizeof(a.m_val) == sizeof(int), "size mismatch"); | ||
| static_assert(sizeof(int) == sizeof(int), "size mismatch"); |
There was a problem hiding this comment.
@copilot this assert doesn't make sense anymore
There was a problem hiding this comment.
Removed the nonsensical assertion sizeof(int) == sizeof(int). This was a bug from the mpz_tagged_ptr refactoring that compared int to itself instead of checking m_val. Fixed in f2ae873.
src/util/mpz.h
Outdated
| // Maximum and minimum values that can be stored as small integers | ||
| static constexpr int64_t SMALL_INT_MAX = (static_cast<int64_t>(1) << (SMALL_BITS - 1)) - 1; | ||
| static constexpr int64_t SMALL_INT_MIN = -(static_cast<int64_t>(1) << (SMALL_BITS - 1)); | ||
| // Use unsigned arithmetic to avoid undefined behavior on left shift |
|
@copilot fix the CI error: |
... Fixed. The issue was in LEHMER_GCD algorithm which used |
…multiple, and log2 for 64-bit platforms Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
…ltiple Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
…iolations Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
…d as small Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
…presented as small" Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
eda2e52 to
4a8aeb0
Compare
Fix mpz_tagged_ptr branch issues
Issues Fixed:
}on line 139 in mpz.hcon line 162 - should beset_signImplementation Complete:
SMALL_INT_MINandSMALL_INT_MAXconstants based on pointer sizefits_in_small()static methods with overloads for int, unsigned, int64_t, uint64_tset64()method for 64-bit small integersvalue()now returnsint64_t(removed separatevalue64()method)(sizeof(uintptr_t) * 8 - 1) - 1instead of static constantvalue()method returning full 64-bit range💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.