From bc8d54d7f20e2e5e219d66ff82b98463101e0883 Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Tue, 29 Oct 2024 12:53:16 +0000 Subject: [PATCH] Promote instructions. This allows yk to constant fold a lot of the resulting instruction decoding. The benefits of doing so can be significant: it speeds big_loop.lua up by about 38%! --- src/lvm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lvm.c b/src/lvm.c index de547a4..f796a75 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -1133,13 +1133,23 @@ void luaV_finishOp (lua_State *L) { /* fetch an instruction and prepare its execution */ -#define vmfetch() { \ +#ifdef USE_YK +# define vmfetch() { \ + if (l_unlikely(trap)) { /* stack reallocation or hooks? */ \ + trap = luaG_traceexec(L, pc); /* handle hooks */ \ + updatebase(ci); /* correct stack */ \ + } \ + i = (Instruction) yk_promote(*(pc++)); \ +} +#else +# define vmfetch() { \ if (l_unlikely(trap)) { /* stack reallocation or hooks? */ \ trap = luaG_traceexec(L, pc); /* handle hooks */ \ updatebase(ci); /* correct stack */ \ } \ - i = *(pc++); \ + i = (Instruction) *(pc++); \ } +#endif #define vmdispatch(o) switch(o) #define vmcase(l) case l: