| 1 |
=head1 NAME |
| 2 |
|
| 3 |
String::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, x86 CPUs and others. |
| 18 |
|
| 19 |
This module uses an optimized implementation for SSE 4.2 targets (GCC |
| 20 |
and compatible supported, SSE 4.2 must be enabled in your Perl) and the |
| 21 |
SlicingBy8 algorithm for anything else. |
| 22 |
|
| 23 |
=cut |
| 24 |
|
| 25 |
package String::CRC32C; |
| 26 |
|
| 27 |
our $IMPL; |
| 28 |
|
| 29 |
BEGIN { |
| 30 |
$VERSION = '1.0'; |
| 31 |
@ISA = qw(Exporter); |
| 32 |
@EXPORT_OK = qw(crc32c); |
| 33 |
|
| 34 |
require XSLoader; |
| 35 |
XSLoader::load String::CRC32C, $VERSION; |
| 36 |
} |
| 37 |
|
| 38 |
use Exporter qw(import); |
| 39 |
|
| 40 |
=over |
| 41 |
|
| 42 |
=item $crc32c = crc32c $string[, $initvalue] |
| 43 |
|
| 44 |
Calculates the CRC32C value of the given C<$string> and returns it as a 32 |
| 45 |
bit unsigned integer. |
| 46 |
|
| 47 |
To get the common hex form, use one of: |
| 48 |
|
| 49 |
sprintf "%08x", crc32c $string |
| 50 |
unpack "H*", pack "L>", crc32c $string |
| 51 |
|
| 52 |
A seed/initial crc value can be given as second argument. Note that both |
| 53 |
the initial value and the result value are inverted (pre-inversion and |
| 54 |
post-inversion), e.g. a common init value of C<-1> from other descriptions |
| 55 |
needs to be given as C<0> (or C<~-1>). |
| 56 |
|
| 57 |
This allows easy chaining, e.g. |
| 58 |
|
| 59 |
(crc32c "abcdefghi") eq (crc32 "ghi", crc32 "def", crc32 "abc") |
| 60 |
|
| 61 |
=item $String::CRC32C::IMPL |
| 62 |
|
| 63 |
Contains a string indicating the implementation that will be used. Currently either C<SlicingBy8> |
| 64 |
for the portable implementation or C<IntelCSSE42> for the SSE 4.2 optimized intel version. |
| 65 |
|
| 66 |
=back |
| 67 |
|
| 68 |
=head1 PERLMULTICORE SUPPORT |
| 69 |
|
| 70 |
This module supports the perl multicore spoecification |
| 71 |
(L<http://perlmulticore.schmorp.de/>): the C<crc32c> function will |
| 72 |
relinquish the current thread for crc32c lengths larger than 64k (the |
| 73 |
break-even point on my machine is around 128k), so multiprocessing makes |
| 74 |
only sense for very long blocks. |
| 75 |
|
| 76 |
=head1 AUTHOR |
| 77 |
|
| 78 |
Marc Lehmann <schmorp@schmorp.de> |
| 79 |
http://home.schmorp.de/ |
| 80 |
|
| 81 |
CRC32C code by various sources, ported from |
| 82 |
https://github.com/htot/crc32c, see sources for details. |
| 83 |
|
| 84 |
=cut |
| 85 |
|
| 86 |
1 |
| 87 |
|