using 'A' for register instead of 'B' in relational opcodes

('R(A)' is already created by default for all instructions.)
This commit is contained in:
Roberto Ierusalimschy 2017-11-22 17:15:44 -02:00
parent 41f2936d8f
commit 3c230cc825
3 changed files with 31 additions and 36 deletions

10
lcode.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 2.133 2017/11/16 12:59:14 roberto Exp roberto $ ** $Id: lcode.c,v 2.134 2017/11/22 18:41:20 roberto Exp roberto $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -969,7 +969,7 @@ static void negatecondition (FuncState *fs, expdesc *e) {
Instruction *pc = getjumpcontrol(fs, e->u.info); Instruction *pc = getjumpcontrol(fs, e->u.info);
lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
GET_OPCODE(*pc) != OP_TEST); GET_OPCODE(*pc) != OP_TEST);
SETARG_A(*pc, !(GETARG_A(*pc))); SETARG_B(*pc, !(GETARG_B(*pc)));
} }
@ -1286,12 +1286,12 @@ static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
case OPR_GT: case OPR_GE: { case OPR_GT: case OPR_GE: {
/* '(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)' */ /* '(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)' */
OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ); OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ);
e1->u.info = condjump(fs, op, 1, rk2, rk1); /* invert operands */ e1->u.info = condjump(fs, op, rk2, 1, rk1); /* invert operands */
break; break;
} }
default: { /* '==', '<', '<=' use their own opcodes */ default: { /* '==', '<', '<=' use their own opcodes */
OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ); OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ);
e1->u.info = condjump(fs, op, 1, rk1, rk2); e1->u.info = condjump(fs, op, rk1, 1, rk2);
break; break;
} }
} }
@ -1325,7 +1325,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
r2 = luaK_exp2anyreg(fs, e2); r2 = luaK_exp2anyreg(fs, e2);
} }
freeexps(fs, e1, e2); freeexps(fs, e1, e2);
e1->u.info = condjump(fs, op, (opr == OPR_EQ), r1, r2); e1->u.info = condjump(fs, op, r1, (opr == OPR_EQ), r2);
e1->k = VJMP; e1->k = VJMP;
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.168 2017/11/16 12:59:14 roberto Exp roberto $ ** $Id: lopcodes.h,v 1.169 2017/11/22 18:41:20 roberto Exp roberto $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -236,12 +236,12 @@ OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
OP_CLOSE,/* A close all upvalues >= R(A) */ OP_CLOSE,/* A close all upvalues >= R(A) */
OP_JMP,/* k sJ pc += sJ (k is used in code generation) */ OP_JMP,/* k sJ pc += sJ (k is used in code generation) */
OP_EQ,/* A B C if ((R(B) == R(C)) ~= A) then pc++ */ OP_EQ,/* A B C if ((R(A) == R(C)) ~= B) then pc++ */
OP_LT,/* A B C if ((R(B) < R(C)) ~= A) then pc++ */ OP_LT,/* A B C if ((R(A) < R(C)) ~= B) then pc++ */
OP_LE,/* A B C if ((R(B) <= R(C)) ~= A) then pc++ */ OP_LE,/* A B C if ((R(A) <= R(C)) ~= B) then pc++ */
OP_EQK,/* A B C if ((R(B) == K(C)) ~= A) then pc++ */ OP_EQK,/* A B C if ((R(A) == K(C)) ~= B) then pc++ */
OP_EQI,/* A B C if ((R(B) == C) ~= A) then pc++ */ OP_EQI,/* A B C if ((R(A) == C) ~= B) then pc++ */
OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ OP_TEST,/* A C if not (R(A) <=> C) then pc++ */
OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */

45
lvm.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lvm.c,v 2.313 2017/11/21 14:17:35 roberto Exp $ ** $Id: lvm.c,v 2.314 2017/11/22 18:41:20 roberto Exp roberto $
** Lua virtual machine ** Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -715,7 +715,7 @@ void luaV_finishOp (lua_State *L) {
res = !res; /* negate result */ res = !res; /* negate result */
} }
lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
if (res != GETARG_A(inst)) /* condition failed? */ if (res != GETARG_B(inst)) /* condition failed? */
ci->u.l.savedpc++; /* skip jump instruction */ ci->u.l.savedpc++; /* skip jump instruction */
break; break;
} }
@ -1340,64 +1340,59 @@ void luaV_execute (lua_State *L) {
vmbreak; vmbreak;
} }
vmcase(OP_EQ) { vmcase(OP_EQ) {
TValue *rb = vRB(i);
TValue *rc = vRC(i); TValue *rc = vRC(i);
int res; int res;
Protect(res = luaV_equalobj(L, rb, rc)); Protect(res = luaV_equalobj(L, s2v(ra), rc));
if (res != GETARG_A(i)) if (res != GETARG_B(i))
pc++; pc++;
else else
donextjump(ci); donextjump(ci);
vmbreak; vmbreak;
} }
vmcase(OP_LT) { vmcase(OP_LT) {
TValue *rb = vRB(i);
TValue *rc = vRC(i); TValue *rc = vRC(i);
int res; int res;
if (ttisinteger(rb) && ttisinteger(rc)) if (ttisinteger(s2v(ra)) && ttisinteger(rc))
res = (ivalue(rb) < ivalue(rc)); res = (ivalue(s2v(ra)) < ivalue(rc));
else if (ttisnumber(rb) && ttisnumber(rc)) else if (ttisnumber(s2v(ra)) && ttisnumber(rc))
res = LTnum(rb, rc); res = LTnum(s2v(ra), rc);
else else
Protect(res = lessthanothers(L, rb, rc)); Protect(res = lessthanothers(L, s2v(ra), rc));
if (res != GETARG_A(i)) if (res != GETARG_B(i))
pc++; pc++;
else else
donextjump(ci); donextjump(ci);
vmbreak; vmbreak;
} }
vmcase(OP_LE) { vmcase(OP_LE) {
TValue *rb = vRB(i);
TValue *rc = vRC(i); TValue *rc = vRC(i);
int res; int res;
if (ttisinteger(rb) && ttisinteger(rc)) if (ttisinteger(s2v(ra)) && ttisinteger(rc))
res = (ivalue(rb) <= ivalue(rc)); res = (ivalue(s2v(ra)) <= ivalue(rc));
else if (ttisnumber(rb) && ttisnumber(rc)) else if (ttisnumber(s2v(ra)) && ttisnumber(rc))
res = LEnum(rb, rc); res = LEnum(s2v(ra), rc);
else else
Protect(res = lessequalothers(L, rb, rc)); Protect(res = lessequalothers(L, s2v(ra), rc));
if (res != GETARG_A(i)) if (res != GETARG_B(i))
pc++; pc++;
else else
donextjump(ci); donextjump(ci);
vmbreak; vmbreak;
} }
vmcase(OP_EQK) { vmcase(OP_EQK) {
TValue *rb = vRB(i);
TValue *rc = KC(i); TValue *rc = KC(i);
/* basic types do not use '__eq'; we can use raw equality */ /* basic types do not use '__eq'; we can use raw equality */
if (luaV_equalobj(NULL, rb, rc) != GETARG_A(i)) if (luaV_equalobj(NULL, s2v(ra), rc) != GETARG_B(i))
pc++; pc++;
else else
donextjump(ci); donextjump(ci);
vmbreak; vmbreak;
} }
vmcase(OP_EQI) { vmcase(OP_EQI) {
TValue *rb = vRB(i);
int ic = GETARG_sC(i); int ic = GETARG_sC(i);
if ((ttisinteger(rb) ? (ivalue(rb) == ic) if ((ttisinteger(s2v(ra)) ? (ivalue(s2v(ra)) == ic)
:ttisfloat(rb) ? luai_numeq(fltvalue(rb), cast_num(ic)) :ttisfloat(s2v(ra)) ? luai_numeq(fltvalue(s2v(ra)), cast_num(ic))
: 0) != GETARG_A(i)) : 0) != GETARG_B(i))
pc++; pc++;
else else
donextjump(ci); donextjump(ci);