xref: /PHP-7.3/Zend/zend_portability.h (revision c4464526)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2018 Zend Technologies Ltd. (http://www.zend.com) |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Andi Gutmans <andi@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    |          Dmitry Stogov <zeev@php.net>                                |
18    +----------------------------------------------------------------------+
19 */
20 
21 #ifndef ZEND_PORTABILITY_H
22 #define ZEND_PORTABILITY_H
23 
24 #ifdef __cplusplus
25 #define BEGIN_EXTERN_C() extern "C" {
26 #define END_EXTERN_C() }
27 #else
28 #define BEGIN_EXTERN_C()
29 #define END_EXTERN_C()
30 #endif
31 
32 /*
33  * general definitions
34  */
35 
36 #ifdef ZEND_WIN32
37 # include "zend_config.w32.h"
38 # define ZEND_PATHS_SEPARATOR		';'
39 #elif defined(__riscos__)
40 # include <zend_config.h>
41 # define ZEND_PATHS_SEPARATOR		';'
42 #else
43 # include <zend_config.h>
44 # define ZEND_PATHS_SEPARATOR		':'
45 #endif
46 
47 #include "../TSRM/TSRM.h"
48 
49 #include <stdio.h>
50 #include <assert.h>
51 #include <math.h>
52 
53 #ifdef HAVE_UNIX_H
54 # include <unix.h>
55 #endif
56 
57 #ifdef HAVE_STDARG_H
58 # include <stdarg.h>
59 #endif
60 
61 #ifdef HAVE_DLFCN_H
62 # include <dlfcn.h>
63 #endif
64 
65 #ifdef HAVE_LIMITS_H
66 # include <limits.h>
67 #endif
68 
69 #if HAVE_ALLOCA_H && !defined(_ALLOCA_H)
70 # include <alloca.h>
71 #endif
72 
73 #if defined(ZEND_WIN32) && !defined(__clang__)
74 #include <intrin.h>
75 #endif
76 
77 #include "zend_range_check.h"
78 
79 /* GCC x.y.z supplies __GNUC__ = x and __GNUC_MINOR__ = y */
80 #ifdef __GNUC__
81 # define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
82 #else
83 # define ZEND_GCC_VERSION 0
84 #endif
85 
86 /* Compatibility with non-clang compilers */
87 #ifndef __has_attribute
88 # define __has_attribute(x) 0
89 #endif
90 #ifndef __has_builtin
91 # define __has_builtin(x) 0
92 #endif
93 
94 #if defined(ZEND_WIN32) && !defined(__clang__)
95 # define ZEND_ASSUME(c)	__assume(c)
96 #elif ((defined(__GNUC__) && ZEND_GCC_VERSION >= 4005) || __has_builtin(__builtin_unreachable)) && PHP_HAVE_BUILTIN_EXPECT
97 # define ZEND_ASSUME(c)	do { \
98 		if (__builtin_expect(!(c), 0)) __builtin_unreachable(); \
99 	} while (0)
100 #else
101 # define ZEND_ASSUME(c)
102 #endif
103 
104 #if ZEND_DEBUG
105 # define ZEND_ASSERT(c)	assert(c)
106 #else
107 # define ZEND_ASSERT(c) ZEND_ASSUME(c)
108 #endif
109 
110 /* Only use this macro if you know for sure that all of the switches values
111    are covered by its case statements */
112 #if ZEND_DEBUG
113 # define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_ASSERT(0); break;
114 #else
115 # define EMPTY_SWITCH_DEFAULT_CASE() default: ZEND_ASSUME(0); break;
116 #endif
117 
118 #if defined(__GNUC__) && __GNUC__ >= 4
119 # define ZEND_IGNORE_VALUE(x) (({ __typeof__ (x) __x = (x); (void) __x; }))
120 #else
121 # define ZEND_IGNORE_VALUE(x) ((void) (x))
122 #endif
123 
124 #define zend_quiet_write(...) ZEND_IGNORE_VALUE(write(__VA_ARGS__))
125 
126 /* all HAVE_XXX test have to be after the include of zend_config above */
127 
128 #if defined(HAVE_LIBDL) && !defined(ZEND_WIN32)
129 
130 # if defined(__has_feature)
131 #  if __has_feature(address_sanitizer)
132 #   define __SANITIZE_ADDRESS__
133 #  endif
134 # endif
135 
136 # ifndef RTLD_LAZY
137 #  define RTLD_LAZY 1    /* Solaris 1, FreeBSD's (2.1.7.1 and older) */
138 # endif
139 
140 # ifndef RTLD_GLOBAL
141 #  define RTLD_GLOBAL 0
142 # endif
143 
144 # if defined(RTLD_GROUP) && defined(RTLD_WORLD) && defined(RTLD_PARENT)
145 #  define DL_LOAD(libname)			dlopen(libname, RTLD_LAZY | RTLD_GLOBAL | RTLD_GROUP | RTLD_WORLD | RTLD_PARENT)
146 # elif defined(RTLD_DEEPBIND) && !defined(__SANITIZE_ADDRESS__)
147 #  define DL_LOAD(libname)			dlopen(libname, RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND)
148 # else
149 #  define DL_LOAD(libname)			dlopen(libname, RTLD_LAZY | RTLD_GLOBAL)
150 # endif
151 # define DL_UNLOAD					dlclose
152 # if defined(DLSYM_NEEDS_UNDERSCORE)
153 #  define DL_FETCH_SYMBOL(h,s)		dlsym((h), "_" s)
154 # else
155 #  define DL_FETCH_SYMBOL			dlsym
156 # endif
157 # define DL_ERROR					dlerror
158 # define DL_HANDLE					void *
159 # define ZEND_EXTENSIONS_SUPPORT	1
160 #elif defined(ZEND_WIN32)
161 # define DL_LOAD(libname)			LoadLibrary(libname)
162 # define DL_FETCH_SYMBOL			GetProcAddress
163 # define DL_UNLOAD					FreeLibrary
164 # define DL_HANDLE					HMODULE
165 # define ZEND_EXTENSIONS_SUPPORT	1
166 #else
167 # define DL_HANDLE					void *
168 # define ZEND_EXTENSIONS_SUPPORT	0
169 #endif
170 
171 /* AIX requires this to be the first thing in the file.  */
172 #ifndef __GNUC__
173 # ifndef HAVE_ALLOCA_H
174 #  ifdef _AIX
175 #   pragma alloca
176 #  else
177 #   ifndef alloca /* predefined by HP cc +Olibcalls */
178 char *alloca();
179 #   endif
180 #  endif
181 # endif
182 #endif
183 
184 #if ZEND_GCC_VERSION >= 2096 || __has_attribute(__malloc__)
185 # define ZEND_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
186 #else
187 # define ZEND_ATTRIBUTE_MALLOC
188 #endif
189 
190 #if ZEND_GCC_VERSION >= 4003 || __has_attribute(alloc_size)
191 # define ZEND_ATTRIBUTE_ALLOC_SIZE(X) __attribute__ ((alloc_size(X)))
192 # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y) __attribute__ ((alloc_size(X,Y)))
193 #else
194 # define ZEND_ATTRIBUTE_ALLOC_SIZE(X)
195 # define ZEND_ATTRIBUTE_ALLOC_SIZE2(X,Y)
196 #endif
197 
198 #if ZEND_GCC_VERSION >= 2007 || __has_attribute(format)
199 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
200 #else
201 # define ZEND_ATTRIBUTE_FORMAT(type, idx, first)
202 #endif
203 
204 #if (ZEND_GCC_VERSION >= 3001 && !defined(__INTEL_COMPILER)) || __has_attribute(format)
205 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first)))
206 #else
207 # define ZEND_ATTRIBUTE_PTR_FORMAT(type, idx, first)
208 #endif
209 
210 #if ZEND_GCC_VERSION >= 3001 || __has_attribute(deprecated)
211 # define ZEND_ATTRIBUTE_DEPRECATED  __attribute__((deprecated))
212 #elif defined(ZEND_WIN32)
213 # define ZEND_ATTRIBUTE_DEPRECATED  __declspec(deprecated)
214 #else
215 # define ZEND_ATTRIBUTE_DEPRECATED
216 #endif
217 
218 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 4003
219 # define ZEND_ATTRIBUTE_UNUSED __attribute__((unused))
220 # define ZEND_COLD __attribute__((cold))
221 # define ZEND_HOT __attribute__((hot))
222 # ifdef __OPTIMIZE__
223 #  define ZEND_OPT_SIZE  __attribute__((optimize("Os")))
224 #  define ZEND_OPT_SPEED __attribute__((optimize("Ofast")))
225 # else
226 #  define ZEND_OPT_SIZE
227 #  define ZEND_OPT_SPEED
228 # endif
229 #else
230 # define ZEND_ATTRIBUTE_UNUSED
231 # define ZEND_COLD
232 # define ZEND_HOT
233 # define ZEND_OPT_SIZE
234 # define ZEND_OPT_SPEED
235 #endif
236 
237 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 5000
238 # define ZEND_ATTRIBUTE_UNUSED_LABEL __attribute__((cold, unused));
239 # define ZEND_ATTRIBUTE_COLD_LABEL __attribute__((cold));
240 # define ZEND_ATTRIBUTE_HOT_LABEL __attribute__((hot));
241 #else
242 # define ZEND_ATTRIBUTE_UNUSED_LABEL
243 # define ZEND_ATTRIBUTE_COLD_LABEL
244 # define ZEND_ATTRIBUTE_HOT_LABEL
245 #endif
246 
247 #if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004 && defined(__i386__)
248 # define ZEND_FASTCALL __attribute__((fastcall))
249 #elif defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER == 1700
250 # define ZEND_FASTCALL __fastcall
251 #elif defined(_MSC_VER) && _MSC_VER >= 1800 && !defined(__clang__)
252 # define ZEND_FASTCALL __vectorcall
253 #else
254 # define ZEND_FASTCALL
255 #endif
256 
257 #ifndef restrict
258 # if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004
259 # else
260 #  define __restrict__
261 # endif
262 # define restrict __restrict__
263 #endif
264 
265 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__)) || __has_attribute(noreturn)
266 # define HAVE_NORETURN
267 # define ZEND_NORETURN __attribute__((noreturn))
268 #elif defined(ZEND_WIN32)
269 # define HAVE_NORETURN
270 # define ZEND_NORETURN __declspec(noreturn)
271 #else
272 # define ZEND_NORETURN
273 #endif
274 
275 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__))
276 # define HAVE_NORETURN_ALIAS
277 # define HAVE_ATTRIBUTE_WEAK
278 #endif
279 
280 #if ZEND_GCC_VERSION >= 3001 || __has_builtin(__builtin_constant_p)
281 # define HAVE_BUILTIN_CONSTANT_P
282 #endif
283 
284 #ifdef HAVE_BUILTIN_CONSTANT_P
285 # define ZEND_CONST_COND(_condition, _default) \
286 	(__builtin_constant_p(_condition) ? (_condition) : (_default))
287 #else
288 # define ZEND_CONST_COND(_condition, _default) \
289 	(_default)
290 #endif
291 
292 #if ZEND_DEBUG
293 # define zend_always_inline inline
294 # define zend_never_inline
295 #else
296 # if defined(__GNUC__)
297 #  if __GNUC__ >= 3
298 #   define zend_always_inline inline __attribute__((always_inline))
299 #   define zend_never_inline __attribute__((noinline))
300 #  else
301 #   define zend_always_inline inline
302 #   define zend_never_inline
303 #  endif
304 # elif defined(_MSC_VER)
305 #  define zend_always_inline __forceinline
306 #  define zend_never_inline __declspec(noinline)
307 # else
308 #  if __has_attribute(always_inline)
309 #   define zend_always_inline inline __attribute__((always_inline))
310 #  else
311 #   define zend_always_inline inline
312 #  endif
313 #  if __has_attribute(noinline)
314 #   define zend_never_inline __attribute__((noinline))
315 #  else
316 #   define zend_never_inline
317 #  endif
318 # endif
319 #endif /* ZEND_DEBUG */
320 
321 #if PHP_HAVE_BUILTIN_EXPECT
322 # define EXPECTED(condition)   __builtin_expect(!!(condition), 1)
323 # define UNEXPECTED(condition) __builtin_expect(!!(condition), 0)
324 #else
325 # define EXPECTED(condition)   (condition)
326 # define UNEXPECTED(condition) (condition)
327 #endif
328 
329 #ifndef XtOffsetOf
330 # if defined(CRAY) || (defined(__ARMCC_VERSION) && !defined(LINUX))
331 # ifdef __STDC__
332 # define XtOffset(p_type, field) _Offsetof(p_type, field)
333 # else
334 # ifdef CRAY2
335 # define XtOffset(p_type, field) \
336     (sizeof(int)*((unsigned int)&(((p_type)NULL)->field)))
337 
338 # else /* !CRAY2 */
339 
340 # define XtOffset(p_type, field) ((unsigned int)&(((p_type)NULL)->field))
341 
342 # endif /* !CRAY2 */
343 # endif /* __STDC__ */
344 # else /* ! (CRAY || __arm) */
345 
346 # define XtOffset(p_type, field) \
347     ((zend_long) (((char *) (&(((p_type)NULL)->field))) - ((char *) NULL)))
348 
349 # endif /* !CRAY */
350 
351 # ifdef offsetof
352 # define XtOffsetOf(s_type, field) offsetof(s_type, field)
353 # else
354 # define XtOffsetOf(s_type, field) XtOffset(s_type*, field)
355 # endif
356 
357 #endif
358 
359 #if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS)) && !(defined(ZTS) && defined(HPUX)) && !defined(DARWIN)
360 # define ZEND_ALLOCA_MAX_SIZE (32 * 1024)
361 # define ALLOCA_FLAG(name) \
362 	zend_bool name;
363 # define SET_ALLOCA_FLAG(name) \
364 	name = 1
365 # define do_alloca_ex(size, limit, use_heap) \
366 	((use_heap = (UNEXPECTED((size) > (limit)))) ? emalloc(size) : alloca(size))
367 # define do_alloca(size, use_heap) \
368 	do_alloca_ex(size, ZEND_ALLOCA_MAX_SIZE, use_heap)
369 # define free_alloca(p, use_heap) \
370 	do { if (UNEXPECTED(use_heap)) efree(p); } while (0)
371 #else
372 # define ALLOCA_FLAG(name)
373 # define SET_ALLOCA_FLAG(name)
374 # define do_alloca(p, use_heap)		emalloc(p)
375 # define free_alloca(p, use_heap)	efree(p)
376 #endif
377 
378 #ifdef HAVE_SIGSETJMP
379 # define SETJMP(a) sigsetjmp(a, 0)
380 # define LONGJMP(a,b) siglongjmp(a, b)
381 # define JMP_BUF sigjmp_buf
382 #else
383 # define SETJMP(a) setjmp(a)
384 # define LONGJMP(a,b) longjmp(a, b)
385 # define JMP_BUF jmp_buf
386 #endif
387 
388 #if ZEND_DEBUG
389 # define ZEND_FILE_LINE_D				const char *__zend_filename, const uint32_t __zend_lineno
390 # define ZEND_FILE_LINE_DC				, ZEND_FILE_LINE_D
391 # define ZEND_FILE_LINE_ORIG_D			const char *__zend_orig_filename, const uint32_t __zend_orig_lineno
392 # define ZEND_FILE_LINE_ORIG_DC			, ZEND_FILE_LINE_ORIG_D
393 # define ZEND_FILE_LINE_RELAY_C			__zend_filename, __zend_lineno
394 # define ZEND_FILE_LINE_RELAY_CC		, ZEND_FILE_LINE_RELAY_C
395 # define ZEND_FILE_LINE_C				__FILE__, __LINE__
396 # define ZEND_FILE_LINE_CC				, ZEND_FILE_LINE_C
397 # define ZEND_FILE_LINE_EMPTY_C			NULL, 0
398 # define ZEND_FILE_LINE_EMPTY_CC		, ZEND_FILE_LINE_EMPTY_C
399 # define ZEND_FILE_LINE_ORIG_RELAY_C	__zend_orig_filename, __zend_orig_lineno
400 # define ZEND_FILE_LINE_ORIG_RELAY_CC	, ZEND_FILE_LINE_ORIG_RELAY_C
401 #else
402 # define ZEND_FILE_LINE_D				void
403 # define ZEND_FILE_LINE_DC
404 # define ZEND_FILE_LINE_ORIG_D			void
405 # define ZEND_FILE_LINE_ORIG_DC
406 # define ZEND_FILE_LINE_RELAY_C
407 # define ZEND_FILE_LINE_RELAY_CC
408 # define ZEND_FILE_LINE_C
409 # define ZEND_FILE_LINE_CC
410 # define ZEND_FILE_LINE_EMPTY_C
411 # define ZEND_FILE_LINE_EMPTY_CC
412 # define ZEND_FILE_LINE_ORIG_RELAY_C
413 # define ZEND_FILE_LINE_ORIG_RELAY_CC
414 #endif	/* ZEND_DEBUG */
415 
416 #if ZEND_DEBUG
417 # define Z_DBG(expr)		(expr)
418 #else
419 # define Z_DBG(expr)
420 #endif
421 
422 #ifdef ZTS
423 # define ZTS_V 1
424 #else
425 # define ZTS_V 0
426 #endif
427 
428 #ifndef LONG_MAX
429 # define LONG_MAX 2147483647L
430 #endif
431 
432 #ifndef LONG_MIN
433 # define LONG_MIN (- LONG_MAX - 1)
434 #endif
435 
436 #define MAX_LENGTH_OF_DOUBLE 32
437 
438 #undef MIN
439 #undef MAX
440 #define MAX(a, b)  (((a)>(b))?(a):(b))
441 #define MIN(a, b)  (((a)<(b))?(a):(b))
442 
443 #define ZEND_BIT_TEST(bits, bit) \
444 	(((bits)[(bit) / (sizeof((bits)[0])*8)] >> ((bit) & (sizeof((bits)[0])*8-1))) & 1)
445 
446 /* We always define a function, even if there's a macro or expression we could
447  * alias, so that using it in contexts where we can't make function calls
448  * won't fail to compile on some machines and not others.
449  */
_zend_get_inf(void)450 static zend_always_inline double _zend_get_inf(void) /* {{{ */
451 {
452 #ifdef INFINITY
453 	return INFINITY;
454 #elif HAVE_HUGE_VAL_INF
455 	return HUGE_VAL;
456 #elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha)
457 # define _zend_DOUBLE_INFINITY_HIGH       0x7ff00000
458 	double val = 0.0;
459 	((uint32_t*)&val)[1] = _zend_DOUBLE_INFINITY_HIGH;
460 	((uint32_t*)&val)[0] = 0;
461 	return val;
462 #elif HAVE_ATOF_ACCEPTS_INF
463 	return atof("INF");
464 #else
465 	return 1.0/0.0;
466 #endif
467 } /* }}} */
468 #define ZEND_INFINITY (_zend_get_inf())
469 
_zend_get_nan(void)470 static zend_always_inline double _zend_get_nan(void) /* {{{ */
471 {
472 #ifdef NAN
473 	return NAN;
474 #elif HAVE_HUGE_VAL_NAN
475 	return HUGE_VAL + -HUGE_VAL;
476 #elif defined(__i386__) || defined(_X86_) || defined(ALPHA) || defined(_ALPHA) || defined(__alpha)
477 # define _zend_DOUBLE_QUIET_NAN_HIGH      0xfff80000
478 	double val = 0.0;
479 	((uint32_t*)&val)[1] = _zend_DOUBLE_QUIET_NAN_HIGH;
480 	((uint32_t*)&val)[0] = 0;
481 	return val;
482 #elif HAVE_ATOF_ACCEPTS_NAN
483 	return atof("NAN");
484 #else
485 	return 0.0/0.0;
486 #endif
487 } /* }}} */
488 #define ZEND_NAN (_zend_get_nan())
489 
490 #define ZEND_STRL(str)		(str), (sizeof(str)-1)
491 #define ZEND_STRS(str)		(str), (sizeof(str))
492 #define ZEND_NORMALIZE_BOOL(n)			\
493 	((n) ? (((n)<0) ? -1 : 1) : 0)
494 #define ZEND_TRUTH(x)		((x) ? 1 : 0)
495 #define ZEND_LOG_XOR(a, b)		(ZEND_TRUTH(a) ^ ZEND_TRUTH(b))
496 
497 #define ZEND_MAX_RESERVED_RESOURCES	6
498 
499 /* excpt.h on Digital Unix 4.0 defines function_table */
500 #undef function_table
501 
502 #ifdef ZEND_WIN32
503 #define ZEND_SECURE_ZERO(var, size) RtlSecureZeroMemory((var), (size))
504 #else
505 #define ZEND_SECURE_ZERO(var, size) explicit_bzero((var), (size))
506 #endif
507 
508 /* This check should only be used on network socket, not file descriptors */
509 #ifdef ZEND_WIN32
510 #define ZEND_VALID_SOCKET(sock) (INVALID_SOCKET != (sock))
511 #else
512 #define ZEND_VALID_SOCKET(sock) ((sock) >= 0)
513 #endif
514 
515 /* va_copy() is __va_copy() in old gcc versions.
516  * According to the autoconf manual, using
517  * memcpy(&dst, &src, sizeof(va_list))
518  * gives maximum portability. */
519 #ifndef va_copy
520 # ifdef __va_copy
521 #  define va_copy(dest, src) __va_copy((dest), (src))
522 # else
523 #  define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
524 # endif
525 #endif
526 
527 /* Intrinsics macros start. */
528 
529 #if defined(HAVE_FUNC_ATTRIBUTE_IFUNC) && defined(HAVE_FUNC_ATTRIBUTE_TARGET)
530 # define ZEND_INTRIN_HAVE_IFUNC_TARGET 1
531 #endif
532 
533 #if (defined(__i386__) || defined(__x86_64__))
534 # if PHP_HAVE_SSSE3_INSTRUCTIONS && defined(HAVE_TMMINTRIN_H)
535 # define PHP_HAVE_SSSE3
536 # endif
537 
538 # if PHP_HAVE_SSE4_2_INSTRUCTIONS && defined(HAVE_NMMINTRIN_H)
539 # define PHP_HAVE_SSE4_2
540 # endif
541 
542 /*
543  * AVX2 support was added in gcc 4.7, but AVX2 intrinsics don't work in
544  * __attribute__((target("avx2"))) functions until gcc 4.9.
545  */
546 # if PHP_HAVE_AVX2_INSTRUCTIONS && defined(HAVE_IMMINTRIN_H) && \
547   (defined(__llvm__) || defined(__clang__) || (defined(__GNUC__) && ZEND_GCC_VERSION >= 4009))
548 # define PHP_HAVE_AVX2
549 # endif
550 #endif
551 
552 #ifdef __SSSE3__
553 /* Instructions compiled directly. */
554 # define ZEND_INTRIN_SSSE3_NATIVE 1
555 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSSE3)) || defined(ZEND_WIN32)
556 /* Function resolved by ifunc or MINIT. */
557 # define ZEND_INTRIN_SSSE3_RESOLVER 1
558 #endif
559 
560 #if ZEND_INTRIN_SSSE3_RESOLVER && ZEND_INTRIN_HAVE_IFUNC_TARGET
561 # define ZEND_INTRIN_SSSE3_FUNC_PROTO 1
562 #elif ZEND_INTRIN_SSSE3_RESOLVER
563 # define ZEND_INTRIN_SSSE3_FUNC_PTR 1
564 #endif
565 
566 #if ZEND_INTRIN_SSSE3_RESOLVER
567 # if defined(HAVE_FUNC_ATTRIBUTE_TARGET)
568 #  define ZEND_INTRIN_SSSE3_FUNC_DECL(func) ZEND_API func __attribute__((target("ssse3")))
569 # else
570 #  define ZEND_INTRIN_SSSE3_FUNC_DECL(func) func
571 # endif
572 #else
573 # define ZEND_INTRIN_SSSE3_FUNC_DECL(func)
574 #endif
575 
576 #if defined(HAVE_SSE4_2_DEF) || (defined(ZEND_WIN32) && defined(__SSE4_2__))
577 /* Instructions compiled directly. */
578 # define ZEND_INTRIN_SSE4_2_NATIVE 1
579 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_SSE4_2)) || defined(ZEND_WIN32)
580 /* Function resolved by ifunc or MINIT. */
581 # define ZEND_INTRIN_SSE4_2_RESOLVER 1
582 #endif
583 
584 #if ZEND_INTRIN_SSE4_2_RESOLVER && ZEND_INTRIN_HAVE_IFUNC_TARGET
585 # define ZEND_INTRIN_SSE4_2_FUNC_PROTO 1
586 #elif ZEND_INTRIN_SSE4_2_RESOLVER
587 # define ZEND_INTRIN_SSE4_2_FUNC_PTR 1
588 #endif
589 
590 #if ZEND_INTRIN_SSE4_2_RESOLVER
591 # if defined(HAVE_FUNC_ATTRIBUTE_TARGET)
592 #  define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) ZEND_API func __attribute__((target("sse4.2")))
593 # else
594 #  define ZEND_INTRIN_SSE4_2_FUNC_DECL(func) func
595 # endif
596 #else
597 # define ZEND_INTRIN_SSE4_2_FUNC_DECL(func)
598 #endif
599 
600 #ifdef __AVX2__
601 # define ZEND_INTRIN_AVX2_NATIVE 1
602 #elif (defined(HAVE_FUNC_ATTRIBUTE_TARGET) && defined(PHP_HAVE_AVX2)) || defined(ZEND_WIN32)
603 # define ZEND_INTRIN_AVX2_RESOLVER 1
604 #endif
605 
606 #if ZEND_INTRIN_AVX2_RESOLVER && ZEND_INTRIN_HAVE_IFUNC_TARGET
607 # define ZEND_INTRIN_AVX2_FUNC_PROTO 1
608 #elif ZEND_INTRIN_AVX2_RESOLVER
609 # define ZEND_INTRIN_AVX2_FUNC_PTR 1
610 #endif
611 
612 #if ZEND_INTRIN_AVX2_RESOLVER
613 # if defined(HAVE_FUNC_ATTRIBUTE_TARGET)
614 #  define ZEND_INTRIN_AVX2_FUNC_DECL(func) ZEND_API func __attribute__((target("avx2")))
615 # else
616 #  define ZEND_INTRIN_AVX2_FUNC_DECL(func) func
617 # endif
618 #else
619 # define ZEND_INTRIN_AVX2_FUNC_DECL(func)
620 #endif
621 
622 /* Intrinsics macros end. */
623 
624 #ifdef ZEND_WIN32
625 # define ZEND_SET_ALIGNED(alignment, decl) __declspec(align(alignment)) decl
626 #elif HAVE_ATTRIBUTE_ALIGNED
627 # define ZEND_SET_ALIGNED(alignment, decl) decl __attribute__ ((__aligned__ (alignment)))
628 #else
629 # define ZEND_SET_ALIGNED(alignment, decl) decl
630 #endif
631 
632 #define ZEND_SLIDE_TO_ALIGNED(alignment, ptr) (((zend_uintptr_t)(ptr) + ((alignment)-1)) & ~((alignment)-1))
633 #define ZEND_SLIDE_TO_ALIGNED16(ptr) ZEND_SLIDE_TO_ALIGNED(Z_UL(16), ptr)
634 
635 #ifdef ZEND_WIN32
636 # define _ZEND_EXPAND_VA(a) a
637 # define ZEND_EXPAND_VA(code) _ZEND_EXPAND_VA(code)
638 #else
639 # define ZEND_EXPAND_VA(code) code
640 #endif
641 
642 #endif /* ZEND_PORTABILITY_H */
643 
644 /*
645  * Local variables:
646  * tab-width: 4
647  * c-basic-offset: 4
648  * indent-tabs-mode: t
649  * End:
650  * vim600: sw=4 ts=4 fdm=marker
651  * vim<600: sw=4 ts=4
652  */
653