mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)
This commit is contained in:
parent
e29684a2ce
commit
2cca3d0dd2
4 changed files with 41 additions and 0 deletions
1
NEWS
1
NEWS
|
@ -43,6 +43,7 @@ PHP NEWS
|
||||||
. Added ability to handle exceptions in destructors. (Marcus)
|
. Added ability to handle exceptions in destructors. (Marcus)
|
||||||
|
|
||||||
- Improved PHP runtime speed and memory usage:
|
- Improved PHP runtime speed and memory usage:
|
||||||
|
. Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)
|
||||||
. Removed direct executor recursion. (Dmitry)
|
. Removed direct executor recursion. (Dmitry)
|
||||||
. Use fastcall calling convention in executor on x86. (Dmitry)
|
. Use fastcall calling convention in executor on x86. (Dmitry)
|
||||||
. Use IS_CV for direct access to $this variable. (Dmitry)
|
. Use IS_CV for direct access to $this variable. (Dmitry)
|
||||||
|
|
|
@ -2355,6 +2355,19 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif SIZEOF_SIZE_T == 4 && defined(HAVE_ZEND_LONG64)
|
||||||
|
|
||||||
|
static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
|
||||||
|
{
|
||||||
|
zend_ulong64 res = (zend_ulong64)nmemb * (zend_ulong64)size + (zend_ulong64)offset;
|
||||||
|
|
||||||
|
if (UNEXPECTED(res > (zend_ulong64)0xFFFFFFFFL)) {
|
||||||
|
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (size_t) res;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
|
static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
|
||||||
|
|
|
@ -31,6 +31,19 @@
|
||||||
else (lval) = __tmpvar; \
|
else (lval) = __tmpvar; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#elif SIZEOF_LONG == 4 && defined(HAVE_ZEND_LONG64)
|
||||||
|
|
||||||
|
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||||
|
zend_long64 __result = (zend_long64) (a) * (zend_long64) (b); \
|
||||||
|
if (__result > LONG_MAX || __result < LONG_MIN) { \
|
||||||
|
(dval) = (double) __result; \
|
||||||
|
(usedval) = 1; \
|
||||||
|
} else { \
|
||||||
|
(lval) = (long) __result; \
|
||||||
|
(usedval) = 0; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
|
||||||
|
|
|
@ -28,6 +28,20 @@ typedef unsigned int zend_uint;
|
||||||
typedef unsigned long zend_ulong;
|
typedef unsigned long zend_ulong;
|
||||||
typedef unsigned short zend_ushort;
|
typedef unsigned short zend_ushort;
|
||||||
|
|
||||||
|
#define HAVE_ZEND_LONG64
|
||||||
|
#ifdef ZEND_WIN32
|
||||||
|
typedef __int64 zend_long64;
|
||||||
|
typedef unsigned __int64 zend_ulong64;
|
||||||
|
#elif SIZEOF_LONG_LONG_INT == 8
|
||||||
|
typedef long long int zend_long64;
|
||||||
|
typedef unsigned long long int zend_ulong64;
|
||||||
|
#elif SIZEOF_LONG_LONG == 8
|
||||||
|
typedef long long zend_long64;
|
||||||
|
typedef unsigned long long zend_ulong64;
|
||||||
|
#else
|
||||||
|
# undef HAVE_ZEND_LONG64
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN64
|
#ifdef _WIN64
|
||||||
typedef __int64 zend_intptr_t;
|
typedef __int64 zend_intptr_t;
|
||||||
typedef unsigned __int64 zend_uintptr_t;
|
typedef unsigned __int64 zend_uintptr_t;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue