aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-04-13 13:51:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-04-13 13:51:01 -0300
commite7c8393682f2977742cdac359cce9e558318aeac (patch)
tree4e3213fdea8c30dcf6f1d2b633eb1a54c755814e
parentceaa97ff5b78db364b1608ede26e3dba9050be0e (diff)
downloadlua-e7c8393682f2977742cdac359cce9e558318aeac.tar.gz
lua-e7c8393682f2977742cdac359cce9e558318aeac.tar.bz2
lua-e7c8393682f2977742cdac359cce9e558318aeac.zip
optimization INCLOCAL is not necessary, with `for'
-rw-r--r--lcode.c28
-rw-r--r--lopcodes.h10
-rw-r--r--ltests.c5
-rw-r--r--lvm.c18
4 files changed, 10 insertions, 51 deletions
diff --git a/lcode.c b/lcode.c
index f75ac359..abf4f537 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 1.23 2000/04/07 19:35:20 roberto Exp roberto $ 2** $Id: lcode.c,v 1.24 2000/04/12 18:57:19 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*/
@@ -460,6 +460,9 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
460 case OP_MULT: case OP_DIV: case OP_POW: 460 case OP_MULT: case OP_DIV: case OP_POW:
461 delta = -1; mode = iO; break; 461 delta = -1; mode = iO; break;
462 462
463 case OP_SETLOCAL: /* `setlocal' default pops one value */
464 delta = -1; arg2 = 1; mode = iAB; break;
465
463 case OP_RETURN: 466 case OP_RETURN:
464 if (GET_OPCODE(i) == OP_CALL && GETARG_B(i) == MULT_RET) { 467 if (GET_OPCODE(i) == OP_CALL && GETARG_B(i) == MULT_RET) {
465 SET_OPCODE(i, OP_TAILCALL); 468 SET_OPCODE(i, OP_TAILCALL);
@@ -501,26 +504,6 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
501 } 504 }
502 break; 505 break;
503 506
504 case OP_SETLOCAL: {
505 int pc = fs->pc;
506 Instruction *code = fs->f->code;
507 delta = -1;
508 if (pc-1 > fs->lasttarget && /* no jumps in-between instructions? */
509 code[pc-2] == CREATE_U(OP_GETLOCAL, arg1) &&
510 GET_OPCODE(i) == OP_ADDI && abs(GETARG_S(i)) <= MAXARG_sA) {
511 /* `local=local+k' */
512 fs->pc = pc-1;
513 code[pc-2] = CREATE_sAB(OP_INCLOCAL, GETARG_S(i), arg1);
514 luaK_deltastack(fs, delta);
515 return pc-1;
516 }
517 else {
518 arg2 = 1; /* `setlocal' default pops one value */
519 mode = iAB;
520 }
521 break;
522 }
523
524 case OP_ADD: 507 case OP_ADD:
525 delta = -1; 508 delta = -1;
526 switch(GET_OPCODE(i)) { 509 switch(GET_OPCODE(i)) {
@@ -585,8 +568,7 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
585 break; 568 break;
586 569
587 case OP_GETDOTTED: case OP_GETINDEXED: 570 case OP_GETDOTTED: case OP_GETINDEXED:
588 case OP_TAILCALL: case OP_INCLOCAL: 571 case OP_TAILCALL: case OP_ADDI:
589 case OP_ADDI:
590 LUA_INTERNALERROR(L, "instruction used only for optimizations"); 572 LUA_INTERNALERROR(L, "instruction used only for optimizations");
591 return 0; /* to avoid warnings */ 573 return 0; /* to avoid warnings */
592 574
diff --git a/lopcodes.h b/lopcodes.h
index 91c74759..d7548d9b 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.56 2000/04/07 19:35:31 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.57 2000/04/12 18:57:19 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*/
@@ -36,8 +36,6 @@
36 36
37 37
38 38
39#define MAXARG_sA (MAXARG_A>>1) /* max value for a signed A */
40
41 39
42/* creates a mask with `n' 1 bits at position `p' */ 40/* creates a mask with `n' 1 bits at position `p' */
43#define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p) 41#define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p)
@@ -73,11 +71,6 @@
73 ((Instruction)(b)<<POS_B))) 71 ((Instruction)(b)<<POS_B)))
74 72
75 73
76#define CREATE_sAB(o,a,b) (CREATE_AB((o),(a)+MAXARG_sA,(b)))
77#define GETARG_sA(i) (GETARG_A(i)-MAXARG_sA)
78
79
80
81/* 74/*
82** K = U argument used as index to `kstr' 75** K = U argument used as index to `kstr'
83** J = S argument used as jump offset (relative to pc of next instruction) 76** J = S argument used as jump offset (relative to pc of next instruction)
@@ -122,7 +115,6 @@ OP_SETTABLE,/* A B v a_a-a_1 i t (pops b values) t[i]=v */
122OP_SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ 115OP_SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
123OP_SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ 116OP_SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
124 117
125OP_INCLOCAL,/* sA L - - LOC[l]+=sA */
126OP_ADD,/* - y x x+y */ 118OP_ADD,/* - y x x+y */
127OP_ADDI,/* S x x+s */ 119OP_ADDI,/* S x x+s */
128OP_SUB,/* - y x x-y */ 120OP_SUB,/* - y x x-y */
diff --git a/ltests.c b/ltests.c
index 1951b446..7762abb3 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.13 2000/04/12 18:57:19 roberto Exp roberto $ 2** $Id: ltests.c,v 1.14 2000/04/12 19:56:50 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -52,7 +52,6 @@ static void setnameval (lua_State *L, lua_Object t, const char *name, int val) {
52#define U(o) sprintf(buff, "%-12s%4u", o, GETARG_U(i)) 52#define U(o) sprintf(buff, "%-12s%4u", o, GETARG_U(i))
53#define S(o) sprintf(buff, "%-12s%4d", o, GETARG_S(i)) 53#define S(o) sprintf(buff, "%-12s%4d", o, GETARG_S(i))
54#define AB(o) sprintf(buff, "%-12s%4d %4d", o, GETARG_A(i), GETARG_B(i)) 54#define AB(o) sprintf(buff, "%-12s%4d %4d", o, GETARG_A(i), GETARG_B(i))
55#define sAB(o) sprintf(buff, "%-12s%4d %4d", o, GETARG_sA(i), GETARG_B(i))
56 55
57 56
58 57
@@ -83,7 +82,6 @@ static int printop (lua_State *L, Instruction i) {
83 case OP_SETLIST: AB("SETLIST"); break; 82 case OP_SETLIST: AB("SETLIST"); break;
84 case OP_SETMAP: U("SETMAP"); break; 83 case OP_SETMAP: U("SETMAP"); break;
85 case OP_ADD: O("ADD"); break; 84 case OP_ADD: O("ADD"); break;
86 case OP_INCLOCAL: sAB("INCLOCAL"); break;
87 case OP_ADDI: S("ADDI"); break; 85 case OP_ADDI: S("ADDI"); break;
88 case OP_SUB: O("SUB"); break; 86 case OP_SUB: O("SUB"); break;
89 case OP_MULT: O("MULT"); break; 87 case OP_MULT: O("MULT"); break;
@@ -147,7 +145,6 @@ static void get_limits (lua_State *L) {
147 setnameval(L, t, "MAXARG_S", MAXARG_S); 145 setnameval(L, t, "MAXARG_S", MAXARG_S);
148 setnameval(L, t, "MAXARG_A", MAXARG_A); 146 setnameval(L, t, "MAXARG_A", MAXARG_A);
149 setnameval(L, t, "MAXARG_B", MAXARG_B); 147 setnameval(L, t, "MAXARG_B", MAXARG_B);
150 setnameval(L, t, "MAXARG_sA", MAXARG_sA);
151 setnameval(L, t, "MAXSTACK", MAXSTACK); 148 setnameval(L, t, "MAXSTACK", MAXSTACK);
152 setnameval(L, t, "MAXLOCALS", MAXLOCALS); 149 setnameval(L, t, "MAXLOCALS", MAXLOCALS);
153 setnameval(L, t, "MAXUPVALUES", MAXUPVALUES); 150 setnameval(L, t, "MAXUPVALUES", MAXUPVALUES);
diff --git a/lvm.c b/lvm.c
index 29819b1e..ceb9b011 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.100 2000/04/07 13:13:11 roberto Exp roberto $ 2** $Id: lvm.c,v 1.101 2000/04/12 18:57:19 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*/
@@ -500,19 +500,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
500 top--; 500 top--;
501 break; 501 break;
502 502
503 case OP_INCLOCAL: {
504 TObject *var = base+GETARG_B(i);
505 int n = GETARG_sA(i);
506 if (tonumber(var)) {
507 *top = *var; /* PUSHLOCAL */
508 addK(L, top+1, n);
509 *var = *top; /* SETLOCAL */
510 }
511 else
512 nvalue(var) += (Number)n;
513 break;
514 }
515
516 case OP_ADDI: 503 case OP_ADDI:
517 if (tonumber(top-1)) 504 if (tonumber(top-1))
518 addK(L, top, GETARG_S(i)); 505 addK(L, top, GETARG_S(i));
@@ -647,7 +634,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
647 Number index; 634 Number index;
648 LUA_ASSERT(L, ttype(top-1) == TAG_NUMBER, "invalid step"); 635 LUA_ASSERT(L, ttype(top-1) == TAG_NUMBER, "invalid step");
649 LUA_ASSERT(L, ttype(top-2) == TAG_NUMBER, "invalid limit"); 636 LUA_ASSERT(L, ttype(top-2) == TAG_NUMBER, "invalid limit");
650 if (tonumber(top-3)) lua_error(L, "`for' index must be a number"); 637 if (ttype(top-3) != TAG_NUMBER)
638 lua_error(L, "`for' index must be a number");
651 index = nvalue(top-3)+step; 639 index = nvalue(top-3)+step;
652 if ((step>0) ? index<=limit : index>=limit) { 640 if ((step>0) ? index<=limit : index>=limit) {
653 nvalue(top-3) = index; 641 nvalue(top-3) = index;