Skip to content

Autotools: Refactor builtin checks #14835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
AX_CHECK_COMPILE_FLAG).
- M4 macro PHP_PROG_RE2C got a new 2nd argument to define common default re2c
command-line options substituted to the Makefile RE2C_FLAGS variable.
- M4 macros PHP_CHECK_BUILTIN_* have been removed in favor of
PHP_CHECK_BUILTIN and all PHP_HAVE_BUILTIN_* symbols changed to be either
undefined or defined to 1 whether compiler supports the builtin.
- Added php-config --lib-dir and --lib-embed options for PHP embed SAPI.
- PDO extensions in php-src don't have the include flag -I$pdo_cv_inc_path
directory anymore.
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_call_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ZEND_API bool zend_call_stack_get(zend_call_stack *stack);
static zend_always_inline void *zend_call_stack_position(void) {
#ifdef ZEND_WIN32
return _AddressOfReturnAddress();
#elif PHP_HAVE_BUILTIN_FRAME_ADDRESS
#elif defined(PHP_HAVE_BUILTIN_FRAME_ADDRESS)
return __builtin_frame_address(0);
#else
void *a;
Expand Down
28 changes: 14 additions & 14 deletions Zend/zend_cpuinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,63 +118,63 @@ ZEND_API int zend_cpu_supports(zend_cpu_feature feature);
# define ZEND_NO_SANITIZE_ADDRESS
#endif

#if PHP_HAVE_BUILTIN_CPU_SUPPORTS
#ifdef PHP_HAVE_BUILTIN_CPU_SUPPORTS
/* NOTE: you should use following inline function in
* resolver functions (ifunc), as it could be called
* before all PLT symbols are resolved. in other words,
* resolver functions should not depend on any external
* functions */
ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_sse2(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("sse2");
}

ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_sse3(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("sse3");
}

ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_ssse3(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("ssse3");
}

ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_sse41(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("sse4.1");
}

ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_sse42(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("sse4.2");
}

ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_avx(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("avx");
}

ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_avx2(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("avx2");
Expand All @@ -183,7 +183,7 @@ static inline int zend_cpu_supports_avx2(void) {
#ifdef PHP_HAVE_AVX512_SUPPORTS
ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_avx512(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("avx512f") && __builtin_cpu_supports("avx512dq")
Expand All @@ -195,7 +195,7 @@ static inline int zend_cpu_supports_avx512(void) {
#ifdef PHP_HAVE_AVX512_VBMI_SUPPORTS
ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_avx512_vbmi(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return zend_cpu_supports_avx512() && __builtin_cpu_supports("avx512vbmi");
Expand Down Expand Up @@ -244,10 +244,10 @@ static zend_always_inline int zend_cpu_supports_avx512_vbmi(void) {
#endif

/* __builtin_cpu_supports has pclmul from gcc9 */
#if PHP_HAVE_BUILTIN_CPU_SUPPORTS && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_pclmul(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("pclmul");
Expand All @@ -259,10 +259,10 @@ static inline int zend_cpu_supports_pclmul(void) {
#endif

/* __builtin_cpu_supports has cldemote from gcc11 */
#if PHP_HAVE_BUILTIN_CPU_SUPPORTS && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
ZEND_NO_SANITIZE_ADDRESS
static inline int zend_cpu_supports_cldemote(void) {
#if PHP_HAVE_BUILTIN_CPU_INIT
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
__builtin_cpu_init();
#endif
return __builtin_cpu_supports("cldemote");
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_multiply.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#ifndef ZEND_MULTIPLY_H
#define ZEND_MULTIPLY_H

#if PHP_HAVE_BUILTIN_SMULL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
#if defined(PHP_HAVE_BUILTIN_SMULL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG

#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
long __tmpvar; \
Expand All @@ -32,7 +32,7 @@
else (lval) = __tmpvar; \
} while (0)

#elif PHP_HAVE_BUILTIN_SMULLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SMULLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG

#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
long long __tmpvar; \
Expand Down
16 changes: 8 additions & 8 deletions Zend/zend_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,15 +550,15 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
return;
overflow: ZEND_ATTRIBUTE_COLD_LABEL
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MAX + 1.0);
#elif PHP_HAVE_BUILTIN_SADDL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SADDL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
long lresult;
if (UNEXPECTED(__builtin_saddl_overflow(Z_LVAL_P(op1), 1, &lresult))) {
/* switch to double */
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MAX + 1.0);
} else {
Z_LVAL_P(op1) = lresult;
}
#elif PHP_HAVE_BUILTIN_SADDLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SADDLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
long long llresult;
if (UNEXPECTED(__builtin_saddll_overflow(Z_LVAL_P(op1), 1, &llresult))) {
/* switch to double */
Expand Down Expand Up @@ -613,15 +613,15 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
return;
overflow: ZEND_ATTRIBUTE_COLD_LABEL
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MIN - 1.0);
#elif PHP_HAVE_BUILTIN_SSUBL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SSUBL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
long lresult;
if (UNEXPECTED(__builtin_ssubl_overflow(Z_LVAL_P(op1), 1, &lresult))) {
/* switch to double */
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MIN - 1.0);
} else {
Z_LVAL_P(op1) = lresult;
}
#elif PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
long long llresult;
if (UNEXPECTED(__builtin_ssubll_overflow(Z_LVAL_P(op1), 1, &llresult))) {
/* switch to double */
Expand Down Expand Up @@ -697,14 +697,14 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
return;
overflow: ZEND_ATTRIBUTE_COLD_LABEL
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
#elif PHP_HAVE_BUILTIN_SADDL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SADDL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
long lresult;
if (UNEXPECTED(__builtin_saddl_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &lresult))) {
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
} else {
ZVAL_LONG(result, lresult);
}
#elif PHP_HAVE_BUILTIN_SADDLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SADDLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
long long llresult;
if (UNEXPECTED(__builtin_saddll_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &llresult))) {
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
Expand Down Expand Up @@ -785,14 +785,14 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
return;
overflow: ZEND_ATTRIBUTE_COLD_LABEL
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));
#elif PHP_HAVE_BUILTIN_SSUBL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SSUBL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
long lresult;
if (UNEXPECTED(__builtin_ssubl_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &lresult))) {
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));
} else {
ZVAL_LONG(result, lresult);
}
#elif PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
#elif defined(PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
long long llresult;
if (UNEXPECTED(__builtin_ssubll_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &llresult))) {
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
#elif defined(__clang__) && __has_builtin(__builtin_assume)
# pragma clang diagnostic ignored "-Wassume"
# define ZEND_ASSUME(c) __builtin_assume(c)
#elif PHP_HAVE_BUILTIN_UNREACHABLE && PHP_HAVE_BUILTIN_EXPECT
#elif defined(PHP_HAVE_BUILTIN_UNREACHABLE) && defined(PHP_HAVE_BUILTIN_EXPECT)
# define ZEND_ASSUME(c) do { \
if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \
} while (0)
Expand Down
Loading
Loading