Skip to content

Commit 9e94d2b

Browse files
authored
Autotools: Refactor builtin checks (#14835)
This creates a single M4 macro PHP_CHECK_BUILTIN and removes other PHP_CHECK_BUILTIN_* macros. Checks are wrapped in AC_CACHE_CHECK and PHP_HAVE_BUILTIN_* CPP macro definitions are defined to 1 if builtin is found and undefined if not. This also changes all PHP_HAVE_BUILTIN_ symbols to be either undefined or defined (to value 1) and syncs all #if/ifdef/defined usages of them in the php-src code. This way it is simpler to use them because they don't need to be defined to value 0 on Windows, for example. This is done as previous usages in php-src were mixed and on many places they were only checked with ifdef.
1 parent 745ae8d commit 9e94d2b

File tree

10 files changed

+87
-399
lines changed

10 files changed

+87
-399
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ PHP 8.4 INTERNALS UPGRADE NOTES
153153
AX_CHECK_COMPILE_FLAG).
154154
- M4 macro PHP_PROG_RE2C got a new 2nd argument to define common default re2c
155155
command-line options substituted to the Makefile RE2C_FLAGS variable.
156+
- M4 macros PHP_CHECK_BUILTIN_* have been removed in favor of
157+
PHP_CHECK_BUILTIN and all PHP_HAVE_BUILTIN_* symbols changed to be either
158+
undefined or defined to 1 whether compiler supports the builtin.
156159
- Added php-config --lib-dir and --lib-embed options for PHP embed SAPI.
157160
- PDO extensions in php-src don't have the include flag -I$pdo_cv_inc_path
158161
directory anymore.

Zend/zend_call_stack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ZEND_API bool zend_call_stack_get(zend_call_stack *stack);
4040
static zend_always_inline void *zend_call_stack_position(void) {
4141
#ifdef ZEND_WIN32
4242
return _AddressOfReturnAddress();
43-
#elif PHP_HAVE_BUILTIN_FRAME_ADDRESS
43+
#elif defined(PHP_HAVE_BUILTIN_FRAME_ADDRESS)
4444
return __builtin_frame_address(0);
4545
#else
4646
void *a;

Zend/zend_cpuinfo.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,63 +118,63 @@ ZEND_API int zend_cpu_supports(zend_cpu_feature feature);
118118
# define ZEND_NO_SANITIZE_ADDRESS
119119
#endif
120120

121-
#if PHP_HAVE_BUILTIN_CPU_SUPPORTS
121+
#ifdef PHP_HAVE_BUILTIN_CPU_SUPPORTS
122122
/* NOTE: you should use following inline function in
123123
* resolver functions (ifunc), as it could be called
124124
* before all PLT symbols are resolved. in other words,
125125
* resolver functions should not depend on any external
126126
* functions */
127127
ZEND_NO_SANITIZE_ADDRESS
128128
static inline int zend_cpu_supports_sse2(void) {
129-
#if PHP_HAVE_BUILTIN_CPU_INIT
129+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
130130
__builtin_cpu_init();
131131
#endif
132132
return __builtin_cpu_supports("sse2");
133133
}
134134

135135
ZEND_NO_SANITIZE_ADDRESS
136136
static inline int zend_cpu_supports_sse3(void) {
137-
#if PHP_HAVE_BUILTIN_CPU_INIT
137+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
138138
__builtin_cpu_init();
139139
#endif
140140
return __builtin_cpu_supports("sse3");
141141
}
142142

143143
ZEND_NO_SANITIZE_ADDRESS
144144
static inline int zend_cpu_supports_ssse3(void) {
145-
#if PHP_HAVE_BUILTIN_CPU_INIT
145+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
146146
__builtin_cpu_init();
147147
#endif
148148
return __builtin_cpu_supports("ssse3");
149149
}
150150

151151
ZEND_NO_SANITIZE_ADDRESS
152152
static inline int zend_cpu_supports_sse41(void) {
153-
#if PHP_HAVE_BUILTIN_CPU_INIT
153+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
154154
__builtin_cpu_init();
155155
#endif
156156
return __builtin_cpu_supports("sse4.1");
157157
}
158158

159159
ZEND_NO_SANITIZE_ADDRESS
160160
static inline int zend_cpu_supports_sse42(void) {
161-
#if PHP_HAVE_BUILTIN_CPU_INIT
161+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
162162
__builtin_cpu_init();
163163
#endif
164164
return __builtin_cpu_supports("sse4.2");
165165
}
166166

167167
ZEND_NO_SANITIZE_ADDRESS
168168
static inline int zend_cpu_supports_avx(void) {
169-
#if PHP_HAVE_BUILTIN_CPU_INIT
169+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
170170
__builtin_cpu_init();
171171
#endif
172172
return __builtin_cpu_supports("avx");
173173
}
174174

175175
ZEND_NO_SANITIZE_ADDRESS
176176
static inline int zend_cpu_supports_avx2(void) {
177-
#if PHP_HAVE_BUILTIN_CPU_INIT
177+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
178178
__builtin_cpu_init();
179179
#endif
180180
return __builtin_cpu_supports("avx2");
@@ -183,7 +183,7 @@ static inline int zend_cpu_supports_avx2(void) {
183183
#ifdef PHP_HAVE_AVX512_SUPPORTS
184184
ZEND_NO_SANITIZE_ADDRESS
185185
static inline int zend_cpu_supports_avx512(void) {
186-
#if PHP_HAVE_BUILTIN_CPU_INIT
186+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
187187
__builtin_cpu_init();
188188
#endif
189189
return __builtin_cpu_supports("avx512f") && __builtin_cpu_supports("avx512dq")
@@ -195,7 +195,7 @@ static inline int zend_cpu_supports_avx512(void) {
195195
#ifdef PHP_HAVE_AVX512_VBMI_SUPPORTS
196196
ZEND_NO_SANITIZE_ADDRESS
197197
static inline int zend_cpu_supports_avx512_vbmi(void) {
198-
#if PHP_HAVE_BUILTIN_CPU_INIT
198+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
199199
__builtin_cpu_init();
200200
#endif
201201
return zend_cpu_supports_avx512() && __builtin_cpu_supports("avx512vbmi");
@@ -244,10 +244,10 @@ static zend_always_inline int zend_cpu_supports_avx512_vbmi(void) {
244244
#endif
245245

246246
/* __builtin_cpu_supports has pclmul from gcc9 */
247-
#if PHP_HAVE_BUILTIN_CPU_SUPPORTS && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
247+
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && (!defined(__GNUC__) || (ZEND_GCC_VERSION >= 9000))
248248
ZEND_NO_SANITIZE_ADDRESS
249249
static inline int zend_cpu_supports_pclmul(void) {
250-
#if PHP_HAVE_BUILTIN_CPU_INIT
250+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
251251
__builtin_cpu_init();
252252
#endif
253253
return __builtin_cpu_supports("pclmul");
@@ -259,10 +259,10 @@ static inline int zend_cpu_supports_pclmul(void) {
259259
#endif
260260

261261
/* __builtin_cpu_supports has cldemote from gcc11 */
262-
#if PHP_HAVE_BUILTIN_CPU_SUPPORTS && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
262+
#if defined(PHP_HAVE_BUILTIN_CPU_SUPPORTS) && defined(__GNUC__) && (ZEND_GCC_VERSION >= 11000)
263263
ZEND_NO_SANITIZE_ADDRESS
264264
static inline int zend_cpu_supports_cldemote(void) {
265-
#if PHP_HAVE_BUILTIN_CPU_INIT
265+
#ifdef PHP_HAVE_BUILTIN_CPU_INIT
266266
__builtin_cpu_init();
267267
#endif
268268
return __builtin_cpu_supports("cldemote");

Zend/zend_multiply.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#ifndef ZEND_MULTIPLY_H
2323
#define ZEND_MULTIPLY_H
2424

25-
#if PHP_HAVE_BUILTIN_SMULL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
25+
#if defined(PHP_HAVE_BUILTIN_SMULL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
2626

2727
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
2828
long __tmpvar; \
@@ -32,7 +32,7 @@
3232
else (lval) = __tmpvar; \
3333
} while (0)
3434

35-
#elif PHP_HAVE_BUILTIN_SMULLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
35+
#elif defined(PHP_HAVE_BUILTIN_SMULLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
3636

3737
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
3838
long long __tmpvar; \

Zend/zend_operators.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,15 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
550550
return;
551551
overflow: ZEND_ATTRIBUTE_COLD_LABEL
552552
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MAX + 1.0);
553-
#elif PHP_HAVE_BUILTIN_SADDL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
553+
#elif defined(PHP_HAVE_BUILTIN_SADDL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
554554
long lresult;
555555
if (UNEXPECTED(__builtin_saddl_overflow(Z_LVAL_P(op1), 1, &lresult))) {
556556
/* switch to double */
557557
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MAX + 1.0);
558558
} else {
559559
Z_LVAL_P(op1) = lresult;
560560
}
561-
#elif PHP_HAVE_BUILTIN_SADDLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
561+
#elif defined(PHP_HAVE_BUILTIN_SADDLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
562562
long long llresult;
563563
if (UNEXPECTED(__builtin_saddll_overflow(Z_LVAL_P(op1), 1, &llresult))) {
564564
/* switch to double */
@@ -613,15 +613,15 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
613613
return;
614614
overflow: ZEND_ATTRIBUTE_COLD_LABEL
615615
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MIN - 1.0);
616-
#elif PHP_HAVE_BUILTIN_SSUBL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
616+
#elif defined(PHP_HAVE_BUILTIN_SSUBL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
617617
long lresult;
618618
if (UNEXPECTED(__builtin_ssubl_overflow(Z_LVAL_P(op1), 1, &lresult))) {
619619
/* switch to double */
620620
ZVAL_DOUBLE(op1, (double)ZEND_LONG_MIN - 1.0);
621621
} else {
622622
Z_LVAL_P(op1) = lresult;
623623
}
624-
#elif PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
624+
#elif defined(PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
625625
long long llresult;
626626
if (UNEXPECTED(__builtin_ssubll_overflow(Z_LVAL_P(op1), 1, &llresult))) {
627627
/* switch to double */
@@ -697,14 +697,14 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
697697
return;
698698
overflow: ZEND_ATTRIBUTE_COLD_LABEL
699699
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
700-
#elif PHP_HAVE_BUILTIN_SADDL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
700+
#elif defined(PHP_HAVE_BUILTIN_SADDL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
701701
long lresult;
702702
if (UNEXPECTED(__builtin_saddl_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &lresult))) {
703703
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
704704
} else {
705705
ZVAL_LONG(result, lresult);
706706
}
707-
#elif PHP_HAVE_BUILTIN_SADDLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
707+
#elif defined(PHP_HAVE_BUILTIN_SADDLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
708708
long long llresult;
709709
if (UNEXPECTED(__builtin_saddll_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &llresult))) {
710710
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) + (double) Z_LVAL_P(op2));
@@ -785,14 +785,14 @@ overflow: ZEND_ATTRIBUTE_COLD_LABEL
785785
return;
786786
overflow: ZEND_ATTRIBUTE_COLD_LABEL
787787
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));
788-
#elif PHP_HAVE_BUILTIN_SSUBL_OVERFLOW && SIZEOF_LONG == SIZEOF_ZEND_LONG
788+
#elif defined(PHP_HAVE_BUILTIN_SSUBL_OVERFLOW) && SIZEOF_LONG == SIZEOF_ZEND_LONG
789789
long lresult;
790790
if (UNEXPECTED(__builtin_ssubl_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &lresult))) {
791791
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));
792792
} else {
793793
ZVAL_LONG(result, lresult);
794794
}
795-
#elif PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
795+
#elif defined(PHP_HAVE_BUILTIN_SSUBLL_OVERFLOW) && SIZEOF_LONG_LONG == SIZEOF_ZEND_LONG
796796
long long llresult;
797797
if (UNEXPECTED(__builtin_ssubll_overflow(Z_LVAL_P(op1), Z_LVAL_P(op2), &llresult))) {
798798
ZVAL_DOUBLE(result, (double) Z_LVAL_P(op1) - (double) Z_LVAL_P(op2));

Zend/zend_portability.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
#elif defined(__clang__) && __has_builtin(__builtin_assume)
9393
# pragma clang diagnostic ignored "-Wassume"
9494
# define ZEND_ASSUME(c) __builtin_assume(c)
95-
#elif PHP_HAVE_BUILTIN_UNREACHABLE && PHP_HAVE_BUILTIN_EXPECT
95+
#elif defined(PHP_HAVE_BUILTIN_UNREACHABLE) && defined(PHP_HAVE_BUILTIN_EXPECT)
9696
# define ZEND_ASSUME(c) do { \
9797
if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \
9898
} while (0)

0 commit comments

Comments
 (0)