| 1 |
=head1 NAME |
| 2 |
|
| 3 |
Strihng::CRC32C - Castagnoli CRC |
| 4 |
|
| 5 |
=head1 SYNOPSIS |
| 6 |
|
| 7 |
use String::CRC32C; # does not export anything by default |
| 8 |
use String::CRC32C 'crc32c'; |
| 9 |
|
| 10 |
$crc = crc32 "some string"; |
| 11 |
$crc = crc32 "some string", $initvalue; |
| 12 |
|
| 13 |
=head1 DESCRIPTION |
| 14 |
|
| 15 |
This module calculates the Castagnoli CRC32 variant (polynomial 0x11EDC6F41). |
| 16 |
|
| 17 |
It is used by iSCSI, SCTP, BTRFS, ext4, leveldb, AMD64 CPUs and others. |
| 18 |
|
| 19 |
This module uses an optimized implementation for SSE 4.2 CPUs and the |
| 20 |
SlicingBy8 algorithm for anything else. |
| 21 |
|
| 22 |
=cut |
| 23 |
|
| 24 |
package String::CRC32C; |
| 25 |
|
| 26 |
BEGIN { |
| 27 |
$VERSION = 0.01; |
| 28 |
@ISA = qw(Exporter); |
| 29 |
@EXPORT_OK = qw(crc32c); |
| 30 |
|
| 31 |
require XSLoader; |
| 32 |
XSLoader::load String::CRC32C, $VERSION; |
| 33 |
} |
| 34 |
|
| 35 |
use Exporter qw(import); |
| 36 |
|
| 37 |
=over |
| 38 |
|
| 39 |
=item $crc32c = crc32c $string[, $initvalue] |
| 40 |
|
| 41 |
Calculates the CRC32C value of the given C<$string> and returns it as a 32 |
| 42 |
bit unsigned integer. |
| 43 |
|
| 44 |
To get the common hex form, use one of: |
| 45 |
|
| 46 |
sprintf "%08x", crc32c $string |
| 47 |
unpack "H*", pack "L>", crc32c $string |
| 48 |
|
| 49 |
A seed/initial crc value can be given as second argument. Note that both |
| 50 |
the initial value and the result value are inverted (pre-inversion and |
| 51 |
post-inversion), e.g. a common init value of C<-1> from other descriptions |
| 52 |
needs to be given as C<0> (or C<~-1>). |
| 53 |
|
| 54 |
This allows easy chaining, e.g. |
| 55 |
|
| 56 |
(crc32c "abcdefghi") eq (crc32 "ghi", crc32 "def", crc32 "abc) |
| 57 |
|
| 58 |
=back |
| 59 |
|
| 60 |
=head1 AUTHOR |
| 61 |
|
| 62 |
Marc Lehmann <schmorp@schmorp.de> |
| 63 |
http://home.schmorp.de/ |
| 64 |
|
| 65 |
CRC32C code by various sources, ported from |
| 66 |
https://github.com/htot/crc32c, see sources for details. |
| 67 |
|
| 68 |
=cut |
| 69 |
|
| 70 |
1 |
| 71 |
|