diff options
-rw-r--r-- | lcode.c | 16 | ||||
-rw-r--r-- | ljumptab.h | 6 | ||||
-rw-r--r-- | lopcodes.c | 6 | ||||
-rw-r--r-- | lopcodes.h | 6 | ||||
-rw-r--r-- | lopnames.h | 6 | ||||
-rw-r--r-- | lvm.c | 24 | ||||
-rw-r--r-- | testes/code.lua | 18 |
7 files changed, 17 insertions, 65 deletions
@@ -1342,7 +1342,7 @@ static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2, | |||
1342 | OpCode op, int v2, int flip, int line, | 1342 | OpCode op, int v2, int flip, int line, |
1343 | OpCode mmop, TMS event) { | 1343 | OpCode mmop, TMS event) { |
1344 | int v1 = luaK_exp2anyreg(fs, e1); | 1344 | int v1 = luaK_exp2anyreg(fs, e1); |
1345 | int pc = luaK_codeABCk(fs, op, 0, v1, v2, flip); | 1345 | int pc = luaK_codeABCk(fs, op, 0, v1, v2, 0); |
1346 | freeexps(fs, e1, e2); | 1346 | freeexps(fs, e1, e2); |
1347 | e1->u.info = pc; | 1347 | e1->u.info = pc; |
1348 | e1->k = VRELOC; /* all those operations are relocatable */ | 1348 | e1->k = VRELOC; /* all those operations are relocatable */ |
@@ -1372,7 +1372,7 @@ static void codebinexpval (FuncState *fs, OpCode op, | |||
1372 | 1372 | ||
1373 | 1373 | ||
1374 | /* | 1374 | /* |
1375 | ** Code binary operators ('+', '-', ...) with immediate operands. | 1375 | ** Code binary operators with immediate operands. |
1376 | */ | 1376 | */ |
1377 | static void codebini (FuncState *fs, OpCode op, | 1377 | static void codebini (FuncState *fs, OpCode op, |
1378 | expdesc *e1, expdesc *e2, int flip, int line, | 1378 | expdesc *e1, expdesc *e2, int flip, int line, |
@@ -1389,15 +1389,12 @@ static void swapexps (expdesc *e1, expdesc *e2) { | |||
1389 | 1389 | ||
1390 | /* | 1390 | /* |
1391 | ** Code arithmetic operators ('+', '-', ...). If second operand is a | 1391 | ** Code arithmetic operators ('+', '-', ...). If second operand is a |
1392 | ** constant in the proper range, use variant opcodes with immediate | 1392 | ** constant in the proper range, use variant opcodes with K operands. |
1393 | ** operands or K operands. | ||
1394 | */ | 1393 | */ |
1395 | static void codearith (FuncState *fs, BinOpr opr, | 1394 | static void codearith (FuncState *fs, BinOpr opr, |
1396 | expdesc *e1, expdesc *e2, int flip, int line) { | 1395 | expdesc *e1, expdesc *e2, int flip, int line) { |
1397 | TMS event = cast(TMS, opr + TM_ADD); | 1396 | TMS event = cast(TMS, opr + TM_ADD); |
1398 | if (isSCint(e2)) /* immediate operand? */ | 1397 | if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */ |
1399 | codebini(fs, cast(OpCode, opr + OP_ADDI), e1, e2, flip, line, event); | ||
1400 | else if (tonumeral(e2, NULL) && luaK_exp2K(fs, e2)) { /* K operand? */ | ||
1401 | int v2 = e2->u.info; /* K index */ | 1398 | int v2 = e2->u.info; /* K index */ |
1402 | OpCode op = cast(OpCode, opr + OP_ADDK); | 1399 | OpCode op = cast(OpCode, opr + OP_ADDK); |
1403 | finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event); | 1400 | finishbinexpval(fs, e1, e2, op, v2, flip, line, OP_MMBINK, event); |
@@ -1423,7 +1420,10 @@ static void codecommutative (FuncState *fs, BinOpr op, | |||
1423 | swapexps(e1, e2); /* change order */ | 1420 | swapexps(e1, e2); /* change order */ |
1424 | flip = 1; | 1421 | flip = 1; |
1425 | } | 1422 | } |
1426 | codearith(fs, op, e1, e2, flip, line); | 1423 | if (op == OPR_ADD && isSCint(e2)) /* immediate operand? */ |
1424 | codebini(fs, cast(OpCode, OP_ADDI), e1, e2, flip, line, TM_ADD); | ||
1425 | else | ||
1426 | codearith(fs, op, e1, e2, flip, line); | ||
1427 | } | 1427 | } |
1428 | 1428 | ||
1429 | 1429 | ||
@@ -45,12 +45,6 @@ static void *disptab[NUM_OPCODES] = { | |||
45 | &&L_OP_NEWTABLE, | 45 | &&L_OP_NEWTABLE, |
46 | &&L_OP_SELF, | 46 | &&L_OP_SELF, |
47 | &&L_OP_ADDI, | 47 | &&L_OP_ADDI, |
48 | &&L_OP_SUBI, | ||
49 | &&L_OP_MULI, | ||
50 | &&L_OP_MODI, | ||
51 | &&L_OP_POWI, | ||
52 | &&L_OP_DIVI, | ||
53 | &&L_OP_IDIVI, | ||
54 | &&L_OP_ADDK, | 48 | &&L_OP_ADDK, |
55 | &&L_OP_SUBK, | 49 | &&L_OP_SUBK, |
56 | &&L_OP_MULK, | 50 | &&L_OP_MULK, |
@@ -39,12 +39,6 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
39 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NEWTABLE */ | 39 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NEWTABLE */ |
40 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ | 40 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ |
41 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ | 41 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ |
42 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBI */ | ||
43 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULI */ | ||
44 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODI */ | ||
45 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWI */ | ||
46 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVI */ | ||
47 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVI */ | ||
48 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ | 42 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ |
49 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ | 43 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ |
50 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ | 44 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ |
@@ -219,12 +219,6 @@ OP_NEWTABLE,/* A B C R(A) := {} */ | |||
219 | OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C):string] */ | 219 | OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C):string] */ |
220 | 220 | ||
221 | OP_ADDI,/* A B sC R(A) := R(B) + C */ | 221 | OP_ADDI,/* A B sC R(A) := R(B) + C */ |
222 | OP_SUBI,/* A B sC R(A) := R(B) - C */ | ||
223 | OP_MULI,/* A B sC R(A) := R(B) * C */ | ||
224 | OP_MODI,/* A B sC R(A) := R(B) % C */ | ||
225 | OP_POWI,/* A B sC R(A) := R(B) ^ C */ | ||
226 | OP_DIVI,/* A B sC R(A) := R(B) / C */ | ||
227 | OP_IDIVI,/* A B sC R(A) := R(B) // C */ | ||
228 | 222 | ||
229 | OP_ADDK,/* A B C R(A) := R(B) + K(C) */ | 223 | OP_ADDK,/* A B C R(A) := R(B) + K(C) */ |
230 | OP_SUBK,/* A B C R(A) := R(B) - K(C) */ | 224 | OP_SUBK,/* A B C R(A) := R(B) - K(C) */ |
@@ -30,12 +30,6 @@ static const char *const opnames[] = { | |||
30 | "NEWTABLE", | 30 | "NEWTABLE", |
31 | "SELF", | 31 | "SELF", |
32 | "ADDI", | 32 | "ADDI", |
33 | "SUBI", | ||
34 | "MULI", | ||
35 | "MODI", | ||
36 | "POWI", | ||
37 | "DIVI", | ||
38 | "IDIVI", | ||
39 | "ADDK", | 33 | "ADDK", |
40 | "SUBK", | 34 | "SUBK", |
41 | "MULK", | 35 | "MULK", |
@@ -1271,30 +1271,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1271 | op_arithI(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i)); | 1271 | op_arithI(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i)); |
1272 | vmbreak; | 1272 | vmbreak; |
1273 | } | 1273 | } |
1274 | vmcase(OP_SUBI) { | ||
1275 | op_arithI(L, l_subi, luai_numsub, TM_SUB, 0); | ||
1276 | vmbreak; | ||
1277 | } | ||
1278 | vmcase(OP_MULI) { | ||
1279 | op_arithI(L, l_muli, luai_nummul, TM_MUL, GETARG_k(i)); | ||
1280 | vmbreak; | ||
1281 | } | ||
1282 | vmcase(OP_MODI) { | ||
1283 | op_arithI(L, luaV_mod, luaV_modf, TM_MOD, 0); | ||
1284 | vmbreak; | ||
1285 | } | ||
1286 | vmcase(OP_POWI) { | ||
1287 | op_arithfI(L, luai_numpow, TM_POW); | ||
1288 | vmbreak; | ||
1289 | } | ||
1290 | vmcase(OP_DIVI) { | ||
1291 | op_arithfI(L, luai_numdiv, TM_DIV); | ||
1292 | vmbreak; | ||
1293 | } | ||
1294 | vmcase(OP_IDIVI) { | ||
1295 | op_arithI(L, luaV_idiv, luai_numidiv, TM_IDIV, 0); | ||
1296 | vmbreak; | ||
1297 | } | ||
1298 | vmcase(OP_ADDK) { | 1274 | vmcase(OP_ADDK) { |
1299 | op_arithK(L, l_addi, luai_numadd, GETARG_k(i)); | 1275 | op_arithK(L, l_addi, luai_numadd, GETARG_k(i)); |
1300 | vmbreak; | 1276 | vmbreak; |
diff --git a/testes/code.lua b/testes/code.lua index 96560166..642dfa68 100644 --- a/testes/code.lua +++ b/testes/code.lua | |||
@@ -296,14 +296,14 @@ checkR(function (x) return x + k1 end, 10, 11, 'ADDI', 'MMBINI', 'RETURN1') | |||
296 | checkR(function (x) return 128 + x end, 0.0, 128.0, | 296 | checkR(function (x) return 128 + x end, 0.0, 128.0, |
297 | 'ADDI', 'MMBINI', 'RETURN1') | 297 | 'ADDI', 'MMBINI', 'RETURN1') |
298 | checkR(function (x) return x * -127 end, -1.0, 127.0, | 298 | checkR(function (x) return x * -127 end, -1.0, 127.0, |
299 | 'MULI', 'MMBINI', 'RETURN1') | 299 | 'MULK', 'MMBINK', 'RETURN1') |
300 | checkR(function (x) return 20 * x end, 2, 40, 'MULI', 'MMBINI', 'RETURN1') | 300 | checkR(function (x) return 20 * x end, 2, 40, 'MULK', 'MMBINK', 'RETURN1') |
301 | checkR(function (x) return x ^ -2 end, 2, 0.25, 'POWI', 'MMBINI', 'RETURN1') | 301 | checkR(function (x) return x ^ -2 end, 2, 0.25, 'POWK', 'MMBINK', 'RETURN1') |
302 | checkR(function (x) return x / 40 end, 40, 1.0, 'DIVI', 'MMBINI', 'RETURN1') | 302 | checkR(function (x) return x / 40 end, 40, 1.0, 'DIVK', 'MMBINK', 'RETURN1') |
303 | checkR(function (x) return x // 1 end, 10.0, 10.0, | 303 | checkR(function (x) return x // 1 end, 10.0, 10.0, |
304 | 'IDIVI', 'MMBINI', 'RETURN1') | 304 | 'IDIVK', 'MMBINK', 'RETURN1') |
305 | checkR(function (x) return x % (100 - 10) end, 91, 1, | 305 | checkR(function (x) return x % (100 - 10) end, 91, 1, |
306 | 'MODI', 'MMBINI', 'RETURN1') | 306 | 'MODK', 'MMBINK', 'RETURN1') |
307 | checkR(function (x) return k1 << x end, 3, 8, 'SHLI', 'MMBINI', 'RETURN1') | 307 | checkR(function (x) return k1 << x end, 3, 8, 'SHLI', 'MMBINI', 'RETURN1') |
308 | checkR(function (x) return x << 2 end, 10, 40, 'SHRI', 'MMBINI', 'RETURN1') | 308 | checkR(function (x) return x << 2 end, 10, 40, 'SHRI', 'MMBINI', 'RETURN1') |
309 | checkR(function (x) return x >> 2 end, 8, 2, 'SHRI', 'MMBINI', 'RETURN1') | 309 | checkR(function (x) return x >> 2 end, 8, 2, 'SHRI', 'MMBINI', 'RETURN1') |
@@ -326,9 +326,9 @@ checkR(function (x) return x % (100.0 - 10) end, 91, 1.0, | |||
326 | 326 | ||
327 | -- no foldings (and immediate operands) | 327 | -- no foldings (and immediate operands) |
328 | check(function () return -0.0 end, 'LOADF', 'UNM', 'RETURN1') | 328 | check(function () return -0.0 end, 'LOADF', 'UNM', 'RETURN1') |
329 | check(function () return k3/0 end, 'LOADI', 'DIVI', 'MMBINI', 'RETURN1') | 329 | check(function () return k3/0 end, 'LOADI', 'DIVK', 'MMBINK', 'RETURN1') |
330 | check(function () return 0%0 end, 'LOADI', 'MODI', 'MMBINI', 'RETURN1') | 330 | check(function () return 0%0 end, 'LOADI', 'MODK', 'MMBINK', 'RETURN1') |
331 | check(function () return -4//0 end, 'LOADI', 'IDIVI', 'MMBINI', 'RETURN1') | 331 | check(function () return -4//0 end, 'LOADI', 'IDIVK', 'MMBINK', 'RETURN1') |
332 | check(function (x) return x >> 2.0 end, 'LOADF', 'SHR', 'MMBIN', 'RETURN1') | 332 | check(function (x) return x >> 2.0 end, 'LOADF', 'SHR', 'MMBIN', 'RETURN1') |
333 | check(function (x) return x & 2.0 end, 'LOADF', 'BAND', 'MMBIN', 'RETURN1') | 333 | check(function (x) return x & 2.0 end, 'LOADF', 'BAND', 'MMBIN', 'RETURN1') |
334 | 334 | ||