-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
write_aig
: Normalize symmetry in multiplication
#1833
Conversation
Unfortunately, this appears to cause the
I will mark this as a draft until I figure out why this happens. |
A smaller example of the issue, distilled from // bug.c
#include <stdint.h>
// returns the index of the first non-zero bit
uint32_t ffs_ref(uint32_t word) {
int i = 0;
if(!word)
return 0;
for(int cnt = 0; cnt < 32; cnt++)
if(((1 << i++) & word) != 0)
return i;
return 0; // notreached
}
uint32_t ffs_musl (uint32_t x)
{
static const char debruijn32[32] = {
0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14
};
return x ? debruijn32[(x&-x)*0x076be629 >> 27]+1 : 0;
}
With this patch, running
Most likely, this is due to the use of multiplication in the implementation of One possible solution would be to change the implementation of |
That didn't work. And indeed, the root of the issue is that Unfortunately, I'm not really sure what to do here, as this implies that the approach to normalizing multiplication, while beneficial for the particular test program in in #1828, is at odds with proving the two |
Oops, this was closed accidentally by #1835 misattributing the issue number. Reopening. |
For the sake of analyzing this outside of SAW, here is the
And after this patch: thm2_after.txt
|
I've pushed a new version of the PR that does not try to maximize the number full adders used in the AIGs that multiplication produces. We still achieve the end result of making |
This bumps the `aig` submodule to bring in the changes from GaloisInc/aig#14, which changes how `aig` performs multiplication to swap the order of arguments if the second argument is a constant. This has two benefits: * This ensures that `write_aig` will produce the same networks for `X * C` and `C * X`, where `C` is a constant and `X` is a variable. * The algorithm that `mul` uses to compute multiplication is biased in its order of arguments, and having the first argument be a constant tends to produce networks that ABC has an easier time verifying. (The FFS example under `doc/tutorial/code/ffs.c` is a notable example of this.) I have added a test case to check to see if the test case from #1828 now produces identical AIGs regardless of the order of arguments. Fixes #1828.
This bumps the
aig
submodule to bring in the changes from GaloisInc/aig#14, which changes howaig
performs multiplication to swap the order of arguments if the second argument is a constant. This has two benefits:write_aig
will produce the same networks forX * C
andC * X
, whereC
is a constant andX
is a variable.mul
uses to compute multiplication is biased in its order of arguments, and having the first argument be a constant tends to produce networks that ABC has an easier time verifying. (The FFS example underdoc/tutorial/code/ffs.c
is a notable example of this.)I have added a test case to check to see if the test case from #1828 now produces identical AIGs regardless of the order of arguments. Since this addresses many of the symptoms of #1788, I've also added a test case for #1788.
Fixes #1828.