aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2015-11-12 14:01:48 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-11-27 20:38:37 +0000
commitc3a818d19e34e08e0759dedce18d9daa5ba7d94e (patch)
treea916ad6bac7f65d2727c64f3389b658081ff1154
parent77de21f93642413fec8f6138be1612129941661d (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>
-rw-r--r--src/qml/jsruntime/qv4math_p.h73
-rw-r--r--src/qmldevtools/qmldevtools.pro2
2 files changed, 11 insertions, 64 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
diff --git a/src/qmldevtools/qmldevtools.pro b/src/qmldevtools/qmldevtools.pro
index 85f21ce6f6..0e32dc51e2 100644
--- a/src/qmldevtools/qmldevtools.pro
+++ b/src/qmldevtools/qmldevtools.pro
@@ -1,6 +1,6 @@
option(host_build)
TARGET = QtQmlDevTools
-QT = core
+QT = core-private
CONFIG += static internal_module qmldevtools_build
# Don't use pch because the auto-generated header refers to QtBootstrap,