Hi, Here's an additional ZEND_SIGNED_MULTIPLY_LONG() for platforms with 32-bit longs that don't use the assembly version (so all Windows systems at least?). On my Windows system, mul_function() is 40% faster with this version (no overflow), which makes PHP's * operator 20% faster; with overflow mul_function() is 20% faster (though I don't see any difference with the * operator). The macro is also used in safe_emalloc()...
Patch just against 5_2 as the file versions are the only difference. Matt
Index: zend_multiply.h =================================================================== RCS file: /repository/ZendEngine2/zend_multiply.h,v retrieving revision 1.10.2.1 diff -u -r1.10.2.1 zend_multiply.h --- zend_multiply.h 4 Jan 2006 23:53:04 -0000 1.10.2.1 +++ zend_multiply.h 9 Nov 2006 03:54:01 -0000 @@ -31,6 +31,19 @@ else (lval) = __tmpvar; \ } while (0) +#elif SIZEOF_LONG_LONG > SIZEOF_LONG + +#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ + long long __result = (long long) (a) * (long long) (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 { \
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php