mirror of
git://projects.qi-hardware.com/wernermisc.git
synced 2024-11-14 08:34:04 +02:00
bitcmp/bitcmp.c: added indication of direction of bit flip (1 -> 0 or 0 -> 1)
This commit is contained in:
parent
78d9fda12f
commit
dd0c4ec3f9
@ -43,9 +43,9 @@ int main(int argc, char *const *argv)
|
||||
const char *name1, *name2;
|
||||
uint8_t buf1[BUFFER], buf2[BUFFER];
|
||||
ssize_t got1, got2, len;
|
||||
uint32_t diff;
|
||||
uint32_t a, b;
|
||||
int i, j;
|
||||
static unsigned bin[32];
|
||||
static unsigned bin[32][2];
|
||||
|
||||
while ((c = getopt(argc, argv, "Blw")) != EOF) {
|
||||
switch (c) {
|
||||
@ -92,24 +92,28 @@ int main(int argc, char *const *argv)
|
||||
if (!len)
|
||||
break;
|
||||
for (i = 0; i < len; i += bytes) {
|
||||
diff = 0;
|
||||
a = b = 0;
|
||||
switch (bytes) {
|
||||
case 4:
|
||||
diff |= (buf1[i+2] ^ buf2[i+2]) << 16;
|
||||
diff |= (buf1[i+3] ^ buf2[i+3]) << 24;
|
||||
a |= buf1[i+2] << 16;
|
||||
b |= buf2[i+2] << 16;
|
||||
a |= buf1[i+3] << 24;
|
||||
b |= buf2[i+3] << 24;
|
||||
/* fall through */
|
||||
case 2:
|
||||
diff |= (buf1[i+1] ^ buf2[i+1]) << 8;
|
||||
a |= buf1[i+1] << 8;
|
||||
b |= buf2[i+1] << 8;
|
||||
/* fall through */
|
||||
case 1:
|
||||
diff |= buf1[i] ^ buf2[i];
|
||||
a |= buf1[i];
|
||||
b |= buf2[i];
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
for (j = 0; j != 32; j++)
|
||||
if (diff & (1 << j))
|
||||
bin[j]++;
|
||||
if ((a ^ b) & (1 << j))
|
||||
bin[j][(b >> j) & 1]++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,8 +122,8 @@ int main(int argc, char *const *argv)
|
||||
i = j;
|
||||
else
|
||||
i = 8*(bytes-1-(j >> 3))+(j & 7);
|
||||
if (bin[i])
|
||||
printf("%2d: %u\n", j, bin[i]);
|
||||
if (bin[i][0] || bin[i][1])
|
||||
printf("%2d: %u %u\n", j, bin[i][0], bin[i][1]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user