diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-08-12 00:10:04 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-08-18 09:58:38 +0000 |
commit | c8a2e4acb101967c254d7e9d3c4e7d9f25c5eecc (patch) | |
tree | 8e2fb1dce06478a8370176b42d69a704ca56104d /src | |
parent | af504fc0dabd65ac5a4eef2233ad87ed9a54c500 (diff) |
Add specialized instructions for loading undefined, null and ints
Change-Id: Iab0b77328f5756972ef6eff82c0041b184290a32
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 25 | ||||
-rw-r--r-- | src/qml/compiler/qv4instr_moth.cpp | 10 | ||||
-rw-r--r-- | src/qml/compiler/qv4instr_moth_p.h | 16 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4vme_moth.cpp | 12 |
4 files changed, 60 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index a91a6e62e0..6492bb6028 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -3001,9 +3001,28 @@ void Codegen::Reference::loadInAccumulator() const case Accumulator: return; case Const: { - Instruction::LoadConst load; - load.index = codegen->registerConstant(constant); - codegen->bytecodeGenerator->addInstruction(load); + if (constant == Encode::null()) { + Instruction::LoadNull load; + codegen->bytecodeGenerator->addInstruction(load); + } else if (constant == Encode::undefined()) { + Instruction::LoadUndefined load; + codegen->bytecodeGenerator->addInstruction(load); + } else { + Value p = Primitive::fromReturnedValue(constant); + if (p.isNumber()) { + double d = p.asDouble(); + int i = static_cast<int>(d); + if (d == i && (d != 0 || !std::signbit(d))) { + Instruction::LoadInt load; + load.value = Primitive::fromReturnedValue(constant).toInt32(); + codegen->bytecodeGenerator->addInstruction(load); + return; + } + } + Instruction::LoadConst load; + load.index = codegen->registerConstant(constant); + codegen->bytecodeGenerator->addInstruction(load); + } } return; case StackSlot: { Instruction::LoadReg load; diff --git a/src/qml/compiler/qv4instr_moth.cpp b/src/qml/compiler/qv4instr_moth.cpp index ed2f556e01..b885db30bf 100644 --- a/src/qml/compiler/qv4instr_moth.cpp +++ b/src/qml/compiler/qv4instr_moth.cpp @@ -133,6 +133,16 @@ void dumpBytecode(const char *code, int len, int nFormals) d << "C" << instr.index; MOTH_END_INSTR(LoadConst) + MOTH_BEGIN_INSTR(LoadNull) + MOTH_END_INSTR(LoadNull) + + MOTH_BEGIN_INSTR(LoadUndefined) + MOTH_END_INSTR(LoadUndefined) + + MOTH_BEGIN_INSTR(LoadInt) + d << instr.value; + MOTH_END_INSTR(LoadInt) + MOTH_BEGIN_INSTR(MoveConst) d << instr.destTemp.dump(nFormals) << ", C" << instr.constIndex; MOTH_END_INSTR(MoveConst) diff --git a/src/qml/compiler/qv4instr_moth_p.h b/src/qml/compiler/qv4instr_moth_p.h index d07e44c41b..df1c9ddef7 100644 --- a/src/qml/compiler/qv4instr_moth_p.h +++ b/src/qml/compiler/qv4instr_moth_p.h @@ -72,6 +72,9 @@ QT_BEGIN_NAMESPACE F(Ret, ret) \ MOTH_DEBUG_INSTR(F) \ F(LoadConst, loadConst) \ + F(LoadNull, loadNull) \ + F(LoadUndefined, loadUndefined) \ + F(LoadInt, loadInt) \ F(MoveConst, moveConst) \ F(LoadReg, loadReg) \ F(StoreReg, storeReg) \ @@ -266,6 +269,16 @@ union Instr MOTH_INSTR_HEADER int index; }; + struct instr_loadNull { + MOTH_INSTR_HEADER + }; + struct instr_loadUndefined { + MOTH_INSTR_HEADER + }; + struct instr_loadInt { + MOTH_INSTR_HEADER + int value; + }; struct instr_moveConst { MOTH_INSTR_HEADER int constIndex; @@ -711,6 +724,9 @@ union Instr instr_line line; instr_debug debug; instr_loadConst loadConst; + instr_loadNull loadNull; + instr_loadUndefined loadUndefined; + instr_loadInt loadInt; instr_moveConst moveConst; instr_loadReg loadReg; instr_storeReg storeReg; diff --git a/src/qml/jsruntime/qv4vme_moth.cpp b/src/qml/jsruntime/qv4vme_moth.cpp index b17341e5e5..72a707fe51 100644 --- a/src/qml/jsruntime/qv4vme_moth.cpp +++ b/src/qml/jsruntime/qv4vme_moth.cpp @@ -468,6 +468,18 @@ QV4::ReturnedValue VME::exec(const FunctionObject *jsFunction, CallData *callDat accumulator = constant(function, instr.index); MOTH_END_INSTR(LoadConst) + MOTH_BEGIN_INSTR(LoadNull) + accumulator = Encode::null(); + MOTH_END_INSTR(LoadNull) + + MOTH_BEGIN_INSTR(LoadUndefined) + accumulator = Encode::undefined(); + MOTH_END_INSTR(LoadUndefined) + + MOTH_BEGIN_INSTR(LoadInt) + accumulator = Encode(instr.value); + MOTH_END_INSTR(LoadInt) + MOTH_BEGIN_INSTR(MoveConst) STACK_VALUE(instr.destTemp) = constant(function, instr.constIndex); MOTH_END_INSTR(MoveConst) |