revert to 32-bit bytecode

Dibyendu Majumdar 9 years ago
parent 0104bfa558
commit fcfcd0d1e1

@ -35,13 +35,13 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
/*
** size and position of opcode arguments.
*/
#define SIZE_C 9
#define SIZE_B 9
#define SIZE_C 8
#define SIZE_B 8
#define SIZE_Bx (SIZE_C + SIZE_B)
#define SIZE_A 8
#define SIZE_A 7
#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A)
#define SIZE_OP 6
#define SIZE_OP 9
#define POS_OP 0
#define POS_A (POS_OP + SIZE_OP)
@ -124,29 +124,6 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
| (cast(Instruction, a)<<POS_Ax))
#define RAVI_GET_OPCODE(i) (cast(OpCode, ((i)>>SIZE_OP) & MASK1(10,0)))
#define RAVI_SET_OPCODE(i,o) ((i) = (((i)&MASK0(16,0)) | \
(((cast(Instruction, o)<<SIZE_OP)|OP_RAVI)&MASK1(SIZE_OP,POS_OP))))
#define RAVI_GETARG_A(i) getarg(i, 16, 16)
#define RAVI_SETARG_A(i,v) setarg(i, v, 16, 16)
#define RAVI_GETARG_B(i) getarg(i, 0, 16)
#define RAVI_SETARG_B(i,v) setarg(i, v, 0, 16)
#define RAVI_GETARG_C(i) getarg(i, 16, 16)
#define RAVI_SETARG_C(i,v) setarg(i, v, 16, 16)
/* A (16 bits) Opcode (10 bits) OP_RAVI (6 bits) */
#define RAVI_CREATE_A(o,a) ((cast(Instruction, a)<<16) \
| (cast(Instruction, o)<<6) \
| cast(Instruction, OP_RAVI))
/* B (16 bits) C (16 bits) */
#define RAVI_CREATE_BC(b,c) ((cast(Instruction, c)<<16) \
| (cast(Instruction, b)))
/*
** Macros to operate RK indices
*/
@ -250,8 +227,6 @@ OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx]) */
OP_VARARG,/* A B R(A), R(A+1), ..., R(A+B-2) = vararg */
OP_EXTRAARG,/* Ax extra (larger) argument for previous opcode */
OP_RAVI, /* Extension point for RAVI */
OP_RAVI_UNMF, /* A B R(A) := -R(B) floating point */
OP_RAVI_UNMI, /* A B R(A) := -R(B) integer */

@ -304,7 +304,7 @@ static void freeexp (FuncState *fs, expdesc *e) {
}
/*
/* Add constant to constant array (ensures uniqueness of each constant)
** Use scanner's table to cache position of constants in constant list
** and try to reuse constants
*/
@ -334,7 +334,7 @@ static int addk (FuncState *fs, TValue *key, TValue *v) {
return k;
}
/* add string constant */
int luaK_stringK (FuncState *fs, TString *s) {
TValue o;
setsvalue(fs->ls->L, &o, s);
@ -342,7 +342,7 @@ int luaK_stringK (FuncState *fs, TString *s) {
}
/*
/* Add integer constant
** Integers use userdata as keys to avoid collision with floats with same
** value; conversion to 'void*' used only for hashing, no "precision"
** problems
@ -354,21 +354,21 @@ int luaK_intK (FuncState *fs, lua_Integer n) {
return addk(fs, &k, &o);
}
/* add number constant */
static int luaK_numberK (FuncState *fs, lua_Number r) {
TValue o;
setfltvalue(&o, r);
return addk(fs, &o, &o);
}
/* add boolean constant */
static int boolK (FuncState *fs, int b) {
TValue o;
setbvalue(&o, b);
return addk(fs, &o, &o);
}
/* add nil constant */
static int nilK (FuncState *fs) {
TValue k, v;
setnilvalue(&v);

@ -64,8 +64,6 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"VARARG",
"EXTRAARG",
"OP_RAVI", /* Extension point for RAVI */
"OP_RAVI_UNMF", /* A B R(A) := -R(B) floating point */
"OP_RAVI_UNMI", /* A B R(A) := -R(B) integer */
@ -246,8 +244,6 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgU, OpArgN, iABC) /* OP_VARARG */
,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_EXTRAARG */
,opmode(0, 0, OpArgU, OpArgU, iAx) /* OP_RAVI Extension point for RAVI */
,opmode(0, 1, OpArgR, OpArgN, iABC)/* OP_RAVI_UNMF A B R(A) := -R(B) floating point */
,opmode(0, 1, OpArgR, OpArgN, iABC)/* OP_RAVI_UNMI A B R(A) := -R(B) integer */

@ -1440,7 +1440,7 @@ static void localfunc (LexState *ls) {
getlocvar(fs, b.u.info)->startpc = fs->pc;
}
/* local statement */
static void localstat (LexState *ls) {
/* stat -> LOCAL NAME {',' NAME} ['=' explist] */
int nvars = 0;

@ -708,7 +708,7 @@ newframe: /* reentry point when frame changes (call/return) */
}
/* WARNING: several calls may realloc the stack and invalidate 'ra' */
OpCode op = GET_OPCODE(i);
ra = (op == OP_RAVI) ? NULL : RA(i);
ra = RA(i);
lua_assert(base == ci->u.l.base);
lua_assert(base <= L->top && L->top < L->stack + L->stacksize);
switch (op) {
@ -1174,21 +1174,13 @@ newframe: /* reentry point when frame changes (call/return) */
lua_assert(0);
} break;
#define OP(i) (i - OP_RAVI)
#define OP(i) (i - OP_RAVI_UNMF)
default: {
Instruction j = *(ci->u.l.savedpc++);
OpCode ravi_opcode = RAVI_GET_OPCODE(i);
int a = RAVI_GETARG_A(i);
int b = RAVI_GETARG_B(j);
int c = RAVI_GETARG_C(j);
ra = base+a;
printf("Instruction %s\n", luaP_opnames[ravi_opcode]);
int b = GETARG_B(i);
int c = GETARG_C(i);
switch (OP(ravi_opcode)) {
switch (OP(op)) {
case OP(OP_RAVI_UNMF): {
/* R(A) = -R(B), R(B) must be a float */
TValue *rb = base+b;
@ -1530,7 +1522,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = k + c;
Protect(
if (cast_int(fltvalue(rb) == fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) == fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1540,7 +1532,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = base + c;
Protect(
if (cast_int(fltvalue(rb) == fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) == fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1550,7 +1542,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = k + c;
Protect(
if (cast_int(fltvalue(rb) == fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) == fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1560,7 +1552,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = base + c;
Protect(
if (cast_int(fltvalue(rb) == fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) == fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1570,7 +1562,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = k + c;
Protect(
if ((ivalue(rb) == ivalue(rc)) != a)
if ((ivalue(rb) == ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1580,7 +1572,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = base + c;
Protect(
if ((ivalue(rb) == ivalue(rc)) != a)
if ((ivalue(rb) == ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1590,7 +1582,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = k + c;
Protect(
if ((ivalue(rb) == ivalue(rc)) != a)
if ((ivalue(rb) == ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1600,7 +1592,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = base + c;
Protect(
if ((ivalue(rb) == ivalue(rc)) != a)
if ((ivalue(rb) == ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1611,7 +1603,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = k + c;
Protect(
if (cast_int(fltvalue(rb) < fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) < fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1621,7 +1613,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = base + c;
Protect(
if (cast_int(fltvalue(rb) < fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) < fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1631,7 +1623,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = k + c;
Protect(
if (cast_int(fltvalue(rb) < fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) < fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1641,7 +1633,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = base + c;
Protect(
if (cast_int(fltvalue(rb) < fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) < fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1651,7 +1643,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = k + c;
Protect(
if ((ivalue(rb) < ivalue(rc)) != a)
if ((ivalue(rb) < ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1661,7 +1653,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = base + c;
Protect(
if ((ivalue(rb) < ivalue(rc)) != a)
if ((ivalue(rb) < ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1671,7 +1663,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = k + c;
Protect(
if ((ivalue(rb) < ivalue(rc)) != a)
if ((ivalue(rb) < ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1681,7 +1673,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = base + c;
Protect(
if ((ivalue(rb) < ivalue(rc)) != a)
if ((ivalue(rb) < ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1692,7 +1684,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = k + c;
Protect(
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1702,7 +1694,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = base + c;
Protect(
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1712,7 +1704,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = k + c;
Protect(
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1722,7 +1714,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = base + c;
Protect(
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != a)
if (cast_int(fltvalue(rb) <= fltvalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1732,7 +1724,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = k + c;
Protect(
if ((ivalue(rb) <= ivalue(rc)) != a)
if ((ivalue(rb) <= ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1742,7 +1734,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = k + b;
TValue *rc = base + c;
Protect(
if ((ivalue(rb) <= ivalue(rc)) != a)
if ((ivalue(rb) <= ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1752,7 +1744,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = k + c;
Protect(
if ((ivalue(rb) <= ivalue(rc)) != a)
if ((ivalue(rb) <= ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);
@ -1762,7 +1754,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rb = base + b;
TValue *rc = base + c;
Protect(
if ((ivalue(rb) <= ivalue(rc)) != a)
if ((ivalue(rb) <= ivalue(rc)) != GETARG_A(i))
ci->u.l.savedpc++;
else
donextjump(ci);

@ -86,12 +86,12 @@ static void PrintConstant(const Proto* f, int i)
#define UPVALNAME(x) ((f->upvalues[x].name) ? getstr(f->upvalues[x].name) : "-")
#define MYK(x) (-1-(x))
static void PrintRaviCode(const Proto* f, Instruction i, Instruction j, int pc)
static void PrintRaviCode(const Proto* f, Instruction i, int pc)
{
OpCode o = RAVI_GET_OPCODE(i);
int a = RAVI_GETARG_A(i);
int b = RAVI_GETARG_B(j);
int c = RAVI_GETARG_C(j);
OpCode o = GET_OPCODE(i);
int a = GETARG_A(i);
int b = GETARG_B(i);
int c = GETARG_C(i);
int line = getfuncline(f, pc);
printf("\t%d\t", pc + 1);
if (line>0) printf("[%d]\t", line); else printf("[-]\t");
@ -116,9 +116,8 @@ static void PrintCode(const Proto* f)
{
Instruction i = code[pc];
OpCode o = GET_OPCODE(i);
if (o == OP_RAVI) {
Instruction j = code[++pc];
PrintRaviCode(f, i, j, pc);
if (o >= OP_RAVI_UNMF) {
PrintRaviCode(f, i, pc);
continue;
}
int a = GETARG_A(i);
@ -353,12 +352,11 @@ static int test_binintop(OpCode o, int p, int q, int expected)
int C = 0;
int RETURN_ITEMS = 1;
/* register A (2) will hold return value */
h->instructions[0] = RAVI_CREATE_A(o, A);
/* register B (1) will hold q */
/* register C (0) will hold p */
h->instructions[1] = RAVI_CREATE_BC(B, C);
h->instructions[0] = CREATE_ABC(o, A, B, C);
/* return register 2 (A) */
h->instructions[2] = CREATE_ABC(OP_RETURN, A, RETURN_ITEMS+1, 0);
h->instructions[1] = CREATE_ABC(OP_RETURN, A, RETURN_ITEMS+1, 0);
/* set register 0 (p) */
setivalue(&h->stack[1], p);
@ -368,7 +366,7 @@ static int test_binintop(OpCode o, int p, int q, int expected)
h->p->maxstacksize = 3; /* need three registers */
h->ci->top = h->ci->u.l.base + h->p->maxstacksize;
h->ci->nresults = 1;
h->p->sizecode = 3;
h->p->sizecode = 2;
DumpFunction(h->L);
h->L->top = h->ci->top;
@ -409,10 +407,9 @@ static int test_unmf()
/* register 1 holds q, so A = 1 */
/* register 0 holds p, so B = 0 */
h->instructions[0] = RAVI_CREATE_A(OP_RAVI_UNMF, 1);
h->instructions[1] = RAVI_CREATE_BC(0, 0);
h->instructions[0] = CREATE_ABC(OP_RAVI_UNMF, 1, 0, 0);
/* return register 1 (q) */
h->instructions[2] = CREATE_ABC(OP_RETURN, 1, 2, 0);
h->instructions[1] = CREATE_ABC(OP_RETURN, 1, 2, 0);
/* set register 0 (p) */
h->stack[1].tt_ = LUA_TNUMFLT;
@ -421,7 +418,7 @@ static int test_unmf()
h->p->maxstacksize = 2; /* need two registers */
h->ci->top = h->ci->u.l.base + h->p->maxstacksize;
h->ci->nresults = 1;
h->p->sizecode = 3;
h->p->sizecode = 2;
DumpFunction(h->L);
h->L->top = h->ci->top;
luaV_execute(h->L);

Loading…
Cancel
Save