optimization INCLOCAL is not necessary, with `for'

This commit is contained in:
Roberto Ierusalimschy 2000-04-13 13:51:01 -03:00
parent ceaa97ff5b
commit e7c8393682
4 changed files with 10 additions and 51 deletions

28
lcode.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 1.23 2000/04/07 19:35:20 roberto Exp roberto $
** $Id: lcode.c,v 1.24 2000/04/12 18:57:19 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -460,6 +460,9 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
case OP_MULT: case OP_DIV: case OP_POW:
delta = -1; mode = iO; break;
case OP_SETLOCAL: /* `setlocal' default pops one value */
delta = -1; arg2 = 1; mode = iAB; break;
case OP_RETURN:
if (GET_OPCODE(i) == OP_CALL && GETARG_B(i) == MULT_RET) {
SET_OPCODE(i, OP_TAILCALL);
@ -501,26 +504,6 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
}
break;
case OP_SETLOCAL: {
int pc = fs->pc;
Instruction *code = fs->f->code;
delta = -1;
if (pc-1 > fs->lasttarget && /* no jumps in-between instructions? */
code[pc-2] == CREATE_U(OP_GETLOCAL, arg1) &&
GET_OPCODE(i) == OP_ADDI && abs(GETARG_S(i)) <= MAXARG_sA) {
/* `local=local+k' */
fs->pc = pc-1;
code[pc-2] = CREATE_sAB(OP_INCLOCAL, GETARG_S(i), arg1);
luaK_deltastack(fs, delta);
return pc-1;
}
else {
arg2 = 1; /* `setlocal' default pops one value */
mode = iAB;
}
break;
}
case OP_ADD:
delta = -1;
switch(GET_OPCODE(i)) {
@ -585,8 +568,7 @@ int luaK_code2 (FuncState *fs, OpCode o, int arg1, int arg2) {
break;
case OP_GETDOTTED: case OP_GETINDEXED:
case OP_TAILCALL: case OP_INCLOCAL:
case OP_ADDI:
case OP_TAILCALL: case OP_ADDI:
LUA_INTERNALERROR(L, "instruction used only for optimizations");
return 0; /* to avoid warnings */

View File

@ -1,5 +1,5 @@
/*
** $Id: lopcodes.h,v 1.56 2000/04/07 19:35:31 roberto Exp roberto $
** $Id: lopcodes.h,v 1.57 2000/04/12 18:57:19 roberto Exp roberto $
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -36,8 +36,6 @@
#define MAXARG_sA (MAXARG_A>>1) /* max value for a signed A */
/* creates a mask with `n' 1 bits at position `p' */
#define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p)
@ -73,11 +71,6 @@
((Instruction)(b)<<POS_B)))
#define CREATE_sAB(o,a,b) (CREATE_AB((o),(a)+MAXARG_sA,(b)))
#define GETARG_sA(i) (GETARG_A(i)-MAXARG_sA)
/*
** K = U argument used as index to `kstr'
** 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 */
OP_SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
OP_SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
OP_INCLOCAL,/* sA L - - LOC[l]+=sA */
OP_ADD,/* - y x x+y */
OP_ADDI,/* S x x+s */
OP_SUB,/* - y x x-y */

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 1.13 2000/04/12 18:57:19 roberto Exp roberto $
** $Id: ltests.c,v 1.14 2000/04/12 19:56:50 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -52,7 +52,6 @@ static void setnameval (lua_State *L, lua_Object t, const char *name, int val) {
#define U(o) sprintf(buff, "%-12s%4u", o, GETARG_U(i))
#define S(o) sprintf(buff, "%-12s%4d", o, GETARG_S(i))
#define AB(o) sprintf(buff, "%-12s%4d %4d", o, GETARG_A(i), GETARG_B(i))
#define sAB(o) sprintf(buff, "%-12s%4d %4d", o, GETARG_sA(i), GETARG_B(i))
@ -83,7 +82,6 @@ static int printop (lua_State *L, Instruction i) {
case OP_SETLIST: AB("SETLIST"); break;
case OP_SETMAP: U("SETMAP"); break;
case OP_ADD: O("ADD"); break;
case OP_INCLOCAL: sAB("INCLOCAL"); break;
case OP_ADDI: S("ADDI"); break;
case OP_SUB: O("SUB"); break;
case OP_MULT: O("MULT"); break;
@ -147,7 +145,6 @@ static void get_limits (lua_State *L) {
setnameval(L, t, "MAXARG_S", MAXARG_S);
setnameval(L, t, "MAXARG_A", MAXARG_A);
setnameval(L, t, "MAXARG_B", MAXARG_B);
setnameval(L, t, "MAXARG_sA", MAXARG_sA);
setnameval(L, t, "MAXSTACK", MAXSTACK);
setnameval(L, t, "MAXLOCALS", MAXLOCALS);
setnameval(L, t, "MAXUPVALUES", MAXUPVALUES);

18
lvm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 1.100 2000/04/07 13:13:11 roberto Exp roberto $
** $Id: lvm.c,v 1.101 2000/04/12 18:57:19 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -500,19 +500,6 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
top--;
break;
case OP_INCLOCAL: {
TObject *var = base+GETARG_B(i);
int n = GETARG_sA(i);
if (tonumber(var)) {
*top = *var; /* PUSHLOCAL */
addK(L, top+1, n);
*var = *top; /* SETLOCAL */
}
else
nvalue(var) += (Number)n;
break;
}
case OP_ADDI:
if (tonumber(top-1))
addK(L, top, GETARG_S(i));
@ -647,7 +634,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, register StkId base) {
Number index;
LUA_ASSERT(L, ttype(top-1) == TAG_NUMBER, "invalid step");
LUA_ASSERT(L, ttype(top-2) == TAG_NUMBER, "invalid limit");
if (tonumber(top-3)) lua_error(L, "`for' index must be a number");
if (ttype(top-3) != TAG_NUMBER)
lua_error(L, "`for' index must be a number");
index = nvalue(top-3)+step;
if ((step>0) ? index<=limit : index>=limit) {
nvalue(top-3) = index;