diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-08-16 14:45:25 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-08-25 11:56:05 +0000 |
commit | 69a1018c9737751c2cc7daae2c03882dc81bd104 (patch) | |
tree | c0aa531dafbffcf0421454229a6bcd7f0aa828ee /src/qml/compiler | |
parent | 29e1531252ef435086a2b84e20a8e83304ca30bc (diff) |
Add optimized branch instructions for comparisons with ints
Change-Id: Ib5d5dc3b0e4a67b950ca9804edd3b6434fcdf9d1
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 22 | ||||
-rw-r--r-- | src/qml/compiler/qv4instr_moth.cpp | 9 | ||||
-rw-r--r-- | src/qml/compiler/qv4instr_moth_p.h | 14 |
3 files changed, 41 insertions, 4 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 379db2cd9c..5a7c12d0a2 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -1064,19 +1064,33 @@ Codegen::Reference Codegen::jumpBinop(QSOperator::Op oper, Reference &left, Refe jumpTarget = _expr.iffalse(); } - if (right.isConst()) { - if (right.constant == Encode::null() || right.constant == Encode::undefined()) { + if (right.isConst() && (oper == QSOperator::Equal || oper == QSOperator::NotEqual)) { + Value c = Primitive::fromReturnedValue(right.constant); + if (c.isNull() || c.isUndefined()) { + left.loadInAccumulator(); if (oper == QSOperator::Equal) { - left.loadInAccumulator(); Instruction::CmpJmpEqNull cjump; bytecodeGenerator->addJumpInstruction(cjump).link(*jumpTarget); return Reference(); } else if (oper == QSOperator::NotEqual) { - left.loadInAccumulator(); Instruction::CmpJmpNeNull cjump; bytecodeGenerator->addJumpInstruction(cjump).link(*jumpTarget); return Reference(); } + } else if (c.isInt32()) { + left.loadInAccumulator(); + if (oper == QSOperator::Equal) { + Instruction::CmpJmpEqInt cjump; + cjump.lhs = c.int_32(); + bytecodeGenerator->addJumpInstruction(cjump).link(*jumpTarget); + return Reference(); + } else if (oper == QSOperator::NotEqual) { + Instruction::CmpJmpNeInt cjump; + cjump.lhs = c.int_32(); + bytecodeGenerator->addJumpInstruction(cjump).link(*jumpTarget); + return Reference(); + } + } } diff --git a/src/qml/compiler/qv4instr_moth.cpp b/src/qml/compiler/qv4instr_moth.cpp index c1d99162f5..f3da508266 100644 --- a/src/qml/compiler/qv4instr_moth.cpp +++ b/src/qml/compiler/qv4instr_moth.cpp @@ -398,6 +398,15 @@ void dumpBytecode(const char *code, int len, int nLocals, int nFormals) d << absoluteInstructionOffset(start, instr); MOTH_END_INSTR(CmpJmpNeNull) + MOTH_BEGIN_INSTR(CmpJmpEqInt) + d << instr.lhs << ", " << absoluteInstructionOffset(start, instr); + MOTH_END_INSTR(CmpJmpEq) + + MOTH_BEGIN_INSTR(CmpJmpNeInt) + d << instr.lhs << ", " << absoluteInstructionOffset(start, instr); + MOTH_END_INSTR(CmpJmpNe) + + MOTH_BEGIN_INSTR(CmpJmpEq) d << instr.lhs.dump(nFormals) << ", " << absoluteInstructionOffset(start, instr); MOTH_END_INSTR(CmpJmpEq) diff --git a/src/qml/compiler/qv4instr_moth_p.h b/src/qml/compiler/qv4instr_moth_p.h index cb55e84442..c7e999e2e1 100644 --- a/src/qml/compiler/qv4instr_moth_p.h +++ b/src/qml/compiler/qv4instr_moth_p.h @@ -142,6 +142,8 @@ QT_BEGIN_NAMESPACE F(JumpNe, jumpNe) \ F(CmpJmpEqNull, cmpJmpEqNull) \ F(CmpJmpNeNull, cmpJmpNeNull) \ + F(CmpJmpEqInt, cmpJmpEqInt) \ + F(CmpJmpNeInt, cmpJmpNeInt) \ F(CmpJmpEq, cmpJmpEq) \ F(CmpJmpNe, cmpJmpNe) \ F(CmpJmpGt, cmpJmpGt) \ @@ -580,6 +582,16 @@ union Instr MOTH_INSTR_HEADER ptrdiff_t offset; }; + struct instr_cmpJmpEqInt { + MOTH_INSTR_HEADER + int lhs; + ptrdiff_t offset; + }; + struct instr_cmpJmpNeInt { + MOTH_INSTR_HEADER + int lhs; + ptrdiff_t offset; + }; struct instr_cmpJmpEq { MOTH_INSTR_HEADER StackSlot lhs; @@ -800,6 +812,8 @@ union Instr instr_jumpNe jumpNe; instr_cmpJmpEqNull cmpJmpEqNull; instr_cmpJmpNeNull cmpJmpNeNull; + instr_cmpJmpEqInt cmpJmpEqInt; + instr_cmpJmpNeInt cmpJmpNeInt; instr_cmpJmpEq cmpJmpEq; instr_cmpJmpNe cmpJmpNe; instr_cmpJmpGt cmpJmpGt; |