diff options
author | Anatol Belski <ab@php.net> | 2014-08-16 11:16:11 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2014-08-16 11:16:11 +0200 |
commit | 8ee2a4a9b5de682c0b37670e1f4f86242b1650ce (patch) | |
tree | 7768898294c125f79de082a986e962aa6cb23094 /Zend/zend_multiply.h | |
parent | 735ec33b828bc4429c4ec8de7ba547925a4b44e3 (diff) | |
download | php-git-8ee2a4a9b5de682c0b37670e1f4f86242b1650ce.tar.gz |
first shot on merging the core fro the int64 branch
Diffstat (limited to 'Zend/zend_multiply.h')
-rw-r--r-- | Zend/zend_multiply.h | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/Zend/zend_multiply.h b/Zend/zend_multiply.h index 74dc7d1452..587346c267 100644 --- a/Zend/zend_multiply.h +++ b/Zend/zend_multiply.h @@ -21,8 +21,8 @@ #if defined(__i386__) && defined(__GNUC__) -#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ - long __tmpvar; \ +#define ZEND_SIGNED_MULTIPLY_INT(a, b, lval, dval, usedval) do { \ + zend_int_t __tmpvar; \ __asm__ ("imul %3,%0\n" \ "adc $0,%1" \ : "=r"(__tmpvar),"=r"(usedval) \ @@ -33,8 +33,8 @@ #elif defined(__x86_64__) && defined(__GNUC__) -#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ - long __tmpvar; \ +#define ZEND_SIGNED_MULTIPLY_INT(a, b, lval, dval, usedval) do { \ + zend_int_t __tmpvar; \ __asm__ ("imul %3,%0\n" \ "adc $0,%1" \ : "=r"(__tmpvar),"=r"(usedval) \ @@ -45,8 +45,8 @@ #elif defined(__arm__) && defined(__GNUC__) -#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ - long __tmpvar; \ +#define ZEND_SIGNED_MULTIPLY_INT(a, b, lval, dval, usedval) do { \ + zend_int_t __tmpvar; \ __asm__("smull %0, %1, %2, %3\n" \ "sub %1, %1, %0, asr #31" \ : "=r"(__tmpvar), "=r"(usedval) \ @@ -57,8 +57,8 @@ #elif defined(__aarch64__) && defined(__GNUC__) -#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ - long __tmpvar; \ +#define ZEND_SIGNED_MULTIPLY_INT(a, b, lval, dval, usedval) do { \ + zend_int_t __tmpvar; \ __asm__("mul %0, %2, %3\n" \ "smulh %1, %2, %3\n" \ "sub %1, %1, %0, asr #63\n" \ @@ -68,11 +68,24 @@ else (lval) = __tmpvar; \ } while (0) +#elif defined(ZEND_WIN32) + +#define ZEND_SIGNED_MULTIPLY_INT(a, b, lval, dval, usedval) do { \ + zend_int_t __lres = (a) * (b); \ + long double __dres = (long double)(a) * (long double)(b); \ + long double __delta = (long double) __lres - __dres; \ + if ( ((usedval) = (( __dres + __delta ) != __dres))) { \ + (dval) = __dres; \ + } else { \ + (lval) = __lres; \ + } \ +} while (0) + #elif SIZEOF_LONG == 4 && defined(HAVE_ZEND_LONG64) -#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ +#define ZEND_SIGNED_MULTIPLY_INT(a, b, lval, dval, usedval) do { \ zend_long64 __result = (zend_long64) (a) * (zend_long64) (b); \ - if (__result > LONG_MAX || __result < LONG_MIN) { \ + if (__result > ZEND_INT_MAX || __result < ZEND_INT_MIN) { \ (dval) = (double) __result; \ (usedval) = 1; \ } else { \ @@ -83,7 +96,7 @@ #else -#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \ +#define ZEND_SIGNED_MULTIPLY_INT(a, b, lval, dval, usedval) do { \ long __lres = (a) * (b); \ long double __dres = (long double)(a) * (long double)(b); \ long double __delta = (long double) __lres - __dres; \ |