Skip to content

Commit

Permalink
Fix build for old gcc.
Browse files Browse the repository at this point in the history
Only enable ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO for gcc9 later,
__builtin_cpu_supports support pclmul later.

Also use _mm_move_epi64 instead.

Signed-off-by: Frank Du <[email protected]>
  • Loading branch information
frankdjx committed Aug 20, 2020
1 parent 1b3319a commit 3d42d38
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Zend/zend_cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,16 @@ static zend_always_inline int zend_cpu_supports_sse42() {
return __builtin_cpu_supports("sse4.2");
}

/* __builtin_cpu_supports has pclmul from GCC9 */
#if (ZEND_GCC_VERSION >= 9000)
ZEND_NO_SANITIZE_ADDRESS
static zend_always_inline int zend_cpu_supports_pclmul() {
#if PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("pclmul");
}
#endif

ZEND_NO_SANITIZE_ADDRESS
static zend_always_inline int zend_cpu_supports_avx() {
Expand Down
6 changes: 4 additions & 2 deletions Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ extern "C++" {
#endif

/* Do not use for conditional declaration of API functions! */
#if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET)
#if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (ZEND_GCC_VERSION >= 9000)
# define ZEND_INTRIN_PCLMUL_FUNC_PROTO 1
#elif defined(ZEND_INTRIN_PCLMUL_RESOLVER)
# define ZEND_INTRIN_PCLMUL_FUNC_PTR 1
Expand All @@ -584,7 +584,8 @@ extern "C++" {
#endif

/* Do not use for conditional declaration of API functions! */
#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET)
#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET) && (ZEND_GCC_VERSION >= 9000)
/* __builtin_cpu_supports has pclmul from GCC9 */
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO 1
#elif defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PTR 1
Expand All @@ -608,6 +609,7 @@ extern "C++" {

/* Do not use for conditional declaration of API functions! */
#if defined(ZEND_INTRIN_AVX2_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET)
/* __builtin_cpu_supports has pclmul from GCC9 */
# define ZEND_INTRIN_AVX2_FUNC_PROTO 1
#elif defined(ZEND_INTRIN_AVX2_RESOLVER)
# define ZEND_INTRIN_AVX2_FUNC_PTR 1
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/crc32_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ size_t crc32_pclmul_batch(uint32_t *crc, const unsigned char *p, size_t nr, cons

/* barrett reduction */
k = _mm_loadu_si128((__m128i*)consts->uPx);
x1 = _mm_loadu_si64(&x0);
x1 = _mm_move_epi64(x0);
x1 = _mm_srli_si128(x1, 4);
x1 = _mm_clmulepi64_si128(x1, k, 0x00);
x1 = _mm_srli_si128(x1, 4);
Expand Down

0 comments on commit 3d42d38

Please sign in to comment.