diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-22 17:15:44 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-22 17:15:44 -0200 |
| commit | 3c230cc8254538d81be300d55481cdac0103e3c5 (patch) | |
| tree | 90f86f5fbbfdace25ce603e2840d53630cf4d6fe | |
| parent | 41f2936d8f2ec3894e0ef013f6b9e8f6ea17c181 (diff) | |
| download | lua-3c230cc8254538d81be300d55481cdac0103e3c5.tar.gz lua-3c230cc8254538d81be300d55481cdac0103e3c5.tar.bz2 lua-3c230cc8254538d81be300d55481cdac0103e3c5.zip | |
using 'A' for register instead of 'B' in relational opcodes
('R(A)' is already created by default for all instructions.)
| -rw-r--r-- | lcode.c | 10 | ||||
| -rw-r--r-- | lopcodes.h | 12 | ||||
| -rw-r--r-- | lvm.c | 45 |
3 files changed, 31 insertions, 36 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lcode.c,v 2.133 2017/11/16 12:59:14 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.134 2017/11/22 18:41:20 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 | */ |
| @@ -969,7 +969,7 @@ static void negatecondition (FuncState *fs, expdesc *e) { | |||
| 969 | Instruction *pc = getjumpcontrol(fs, e->u.info); | 969 | Instruction *pc = getjumpcontrol(fs, e->u.info); |
| 970 | lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && | 970 | lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET && |
| 971 | GET_OPCODE(*pc) != OP_TEST); | 971 | GET_OPCODE(*pc) != OP_TEST); |
| 972 | SETARG_A(*pc, !(GETARG_A(*pc))); | 972 | SETARG_B(*pc, !(GETARG_B(*pc))); |
| 973 | } | 973 | } |
| 974 | 974 | ||
| 975 | 975 | ||
| @@ -1286,12 +1286,12 @@ static void codeorder (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { | |||
| 1286 | case OPR_GT: case OPR_GE: { | 1286 | case OPR_GT: case OPR_GE: { |
| 1287 | /* '(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)' */ | 1287 | /* '(a > b)' ==> '(b < a)'; '(a >= b)' ==> '(b <= a)' */ |
| 1288 | OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ); | 1288 | OpCode op = cast(OpCode, (opr - OPR_NE) + OP_EQ); |
| 1289 | e1->u.info = condjump(fs, op, 1, rk2, rk1); /* invert operands */ | 1289 | e1->u.info = condjump(fs, op, rk2, 1, rk1); /* invert operands */ |
| 1290 | break; | 1290 | break; |
| 1291 | } | 1291 | } |
| 1292 | default: { /* '==', '<', '<=' use their own opcodes */ | 1292 | default: { /* '==', '<', '<=' use their own opcodes */ |
| 1293 | OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ); | 1293 | OpCode op = cast(OpCode, (opr - OPR_EQ) + OP_EQ); |
| 1294 | e1->u.info = condjump(fs, op, 1, rk1, rk2); | 1294 | e1->u.info = condjump(fs, op, rk1, 1, rk2); |
| 1295 | break; | 1295 | break; |
| 1296 | } | 1296 | } |
| 1297 | } | 1297 | } |
| @@ -1325,7 +1325,7 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { | |||
| 1325 | r2 = luaK_exp2anyreg(fs, e2); | 1325 | r2 = luaK_exp2anyreg(fs, e2); |
| 1326 | } | 1326 | } |
| 1327 | freeexps(fs, e1, e2); | 1327 | freeexps(fs, e1, e2); |
| 1328 | e1->u.info = condjump(fs, op, (opr == OPR_EQ), r1, r2); | 1328 | e1->u.info = condjump(fs, op, r1, (opr == OPR_EQ), r2); |
| 1329 | e1->k = VJMP; | 1329 | e1->k = VJMP; |
| 1330 | } | 1330 | } |
| 1331 | 1331 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.168 2017/11/16 12:59:14 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.169 2017/11/22 18:41:20 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 | */ |
| @@ -236,12 +236,12 @@ OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ | |||
| 236 | 236 | ||
| 237 | OP_CLOSE,/* A close all upvalues >= R(A) */ | 237 | OP_CLOSE,/* A close all upvalues >= R(A) */ |
| 238 | OP_JMP,/* k sJ pc += sJ (k is used in code generation) */ | 238 | OP_JMP,/* k sJ pc += sJ (k is used in code generation) */ |
| 239 | OP_EQ,/* A B C if ((R(B) == R(C)) ~= A) then pc++ */ | 239 | OP_EQ,/* A B C if ((R(A) == R(C)) ~= B) then pc++ */ |
| 240 | OP_LT,/* A B C if ((R(B) < R(C)) ~= A) then pc++ */ | 240 | OP_LT,/* A B C if ((R(A) < R(C)) ~= B) then pc++ */ |
| 241 | OP_LE,/* A B C if ((R(B) <= R(C)) ~= A) then pc++ */ | 241 | OP_LE,/* A B C if ((R(A) <= R(C)) ~= B) then pc++ */ |
| 242 | 242 | ||
| 243 | OP_EQK,/* A B C if ((R(B) == K(C)) ~= A) then pc++ */ | 243 | OP_EQK,/* A B C if ((R(A) == K(C)) ~= B) then pc++ */ |
| 244 | OP_EQI,/* A B C if ((R(B) == C) ~= A) then pc++ */ | 244 | OP_EQI,/* A B C if ((R(A) == C) ~= B) then pc++ */ |
| 245 | 245 | ||
| 246 | OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ | 246 | OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ |
| 247 | OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ | 247 | OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.313 2017/11/21 14:17:35 roberto Exp $ | 2 | ** $Id: lvm.c,v 2.314 2017/11/22 18:41:20 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 | */ |
| @@ -715,7 +715,7 @@ void luaV_finishOp (lua_State *L) { | |||
| 715 | res = !res; /* negate result */ | 715 | res = !res; /* negate result */ |
| 716 | } | 716 | } |
| 717 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); | 717 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); |
| 718 | if (res != GETARG_A(inst)) /* condition failed? */ | 718 | if (res != GETARG_B(inst)) /* condition failed? */ |
| 719 | ci->u.l.savedpc++; /* skip jump instruction */ | 719 | ci->u.l.savedpc++; /* skip jump instruction */ |
| 720 | break; | 720 | break; |
| 721 | } | 721 | } |
| @@ -1340,64 +1340,59 @@ void luaV_execute (lua_State *L) { | |||
| 1340 | vmbreak; | 1340 | vmbreak; |
| 1341 | } | 1341 | } |
| 1342 | vmcase(OP_EQ) { | 1342 | vmcase(OP_EQ) { |
| 1343 | TValue *rb = vRB(i); | ||
| 1344 | TValue *rc = vRC(i); | 1343 | TValue *rc = vRC(i); |
| 1345 | int res; | 1344 | int res; |
| 1346 | Protect(res = luaV_equalobj(L, rb, rc)); | 1345 | Protect(res = luaV_equalobj(L, s2v(ra), rc)); |
| 1347 | if (res != GETARG_A(i)) | 1346 | if (res != GETARG_B(i)) |
| 1348 | pc++; | 1347 | pc++; |
| 1349 | else | 1348 | else |
| 1350 | donextjump(ci); | 1349 | donextjump(ci); |
| 1351 | vmbreak; | 1350 | vmbreak; |
| 1352 | } | 1351 | } |
| 1353 | vmcase(OP_LT) { | 1352 | vmcase(OP_LT) { |
| 1354 | TValue *rb = vRB(i); | ||
| 1355 | TValue *rc = vRC(i); | 1353 | TValue *rc = vRC(i); |
| 1356 | int res; | 1354 | int res; |
| 1357 | if (ttisinteger(rb) && ttisinteger(rc)) | 1355 | if (ttisinteger(s2v(ra)) && ttisinteger(rc)) |
| 1358 | res = (ivalue(rb) < ivalue(rc)); | 1356 | res = (ivalue(s2v(ra)) < ivalue(rc)); |
| 1359 | else if (ttisnumber(rb) && ttisnumber(rc)) | 1357 | else if (ttisnumber(s2v(ra)) && ttisnumber(rc)) |
| 1360 | res = LTnum(rb, rc); | 1358 | res = LTnum(s2v(ra), rc); |
| 1361 | else | 1359 | else |
| 1362 | Protect(res = lessthanothers(L, rb, rc)); | 1360 | Protect(res = lessthanothers(L, s2v(ra), rc)); |
| 1363 | if (res != GETARG_A(i)) | 1361 | if (res != GETARG_B(i)) |
| 1364 | pc++; | 1362 | pc++; |
| 1365 | else | 1363 | else |
| 1366 | donextjump(ci); | 1364 | donextjump(ci); |
| 1367 | vmbreak; | 1365 | vmbreak; |
| 1368 | } | 1366 | } |
| 1369 | vmcase(OP_LE) { | 1367 | vmcase(OP_LE) { |
| 1370 | TValue *rb = vRB(i); | ||
| 1371 | TValue *rc = vRC(i); | 1368 | TValue *rc = vRC(i); |
| 1372 | int res; | 1369 | int res; |
| 1373 | if (ttisinteger(rb) && ttisinteger(rc)) | 1370 | if (ttisinteger(s2v(ra)) && ttisinteger(rc)) |
| 1374 | res = (ivalue(rb) <= ivalue(rc)); | 1371 | res = (ivalue(s2v(ra)) <= ivalue(rc)); |
| 1375 | else if (ttisnumber(rb) && ttisnumber(rc)) | 1372 | else if (ttisnumber(s2v(ra)) && ttisnumber(rc)) |
| 1376 | res = LEnum(rb, rc); | 1373 | res = LEnum(s2v(ra), rc); |
| 1377 | else | 1374 | else |
| 1378 | Protect(res = lessequalothers(L, rb, rc)); | 1375 | Protect(res = lessequalothers(L, s2v(ra), rc)); |
| 1379 | if (res != GETARG_A(i)) | 1376 | if (res != GETARG_B(i)) |
| 1380 | pc++; | 1377 | pc++; |
| 1381 | else | 1378 | else |
| 1382 | donextjump(ci); | 1379 | donextjump(ci); |
| 1383 | vmbreak; | 1380 | vmbreak; |
| 1384 | } | 1381 | } |
| 1385 | vmcase(OP_EQK) { | 1382 | vmcase(OP_EQK) { |
| 1386 | TValue *rb = vRB(i); | ||
| 1387 | TValue *rc = KC(i); | 1383 | TValue *rc = KC(i); |
| 1388 | /* basic types do not use '__eq'; we can use raw equality */ | 1384 | /* basic types do not use '__eq'; we can use raw equality */ |
| 1389 | if (luaV_equalobj(NULL, rb, rc) != GETARG_A(i)) | 1385 | if (luaV_equalobj(NULL, s2v(ra), rc) != GETARG_B(i)) |
| 1390 | pc++; | 1386 | pc++; |
| 1391 | else | 1387 | else |
| 1392 | donextjump(ci); | 1388 | donextjump(ci); |
| 1393 | vmbreak; | 1389 | vmbreak; |
| 1394 | } | 1390 | } |
| 1395 | vmcase(OP_EQI) { | 1391 | vmcase(OP_EQI) { |
| 1396 | TValue *rb = vRB(i); | ||
| 1397 | int ic = GETARG_sC(i); | 1392 | int ic = GETARG_sC(i); |
| 1398 | if ((ttisinteger(rb) ? (ivalue(rb) == ic) | 1393 | if ((ttisinteger(s2v(ra)) ? (ivalue(s2v(ra)) == ic) |
| 1399 | :ttisfloat(rb) ? luai_numeq(fltvalue(rb), cast_num(ic)) | 1394 | :ttisfloat(s2v(ra)) ? luai_numeq(fltvalue(s2v(ra)), cast_num(ic)) |
| 1400 | : 0) != GETARG_A(i)) | 1395 | : 0) != GETARG_B(i)) |
| 1401 | pc++; | 1396 | pc++; |
| 1402 | else | 1397 | else |
| 1403 | donextjump(ci); | 1398 | donextjump(ci); |
