From a4f8b9ae6dfacf9ad5c190cde6098ebf13102f41 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 24 Aug 2017 14:10:41 +0200 Subject: Decode instructions into registers Don't use the old instruction structures in the VME anymore, instead directly decode into scoped registers. Change-Id: Ie03ebad98050ebfd9eb9cc7e9273e5db92884a89 Reviewed-by: Simon Hausmann --- src/qml/compiler/qv4bytecodegenerator.cpp | 2 +- src/qml/compiler/qv4bytecodegenerator_p.h | 4 ++-- src/qml/compiler/qv4instr_moth.cpp | 4 ++-- src/qml/compiler/qv4instr_moth_p.h | 34 ++++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) (limited to 'src/qml/compiler') diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp index 3c28f6a719..1d4e91bdf6 100644 --- a/src/qml/compiler/qv4bytecodegenerator.cpp +++ b/src/qml/compiler/qv4bytecodegenerator.cpp @@ -97,7 +97,7 @@ void BytecodeGenerator::finalize(Compiler::Context *context) int offset = instructionOffsets.at(j.instructionIndex) + j.offset; // qDebug() << "offset data is at" << offset; char *c = code.data() + offset; - int linkedInstructionOffset = instructionOffsets.at(linkedInstruction) - offset; + int linkedInstructionOffset = instructionOffsets.at(linkedInstruction) - instructionOffsets.at(j.instructionIndex + 1); // qDebug() << "linked instruction" << linkedInstruction << "at " << instructionOffsets.at(linkedInstruction); memcpy(c, &linkedInstructionOffset, sizeof(int)); } diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h index a0255b2059..594c97790b 100644 --- a/src/qml/compiler/qv4bytecodegenerator_p.h +++ b/src/qml/compiler/qv4bytecodegenerator_p.h @@ -149,7 +149,7 @@ public: void addInstruction(const InstrData &data) { Instr genericInstr; - genericInstr.Common.instructionType = static_cast(InstrT); + genericInstr.Common.instructionType = InstrT; InstrMeta::setDataNoCommon(genericInstr, data); addInstructionHelper(InstrMeta::Size, genericInstr); } @@ -229,7 +229,7 @@ public: Jump addJumpInstruction(const InstrData &data) { Instr genericInstr; - genericInstr.Common.instructionType = static_cast(InstrT); + genericInstr.Common.instructionType = InstrT; InstrMeta::setDataNoCommon(genericInstr, data); return Jump(this, addInstructionHelper(InstrMeta::Size, genericInstr), offsetof(InstrData, offset)); } diff --git a/src/qml/compiler/qv4instr_moth.cpp b/src/qml/compiler/qv4instr_moth.cpp index ec4e99c4bf..ba52fc5f9a 100644 --- a/src/qml/compiler/qv4instr_moth.cpp +++ b/src/qml/compiler/qv4instr_moth.cpp @@ -86,7 +86,7 @@ static QString toString(QV4::ReturnedValue v) template size_t absoluteInstructionOffset(const char *codeStart, const T &instr) { - return reinterpret_cast(&instr) - codeStart + offsetof(T, offset) + instr.offset; + return reinterpret_cast(&instr) - codeStart + sizeof(T) + instr.offset; } #define MOTH_BEGIN_INSTR(I) \ @@ -126,7 +126,7 @@ void dumpBytecode(const char *code, int len, int nLocals, int nFormals, int star lastLine = line; else line = -1; - switch (genericInstr->Common.instructionType) { + switch (Instr::Type(genericInstr->Common.instructionType)) { MOTH_BEGIN_INSTR(LoadReg) d << StackSlot::createRegister(instr.reg).dump(nFormals); diff --git a/src/qml/compiler/qv4instr_moth_p.h b/src/qml/compiler/qv4instr_moth_p.h index 529584f1dd..6af80689a6 100644 --- a/src/qml/compiler/qv4instr_moth_p.h +++ b/src/qml/compiler/qv4instr_moth_p.h @@ -297,7 +297,7 @@ QT_BEGIN_NAMESPACE #define MOTH_INSTR_ALIGN_MASK (Q_ALIGNOF(QV4::Moth::Instr) - 1) -#define MOTH_INSTR_HEADER union { Instr::Type instructionType; quint64 _dummy; }; +#define MOTH_INSTR_HEADER int instructionType; #define MOTH_INSTR_ENUM(I) I, #define MOTH_INSTR_SIZE(I) ((sizeof(QV4::Moth::Instr::instr_##I) + MOTH_INSTR_ALIGN_MASK) & ~MOTH_INSTR_ALIGN_MASK) @@ -340,6 +340,38 @@ QT_BEGIN_NAMESPACE instr_##name name; +#define MOTH_DECODE_ARG(arg, type, offset) \ + arg = reinterpret_cast(code)[offset] +#define MOTH_ADJUST_CODE(type, nargs) \ + code += nargs*sizeof(type) + +#define MOTH_DECODE_INSTRUCTION(name, nargs, ...) \ + MOTH_DEFINE_ARGS(nargs, __VA_ARGS__) \ + op_int_##name: \ + MOTH_DECODE_ARGS(name, int, nargs, __VA_ARGS__) \ + MOTH_ADJUST_CODE(int, nargs); \ + +#define MOTH_DECODE_ARGS(name, type, nargs, ...) \ + MOTH_DECODE_ARGS##nargs(name, type, __VA_ARGS__) + +#define MOTH_DECODE_ARGS0(name, type, dummy) +#define MOTH_DECODE_ARGS1(name, type, arg) \ + MOTH_DECODE_ARG(arg, type, 0); +#define MOTH_DECODE_ARGS2(name, type, arg1, arg2) \ + MOTH_DECODE_ARGS1(name, type, arg1); \ + MOTH_DECODE_ARG(arg2, type, 1); +#define MOTH_DECODE_ARGS3(name, type, arg1, arg2, arg3) \ + MOTH_DECODE_ARGS2(name, type, arg1, arg2); \ + MOTH_DECODE_ARG(arg3, type, 2); +#define MOTH_DECODE_ARGS4(name, type, arg1, arg2, arg3, arg4) \ + MOTH_DECODE_ARGS3(name, type, arg1, arg2, arg3); \ + MOTH_DECODE_ARG(arg4, type, 3); + +#define MOTH_DISPATCH() \ + int instr = *reinterpret_cast(code); \ + code += 4; \ + goto *jumpTable[instr]; + namespace QV4 { namespace Moth { -- cgit v1.2.3