3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-02-08 18:19:40 +00:00

Optimize iterator bit scanning and variable matching per TODO directives (#8416)

* Initial plan

* Optimize approx_set iterator and variable_intersection populate

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

* Add clarifying comment for iterator optimization

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
This commit is contained in:
Copilot 2026-01-29 19:02:13 -08:00 committed by GitHub
parent 477e4d695d
commit 0519e6231c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 47 additions and 18 deletions

View file

@ -164,14 +164,23 @@ public:
unsigned long long m_set;
unsigned m_val;
void move_to_next() {
// TODO: this code can be optimized in platforms with special
// instructions to count leading (trailing) zeros in a word.
while (m_set > 0) {
if ((m_set & 1ull) != 0) {
return;
if (m_set > 0) {
#ifdef __GNUC__
// Use compiler builtin for trailing zero count (optimized)
// After shift, LSB will be set to 1 (same as fallback behavior)
unsigned tz = __builtin_ctzll(m_set);
m_val += tz;
m_set >>= tz;
#else
// Fallback to loop-based approach
while (m_set > 0) {
if ((m_set & 1ull) != 0) {
return;
}
m_val++;
m_set = m_set >> 1;
}
m_val ++;
m_set = m_set >> 1;
#endif
}
}
public: