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 (11 months, 1 week ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +23 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4
5 #include "perlmulticore.h"
6
7 /* 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 // 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 #if __GNUC__ >= 8 && (__i386__ || __x86_64__) && __SSE4_2__ /* for __builtin__crc32 */
37
38 #include <cpuid.h>
39 #include "crc32intelc.c"
40
41 static const char *
42 detect (void)
43 {
44 unsigned int eax, ebx, ecx = 0, edx;
45
46 __get_cpuid (1, &eax, &ebx, &ecx, &edx);
47
48 if (ecx & bit_SSE4_2)
49 {
50 crc32c = crc32cIntelC;
51 return "IntelCSSE42";
52 }
53
54 return "SlicingBy8";
55 }
56
57 #else
58
59 static const char *
60 detect (void)
61 {
62 return "SlicingBy8";
63 }
64
65 #endif
66
67 MODULE = String::CRC32C PACKAGE = String::CRC32C
68
69 BOOT:
70 perlmulticore_support ();
71 sv_setpv (get_sv ("String::CRC32C::IMPL", GV_ADD), detect ());
72
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 if (len > 65536) perlinterp_release ();
81 RETVAL = ~crc32c (~initvalue, ptr, len);
82 if (len > 65536) perlinterp_acquire ();
83 }
84 OUTPUT: RETVAL
85
86