Subject: | Fix a few issues with CRC.xs |
0) crc2.pl is a (silly) test that uses several methods to compute
identical CRC32 checksums. It uses the convenience wrappers I suggested
in buh #70672.
Output currently is:
crc8 : 244
crc8 : 244
crc8i : 4
crc8i : 179
crc8o : 0
crc8o : 0
crc8r : 32
crc8r : 32
crcccitt : 10673
crcccitt : 10673
crcccitti: 35318
crcccitti: 45368
crcccitto: 0
crcccitto: 0
crcccittr: 28561
crcccittr: 28561
crc16n : 65256
crc16n : 65256
crc16i : 48349
crc16i : 25117
crc16o : 0
crc16o : 0
crc16 : 47933
crc16 : 47933
crc32n : 4236843288
crc32n : 4236843288
crc32i : 1687957459
crc32i : 3600338594
crc32o : 4294967295
crc32o : 4294967295
crc32 : 3421780262
crc32 : 3421780262
crc64 : 5090661014116757502
crc64 : 5090661014116757502
testn : 339470139
testn : 339470139
testi : 2351878640
testi : 2930071031
testo : 4294967295
testo : 4294967295
testr : 260797489
testr : 260797489
(The n, i, o and r suffixes mean no reflect, in reflect, out reflect and
reflect twice.)
Note that out reflect is broken and in reflect is broken in two step mode.
1) refin_refout.patch adds the few fixes needed to address these issues
in CRC.xs. Feel free to ask to to break down what they do individually.
Boring output using this patch:
crc8 : 244
crc8 : 244
crc8i : 4
crc8i : 4
crc8o : 47
crc8o : 47
crc8r : 32
crc8r : 32
crcccitt : 10673
crcccitt : 10673
crcccitti: 35318
crcccitti: 35318
crcccitto: 36244
crcccitto: 36244
crcccittr: 28561
crcccittr: 28561
crc16n : 65256
crc16n : 65256
crc16i : 48349
crc16i : 48349
crc16o : 6015
crc16o : 6015
crc16 : 47933
crc16 : 47933
crc32n : 4236843288
crc32n : 4236843288
crc32i : 1687957459
crc32i : 1687957459
crc32o : 412651839
crc32o : 412651839
crc32 : 3421780262
crc32 : 3421780262
crc64 : 5090661014116757502
crc64 : 5090661014116757502
testn : 339470139
testn : 339470139
testi : 2351878640
testi : 2351878640
testo : 3706182696
testo : 3706182696
testr : 260797489
testr : 260797489
(Note that I cross checked these checksums using the crcmodel.[ch]
reference code.)
2) If (something like) this patch is acceptable, I might be tempted to:
- fix the non-xs code too. (How does one trigger the usage of that code?);
- make sure the documentation is updated (ie, inludes some recent
enhancements).
Subject: | crc2.pl |
#! /usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Digest::CRC 0.17 qw( crc crc8 crcccitt crc16 crc32 crc64 );
my $in0 = "12345";
my $in1 = "6789";
my $out;
$out = crc8( $in0 . $in1);
printf "crc8 : %u\n", $out;
$out = crc8( $in0 );
$out = crc8( $in1, $out );
printf "crc8 : %u\n", $out;
$out = crc( $in0 . $in1, 8, 0x00, 0x00, 0, 0x7, 1, 0 );
printf "crc8i : %u\n", $out;
$out = crc( $in0 , 8, 0x00, 0x00, 0, 0x7, 1, 0 );
$out = crc( $in1 , 8, $out, 0x00, 0, 0x7, 1, 1 );
printf "crc8i : %u\n", $out;
$out = crc( $in0 . $in1, 8, 0x00, 0x00, 1, 0x7, 0, 0 );
printf "crc8o : %u\n", $out;
$out = crc( $in0 , 8, 0x00, 0x00, 1, 0x7, 0, 0 );
$out = crc( $in1 , 8, $out, 0x00, 1, 0x7, 0, 1 );
printf "crc8o : %u\n", $out;
$out = crc( $in0 . $in1, 8, 0x00, 0x00, 1, 0x7, 1, 0 );
printf "crc8r : %u\n", $out;
$out = crc( $in0 , 8, 0x00, 0x00, 1, 0x7, 1, 0 );
$out = crc( $in1 , 8, $out, 0x00, 1, 0x7, 1, 1 );
printf "crc8r : %u\n", $out;
$out = crcccitt( $in0 . $in1);
printf "crcccitt : %u\n", $out;
$out = crcccitt( $in0 );
$out = crcccitt( $in1, $out );
printf "crcccitt : %u\n", $out;
$out = crc( $in0 . $in1, 16, 0xFFFF, 0x0000, 0, 0x1021, 1, 0);
printf "crcccitti: %u\n", $out;
$out = crc( $in0 , 16, 0xFFFF, 0x0000, 0, 0x1021, 1, 0);
$out = crc( $in1 , 16, $out , 0x0000, 0, 0x1021, 1, 1);
printf "crcccitti: %u\n", $out;
$out = crc( $in0 . $in1, 16, 0xFFFF, 0x0000, 1, 0x1021, 0, 0);
printf "crcccitto: %u\n", $out;
$out = crc( $in0 , 16, 0xFFFF, 0x0000, 1, 0x1021, 0, 0);
$out = crc( $in1 , 16, $out , 0x0000, 1, 0x1021, 0, 1);
printf "crcccitto: %u\n", $out;
$out = crc( $in0 . $in1, 16, 0xFFFF, 0x0000, 1, 0x1021, 1, 0);
printf "crcccittr: %u\n", $out;
$out = crc( $in0 , 16, 0xFFFF, 0x0000, 1, 0x1021, 1, 0);
$out = crc( $in1 , 16, $out , 0x0000, 1, 0x1021, 1, 1);
printf "crcccittr: %u\n", $out;
$out = crc( $in0 . $in1, 16, 0x0000, 0x0000, 0, 0x8005, 0, 0);
printf "crc16n : %u\n", $out;
$out = crc( $in0 , 16, 0x0000, 0x0000, 0, 0x8005, 0, 0);
$out = crc( $in1 , 16, $out , 0x0000, 0, 0x8005, 0, 1);
printf "crc16n : %u\n", $out;
$out = crc( $in0 . $in1, 16, 0x0000, 0x0000, 0, 0x8005, 1, 0);
printf "crc16i : %u\n", $out;
$out = crc( $in0 , 16, 0x0000, 0x0000, 0, 0x8005, 1, 0);
$out = crc( $in1 , 16, $out , 0x0000, 0, 0x8005, 1, 1);
printf "crc16i : %u\n", $out;
$out = crc( $in0 . $in1, 16, 0x0000, 0x0000, 1, 0x8005, 0, 0);
printf "crc16o : %u\n", $out;
$out = crc( $in0 , 16, 0x0000, 0x0000, 1, 0x8005, 0, 0);
$out = crc( $in1 , 16, $out , 0x0000, 1, 0x8005, 0, 1);
printf "crc16o : %u\n", $out;
$out = crc16( $in0 . $in1);
printf "crc16 : %u\n", $out;
$out = crc16( $in0 );
$out = crc16( $in1, $out );
printf "crc16 : %u\n", $out;
$out = crc( $in0 . $in1, 32, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0x04C11DB7, 0, 0);
printf "crc32n : %u\n", $out;
$out = crc( $in0 , 32, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0x04C11DB7, 0, 0);
$out = crc( $in1 , 32, $out , 0xFFFFFFFF, 0, 0x04C11DB7, 0, 1);
printf "crc32n : %u\n", $out;
$out = crc( $in0 . $in1, 32, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0x04C11DB7, 1, 0);
printf "crc32i : %u\n", $out;
$out = crc( $in0 , 32, 0xFFFFFFFF, 0xFFFFFFFF, 0, 0x04C11DB7, 1, 0);
$out = crc( $in1 , 32, $out , 0xFFFFFFFF, 0, 0x04C11DB7, 1, 1);
printf "crc32i : %u\n", $out;
$out = crc( $in0 . $in1, 32, 0xFFFFFFFF, 0xFFFFFFFF, 1, 0x04C11DB7, 0, 0);
printf "crc32o : %u\n", $out;
$out = crc( $in0 , 32, 0xFFFFFFFF, 0xFFFFFFFF, 1, 0x04C11DB7, 0, 0);
$out = crc( $in1 , 32, $out , 0xFFFFFFFF, 1, 0x04C11DB7, 0, 1);
printf "crc32o : %u\n", $out;
$out = crc32( $in0 . $in1);
printf "crc32 : %u\n", $out;
$out = crc32( $in0 );
$out = crc32( $in1, $out );
printf "crc32 : %u\n", $out;
$out = crc64( $in0 . $in1);
printf "crc64 : %u\n", $out;
$out = crc64( $in0 );
$out = crc64( $in1, $out );
printf "crc64 : %u\n", $out;
$out = crc( $in0 . $in1, 32, 0x12345678, 0xFFFFFFFF, 0, 0x04C11DB7, 0, 0);
printf "testn : %u\n", $out;
$out = crc( $in0 , 32, 0x12345678, 0xFFFFFFFF, 0, 0x04C11DB7, 0, 0);
$out = crc( $in1 , 32, $out , 0xFFFFFFFF, 0, 0x04C11DB7, 0, 1);
printf "testn : %u\n", $out;
$out = crc( $in0 . $in1, 32, 0x12345678, 0xFFFFFFFF, 0, 0x04C11DB7, 1, 0);
printf "testi : %u\n", $out;
$out = crc( $in0 , 32, 0x12345678, 0xFFFFFFFF, 0, 0x04C11DB7, 1, 0);
$out = crc( $in1 , 32, $out , 0xFFFFFFFF, 0, 0x04C11DB7, 1, 1);
printf "testi : %u\n", $out;
$out = crc( $in0 . $in1, 32, 0x12345678, 0xFFFFFFFF, 1, 0x04C11DB7, 0, 0);
printf "testo : %u\n", $out;
$out = crc( $in0 , 32, 0x12345678, 0xFFFFFFFF, 1, 0x04C11DB7, 0, 0);
$out = crc( $in1 , 32, $out , 0xFFFFFFFF, 1, 0x04C11DB7, 0, 1);
printf "testo : %u\n", $out;
$out = crc( $in0 . $in1, 32, 0x12345678, 0xFFFFFFFF, 1, 0x04C11DB7, 1, 0);
printf "testr : %u\n", $out;
$out = crc( $in0 , 32, 0x12345678, 0xFFFFFFFF, 1, 0x04C11DB7, 1, 0);
$out = crc( $in1 , 32, $out , 0xFFFFFFFF, 1, 0x04C11DB7, 1, 1);
printf "testr : %u\n", $out;