Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)

This commit is contained in:
Dmitry Stogov 2008-07-24 13:46:28 +00:00
parent e29684a2ce
commit 2cca3d0dd2
4 changed files with 41 additions and 0 deletions

1
NEWS
View file

@ -43,6 +43,7 @@ PHP NEWS
. Added ability to handle exceptions in destructors. (Marcus)
- Improved PHP runtime speed and memory usage:
. Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)
. Removed direct executor recursion. (Dmitry)
. Use fastcall calling convention in executor on x86. (Dmitry)
. Use IS_CV for direct access to $this variable. (Dmitry)

View file

@ -2355,6 +2355,19 @@ static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
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
static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)

View file

@ -31,6 +31,19 @@
else (lval) = __tmpvar; \
} 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
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \

View file

@ -28,6 +28,20 @@ typedef unsigned int zend_uint;
typedef unsigned long zend_ulong;
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
typedef __int64 zend_intptr_t;
typedef unsigned __int64 zend_uintptr_t;