Skip to content

Make Aig_And commutative when fAddStrash is enabled. - #553

Closed
TrevorHansen wants to merge 1 commit into
berkeley-abc:masterfrom
TrevorHansen:upstream-commutative-and
Closed

Make Aig_And commutative when fAddStrash is enabled.#553
TrevorHansen wants to merge 1 commit into
berkeley-abc:masterfrom
TrevorHansen:upstream-commutative-and

Conversation

@TrevorHansen

@TrevorHansen TrevorHansen commented Aug 29, 2026

Copy link
Copy Markdown

ANDs' operands are ordered by regular id, but if fAddStrash is enabled, after p0's children are compared against p1's .

A different node can be a produced when p0 and p1 are swapped. That is Aig_And(p0, p1) does not necessarily produce the same result as Aig_And(p1, p0).

This patch makes Aig_And commutative when fAddStresh is enabled.

Aig_ObjCreateGhost() orders an AND's operands by regular id, but that
happens after the fAddStrash block has run. That block tests p0's
grandchildren against p1 before testing p1's against p0, so where two of
its rules could both fire, the argument order decides which one wins:
Aig_And(p,a,b) and Aig_And(p,b,a) can return different nodes for the
same function.

Order the operands at the top of that block. Measured over 16000
ordered pairs of random gates with fAddStrash set, 126 returned
different nodes before this change and none do after. With fAddStrash
clear the block never runs and Aig_And is already commutative, which is
why the swap belongs inside it rather than ahead of it: ABC's default
configuration then pays nothing.

It does not cost nodes. On the same measurement the resulting AIGs are
slightly smaller in total -- 14517 AND nodes against 14627, about 0.75%
-- because equivalent requests now take the same path through the rules
and so land on the same node. On structured circuits it is neutral:
gen -N 20 -m and gen -N 24 -a give identical AND counts through
strash and dc2, and cec reports the results equivalent in both builds.

Note that this changes the AIG built for a given sequence of Aig_And
calls, and so anything derived from it, including CNF.
@TrevorHansen
TrevorHansen force-pushed the upstream-commutative-and branch from 265b8f1 to fce0338 Compare August 29, 2026 12:34
@TrevorHansen TrevorHansen closed this by deleting the head repository Aug 29, 2026
@TrevorHansen

Copy link
Copy Markdown
Author

I reopened this in #554 because I accidentally closed this by deleting the head repo.

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.

1 participant