| 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 |
|
|
static void |
| 17 |
|
|
detect (void) |
| 18 |
|
|
{ |
| 19 |
|
|
unsigned int eax, ebx = 0, ecx = 0, edx; |
| 20 |
|
|
|
| 21 |
|
|
if (__get_cpuid_max (0, 0) >= 1) |
| 22 |
|
|
__cpuid (1, eax, ebx, ecx, edx); |
| 23 |
|
|
|
| 24 |
|
|
if (ecx & bit_SSE4_2) |
| 25 |
|
|
crc32c = crc32cIntelC; |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
|
#else |
| 29 |
|
|
|
| 30 |
|
|
static void |
| 31 |
|
|
detect (void) |
| 32 |
|
|
{ |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
|
#endif |
| 36 |
|
|
|
| 37 |
|
|
MODULE = String::CRC32C PACKAGE = String::CRC32C |
| 38 |
|
|
|
| 39 |
|
|
BOOT: |
| 40 |
|
|
detect (); |
| 41 |
|
|
|
| 42 |
|
|
PROTOTYPES: ENABLE |
| 43 |
|
|
|
| 44 |
|
|
U32 crc32c (SV *data, U32 initvalue = 0) |
| 45 |
|
|
CODE: |
| 46 |
|
|
{ |
| 47 |
|
|
STRLEN len; |
| 48 |
|
|
const char *ptr = SvPVbyte (data, len); |
| 49 |
|
|
RETVAL = ~crc32c (~initvalue, ptr, len); |
| 50 |
|
|
} |
| 51 |
|
|
OUTPUT: RETVAL |
| 52 |
|
|
|
| 53 |
|
|
|