Introduce the wide/xwide instruction prefixes

And add proper decoding for the prefixed instructions to the
VME and bytecode dumper.

We still only generate XWide instructions, that will get fixed
in the next change.

Change-Id: I6d2dc6a0a4f706044038274ca79e019a6c9bb7d9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Lars Knoll 2017-08-24 16:04:19 +02:00
parent cd67176bb2
commit 2951f6105a
4 changed files with 76 additions and 27 deletions

View File

@ -71,11 +71,12 @@ void BytecodeGenerator::compressInstructions()
{
for (auto &i : instructions) {
Instr instr = i.instr;
i.packed[0] = static_cast<char>(i.type);
memcpy(i.packed + 1, reinterpret_cast<char *>(&instr), i.size);
++i.size;
i.packed[0] = static_cast<char>(Instr::Type::XWide);
i.packed[1] = static_cast<char>(i.type);
memcpy(i.packed + 2, reinterpret_cast<char *>(&instr), i.size);
i.size += 2;
if (i.offsetForJump != -1)
++i.offsetForJump;
i.offsetForJump += 2;
}
}

View File

@ -92,7 +92,12 @@ static QString toString(QV4::ReturnedValue v)
QDebug d = qDebug(); \
d.noquote(); \
d.nospace(); \
d << alignedLineNumber(line) << alignedNumber(int(code - start)).constData() << ": " << #instr << " ";
d << alignedLineNumber(line) << alignedNumber(codeOffset).constData() << ": " << #instr; \
switch(mode) { \
case Normal: d << " "; break; \
case Wide: d << ".Wide "; break; \
case XWide: d << ".XWide "; break; \
}
#define MOTH_END_INSTR(instr) \
continue; \
@ -114,13 +119,7 @@ void dumpConstantTable(const Value *constants, uint count)
void dumpBytecode(const char *code, int len, int nLocals, int nFormals, int startLine, const QVector<int> &lineNumberMapping)
{
#ifdef MOTH_THREADED_INTERPRETER
#define MOTH_INSTR_ADDR(I) &&op_int_##I,
static void *jumpTable[] = {
FOR_EACH_MOTH_INSTR(MOTH_INSTR_ADDR)
};
#undef MOTH_INSTR_ADDR
#endif
MOTH_JUMP_TABLE;
int lastLine = -1;
const char *start = code;
@ -131,16 +130,30 @@ void dumpBytecode(const char *code, int len, int nLocals, int nFormals, int star
lastLine = line;
else
line = -1;
enum Mode {
Normal,
Wide,
XWide
} mode = Normal;
int codeOffset = (code - start);
MOTH_DISPATCH()
MOTH_BEGIN_INSTR(Nop)
MOTH_END_INSTR(Nop)
MOTH_BEGIN_INSTR(Wide)
MOTH_END_INSTR(Wide)
{
INSTR_Wide(MOTH_DECODE) \
mode = Wide;
MOTH_DISPATCH_WIDE();
}
MOTH_BEGIN_INSTR(XWide)
MOTH_END_INSTR(XWide)
{
INSTR_XWide(MOTH_DECODE) \
mode = XWide;
MOTH_DISPATCH_XWIDE();
}
MOTH_BEGIN_INSTR(LoadReg)
d << StackSlot::createRegister(reg).dump(nFormals);

View File

@ -341,6 +341,27 @@ QT_BEGIN_NAMESPACE
#define MOTH_EMIT_INSTR_MEMBER_INSTRUCTION(name, nargs, ...) \
instr_##name name;
/* collect jump labels */
#define COLLECT_LABELS(instr) \
INSTR_##instr(GET_LABEL)
#define GET_LABEL_INSTRUCTION(name, ...) \
&&op_char_##name,
#define COLLECT_LABELS_WIDE(instr) \
INSTR_##instr(GET_LABEL_WIDE)
#define GET_LABEL_WIDE_INSTRUCTION(name, ...) \
&&op_short_##name,
#define COLLECT_LABELS_XWIDE(instr) \
INSTR_##instr(GET_LABEL_XWIDE)
#define GET_LABEL_XWIDE_INSTRUCTION(name, ...) \
&&op_int_##name,
#define MOTH_JUMP_TABLE \
static const void *jumpTable[] = { FOR_EACH_MOTH_INSTR(COLLECT_LABELS) }; \
static const void *jumpTableWide[] = { FOR_EACH_MOTH_INSTR(COLLECT_LABELS_WIDE) }; \
static const void *jumpTableXWide[] = { FOR_EACH_MOTH_INSTR(COLLECT_LABELS_XWIDE) }
#define MOTH_DECODE_ARG(arg, type, offset) \
arg = reinterpret_cast<const type *>(code)[offset]
@ -352,6 +373,16 @@ QT_BEGIN_NAMESPACE
op_int_##name: \
MOTH_DECODE_ARGS(name, int, nargs, __VA_ARGS__) \
MOTH_ADJUST_CODE(int, nargs); \
goto op_main_##name; \
op_short_##name: \
MOTH_DECODE_ARGS(name, short, nargs, __VA_ARGS__) \
MOTH_ADJUST_CODE(short, nargs); \
goto op_main_##name; \
op_char_##name: \
MOTH_DECODE_ARGS(name, char, nargs, __VA_ARGS__) \
MOTH_ADJUST_CODE(char, nargs); \
op_main_##name: \
; \
#define MOTH_DECODE_ARGS(name, type, nargs, ...) \
MOTH_DECODE_ARGS##nargs(name, type, __VA_ARGS__)
@ -374,6 +405,16 @@ QT_BEGIN_NAMESPACE
++code; \
goto *jumpTable[instr];
#define MOTH_DISPATCH_WIDE() \
int winstr = *code; \
++code; \
goto *jumpTableWide[winstr];
#define MOTH_DISPATCH_XWIDE() \
int xwinstr = *code; \
++code; \
goto *jumpTableXWide[xwinstr];
namespace QV4 {
namespace Moth {

View File

@ -519,13 +519,7 @@ QV4::ReturnedValue VME::exec(const FunctionObject *jsFunction, CallData *callDat
{
qt_v4ResolvePendingBreakpointsHook();
#ifdef MOTH_THREADED_INTERPRETER
#define MOTH_INSTR_ADDR(I) &&op_int_##I,
static void *jumpTable[] = {
FOR_EACH_MOTH_INSTR(MOTH_INSTR_ADDR)
};
#undef MOTH_INSTR_ADDR
#endif
MOTH_JUMP_TABLE;
ExecutionEngine *engine = function->internalClass->engine;
Profiling::FunctionCallProfiler(engine, function);
@ -565,12 +559,12 @@ QV4::ReturnedValue VME::exec(const FunctionObject *jsFunction, CallData *callDat
MOTH_END_INSTR(Nop)
MOTH_BEGIN_INSTR(Wide)
; // nop
MOTH_END_INSTR(Wide)
MOTH_DISPATCH_WIDE()
}
MOTH_BEGIN_INSTR(XWide)
; // nop
MOTH_END_INSTR(XWide)
MOTH_DISPATCH_XWIDE()
}
MOTH_BEGIN_INSTR(LoadConst)
accumulator = constant(function, index);