From c3a818d19e34e08e0759dedce18d9daa5ba7d94e Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 12 Nov 2015 14:01:48 +0100 Subject: 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 --- src/qml/jsruntime/qv4math_p.h | 73 ++++++------------------------------------- 1 file changed, 10 insertions(+), 63 deletions(-) (limited to 'src/qml/jsruntime') 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 #include +#include #include #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(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(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(a) * b).asReturnedValue(); - return Primitive::fromInt32(aa).asReturnedValue(); -} - -#else - -static inline QMLJS_READONLY ReturnedValue add_int32(int a, int b) -{ - qint64 result = static_cast(a) + b; - if (Q_UNLIKELY(result > INT_MAX || result < INT_MIN)) - return Primitive::fromDouble(static_cast(a) + b).asReturnedValue(); - return Primitive::fromInt32(static_cast(result)).asReturnedValue(); + return Primitive::fromInt32(result).asReturnedValue(); } -static inline QMLJS_READONLY ReturnedValue sub_int32(int a, int b) -{ - qint64 result = static_cast(a) - b; - if (Q_UNLIKELY(result > INT_MAX || result < INT_MIN)) - return Primitive::fromDouble(static_cast(a) - b).asReturnedValue(); - return Primitive::fromInt32(static_cast(result)).asReturnedValue(); -} - -static inline QMLJS_READONLY ReturnedValue mul_int32(int a, int b) -{ - qint64 result = static_cast(a) * b; - if (Q_UNLIKELY(result > INT_MAX || result < INT_MIN)) - return Primitive::fromDouble(static_cast(a) * b).asReturnedValue(); - return Primitive::fromInt32(static_cast(result)).asReturnedValue(); -} - -#endif - } QT_END_NAMESPACE -- cgit v1.2.3