From 0316308c0d8ee9834641dacf81b43bcfd396095d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 4 Apr 2005 15:12:51 -0300 Subject: removed dirt optimizations that gave small gains --- lapi.c | 10 ++++---- ldebug.c | 36 +++++++++++++------------- lvm.c | 89 ++++++++++++++++++++-------------------------------------------- lvm.h | 8 +++--- 4 files changed, 54 insertions(+), 89 deletions(-) diff --git a/lapi.c b/lapi.c index b336014f..b1b13124 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.35 2005/03/21 18:12:21 roberto Exp roberto $ +** $Id: lapi.c,v 2.36 2005/03/22 16:04:29 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -526,7 +526,7 @@ LUA_API void lua_gettable (lua_State *L, int idx) { lua_lock(L); t = index2adr(L, idx); api_checkvalidindex(L, t); - luaV_gettable(L, t, L->top - 1, L->top - 1, NULL); + luaV_gettable(L, t, L->top - 1, L->top - 1); lua_unlock(L); } @@ -538,7 +538,7 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { t = index2adr(L, idx); api_checkvalidindex(L, t); setsvalue(L, &key, luaS_new(L, k)); - luaV_gettable(L, t, &key, L->top, NULL); + luaV_gettable(L, t, &key, L->top); api_incr_top(L); lua_unlock(L); } @@ -632,7 +632,7 @@ LUA_API void lua_settable (lua_State *L, int idx) { api_checknelems(L, 2); t = index2adr(L, idx); api_checkvalidindex(L, t); - luaV_settable(L, t, L->top - 2, L->top - 1, NULL); + luaV_settable(L, t, L->top - 2, L->top - 1); L->top -= 2; /* pop index and value */ lua_unlock(L); } @@ -646,7 +646,7 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { t = index2adr(L, idx); api_checkvalidindex(L, t); setsvalue(L, &key, luaS_new(L, k)); - luaV_settable(L, t, &key, L->top - 1, NULL); + luaV_settable(L, t, &key, L->top - 1); L->top--; /* pop value */ lua_unlock(L); } diff --git a/ldebug.c b/ldebug.c index ca1f5410..19a1453e 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.11 2004/12/03 20:35:33 roberto Exp roberto $ +** $Id: ldebug.c,v 2.12 2004/12/20 15:50:00 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -30,17 +30,18 @@ -static const char *getfuncname (CallInfo *ci, const char **name); +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name); -static int currentpc (CallInfo *ci) { +static int currentpc (lua_State *L, CallInfo *ci) { + UNUSED(L); if (!isLua(ci)) return -1; /* function is not a Lua function? */ return pcRel(ci->savedpc, ci_func(ci)->l.p); } -static int currentline (CallInfo *ci) { - int pc = currentpc(ci); +static int currentline (lua_State *L, CallInfo *ci) { + int pc = currentpc(L, ci); if (pc < 0) return -1; /* only active lua functions have current-line information */ else @@ -116,7 +117,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { ci = L->base_ci + ar->i_ci; fp = getluaproto(ci); if (fp) { /* is a Lua function? */ - name = luaF_getlocalname(fp, n, currentpc(ci)); + name = luaF_getlocalname(fp, n, currentpc(L, ci)); if (name) luaA_pushobject(L, ci->base+(n-1)); /* push value */ } @@ -135,7 +136,7 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { fp = getluaproto(ci); L->top--; /* pop new value */ if (fp) { /* is a Lua function? */ - name = luaF_getlocalname(fp, n, currentpc(ci)); + name = luaF_getlocalname(fp, n, currentpc(L, ci)); if (!name || name[0] == '(') /* `(' starts private locals */ name = NULL; else @@ -183,7 +184,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, break; } case 'l': { - ar->currentline = (ci) ? currentline(ci) : -1; + ar->currentline = (ci) ? currentline(L, ci) : -1; break; } case 'u': { @@ -191,7 +192,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, break; } case 'n': { - ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL; + ar->namewhat = (ci) ? getfuncname(L, ci, &ar->name) : NULL; if (ar->namewhat == NULL) { ar->namewhat = ""; /* not found */ ar->name = NULL; @@ -446,10 +447,11 @@ static const char *kname (Proto *p, int c) { } -static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { +static const char *getobjname (lua_State *L, CallInfo *ci, int stackpos, + const char **name) { if (isLua(ci)) { /* a Lua function? */ Proto *p = ci_func(ci)->l.p; - int pc = currentpc(ci); + int pc = currentpc(L, ci); Instruction i; *name = luaF_getlocalname(p, stackpos+1, pc); if (*name) /* is a local? */ @@ -467,7 +469,7 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { int a = GETARG_A(i); int b = GETARG_B(i); /* move from `b' to `a' */ if (b < a) - return getobjname(ci, b, name); /* get name for `b' */ + return getobjname(L, ci, b, name); /* get name for `b' */ break; } case OP_GETTABLE: { @@ -492,15 +494,15 @@ static const char *getobjname (CallInfo *ci, int stackpos, const char **name) { } -static const char *getfuncname (CallInfo *ci, const char **name) { +static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) { Instruction i; if ((isLua(ci) && ci->tailcalls > 0) || !isLua(ci - 1)) return NULL; /* calling function is not Lua (or is unknown) */ ci--; /* calling function */ - i = ci_func(ci)->l.p->code[currentpc(ci)]; + i = ci_func(ci)->l.p->code[currentpc(L, ci)]; if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL || GET_OPCODE(i) == OP_TFORLOOP) - return getobjname(ci, GETARG_A(i), name); + return getobjname(L, ci, GETARG_A(i), name); else return NULL; /* no useful name can be found */ } @@ -519,7 +521,7 @@ void luaG_typeerror (lua_State *L, const TValue *o, const char *op) { const char *name = NULL; const char *t = luaT_typenames[ttype(o)]; const char *kind = (isinstack(L->ci, o)) ? - getobjname(L->ci, o - L->base, &name) : NULL; + getobjname(L, L->ci, o - L->base, &name) : NULL; if (kind) luaG_runerror(L, "attempt to %s %s `%s' (a %s value)", op, kind, name, t); @@ -558,7 +560,7 @@ static void addinfo (lua_State *L, const char *msg) { CallInfo *ci = L->ci; if (isLua(ci)) { /* is Lua code? */ char buff[LUA_IDSIZE]; /* add file:line information */ - int line = currentline(ci); + int line = currentline(L, ci); luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE); luaO_pushfstring(L, "%s:%d: %s", buff, line, msg); } diff --git a/lvm.c b/lvm.c index 5456e74d..6f3e6d05 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.34 2005/03/18 18:01:37 roberto Exp roberto $ +** $Id: lvm.c,v 2.35 2005/03/28 17:17:53 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -108,8 +108,7 @@ static void callTM (lua_State *L) { } -StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, - const Instruction *pc) { +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { int loop; for (loop = 0; loop < MAXTAGLOOP; loop++) { const TValue *tm; @@ -119,30 +118,24 @@ StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, if (!ttisnil(res) || /* result is no nil? */ (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ setobj2s(L, val, res); - return L->base; + return; } /* else will try the tag method */ } - else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) { - L->ci->savedpc = pc; + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) luaG_typeerror(L, t, "index"); - } if (ttisfunction(tm)) { - L->ci->savedpc = pc; prepTMcall(L, tm, t, key); callTMres(L, val); - return L->base; + return; } t = tm; /* else repeat with `tm' */ } - L->ci->savedpc = pc; luaG_runerror(L, "loop in gettable"); - return NULL; /* to avoid warnings */ } -StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, - const Instruction *pc) { +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { int loop; for (loop = 0; loop < MAXTAGLOOP; loop++) { const TValue *tm; @@ -153,26 +146,21 @@ StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */ setobj2t(L, oldval, val); luaC_barriert(L, h, val); - return L->base; + return; } /* else will try the tag method */ } - else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) { - L->ci->savedpc = pc; + else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) luaG_typeerror(L, t, "index"); - } if (ttisfunction(tm)) { - L->ci->savedpc = pc; prepTMcall(L, tm, t, key); setobj2s(L, L->top+3, val); /* 3th argument */ callTM(L); - return L->base; + return; } t = tm; /* else repeat with `tm' */ } - L->ci->savedpc = pc; luaG_runerror(L, "loop in settable"); - return NULL; /* to avoid warnings */ } @@ -330,10 +318,9 @@ void luaV_concat (lua_State *L, int total, int last) { static StkId Arith (lua_State *L, StkId ra, const TValue *rb, - const TValue *rc, TMS op, const Instruction *pc) { + const TValue *rc, TMS op) { TValue tempb, tempc; const TValue *b, *c; - L->ci->savedpc = pc; if ((b = luaV_tonumber(rb, &tempb)) != NULL && (c = luaV_tonumber(rc, &tempc)) != NULL) { lua_Number nb = nvalue(b), nc = nvalue(c); @@ -377,7 +364,6 @@ static StkId Arith (lua_State *L, StkId ra, const TValue *rb, StkId luaV_execute (lua_State *L, int nexeccalls) { LClosure *cl; TValue *k; - StkId base; const Instruction *pc; callentry: /* entry point when calling new functions */ if (L->hookmask & LUA_MASKCALL) @@ -385,10 +371,10 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { retentry: /* entry point when returning to old functions */ pc = L->ci->savedpc; cl = &clvalue(L->ci->func)->l; - base = L->base; k = cl->p->k; /* main loop of interpreter */ for (;;) { + StkId base; const Instruction i = *pc++; StkId ra; if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) && @@ -398,11 +384,12 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { L->ci->savedpc = pc - 1; return NULL; } - base = L->base; } /* warning!! several calls may realloc the stack and invalidate `ra' */ + base = L->base; ra = RA(i); - lua_assert(base == L->ci->base && base == L->base); + L->ci->savedpc = pc; + lua_assert(base == L->ci->base); lua_assert(base <= L->top && L->top <= L->stack + L->stacksize); lua_assert(L->top == L->ci->top || luaG_checkopenop(i)); switch (GET_OPCODE(i)) { @@ -436,18 +423,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { TValue *rb = KBx(i); sethvalue(L, &g, cl->env); lua_assert(ttisstring(rb)); - base = luaV_gettable(L, &g, rb, ra, pc); /***/ + luaV_gettable(L, &g, rb, ra); /***/ continue; } case OP_GETTABLE: { - base = luaV_gettable(L, RB(i), RKC(i), ra, pc); /***/ + luaV_gettable(L, RB(i), RKC(i), ra); /***/ continue; } case OP_SETGLOBAL: { TValue g; sethvalue(L, &g, cl->env); lua_assert(ttisstring(KBx(i))); - base = luaV_settable(L, &g, KBx(i), ra, pc); /***/ + luaV_settable(L, &g, KBx(i), ra); /***/ continue; } case OP_SETUPVAL: { @@ -457,22 +444,20 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { continue; } case OP_SETTABLE: { - base = luaV_settable(L, ra, RKB(i), RKC(i), pc); /***/ + luaV_settable(L, ra, RKB(i), RKC(i)); /***/ continue; } case OP_NEWTABLE: { int b = GETARG_B(i); int c = GETARG_C(i); sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c))); - L->ci->savedpc = pc; luaC_checkGC(L); /***/ - base = L->base; continue; } case OP_SELF: { StkId rb = RB(i); setobjs2s(L, ra+1, rb); - base = luaV_gettable(L, rb, RKC(i), ra, pc); /***/ + luaV_gettable(L, rb, RKC(i), ra); /***/ continue; } case OP_ADD: { @@ -483,7 +468,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setnvalue(ra, luai_numadd(nb, nc)); } else - base = Arith(L, ra, rb, rc, TM_ADD, pc); /***/ + Arith(L, ra, rb, rc, TM_ADD); /***/ continue; } case OP_SUB: { @@ -494,7 +479,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setnvalue(ra, luai_numsub(nb, nc)); } else - base = Arith(L, ra, rb, rc, TM_SUB, pc); /***/ + Arith(L, ra, rb, rc, TM_SUB); /***/ continue; } case OP_MUL: { @@ -505,7 +490,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setnvalue(ra, luai_nummul(nb, nc)); } else - base = Arith(L, ra, rb, rc, TM_MUL, pc); /***/ + Arith(L, ra, rb, rc, TM_MUL); /***/ continue; } case OP_DIV: { @@ -516,7 +501,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setnvalue(ra, luai_numdiv(nb, nc)); } else - base = Arith(L, ra, rb, rc, TM_DIV, pc); /***/ + Arith(L, ra, rb, rc, TM_DIV); /***/ continue; } case OP_MOD: { @@ -527,7 +512,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setnvalue(ra, luai_nummod(nb, nc)); } else - base = Arith(L, ra, rb, rc, TM_MOD, pc); /***/ + Arith(L, ra, rb, rc, TM_MOD); /***/ continue; } case OP_POW: { @@ -538,7 +523,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setnvalue(ra, luai_numpow(nb, nc)); } else - base = Arith(L, ra, rb, rc, TM_POW, pc); /***/ + Arith(L, ra, rb, rc, TM_POW); /***/ continue; } case OP_UNM: { @@ -550,10 +535,8 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { } else { setnilvalue(&temp); - L->ci->savedpc = pc; if (!call_binTM(L, RB(i), &temp, ra, TM_UNM)) /***/ luaG_aritherror(L, RB(i), &temp); - base = L->base; } continue; } @@ -572,7 +555,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setnvalue(ra, cast(lua_Number, tsvalue(rb)->len)); break; default: /* no metamethod?? */ - L->ci->savedpc = pc; luaG_typeerror(L, rb, "get the size of"); } continue; @@ -580,7 +562,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { case OP_CONCAT: { int b = GETARG_B(i); int c = GETARG_C(i); - L->ci->savedpc = pc; luaV_concat(L, c-b+1, c); /* may change `base' (and `ra') */ /***/ luaC_checkGC(L); /***/ base = L->base; @@ -592,24 +573,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { continue; } case OP_EQ: { - L->ci->savedpc = pc; if (equalobj(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ else dojump(L, pc, GETARG_sBx(*pc) + 1); - base = L->base; continue; } case OP_LT: { - L->ci->savedpc = pc; if (luaV_lessthan(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ else dojump(L, pc, GETARG_sBx(*pc) + 1); - base = L->base; continue; } case OP_LE: { - L->ci->savedpc = pc; if (lessequal(L, RKB(i), RKC(i)) != GETARG_A(i)) pc++; /***/ else dojump(L, pc, GETARG_sBx(*pc) + 1); - base = L->base; continue; } case OP_TEST: { @@ -626,7 +601,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { int b = GETARG_B(i); int nresults = GETARG_C(i) - 1; if (b != 0) L->top = ra+b; /* else previous instruction set top */ - L->ci->savedpc = pc; pcr = luaD_precall(L, ra, nresults); if (pcr == PCRLUA) { nexeccalls++; @@ -635,7 +609,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { else if (pcr == PCRC) { /* it was a C function (`precall' called it); adjust results */ if (nresults >= 0) L->top = L->ci->top; - base = L->base; continue; } else { @@ -647,7 +620,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { int pcr; int b = GETARG_B(i); if (b != 0) L->top = ra+b; /* else previous instruction set top */ - L->ci->savedpc = pc; lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); pcr = luaD_precall(L, ra, LUA_MULTRET); if (pcr == PCRLUA) { @@ -657,20 +629,18 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { StkId func = ci->func; StkId pfunc = (ci+1)->func; /* previous function index */ if (L->openupval) luaF_close(L, ci->base); - base = ci->base = ci->func + ((ci+1)->base - pfunc); - L->base = base; + L->base = ci->base = ci->func + ((ci+1)->base - pfunc); for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */ setobjs2s(L, func+aux, pfunc+aux); ci->top = L->top = func+aux; /* correct top */ lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize); - ci->savedpc = L->ci->savedpc; + ci->savedpc = (ci+1)->savedpc; ci->tailcalls++; /* one more call lost */ L->ci--; /* remove new frame */ goto callentry; } else if (pcr == PCRC) { /* it was a C function (`precall' called it) */ - base = L->base; continue; } else { @@ -683,7 +653,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { int b = GETARG_B(i); if (b != 0) L->top = ra+b-1; if (L->openupval) luaF_close(L, base); - L->ci->savedpc = pc; if (--nexeccalls == 0) /* was previous function running `here'? */ return ra; /* no: return */ else { /* yes: continue its execution */ @@ -710,7 +679,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { const TValue *init = ra; const TValue *plimit = ra+1; const TValue *pstep = ra+2; - L->ci->savedpc = pc; if (!tonumber(init, ra)) luaG_runerror(L, "`for' initial value must be a number"); else if (!tonumber(plimit, ra+1)) @@ -727,7 +695,6 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { setobjs2s(L, cb+1, ra+1); setobjs2s(L, cb, ra); L->top = cb+3; /* func. + 2 args (state and index) */ - L->ci->savedpc = pc; luaD_call(L, cb, GETARG_C(i)); /***/ L->top = L->ci->top; base = L->base; @@ -791,9 +758,7 @@ StkId luaV_execute (lua_State *L, int nexeccalls) { } } setclvalue(L, ra, ncl); - L->ci->savedpc = pc; luaC_checkGC(L); /***/ - base = L->base; continue; } case OP_VARARG: { diff --git a/lvm.h b/lvm.h index 0cae36c9..0e096c96 100644 --- a/lvm.h +++ b/lvm.h @@ -1,5 +1,5 @@ /* -** $Id: lvm.h,v 2.1 2003/12/10 12:13:36 roberto Exp roberto $ +** $Id: lvm.h,v 2.2 2004/05/14 19:25:09 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -26,10 +26,8 @@ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); const TValue *luaV_tonumber (const TValue *obj, TValue *n); int luaV_tostring (lua_State *L, StkId obj); -StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val, - const Instruction *pc); -StkId luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val, - const Instruction *pc); +void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val); +void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val); StkId luaV_execute (lua_State *L, int nexeccalls); void luaV_concat (lua_State *L, int total, int last); -- cgit v1.2.3-55-g6feb