Skip to content

Commit

Permalink
explicitly call the simd routine
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Du <[email protected]>
  • Loading branch information
frankdjx committed Aug 29, 2020
1 parent 1402ac1 commit af9ba07
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 12 additions & 6 deletions ext/hash/hash_crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ PHP_HASH_API void PHP_CRC32Init(PHP_CRC32_CTX *context)

PHP_HASH_API void PHP_CRC32Update(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
{
size_t i;
size_t i = 0;

i = crc32_x86_simd_update(X86_CRC32, &context->state, input, len);
#if ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE || ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER
i += crc32_x86_simd_update(X86_CRC32, &context->state, input, len);
#endif

for (; i < len; ++i) {
context->state = (context->state << 8) ^ crc32_table[(context->state >> 24) ^ (input[i] & 0xff)];
Expand All @@ -38,9 +40,11 @@ PHP_HASH_API void PHP_CRC32Update(PHP_CRC32_CTX *context, const unsigned char *i

PHP_HASH_API void PHP_CRC32BUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
{
size_t i;
size_t i = 0;

i = crc32_x86_simd_update(X86_CRC32B, &context->state, input, len);
#if ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE || ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER
i += crc32_x86_simd_update(X86_CRC32B, &context->state, input, len);
#endif

for (; i < len; ++i) {
context->state = (context->state >> 8) ^ crc32b_table[(context->state ^ input[i]) & 0xff];
Expand All @@ -49,9 +53,11 @@ PHP_HASH_API void PHP_CRC32BUpdate(PHP_CRC32_CTX *context, const unsigned char *

PHP_HASH_API void PHP_CRC32CUpdate(PHP_CRC32_CTX *context, const unsigned char *input, size_t len)
{
size_t i;
size_t i = 0;

i = crc32_x86_simd_update(X86_CRC32C, &context->state, input, len);
#if ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE || ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER
i += crc32_x86_simd_update(X86_CRC32C, &context->state, input, len);
#endif

for (; i < len; ++i) {
context->state = (context->state >> 8) ^ crc32c_table[(context->state ^ input[i]) & 0xff];
Expand Down
6 changes: 4 additions & 2 deletions ext/standard/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static uint32_t crc32_aarch64(uint32_t crc, char *p, size_t nr) {
PHP_FUNCTION(crc32)
{
char *p;
size_t nr, nr_simd;
size_t nr;
uint32_t crcinit = 0;
uint32_t crc;

Expand All @@ -90,9 +90,11 @@ PHP_FUNCTION(crc32)
}
#endif

nr_simd = crc32_x86_simd_update(X86_CRC32B, &crc, (const unsigned char *)p, nr);
#if ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE || ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER
size_t nr_simd = crc32_x86_simd_update(X86_CRC32B, &crc, (const unsigned char *)p, nr);
nr -= nr_simd;
p += nr_simd;
#endif

for (; nr--; ++p) {
crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*p)) & 0xFF ];
Expand Down

0 comments on commit af9ba07

Please sign in to comment.