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:
parent
477e4d695d
commit
0519e6231c
2 changed files with 47 additions and 18 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue