pike.git
/
src
/
post_modules
/
Nettle
/
nettle.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/post_modules/Nettle/nettle.cmod:456:
magic->len, magic->str); } push_text(hash); } #ifdef HAVE_CRC32_INTRINSICS static int supports_sse42 = 0; static ATTRIBUTE((target("sse4")))
-
unsigned int intel_crc32c(const unsigned int *p, size_t len)
+
unsigned int intel_crc32c(const unsigned int *p, size_t len
,
+
unsigned int h
)
{
-
unsigned int h=0xffffffff;
+
const unsigned int *e = p + (len>>2); const unsigned char *c = (const unsigned char*)e;
-
+
h = ~h;
/* .. all full integers .. */ while( p<e ) h = __builtin_ia32_crc32si(h, *(p++)); len &= 3; /* any remaining bytes. */ while( len-- ) h = __builtin_ia32_crc32qi(h, *(c++));
-
return h
^ 0xffffffff
;
+
return
~
h;
} #endif /* HAVE_CRC32_INTRINSICS */ /* Copyright 2001, D. Otis. Use this program, code or tables */ /* extracted from it, as desired without restriction. */ static const INT32 crc[256] = { 0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB, 0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,
pike.git/src/post_modules/Nettle/nettle.cmod:545:
0xE330A81A, 0x115B2B19, 0x020BD8ED, 0xF0605BEE, 0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1, 0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321, 0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E, 0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E, 0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351, };
-
/*! @decl int(0..) crc32c(string(8bit) data)
+
/*! @decl int(0..) crc32c(string(8bit) data
, void|int seed
)
*! Implements the Castagnoli CRC, CRC32C. Hardware optimized on Intel *! CPUs with SSE 4.2.
-
+
*!
+
*! @param seed
+
*! Can be fed with the result of the previous invocation to chain on new data.
+
*! Defaults to zero on virgin runs.
*/
-
PIKEFUN int(0..) crc32c(string(8bit) data)
+
PIKEFUN int(0..) crc32c(string(8bit) data
, void|int seed
)
{
-
+
unsigned int h = 0;
+
if(seed) {
+
if (TYPEOF(*seed) != PIKE_T_INT)
+
Pike_error("Bad argument type.\n");
+
h = seed->u.integer;
+
}
#ifdef HAVE_CRC32_INTRINSICS if(supports_sse42) {
-
push_int64(intel_crc32c((const unsigned int *)data->str, data->len));
+
push_int64(intel_crc32c((const unsigned int *)data->str, data->len
, h
));
} else #endif /* HAVE_CRC32_INTRISINCS */ {
-
unsigned int
h
=
0xffffffff
,
i
=
0
;
-
for(; i<
data->
len; i++)
+
unsigned int
i
=
0
,
len
=
data->len
;
+
for(
h = ~h
; i<len; i++)
h = (h>>8)^crc[(h^data->str[i])&0xFF];
-
push_int64(h
^ 0xffffffff
);
+
push_int64(
~
h);
} } /*! @endmodule */ #endif /* HAVE_LIBNETTLE */ PIKE_MODULE_INIT {