From 058c1a8060a38fd24a02a7152c2a34e04c72b422 Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 19 May 2019 03:54:08 +0000 Subject: [PATCH] Simplify the beginning of VM_Execute() This also moves the loop control stuff into #ifndef CON_DIRECT_THREADING_DISPATCH blocks, since we don't actually need a loop anymore when using the computed goto stuff. git-svn-id: https://svn.eduke32.com/eduke32@7646 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/duke3d/src/gameexec.cpp | 50 ++++++++++++---------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index fe16b2a0a..433f24fa7 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -1284,6 +1284,7 @@ void Screen_Play(void) #else # define vInstruction(KEYWORDID) case KEYWORDID # define vmErrorCase default +# define dispatch_unconditionally(...) continue # define dispatch(...) continue # define eval(INSTRUCTION) switch(INSTRUCTION) # define abort_after_error(...) continue // non-threaded dispatch handles this in the loop condition in VM_Execute() @@ -1303,38 +1304,18 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/) { native_t loopcnt = loop; +#ifndef CON_DIRECT_THREADING_DISPATCH do { -#ifndef CON_DIRECT_THREADING_DISPATCH - next_instruction: +#else + static void* jumpTable[] = JUMP_TABLE_ARRAY_LITERAL; #endif native_t tw = *insptr; g_errorLineNum = tw >> 12; g_tw = tw &= VM_INSTMASK; -#ifdef CON_DIRECT_THREADING_DISPATCH - static void* jumpTable[] = JUMP_TABLE_ARRAY_LITERAL; -#else - if (tw == CON_ELSE) - { - insptr = (intptr_t *)insptr[1]; - goto next_instruction; - } - else if (tw == CON_LEFTBRACE) - { - insptr++, loopcnt++; - goto next_instruction; - } - else if (tw == CON_RIGHTBRACE) - { - insptr++, loopcnt--; - continue; - } - else -#endif eval(tw) { -#ifdef CON_DIRECT_THREADING_DISPATCH vInstruction(CON_LEFTBRACE): { insptr++, loopcnt++; @@ -1352,15 +1333,15 @@ GAMEEXEC_STATIC void VM_Execute(bool const loop /*= false*/) insptr = (intptr_t *)insptr[1]; dispatch_unconditionally(); } -#endif + vInstruction(CON_STATE): - { - auto tempscrptr = &insptr[2]; - insptr = (intptr_t *)insptr[1]; - VM_Execute(true); - insptr = tempscrptr; - } - dispatch(); + { + auto tempscrptr = &insptr[2]; + insptr = (intptr_t *)insptr[1]; + VM_Execute(true); + insptr = tempscrptr; + } + dispatch(); #ifdef CON_DISCRETE_VAR_ACCESS vInstruction(CON_IFVARE_GLOBAL): @@ -6232,11 +6213,14 @@ badindex: "If you are a developer, please attach all of your script files\n" "along with instructions on how to reproduce this error.\n\n" "Thank you!"); -#if !defined CON_DIRECT_THREADING_DISPATCH +#ifndef CON_DIRECT_THREADING_DISPATCH break; #endif } - } while (loopcnt && (vm.flags & (VM_RETURN|VM_KILL|VM_NOEXECUTE)) == 0); +#ifndef CON_DIRECT_THREADING_DISPATCH + } + while (loopcnt && (vm.flags & (VM_RETURN|VM_KILL|VM_NOEXECUTE)) == 0); +#endif } // NORECURSE