ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/String-CRC32C/CRC32C.pm
Revision: 1.2
Committed: Tue Mar 25 09:57:48 2025 UTC (17 months, 3 weeks ago) by root
Branch: MAIN
Changes since 1.1: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.2 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 root 1.1 SlicingBy8 algorithm for anything else.
22    
23     =cut
24    
25     package String::CRC32C;
26    
27     BEGIN {
28     $VERSION = 0.01;
29     @ISA = qw(Exporter);
30     @EXPORT_OK = qw(crc32c);
31    
32     require XSLoader;
33     XSLoader::load String::CRC32C, $VERSION;
34     }
35    
36     use Exporter qw(import);
37    
38     =over
39    
40     =item $crc32c = crc32c $string[, $initvalue]
41    
42     Calculates the CRC32C value of the given C<$string> and returns it as a 32
43     bit unsigned integer.
44    
45     To get the common hex form, use one of:
46    
47     sprintf "%08x", crc32c $string
48     unpack "H*", pack "L>", crc32c $string
49    
50     A seed/initial crc value can be given as second argument. Note that both
51     the initial value and the result value are inverted (pre-inversion and
52     post-inversion), e.g. a common init value of C<-1> from other descriptions
53     needs to be given as C<0> (or C<~-1>).
54    
55     This allows easy chaining, e.g.
56    
57     (crc32c "abcdefghi") eq (crc32 "ghi", crc32 "def", crc32 "abc)
58    
59     =back
60    
61     =head1 AUTHOR
62    
63     Marc Lehmann <schmorp@schmorp.de>
64     http://home.schmorp.de/
65    
66     CRC32C code by various sources, ported from
67     https://github.com/htot/crc32c, see sources for details.
68    
69     =cut
70    
71     1
72