| 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.5 |
perlmulticore_support (); |
| 48 |
root |
1.3 |
sv_setpv (get_sv ("String::CRC32C::IMPL", GV_ADD), detect ()); |
| 49 |
root |
1.1 |
|
| 50 |
|
|
PROTOTYPES: ENABLE |
| 51 |
|
|
|
| 52 |
|
|
U32 crc32c (SV *data, U32 initvalue = 0) |
| 53 |
|
|
CODE: |
| 54 |
|
|
{ |
| 55 |
|
|
STRLEN len; |
| 56 |
|
|
const char *ptr = SvPVbyte (data, len); |
| 57 |
root |
1.4 |
if (len > 65536) perlinterp_release (); |
| 58 |
root |
1.1 |
RETVAL = ~crc32c (~initvalue, ptr, len); |
| 59 |
root |
1.4 |
if (len > 65536) perlinterp_acquire (); |
| 60 |
root |
1.1 |
} |
| 61 |
|
|
OUTPUT: RETVAL |
| 62 |
|
|
|
| 63 |
|
|
|