From 4758113043b6c362a0fdce77715c711332d909dc Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 19 Apr 2011 13:22:13 -0300 Subject: [PATCH] change in opcode OP_LOADNIL: B is used as a counter instead of a register. (Avoids an assignment to R(B), not present in any other instruction.) --- lcode.c | 18 +++++++++++------- ldebug.c | 6 +++--- lopcodes.c | 4 ++-- lopcodes.h | 4 ++-- lvm.c | 8 ++++---- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lcode.c b/lcode.c index ab2a8295..d2d4b819 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.51 2011/02/01 18:03:10 roberto Exp roberto $ +** $Id: lcode.c,v 2.52 2011/04/07 18:14:12 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -35,19 +35,23 @@ static int isnumeral(expdesc *e) { void luaK_nil (FuncState *fs, int from, int n) { Instruction *previous; + int l = from + n - 1; /* last register to set nil */ if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ previous = &fs->f->code[fs->pc-1]; if (GET_OPCODE(*previous) == OP_LOADNIL) { int pfrom = GETARG_A(*previous); - int pto = GETARG_B(*previous); - if (pfrom <= from && from <= pto+1) { /* can connect both? */ - if (from+n-1 > pto) - SETARG_B(*previous, from+n-1); + int pl = pfrom + GETARG_B(*previous); + if ((pfrom <= from && from <= pl + 1) || + (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */ + if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */ + if (pl > l) l = pl; /* l = max(l, pl) */ + SETARG_A(*previous, from); + SETARG_B(*previous, l - from); return; } - } + } /* else go through */ } - luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ + luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */ } diff --git a/ldebug.c b/ldebug.c index 65b79090..1d0be89e 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.78 2011/04/18 15:02:37 roberto Exp roberto $ +** $Id: ldebug.c,v 2.79 2011/04/18 19:49:13 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -355,8 +355,8 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg, break; } case OP_LOADNIL: { - int b = GETARG_B(i); /* move from 'b' to 'a' */ - if (a <= reg && reg <= b) /* set registers from 'a' to 'b' */ + int b = GETARG_B(i); + if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */ what = NULL; break; } diff --git a/lopcodes.c b/lopcodes.c index dbacf317..d289ae7d 100644 --- a/lopcodes.c +++ b/lopcodes.c @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.c,v 1.46 2011/04/07 18:14:12 roberto Exp roberto $ +** $Id: lopcodes.c,v 1.47 2011/04/12 17:27:35 roberto Exp roberto $ ** See Copyright Notice in lua.h */ @@ -66,7 +66,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ - ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ + ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */ ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ diff --git a/lopcodes.h b/lopcodes.h index 60d1492d..5ab88228 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -1,5 +1,5 @@ /* -** $Id: lopcodes.h,v 1.139 2011/02/07 12:24:42 roberto Exp roberto $ +** $Id: lopcodes.h,v 1.140 2011/04/07 18:14:12 roberto Exp roberto $ ** Opcodes for Lua virtual machine ** See Copyright Notice in lua.h */ @@ -170,7 +170,7 @@ OP_MOVE,/* A B R(A) := R(B) */ OP_LOADK,/* A Bx R(A) := Kst(Bx) */ OP_LOADKX,/* A R(A) := Kst(extra arg) */ OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ -OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ +OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */ OP_GETUPVAL,/* A B R(A) := UpValue[B] */ OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */ diff --git a/lvm.c b/lvm.c index 7356a398..decd2219 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 2.134 2011/04/07 18:14:12 roberto Exp roberto $ +** $Id: lvm.c,v 2.135 2011/04/18 19:48:53 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -541,10 +541,10 @@ void luaV_execute (lua_State *L) { if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */ ) vmcase(OP_LOADNIL, - TValue *rb = RB(i); + int b = GETARG_B(i); do { - setnilvalue(rb--); - } while (rb >= ra); + setnilvalue(ra++); + } while (b--); ) vmcase(OP_GETUPVAL, int b = GETARG_B(i);