-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
phar: use crc32 bulk method instead. Benefit from the hardware crc32 computing. Signed-off-by: Frank Du <frank.du@intel.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,24 +89,12 @@ static uint32_t crc32_aarch64(uint32_t crc, char *p, size_t nr) { | |
# endif | ||
#endif | ||
|
||
/* {{{ Calculate the crc32 polynomial of a string */ | ||
PHP_FUNCTION(crc32) | ||
uint32_t crc32_bulk_update(uint32_t crc, const char *p, size_t nr) | ||
{ | ||
char *p; | ||
size_t nr; | ||
uint32_t crcinit = 0; | ||
uint32_t crc; | ||
|
||
ZEND_PARSE_PARAMETERS_START(1, 1) | ||
Z_PARAM_STRING(p, nr) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
crc = crcinit^0xFFFFFFFF; | ||
|
||
#if HAVE_AARCH64_CRC32 | ||
if (has_crc32_insn()) { | ||
crc = crc32_aarch64(crc, p, nr); | ||
RETURN_LONG(crc^0xFFFFFFFF); | ||
return crc; | ||
} | ||
#endif | ||
|
||
|
@@ -116,9 +104,51 @@ PHP_FUNCTION(crc32) | |
p += nr_simd; | ||
#endif | ||
|
||
/* The trailing part */ | ||
for (; nr--; ++p) { | ||
crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*p)) & 0xFF ]; | ||
} | ||
|
||
return crc; | ||
} | ||
|
||
int crc32_stream_bulk_update(uint32_t *crc, php_stream *fp, size_t nr) | ||
{ | ||
size_t handled = 0, n; | ||
char buf[1024]; | ||
|
||
while (handled < nr) { | ||
n = nr - handled; | ||
n = (n < sizeof(buf)) ? n : sizeof(buf); /* tweak to buf size */ | ||
|
||
n = php_stream_read(fp, buf, n); | ||
if (n > 0) { | ||
*crc = crc32_bulk_update(*crc, buf, n); | ||
handled += n; | ||
} else { /* EOF */ | ||
return FAILURE; | ||
} | ||
} | ||
|
||
return SUCCESS; | ||
} | ||
|
||
/* {{{ Calculate the crc32 polynomial of a string */ | ||
PHP_FUNCTION(crc32) | ||
{ | ||
char *p; | ||
size_t nr; | ||
uint32_t crcinit = 0; | ||
uint32_t crc; | ||
|
||
ZEND_PARSE_PARAMETERS_START(1, 1) | ||
Z_PARAM_STRING(p, nr) | ||
ZEND_PARSE_PARAMETERS_END(); | ||
|
||
crc = crcinit^0xFFFFFFFF; | ||
|
||
crc = crc32_bulk_update(crc, p, nr); | ||
|
||
RETURN_LONG(crc^0xFFFFFFFF); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
weltling
Contributor
|
||
} | ||
/* }}} */ |
To be cleaner, especially as now public and used in other extension (at least phar), I think we need init / end function (macro ?)