ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/String-CRC32C/CRC32C.xs
Revision: 1.6
Committed: Mon Mar 31 00:37:42 2025 UTC (17 months, 2 weeks ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +23 -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.6 /* windows perl pisses me off. 26 years since c99, and still we have broken headers */
8     /* this has been copied from libecb */
9     #if defined (_WIN32) && !defined (__MINGW32__)
10     typedef signed short uint16_t;
11     typedef signed int int32_t;
12     typedef unsigned int uint32_t;
13     #if __GNUC__
14     typedef unsigned long long uint64_t;
15     #else /* _MSC_VER || __BORLANDC__ */
16     typedef unsigned __int64 uint64_t;
17     #endif
18     typedef unsigned long long uint64_t;
19     #ifdef _WIN64
20     typedef uint64_t uintptr_t;
21     typedef int64_t intptr_t;
22     #else
23     typedef uint32_t uintptr_t;
24     typedef int32_t intptr_t;
25     #endif
26     #else
27     #include <inttypes.h>
28     #endif
29    
30 root 1.1 // portable impl
31     #include "crc32csb8.c"
32    
33     static uint32_t (*crc32c) (uint32_t crc, const void *data, size_t length) = crc32cSlicingBy8;
34    
35     // optimized sse4.2 impl
36 root 1.2 #if __GNUC__ >= 8 && (__i386__ || __x86_64__) && __SSE4_2__ /* for __builtin__crc32 */
37 root 1.1
38     #include <cpuid.h>
39     #include "crc32intelc.c"
40    
41 root 1.3 static const char *
42 root 1.1 detect (void)
43     {
44 root 1.3 unsigned int eax, ebx, ecx = 0, edx;
45 root 1.1
46 root 1.3 __get_cpuid (1, &eax, &ebx, &ecx, &edx);
47 root 1.1
48     if (ecx & bit_SSE4_2)
49 root 1.3 {
50     crc32c = crc32cIntelC;
51     return "IntelCSSE42";
52     }
53    
54     return "SlicingBy8";
55 root 1.1 }
56    
57     #else
58    
59 root 1.3 static const char *
60 root 1.1 detect (void)
61     {
62 root 1.3 return "SlicingBy8";
63 root 1.1 }
64    
65     #endif
66    
67     MODULE = String::CRC32C PACKAGE = String::CRC32C
68    
69     BOOT:
70 root 1.5 perlmulticore_support ();
71 root 1.3 sv_setpv (get_sv ("String::CRC32C::IMPL", GV_ADD), detect ());
72 root 1.1
73     PROTOTYPES: ENABLE
74    
75     U32 crc32c (SV *data, U32 initvalue = 0)
76     CODE:
77     {
78     STRLEN len;
79     const char *ptr = SvPVbyte (data, len);
80 root 1.4 if (len > 65536) perlinterp_release ();
81 root 1.1 RETVAL = ~crc32c (~initvalue, ptr, len);
82 root 1.4 if (len > 65536) perlinterp_acquire ();
83 root 1.1 }
84     OUTPUT: RETVAL
85    
86