Skip to content

Commit 9b81ce0

Browse files
committed
Add build support for PCLMUL
Signed-off-by: Frank Du <[email protected]>
1 parent fb76210 commit 9b81ce0

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

Zend/zend_cpuinfo.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ static zend_always_inline int zend_cpu_supports_sse42() {
159159
return __builtin_cpu_supports("sse4.2");
160160
}
161161

162+
ZEND_NO_SANITIZE_ADDRESS
163+
static zend_always_inline int zend_cpu_supports_pclmul() {
164+
#if PHP_HAVE_BUILTIN_CPU_INIT
165+
__builtin_cpu_init();
166+
#endif
167+
return __builtin_cpu_supports("pclmul");
168+
}
169+
162170
ZEND_NO_SANITIZE_ADDRESS
163171
static zend_always_inline int zend_cpu_supports_avx() {
164172
#if PHP_HAVE_BUILTIN_CPU_INIT
@@ -196,6 +204,10 @@ static zend_always_inline int zend_cpu_supports_sse42() {
196204
return zend_cpu_supports(ZEND_CPU_FEATURE_SSE42);
197205
}
198206

207+
static zend_always_inline int zend_cpu_supports_pclmul() {
208+
return zend_cpu_supports(ZEND_CPU_FEATURE_PCLMULQDQ);
209+
}
210+
199211
static zend_always_inline int zend_cpu_supports_avx() {
200212
return zend_cpu_supports(ZEND_CPU_FEATURE_AVX);
201213
}

Zend/zend_portability.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ extern "C++" {
486486
# define PHP_HAVE_SSE4_2
487487
# endif
488488

489+
# if defined(HAVE_WMMINTRIN_H)
490+
# define PHP_HAVE_PCLMUL
491+
# endif
492+
489493
/*
490494
* AVX2 support was added in gcc 4.7, but AVX2 intrinsics don't work in
491495
* __attribute__((target("avx2"))) functions until gcc 4.9.
@@ -546,6 +550,56 @@ extern "C++" {
546550
# define ZEND_INTRIN_SSE4_2_FUNC_DECL(func)
547551
#endif
548552

553+
#ifdef __PCLMUL__
554+
/* Instructions compiled directly. */
555+
# define ZEND_INTRIN_PCLMUL_NATIVE 1
556+
#elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_PCLMUL)) || defined(ZEND_WIN32)
557+
/* Function resolved by ifunc or MINIT. */
558+
# define ZEND_INTRIN_PCLMUL_RESOLVER 1
559+
#endif
560+
561+
/* Do not use for conditional declaration of API functions! */
562+
#if defined(ZEND_INTRIN_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET)
563+
# define ZEND_INTRIN_PCLMUL_FUNC_PROTO 1
564+
#elif defined(ZEND_INTRIN_PCLMUL_RESOLVER)
565+
# define ZEND_INTRIN_PCLMUL_FUNC_PTR 1
566+
#endif
567+
568+
#ifdef ZEND_INTRIN_PCLMUL_RESOLVER
569+
# ifdef HAVE_FUNC_ATTRIBUTE_TARGET
570+
# define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) ZEND_API func __attribute__((target("pclmul")))
571+
# else
572+
# define ZEND_INTRIN_PCLMUL_FUNC_DECL(func) func
573+
# endif
574+
#else
575+
# define ZEND_INTRIN_PCLMUL_FUNC_DECL(func)
576+
#endif
577+
578+
#if defined(ZEND_INTRIN_SSE4_2_NATIVE) && defined(ZEND_INTRIN_PCLMUL_NATIVE)
579+
/* Instructions compiled directly. */
580+
# define ZEND_INTRIN_SSE4_2_PCLMUL_NATIVE 1
581+
#elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSE4_2) && defined(PHP_HAVE_PCLMUL)) || defined(ZEND_WIN32)
582+
/* Function resolved by ifunc or MINIT. */
583+
# define ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER 1
584+
#endif
585+
586+
/* Do not use for conditional declaration of API functions! */
587+
#if defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER) && defined(ZEND_INTRIN_HAVE_IFUNC_TARGET)
588+
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PROTO 1
589+
#elif defined(ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER)
590+
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_PTR 1
591+
#endif
592+
593+
#ifdef ZEND_INTRIN_SSE4_2_PCLMUL_RESOLVER
594+
# ifdef HAVE_FUNC_ATTRIBUTE_TARGET
595+
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) ZEND_API func __attribute__((target("sse4.2,pclmul")))
596+
# else
597+
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func) func
598+
# endif
599+
#else
600+
# define ZEND_INTRIN_SSE4_2_PCLMUL_FUNC_DECL(func)
601+
#endif
602+
549603
#ifdef __AVX2__
550604
# define ZEND_INTRIN_AVX2_NATIVE 1
551605
#elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_AVX2)) || defined(ZEND_WIN32)

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ sys/ipc.h \
409409
dlfcn.h \
410410
tmmintrin.h \
411411
nmmintrin.h \
412+
wmmintrin.h \
412413
immintrin.h
413414
],[],[],[
414415
#ifdef HAVE_SYS_PARAM_H

0 commit comments

Comments
 (0)