From 7211e041dfaa710950bb778e5cb5dc40fa834a30 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 2 Jan 2023 15:29:44 +0100 Subject: Optimizations for GDScript VM * Removed instruction argument count and instruction prefetching. This is now done on the fly. Reduces jumps. * OPCODE_DISPATCH now goes directly to the next instruction, like in Godot 3.x. I have nothing I can use to test performance, so if anyone wants to lend a hand and compare with master (both on debug and release), it would be very welcome. --- modules/gdscript/gdscript_disassembler.cpp | 33 +++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) (limited to 'modules/gdscript/gdscript_disassembler.cpp') diff --git a/modules/gdscript/gdscript_disassembler.cpp b/modules/gdscript/gdscript_disassembler.cpp index b5a209c805..5881adcd5b 100644 --- a/modules/gdscript/gdscript_disassembler.cpp +++ b/modules/gdscript/gdscript_disassembler.cpp @@ -104,8 +104,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { text += ": "; // This makes the compiler complain if some opcode is unchecked in the switch. - Opcode opcode = Opcode(_code_ptr[ip] & INSTR_MASK); - int instr_var_args = (_code_ptr[ip] & INSTR_ARGS_MASK) >> INSTR_BITS; + Opcode opcode = Opcode(_code_ptr[ip]); switch (opcode) { case OPCODE_OPERATOR: { @@ -372,6 +371,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { incr += 4; } break; case OPCODE_CONSTRUCT: { + int instr_var_args = _code_ptr[++ip]; Variant::Type t = Variant::Type(_code_ptr[ip + 3 + instr_var_args]); int argc = _code_ptr[ip + 1 + instr_var_args]; @@ -391,6 +391,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { incr = 3 + instr_var_args; } break; case OPCODE_CONSTRUCT_VALIDATED: { + int instr_var_args = _code_ptr[++ip]; int argc = _code_ptr[ip + 1 + instr_var_args]; text += "construct validated "; @@ -409,6 +410,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { incr = 3 + instr_var_args; } break; case OPCODE_CONSTRUCT_ARRAY: { + int instr_var_args = _code_ptr[++ip]; int argc = _code_ptr[ip + 1 + instr_var_args]; text += " make_array "; text += DADDR(1 + argc); @@ -426,6 +428,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { incr += 3 + argc; } break; case OPCODE_CONSTRUCT_TYPED_ARRAY: { + int instr_var_args = _code_ptr[++ip]; int argc = _code_ptr[ip + 1 + instr_var_args]; Ref