summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo Frederico Temple Pedrosa <gustavo.pedrosa@eldorado.org.br>2014-12-15 12:59:55 +0000
committerRemi Collet <remi@php.net>2014-12-16 08:20:01 +0100
commit1e82da8d170066fa8c456a98f0242b8a6d1e6f86 (patch)
tree273a1ecdff3bf1c696ac11276c35ca7d5dd75187
parentcaf55214165ed32014aae7863bce621d1cb19a9e (diff)
downloadphp-git-1e82da8d170066fa8c456a98f0242b8a6d1e6f86.tar.gz
PowerPC64 support in safe_address function
Add a ppc64-specific implementation of the safe_address function with overflow checking.
-rw-r--r--Zend/zend_multiply.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/Zend/zend_multiply.h b/Zend/zend_multiply.h
index ab5fd6279d..b0000449af 100644
--- a/Zend/zend_multiply.h
+++ b/Zend/zend_multiply.h
@@ -224,6 +224,30 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si
return res;
}
+#elif defined(__GNUC__) && defined(__powerpc64__)
+
+static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, int *overflow)
+{
+ size_t res;
+ unsigned long m_overflow;
+
+ __asm__ ("mulld %0,%2,%3\n\t"
+ "mulhdu %1,%2,%3\n\t"
+ "addc %0,%0,%4\n\t"
+ "addze %1,%1\n"
+ : "=&r"(res), "=&r"(m_overflow)
+ : "r"(nmemb),
+ "r"(size),
+ "r"(offset));
+
+ if (UNEXPECTED(m_overflow)) {
+ *overflow = 1;
+ return 0;
+ }
+ *overflow = 0;
+ return res;
+}
+
#elif SIZEOF_SIZE_T == 4
static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, size_t offset, int *overflow)