Skip to content

Avoid pointer chasing for pFanout->Id when we already have it in Aig_ManUpdateReverseLevel - #559

Merged
alanminko merged 1 commit into
berkeley-abc:masterfrom
calewis:fast_reverse_level
Sep 2, 2026
Merged

Avoid pointer chasing for pFanout->Id when we already have it in Aig_ManUpdateReverseLevel#559
alanminko merged 1 commit into
berkeley-abc:masterfrom
calewis:fast_reverse_level

Conversation

@calewis

@calewis calewis commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The diff makes it hard to see, but doing some manual inlining shows the changes we are trying to make look like:
Before:

    pFanout = p->vObjs->pArray[iFanout >> 1];
    int FanoutId = pFanout->Id;
    Vec_IntFillExtra( p->vLevelR, FanoutId + 1, 0 );
    LevelCur = p->vLevelR->pArray[FanoutId];

After:

    int FanoutId = iFanout >> 1;
    Vec_IntFillExtra( p->vLevelR, FanoutId + 1, 0 );
    LevelCur = p->vLevelR->pArray[FanoutId];

By using Vec_IntGetEntry(p->vLevelR, FanoutId) directly, the memory loads to retrieve pFanout and dereference pFanout->Id are completely eliminated.

The Vec_IntFillExtra( p->vLevelR, Aig_ManObjNumMax(p), 0 ); seeks to avoid any resizing in the loop.

This can speed up Aig_ManUpdateReverseLevel about 40% in our tests, our profiling showed a large amount of time spent waiting on the pFanout data to fetch from memory.

There is an assumption that int FanoutId = iFanout >> 1; will remain valid in the future, but who ever is reviewing hopefully can comment on that.

Signed-off-by: Drew Lewis <cannada@google.com>
@alanminko
alanminko merged commit 5f5de7a into berkeley-abc:master Sep 2, 2026
9 checks passed
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