ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/String-CRC32C/CRC32C.xs
Revision: 1.4
Committed: Sun Mar 30 12:21:46 2025 UTC (17 months, 2 weeks ago) by root
Branch: MAIN
Changes since 1.3: +4 -0 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 root 1.4 #include "perlmulticore.h"
6    
7 root 1.1 // portable impl
8     #include "crc32csb8.c"
9    
10     static uint32_t (*crc32c) (uint32_t crc, const void *data, size_t length) = crc32cSlicingBy8;
11    
12     // optimized sse4.2 impl
13 root 1.2 #if __GNUC__ >= 8 && (__i386__ || __x86_64__) && __SSE4_2__ /* for __builtin__crc32 */
14 root 1.1
15     #include <cpuid.h>
16     #include "crc32intelc.c"
17    
18 root 1.3 static const char *
19 root 1.1 detect (void)
20     {
21 root 1.3 unsigned int eax, ebx, ecx = 0, edx;
22 root 1.1
23 root 1.3 __get_cpuid (1, &eax, &ebx, &ecx, &edx);
24 root 1.1
25     if (ecx & bit_SSE4_2)
26 root 1.3 {
27     crc32c = crc32cIntelC;
28     return "IntelCSSE42";
29     }
30    
31     return "SlicingBy8";
32 root 1.1 }
33    
34     #else
35    
36 root 1.3 static const char *
37 root 1.1 detect (void)
38     {
39 root 1.3 return "SlicingBy8";
40 root 1.1 }
41    
42     #endif
43    
44     MODULE = String::CRC32C PACKAGE = String::CRC32C
45    
46     BOOT:
47 root 1.3 sv_setpv (get_sv ("String::CRC32C::IMPL", GV_ADD), detect ());
48 root 1.1
49     PROTOTYPES: ENABLE
50    
51     U32 crc32c (SV *data, U32 initvalue = 0)
52     CODE:
53     {
54     STRLEN len;
55     const char *ptr = SvPVbyte (data, len);
56 root 1.4 if (len > 65536) perlinterp_release ();
57 root 1.1 RETVAL = ~crc32c (~initvalue, ptr, len);
58 root 1.4 if (len > 65536) perlinterp_acquire ();
59 root 1.1 }
60     OUTPUT: RETVAL
61    
62