diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2015-11-12 14:01:48 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-11-27 20:38:37 +0000 |
commit | c3a818d19e34e08e0759dedce18d9daa5ba7d94e (patch) | |
tree | a916ad6bac7f65d2727c64f3389b658081ff1154 /src/qml/jsruntime/qv4math_p.h | |
parent | 77de21f93642413fec8f6138be1612129941661d (diff) |
Use qtbase add/sub/mul with overflow implementations.
Those use compiler intrinsics when available. If not, the same code that
was previously in qtdeclarative is used.
Depends on 5ff7a3d96e0ce0dcb3d388b53d038cdd40c7a975 in qtbase.
Change-Id: I8adf1a9d368ffc4e368260de518725ed7be6d2b8
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/qml/jsruntime/qv4math_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4math_p.h | 73 |
1 files changed, 10 insertions, 63 deletions
diff --git a/src/qml/jsruntime/qv4math_p.h b/src/qml/jsruntime/qv4math_p.h index cf627bcc5d..51031356bc 100644 --- a/src/qml/jsruntime/qv4math_p.h +++ b/src/qml/jsruntime/qv4math_p.h @@ -47,6 +47,7 @@ #include <qglobal.h> #include <QtCore/qnumeric.h> +#include <QtCore/private/qnumeric_p.h> #include <cmath> #if defined(Q_CC_GNU) @@ -59,84 +60,30 @@ QT_BEGIN_NAMESPACE namespace QV4 { -#if defined(Q_CC_GNU) && defined(Q_PROCESSOR_X86) - static inline QMLJS_READONLY ReturnedValue add_int32(int a, int b) { - quint8 overflow = 0; - int aa = a; - - asm ("addl %2, %1\n" - "seto %0" - : "=q" (overflow), "=r" (aa) - : "r" (b), "1" (aa) - : "cc" - ); - if (Q_UNLIKELY(overflow)) + int result; + if (Q_UNLIKELY(add_overflow(a, b, &result))) return Primitive::fromDouble(static_cast<double>(a) + b).asReturnedValue(); - return Primitive::fromInt32(aa).asReturnedValue(); + return Primitive::fromInt32(result).asReturnedValue(); } static inline QMLJS_READONLY ReturnedValue sub_int32(int a, int b) { - quint8 overflow = 0; - int aa = a; - - asm ("subl %2, %1\n" - "seto %0" - : "=q" (overflow), "=r" (aa) - : "r" (b), "1" (aa) - : "cc" - ); - if (Q_UNLIKELY(overflow)) + int result; + if (Q_UNLIKELY(sub_overflow(a, b, &result))) return Primitive::fromDouble(static_cast<double>(a) - b).asReturnedValue(); - return Primitive::fromInt32(aa).asReturnedValue(); + return Primitive::fromInt32(result).asReturnedValue(); } static inline QMLJS_READONLY ReturnedValue mul_int32(int a, int b) { - quint8 overflow = 0; - int aa = a; - - asm ("imul %2, %1\n" - "setc %0" - : "=q" (overflow), "=r" (aa) - : "r" (b), "1" (aa) - : "cc" - ); - if (Q_UNLIKELY(overflow)) + int result; + if (Q_UNLIKELY(mul_overflow(a, b, &result))) return Primitive::fromDouble(static_cast<double>(a) * b).asReturnedValue(); - return Primitive::fromInt32(aa).asReturnedValue(); -} - -#else - -static inline QMLJS_READONLY ReturnedValue add_int32(int a, int b) -{ - qint64 result = static_cast<qint64>(a) + b; - if (Q_UNLIKELY(result > INT_MAX || result < INT_MIN)) - return Primitive::fromDouble(static_cast<double>(a) + b).asReturnedValue(); - return Primitive::fromInt32(static_cast<int>(result)).asReturnedValue(); + return Primitive::fromInt32(result).asReturnedValue(); } -static inline QMLJS_READONLY ReturnedValue sub_int32(int a, int b) -{ - qint64 result = static_cast<qint64>(a) - b; - if (Q_UNLIKELY(result > INT_MAX || result < INT_MIN)) - return Primitive::fromDouble(static_cast<double>(a) - b).asReturnedValue(); - return Primitive::fromInt32(static_cast<int>(result)).asReturnedValue(); -} - -static inline QMLJS_READONLY ReturnedValue mul_int32(int a, int b) -{ - qint64 result = static_cast<qint64>(a) * b; - if (Q_UNLIKELY(result > INT_MAX || result < INT_MIN)) - return Primitive::fromDouble(static_cast<double>(a) * b).asReturnedValue(); - return Primitive::fromInt32(static_cast<int>(result)).asReturnedValue(); -} - -#endif - } QT_END_NAMESPACE |