cvs: ZendEngine2(PHP_5_3) / zend_alloc.c zend_multiply.h zend_types.h php-src NEWS

"Dmitry Stogov" <[email protected]>
Newsgroups gmane.comp.php.cvs.zend
Message-ID <cvsdmitry1216907188@cvsserver>
dmitry		Thu Jul 24 13:46:28 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src	NEWS 
    /ZendEngine2	zend_alloc.c zend_multiply.h zend_types.h 
  Log:
  Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.217&r2=1.2027.2.547.2.965.2.218&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.217 php-src/NEWS:1.2027.2.547.2.965.2.218
--- php-src/NEWS:1.2027.2.547.2.965.2.217	Thu Jul 24 13:01:49 2008
+++ php-src/NEWS	Thu Jul 24 13:46:28 2008
@@ -43,6 +43,7 @@
   . 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)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.144.2.3.2.43.2.13&r2=1.144.2.3.2.43.2.14&diff_format=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.13 ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.14
--- ZendEngine2/zend_alloc.c:1.144.2.3.2.43.2.13	Mon Jul 21 17:06:35 2008
+++ ZendEngine2/zend_alloc.c	Thu Jul 24 13:46:28 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_alloc.c,v 1.144.2.3.2.43.2.13 2008/07/21 17:06:35 dmitry Exp $ */
+/* $Id: zend_alloc.c,v 1.144.2.3.2.43.2.14 2008/07/24 13:46:28 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_alloc.h"
@@ -2355,6 +2355,19 @@
         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)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_multiply.h?r1=1.10.2.1.2.2.2.1&r2=1.10.2.1.2.2.2.2&diff_format=u
Index: ZendEngine2/zend_multiply.h
diff -u ZendEngine2/zend_multiply.h:1.10.2.1.2.2.2.1 ZendEngine2/zend_multiply.h:1.10.2.1.2.2.2.2
--- ZendEngine2/zend_multiply.h:1.10.2.1.2.2.2.1	Mon Dec 31 07:17:04 2007
+++ ZendEngine2/zend_multiply.h	Thu Jul 24 13:46:28 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_multiply.h,v 1.10.2.1.2.2.2.1 2007/12/31 07:17:04 sebastian Exp $ */
+/* $Id: zend_multiply.h,v 1.10.2.1.2.2.2.2 2008/07/24 13:46:28 dmitry Exp $ */
 
 #if defined(__i386__) && defined(__GNUC__)
 
@@ -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 {		\
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_types.h?r1=1.6.2.2.2.3.2.1&r2=1.6.2.2.2.3.2.2&diff_format=u
Index: ZendEngine2/zend_types.h
diff -u ZendEngine2/zend_types.h:1.6.2.2.2.3.2.1 ZendEngine2/zend_types.h:1.6.2.2.2.3.2.2
--- ZendEngine2/zend_types.h:1.6.2.2.2.3.2.1	Mon Dec 31 07:17:05 2007
+++ ZendEngine2/zend_types.h	Thu Jul 24 13:46:28 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_types.h,v 1.6.2.2.2.3.2.1 2007/12/31 07:17:05 sebastian Exp $ */
+/* $Id: zend_types.h,v 1.6.2.2.2.3.2.2 2008/07/24 13:46:28 dmitry Exp $ */
 
 #ifndef ZEND_TYPES_H
 #define ZEND_TYPES_H
@@ -28,6 +28,20 @@
 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;



-- 
Zend Engine CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.