issue #60 explore further optimization of table operations

pull/81/head
Dibyendu Majumdar 9 years ago
parent ed44f85a3d
commit 4115f35867

@ -298,11 +298,18 @@ OP_RAVI_LT_II,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
OP_RAVI_LT_FF,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
OP_RAVI_LE_II,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
OP_RAVI_LE_FF,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
OP_RAVI_GETTABLEI,/* A B C R(A) := R(B)[RK(C)], integer key */
OP_RAVI_GETTABLES,/* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_SETTABLEI,/* A B C R(A)[RK(B)] := RK(C), integer key */
OP_RAVI_SETTABLES,/* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_TOTAB, /* A R(A) := to_table(R(A)) */
OP_RAVI_MOVETAB, /* A B R(A) := R(B), check R(B) is a table */
} OpCode;
#define NUM_OPCODES (cast(int, OP_RAVI_LE_FF) + 1)
#define NUM_OPCODES (cast(int, OP_RAVI_MOVETAB) + 1)
/*===========================================================================
Notes:

@ -142,6 +142,13 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"LT_FF", /* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */
"LE_II", /* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
"LE_FF", /* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */
"GETTABLEI", /* A B C R(A) := R(B)[RK(C)], integer key */
"GETTABLES", /* A B C R(A) := R(B)[RK(C)], string key */
"SETTABLEI", /* A B C R(A)[RK(B)] := RK(C), integer key */
"SETTABLES", /* A B C R(A)[RK(B)] := RK(C), string key */
"TOTAB", /* A R(A) := to_table(R(A)) */
"MOVETAB", /* A B R(A) := R(B), check R(B) is a table */
NULL
};
@ -267,6 +274,14 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_LE_II */
,opmode(1, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_LE_FF */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLEI */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLES */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLEI */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLES */
,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOTAB A R(A) := check_table(R(A)) */
,opmode(0, 1, OpArgR, OpArgN, iABC) /* OP_RAVI_MOVETAB A B R(A) := R(B), check R(B) is a table */
};
@ -308,30 +323,6 @@ const char* raviP_instruction_to_str(char *buf, size_t n, Instruction i) {
return buf;
}
static char *buildop(Proto *p, int pc, char *buff) {
Instruction i = p->code[pc];
OpCode o = GET_OPCODE(i);
const char *name = luaP_opnames[o];
int line = getfuncline(p, pc);
sprintf(buff, "(%4d) %4d - ", line, pc);
switch (getOpMode(o)) {
case iABC:
sprintf(buff + strlen(buff), "%-12s%4d %4d %4d", name,
GETARG_A(i), GETARG_B(i), GETARG_C(i));
break;
case iABx:
sprintf(buff + strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), GETARG_Bx(i));
break;
case iAsBx:
sprintf(buff + strlen(buff), "%-12s%4d %4d", name, GETARG_A(i), GETARG_sBx(i));
break;
case iAx:
sprintf(buff + strlen(buff), "%-12s%4d", name, GETARG_Ax(i));
break;
}
return buff;
}
static void PrintString(const TString* ts)
{
const char* s=getstr(ts);
@ -611,13 +602,7 @@ static void setnameval(lua_State *L, const char *name, int val) {
#define obj_at(L,k) (L->ci->func + (k))
#define getfuncline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : -1)
static void pushobject(lua_State *L, const TValue *o) {
setobj2s(L, L->top, o);
api_incr_top(L);
}
static char *buildop2(Proto *p, int pc, char *buff, size_t len) {
Instruction i = p->code[pc];
int line = getfuncline(p, pc);
snprintf(buff, len, "(%4d) %4d - ", line, pc);
raviP_instruction_to_str(buff + strlen(buff), len - strlen(buff), p->code[pc]);

@ -871,6 +871,8 @@ newframe: /* reentry point when frame changes (call/return) */
int b = GETARG_B(i);
Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
} break;
case OP_RAVI_GETTABLEI:
case OP_RAVI_GETTABLES:
case OP_GETTABLE: {
Protect(luaV_gettable(L, RB(i), RKC(i), ra));
} break;
@ -883,6 +885,8 @@ newframe: /* reentry point when frame changes (call/return) */
setobj(L, uv->v, ra);
luaC_upvalbarrier(L, uv);
} break;
case OP_RAVI_SETTABLEI:
case OP_RAVI_SETTABLES:
case OP_SETTABLE: {
Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
} break;
@ -1601,6 +1605,10 @@ newframe: /* reentry point when frame changes (call/return) */
luaG_runerror(L, "MOVEF: number expected");
} break;
case OP_RAVI_TOTAB: {
if (!ttistable(ra) || hvalue(ra)->ravi_array.array_type != RAVI_TTABLE)
luaG_runerror(L, "table expected");
} break;
case OP_RAVI_TOARRAYI: {
if (!ttistable(ra) || hvalue(ra)->ravi_array.array_type != RAVI_TARRAYINT)
luaG_runerror(L, "integer[] expected");
@ -1623,6 +1631,13 @@ newframe: /* reentry point when frame changes (call/return) */
} else
luaG_runerror(L, "number[] expected");
} break;
case OP_RAVI_MOVETAB: {
TValue *rb = RB(i);
if (ttistable(rb) && hvalue(rb)->ravi_array.array_type == RAVI_TTABLE) {
setobjs2s(L, ra, rb);
} else
luaG_runerror(L, "table expected");
} break;
case OP_RAVI_GETTABLE_AI: {
TValue *rb = RB(i);
TValue *rc = RKC(i);

Loading…
Cancel
Save