ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/String-CRC32C/CRC32C.xs
Revision: 1.3
Committed: Wed Mar 26 23:54:56 2025 UTC (17 months, 2 weeks ago) by root
Branch: MAIN
Changes since 1.2: +12 -7 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include "EXTERN.h"
2     #include "perl.h"
3     #include "XSUB.h"
4    
5     // portable impl
6     #include "crc32csb8.c"
7    
8     static uint32_t (*crc32c) (uint32_t crc, const void *data, size_t length) = crc32cSlicingBy8;
9    
10     // optimized sse4.2 impl
11 root 1.2 #if __GNUC__ >= 8 && (__i386__ || __x86_64__) && __SSE4_2__ /* for __builtin__crc32 */
12 root 1.1
13     #include <cpuid.h>
14     #include "crc32intelc.c"
15    
16 root 1.3 static const char *
17 root 1.1 detect (void)
18     {
19 root 1.3 unsigned int eax, ebx, ecx = 0, edx;
20 root 1.1
21 root 1.3 __get_cpuid (1, &eax, &ebx, &ecx, &edx);
22 root 1.1
23     if (ecx & bit_SSE4_2)
24 root 1.3 {
25     crc32c = crc32cIntelC;
26     return "IntelCSSE42";
27     }
28    
29     return "SlicingBy8";
30 root 1.1 }
31    
32     #else
33    
34 root 1.3 static const char *
35 root 1.1 detect (void)
36     {
37 root 1.3 return "SlicingBy8";
38 root 1.1 }
39    
40     #endif
41    
42     MODULE = String::CRC32C PACKAGE = String::CRC32C
43    
44     BOOT:
45 root 1.3 sv_setpv (get_sv ("String::CRC32C::IMPL", GV_ADD), detect ());
46 root 1.1
47     PROTOTYPES: ENABLE
48    
49     U32 crc32c (SV *data, U32 initvalue = 0)
50     CODE:
51     {
52     STRLEN len;
53     const char *ptr = SvPVbyte (data, len);
54     RETVAL = ~crc32c (~initvalue, ptr, len);
55     }
56     OUTPUT: RETVAL
57    
58