diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2014-08-22 12:29:20 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@digia.com> | 2014-09-10 15:52:24 +0200 |
commit | 36b365040a18653b3c522ea573a506b955b6c4da (patch) | |
tree | 09a2aac4ce9c246aeb7272fe59ee8ed0ed981678 /src/qml/jsruntime/qv4math_p.h | |
parent | dac6bad5ba411ccc4e6e5fe18250a912d7e87b9c (diff) |
V4 runtime: tune Runtime::add/sub/mul a bit.
Tell the compiler to schedule the int32 case first, tune the double
conversion a bit (int64->double is quite expensive), and write the
function in such a way that it matches typical overflow idiom which
compilers recognize.
Change-Id: Ieae9a60275716002fbdbc54e1d7291c8aad8c927
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4math_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4math_p.h | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/src/qml/jsruntime/qv4math_p.h b/src/qml/jsruntime/qv4math_p.h index 7f194bdc3f..4fdad40a69 100644 --- a/src/qml/jsruntime/qv4math_p.h +++ b/src/qml/jsruntime/qv4math_p.h @@ -35,9 +35,7 @@ #include <qglobal.h> -#ifndef QMLJS_LLVM_RUNTIME -# include <QtCore/qnumeric.h> -#endif // QMLJS_LLVM_RUNTIME +#include <QtCore/qnumeric.h> #include <cmath> #if defined(Q_CC_GNU) @@ -50,9 +48,9 @@ QT_BEGIN_NAMESPACE namespace QV4 { -#if !defined(QMLJS_LLVM_RUNTIME) && defined(Q_CC_GNU) && defined(Q_PROCESSOR_X86) +#if defined(Q_CC_GNU) && defined(Q_PROCESSOR_X86) -static inline QMLJS_READONLY Value add_int32(int a, int b) +static inline QMLJS_READONLY ReturnedValue add_int32(int a, int b) { quint8 overflow = 0; int aa = a; @@ -63,13 +61,12 @@ static inline QMLJS_READONLY Value add_int32(int a, int b) : "r" (b), "1" (aa) : "cc" ); - if (!overflow) - return Primitive::fromInt32(aa); - qint64 result = static_cast<qint64>(a) + b; - return Primitive::fromDouble(result); + if (Q_UNLIKELY(overflow)) + return Primitive::fromDouble(static_cast<double>(a) + b).asReturnedValue(); + return Primitive::fromInt32(aa).asReturnedValue(); } -static inline QMLJS_READONLY Value sub_int32(int a, int b) +static inline QMLJS_READONLY ReturnedValue sub_int32(int a, int b) { quint8 overflow = 0; int aa = a; @@ -80,13 +77,12 @@ static inline QMLJS_READONLY Value sub_int32(int a, int b) : "r" (b), "1" (aa) : "cc" ); - if (!overflow) - return Primitive::fromInt32(aa); - qint64 result = static_cast<qint64>(a) - b; - return Primitive::fromDouble(result); + if (Q_UNLIKELY(overflow)) + return Primitive::fromDouble(static_cast<double>(a) - b).asReturnedValue(); + return Primitive::fromInt32(aa).asReturnedValue(); } -static inline QMLJS_READONLY Value mul_int32(int a, int b) +static inline QMLJS_READONLY ReturnedValue mul_int32(int a, int b) { quint8 overflow = 0; int aa = a; @@ -97,39 +93,38 @@ static inline QMLJS_READONLY Value mul_int32(int a, int b) : "r" (b), "1" (aa) : "cc" ); - if (!overflow) - return Primitive::fromInt32(aa); - qint64 result = static_cast<qint64>(a) * b; - return Primitive::fromDouble(result); + if (Q_UNLIKELY(overflow)) + return Primitive::fromDouble(static_cast<double>(a) * b).asReturnedValue(); + return Primitive::fromInt32(aa).asReturnedValue(); } #else -static inline QMLJS_READONLY Value add_int32(int a, int b) +static inline QMLJS_READONLY ReturnedValue add_int32(int a, int b) { qint64 result = static_cast<qint64>(a) + b; - if (result > INT_MAX || result < INT_MIN) - return Primitive::fromDouble(result); - return Primitive::fromInt32(static_cast<int>(result)); + 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 Value sub_int32(int a, int b) +static inline QMLJS_READONLY ReturnedValue sub_int32(int a, int b) { qint64 result = static_cast<qint64>(a) - b; - if (result > INT_MAX || result < INT_MIN) - return Primitive::fromDouble(result); - return Primitive::fromInt32(static_cast<int>(result)); + 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 Value mul_int32(int a, int b) +static inline QMLJS_READONLY ReturnedValue mul_int32(int a, int b) { qint64 result = static_cast<qint64>(a) * b; - if (result > INT_MAX || result < INT_MIN) - return Primitive::fromDouble(result); - return Primitive::fromInt32(static_cast<int>(result)); + 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 // defined(QMLJS_INLINE_MATH) +#endif } |