diff options
| author | Lars Knoll <lars.knoll@qt.io> | 2017-08-06 22:07:52 +0200 |
|---|---|---|
| committer | Lars Knoll <lars.knoll@qt.io> | 2017-08-08 18:59:47 +0000 |
| commit | 01c338023a3a604bb24c2efb18d48f9bac33e6bc (patch) | |
| tree | dd5fbedf26dd680323a64bdc5bfe82263199d413 /src/qml/jsruntime | |
| parent | a0720e562c464a5b22e4cbd74b48212e5d3bf6e4 (diff) | |
Inline more of the runtime code into the interpreter
Change-Id: I4744c9b39d4de599f02dd91622dd19713c8cc7eb
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime')
| -rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 79 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4runtimeapi_p.h | 8 | ||||
| -rw-r--r-- | src/qml/jsruntime/qv4vme_moth.cpp | 42 |
3 files changed, 25 insertions, 104 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index d310eba434..8def6ecdae 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -1324,30 +1324,6 @@ QV4::ReturnedValue Runtime::method_setupArgumentsObject(ExecutionEngine *engine) #endif // V4_BOOTSTRAP -QV4::ReturnedValue Runtime::method_increment(const Value &value) -{ - TRACE1(value); - - if (value.isInteger() && value.integerValue() < INT_MAX) - return Encode(value.integerValue() + 1); - else { - double d = value.toNumber(); - return Encode(d + 1.); - } -} - -QV4::ReturnedValue Runtime::method_decrement(const Value &value) -{ - TRACE1(value); - - if (value.isInteger() && value.integerValue() > INT_MIN) - return Encode(value.integerValue() - 1); - else { - double d = value.toNumber(); - return Encode(d - 1.); - } -} - ReturnedValue Runtime::method_toDouble(const Value &value) { TRACE1(value); @@ -1455,19 +1431,6 @@ void Runtime::method_convertThisToObject(ExecutionEngine *engine) } } -ReturnedValue Runtime::method_uPlus(const Value &value) -{ - TRACE1(value); - - if (value.isNumber()) - return value.asReturnedValue(); - if (value.integerCompatible()) - return Encode(value.int_32()); - - double n = value.toNumberImpl(); - return Encode(n); -} - ReturnedValue Runtime::method_uMinus(const Value &value) { TRACE1(value); @@ -1482,49 +1445,7 @@ ReturnedValue Runtime::method_uMinus(const Value &value) } } -ReturnedValue Runtime::method_complement(const Value &value) -{ - TRACE1(value); - - int n = value.toInt32(); - return Encode((int)~n); -} - -ReturnedValue Runtime::method_uNot(const Value &value) -{ - TRACE1(value); - - bool b = value.toBoolean(); - return Encode(!b); -} - // binary operators -ReturnedValue Runtime::method_bitOr(const Value &left, const Value &right) -{ - TRACE2(left, right); - - int lval = left.toInt32(); - int rval = right.toInt32(); - return Encode(lval | rval); -} - -ReturnedValue Runtime::method_bitXor(const Value &left, const Value &right) -{ - TRACE2(left, right); - - int lval = left.toInt32(); - int rval = right.toInt32(); - return Encode(lval ^ rval); -} - -ReturnedValue Runtime::method_bitAnd(const Value &left, const Value &right) -{ - TRACE2(left, right); - - int lval = left.toInt32(); - int rval = right.toInt32(); - return Encode(lval & rval); -} #ifndef V4_BOOTSTRAP ReturnedValue Runtime::method_add(ExecutionEngine *engine, const Value &left, const Value &right) diff --git a/src/qml/jsruntime/qv4runtimeapi_p.h b/src/qml/jsruntime/qv4runtimeapi_p.h index 38e5d027ce..0fbffde944 100644 --- a/src/qml/jsruntime/qv4runtimeapi_p.h +++ b/src/qml/jsruntime/qv4runtimeapi_p.h @@ -150,21 +150,13 @@ struct ExceptionCheck<void (*)(QV4::NoThrowEngine *, A, B, C)> { F(ReturnedValue, foreachNextPropertyName, (const Value &foreach_iterator)) \ \ /* unary operators */ \ - F(ReturnedValue, uPlus, (const Value &value)) \ F(ReturnedValue, uMinus, (const Value &value)) \ - F(ReturnedValue, uNot, (const Value &value)) \ - F(ReturnedValue, complement, (const Value &value)) \ - F(ReturnedValue, increment, (const Value &value)) \ - F(ReturnedValue, decrement, (const Value &value)) \ \ /* binary operators */ \ F(ReturnedValue, instanceof, (ExecutionEngine *engine, const Value &left, const Value &right)) \ F(ReturnedValue, in, (ExecutionEngine *engine, const Value &left, const Value &right)) \ F(ReturnedValue, add, (ExecutionEngine *engine, const Value &left, const Value &right)) \ F(ReturnedValue, addString, (ExecutionEngine *engine, const Value &left, const Value &right)) \ - F(ReturnedValue, bitOr, (const Value &left, const Value &right)) \ - F(ReturnedValue, bitXor, (const Value &left, const Value &right)) \ - F(ReturnedValue, bitAnd, (const Value &left, const Value &right)) \ F(ReturnedValue, sub, (const Value &left, const Value &right)) \ F(ReturnedValue, mul, (const Value &left, const Value &right)) \ F(ReturnedValue, div, (const Value &left, const Value &right)) \ diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index e7cfb8b7e1..21a2095196 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -887,50 +887,49 @@ QV4::ReturnedValue VME::exec(Function *function) if (accumulator.integerCompatible()) { STORE_ACCUMULATOR(Encode(!static_cast<bool>(accumulator.int_32()))) } else { - STORE_ACCUMULATOR(Runtime::method_uNot(accumulator)); + STORE_ACCUMULATOR(Encode(!accumulator.toBoolean())); } MOTH_END_INSTR(UNot) MOTH_BEGIN_INSTR(UPlus) - if (!accumulator.isNumber()) { - STORE_ACCUMULATOR(Runtime::method_uPlus(accumulator)); - } + if (!accumulator.isNumber()) + STORE_ACCUMULATOR(Encode(accumulator.toNumberImpl())); MOTH_END_INSTR(UPlus) MOTH_BEGIN_INSTR(UMinus) - if (Q_LIKELY(accumulator.isInteger() && accumulator.int_32() != 0 && + if (Q_LIKELY(accumulator.integerCompatible() && accumulator.int_32() != 0 && accumulator.int_32() != std::numeric_limits<int>::min())) { accumulator = sub_int32(0, accumulator.int_32()); } else { - STORE_ACCUMULATOR(Encode(!accumulator.toBoolean())); + STORE_ACCUMULATOR(Encode(-accumulator.toNumber())); } MOTH_END_INSTR(UMinus) MOTH_BEGIN_INSTR(UCompl) - if (Q_LIKELY(accumulator.isInteger())) { + if (Q_LIKELY(accumulator.integerCompatible())) { accumulator.setInt_32(~accumulator.int_32()); } else { - STORE_ACCUMULATOR(Runtime::method_complement(accumulator)); + STORE_ACCUMULATOR(Encode((int)~accumulator.toInt32())); } MOTH_END_INSTR(UCompl) MOTH_BEGIN_INSTR(Increment) - if (Q_LIKELY(accumulator.isInteger())) { + if (Q_LIKELY(accumulator.integerCompatible())) { accumulator = add_int32(accumulator.int_32(), 1); } else if (accumulator.isDouble()) { accumulator = QV4::Encode(accumulator.doubleValue() + 1.); } else { - STORE_ACCUMULATOR(Runtime::method_increment(accumulator)); + STORE_ACCUMULATOR(Encode(accumulator.toNumberImpl() + 1.)); } MOTH_END_INSTR(Increment) MOTH_BEGIN_INSTR(Decrement) - if (Q_LIKELY(accumulator.isInteger())) { + if (Q_LIKELY(accumulator.integerCompatible())) { accumulator = sub_int32(accumulator.int_32(), 1); } else if (accumulator.isDouble()) { accumulator = QV4::Encode(accumulator.doubleValue() - 1.); } else { - STORE_ACCUMULATOR(Runtime::method_decrement(accumulator)); + STORE_ACCUMULATOR(Encode(accumulator.toNumberImpl() - 1.)); } MOTH_END_INSTR(Decrement) @@ -943,6 +942,8 @@ QV4::ReturnedValue VME::exec(Function *function) QV4::Value lhs = STACK_VALUE(instr.lhs); if (Q_LIKELY(Value::integerCompatible(lhs, accumulator))) { accumulator = add_int32(lhs.int_32(), accumulator.int_32()); + } else if (lhs.isNumber() && accumulator.isNumber()) { + accumulator = Encode(lhs.asDouble() + accumulator.asDouble()); } else { STORE_ACCUMULATOR(Runtime::method_add(engine, lhs, accumulator)); } @@ -952,6 +953,8 @@ QV4::ReturnedValue VME::exec(Function *function) QV4::Value lhs = STACK_VALUE(instr.lhs); if (Q_LIKELY(Value::integerCompatible(lhs, accumulator))) { accumulator = sub_int32(lhs.int_32(), accumulator.int_32()); + } else if (lhs.isNumber() && accumulator.isNumber()) { + accumulator = Encode(lhs.asDouble() - accumulator.asDouble()); } else { STORE_ACCUMULATOR(Runtime::method_sub(lhs, accumulator)); } @@ -961,29 +964,31 @@ QV4::ReturnedValue VME::exec(Function *function) QV4::Value lhs = STACK_VALUE(instr.lhs); if (Q_LIKELY(Value::integerCompatible(lhs, accumulator))) { accumulator = mul_int32(lhs.int_32(), accumulator.int_32()); + } else if (lhs.isNumber() && accumulator.isNumber()) { + accumulator = Encode(lhs.asDouble() * accumulator.asDouble()); } else { STORE_ACCUMULATOR(Runtime::method_mul(lhs, accumulator)); } MOTH_END_INSTR(Mul) MOTH_BEGIN_INSTR(BitAnd) - STORE_ACCUMULATOR(Runtime::method_bitAnd(STACK_VALUE(instr.lhs), accumulator)); + STORE_ACCUMULATOR(Encode((int)(STACK_VALUE(instr.lhs).toInt32() & accumulator.toInt32()))); MOTH_END_INSTR(BitAnd) MOTH_BEGIN_INSTR(BitOr) - STORE_ACCUMULATOR(Runtime::method_bitOr(STACK_VALUE(instr.lhs), accumulator)); + STORE_ACCUMULATOR(Encode((int)(STACK_VALUE(instr.lhs).toInt32() | accumulator.toInt32()))); MOTH_END_INSTR(BitOr) MOTH_BEGIN_INSTR(BitXor) - STORE_ACCUMULATOR(Runtime::method_bitXor(STACK_VALUE(instr.lhs), accumulator)); + STORE_ACCUMULATOR(Encode((int)(STACK_VALUE(instr.lhs).toInt32() ^ accumulator.toInt32()))); MOTH_END_INSTR(BitXor) MOTH_BEGIN_INSTR(Shr) - STORE_ACCUMULATOR(Runtime::method_shr(STACK_VALUE(instr.lhs), accumulator)); + STORE_ACCUMULATOR(Encode((int)(STACK_VALUE(instr.lhs).toInt32() >> (accumulator.toInt32() & 0x1f)))); MOTH_END_INSTR(Shr) MOTH_BEGIN_INSTR(Shl) - STORE_ACCUMULATOR(Runtime::method_shl(STACK_VALUE(instr.lhs), accumulator)); + STORE_ACCUMULATOR(Encode((int)(STACK_VALUE(instr.lhs).toInt32() << (accumulator.toInt32() & 0x1f)))); MOTH_END_INSTR(Shl) MOTH_BEGIN_INSTR(BitAndConst) @@ -997,6 +1002,9 @@ QV4::ReturnedValue VME::exec(Function *function) MOTH_BEGIN_INSTR(BitOrConst) if (Q_LIKELY(accumulator.isInteger())) { accumulator.setInt_32(accumulator.int_32() | instr.rhs); + } else if (accumulator.isDouble()) { + int i = (int)(qint64)accumulator.doubleValue(); + STORE_ACCUMULATOR(QV4::Primitive::fromInt32(i | instr.rhs)); } else { STORE_ACCUMULATOR(QV4::Primitive::fromInt32(accumulator.toInt32() | instr.rhs)); } |
