aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-04-19 13:22:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-04-19 13:22:13 -0300
commit4758113043b6c362a0fdce77715c711332d909dc (patch)
treedeea8a795161332bb1579f201f8a7eb5e4b102b9
parenta4e644add264b6bac3171a03aa6febcf61e89ae6 (diff)
downloadlua-4758113043b6c362a0fdce77715c711332d909dc.tar.gz
lua-4758113043b6c362a0fdce77715c711332d909dc.tar.bz2
lua-4758113043b6c362a0fdce77715c711332d909dc.zip
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.)
-rw-r--r--lcode.c18
-rw-r--r--ldebug.c6
-rw-r--r--lopcodes.c4
-rw-r--r--lopcodes.h4
-rw-r--r--lvm.c8
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 @@
1/* 1/*
2** $Id: lcode.c,v 2.51 2011/02/01 18:03:10 roberto Exp roberto $ 2** $Id: lcode.c,v 2.52 2011/04/07 18:14:12 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -35,19 +35,23 @@ static int isnumeral(expdesc *e) {
35 35
36void luaK_nil (FuncState *fs, int from, int n) { 36void luaK_nil (FuncState *fs, int from, int n) {
37 Instruction *previous; 37 Instruction *previous;
38 int l = from + n - 1; /* last register to set nil */
38 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ 39 if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
39 previous = &fs->f->code[fs->pc-1]; 40 previous = &fs->f->code[fs->pc-1];
40 if (GET_OPCODE(*previous) == OP_LOADNIL) { 41 if (GET_OPCODE(*previous) == OP_LOADNIL) {
41 int pfrom = GETARG_A(*previous); 42 int pfrom = GETARG_A(*previous);
42 int pto = GETARG_B(*previous); 43 int pl = pfrom + GETARG_B(*previous);
43 if (pfrom <= from && from <= pto+1) { /* can connect both? */ 44 if ((pfrom <= from && from <= pl + 1) ||
44 if (from+n-1 > pto) 45 (from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
45 SETARG_B(*previous, from+n-1); 46 if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
47 if (pl > l) l = pl; /* l = max(l, pl) */
48 SETARG_A(*previous, from);
49 SETARG_B(*previous, l - from);
46 return; 50 return;
47 } 51 }
48 } 52 } /* else go through */
49 } 53 }
50 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */ 54 luaK_codeABC(fs, OP_LOADNIL, from, n - 1, 0); /* else no optimization */
51} 55}
52 56
53 57
diff --git a/ldebug.c b/ldebug.c
index 65b79090..1d0be89e 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.78 2011/04/18 15:02:37 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.79 2011/04/18 19:49:13 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -355,8 +355,8 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
355 break; 355 break;
356 } 356 }
357 case OP_LOADNIL: { 357 case OP_LOADNIL: {
358 int b = GETARG_B(i); /* move from 'b' to 'a' */ 358 int b = GETARG_B(i);
359 if (a <= reg && reg <= b) /* set registers from 'a' to 'b' */ 359 if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
360 what = NULL; 360 what = NULL;
361 break; 361 break;
362 } 362 }
diff --git a/lopcodes.c b/lopcodes.c
index dbacf317..d289ae7d 100644
--- a/lopcodes.c
+++ b/lopcodes.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.c,v 1.46 2011/04/07 18:14:12 roberto Exp roberto $ 2** $Id: lopcodes.c,v 1.47 2011/04/12 17:27:35 roberto Exp roberto $
3** See Copyright Notice in lua.h 3** See Copyright Notice in lua.h
4*/ 4*/
5 5
@@ -66,7 +66,7 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
66 ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */ 66 ,opmode(0, 1, OpArgK, OpArgN, iABx) /* OP_LOADK */
67 ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */ 67 ,opmode(0, 1, OpArgN, OpArgN, iABx) /* OP_LOADKX */
68 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */ 68 ,opmode(0, 1, OpArgU, OpArgU, iABC) /* OP_LOADBOOL */
69 ,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_LOADNIL */ 69 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_LOADNIL */
70 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */ 70 ,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_GETUPVAL */
71 ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */ 71 ,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_GETTABUP */
72 ,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_GETTABLE */ 72 ,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 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.139 2011/02/07 12:24:42 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.140 2011/04/07 18:14:12 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -170,7 +170,7 @@ OP_MOVE,/* A B R(A) := R(B) */
170OP_LOADK,/* A Bx R(A) := Kst(Bx) */ 170OP_LOADK,/* A Bx R(A) := Kst(Bx) */
171OP_LOADKX,/* A R(A) := Kst(extra arg) */ 171OP_LOADKX,/* A R(A) := Kst(extra arg) */
172OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ 172OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */
173OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ 173OP_LOADNIL,/* A B R(A), R(A+1), ..., R(A+B) := nil */
174OP_GETUPVAL,/* A B R(A) := UpValue[B] */ 174OP_GETUPVAL,/* A B R(A) := UpValue[B] */
175 175
176OP_GETTABUP,/* A B C R(A) := UpValue[B][RK(C)] */ 176OP_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 @@
1/* 1/*
2** $Id: lvm.c,v 2.134 2011/04/07 18:14:12 roberto Exp roberto $ 2** $Id: lvm.c,v 2.135 2011/04/18 19:48:53 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -541,10 +541,10 @@ void luaV_execute (lua_State *L) {
541 if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */ 541 if (GETARG_C(i)) ci->u.l.savedpc++; /* skip next instruction (if C) */
542 ) 542 )
543 vmcase(OP_LOADNIL, 543 vmcase(OP_LOADNIL,
544 TValue *rb = RB(i); 544 int b = GETARG_B(i);
545 do { 545 do {
546 setnilvalue(rb--); 546 setnilvalue(ra++);
547 } while (rb >= ra); 547 } while (b--);
548 ) 548 )
549 vmcase(OP_GETUPVAL, 549 vmcase(OP_GETUPVAL,
550 int b = GETARG_B(i); 550 int b = GETARG_B(i);