aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-26 15:14:45 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-09-26 15:14:45 -0300
commit00e728af885d2781e365071557530a6685110d7e (patch)
tree3e864db8a1ffa0dcb8b60a8b5c18418709ca6fc2 /lcode.c
parent13256a4173af4004518d65211b4bf1aebcd5fc25 (diff)
downloadlua-00e728af885d2781e365071557530a6685110d7e.tar.gz
lua-00e728af885d2781e365071557530a6685110d7e.tar.bz2
lua-00e728af885d2781e365071557530a6685110d7e.zip
binary operators use R instead of RK
faster + nobody uses RK(B), so B can be smaller (freeing one bit for more opcodes, soon)
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/lcode.c b/lcode.c
index 0fcde154..775a22c3 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.123 2017/09/19 18:38:14 roberto Exp roberto $ 2** $Id: lcode.c,v 2.124 2017/09/26 17:10:49 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*/
@@ -1157,7 +1157,7 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) {
1157** (everything but logical operators 'and'/'or' and comparison 1157** (everything but logical operators 'and'/'or' and comparison
1158** operators). 1158** operators).
1159** Expression to produce final result will be encoded in 'e1'. 1159** Expression to produce final result will be encoded in 'e1'.
1160** Because 'luaK_exp2RK' can free registers, its calls must be 1160** Because 'luaK_exp2anyreg' can free registers, its calls must be
1161** in "stack order" (that is, first on 'e2', which may have more 1161** in "stack order" (that is, first on 'e2', which may have more
1162** recent registers to be released). 1162** recent registers to be released).
1163*/ 1163*/
@@ -1176,8 +1176,8 @@ static void codebinexpval (FuncState *fs, OpCode op,
1176 op = OP_ADDI; 1176 op = OP_ADDI;
1177 } 1177 }
1178 else { 1178 else {
1179 v2 = luaK_exp2RK(fs, e2); /* both operands are "RK" */ 1179 v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */
1180 v1 = luaK_exp2RK(fs, e1); 1180 v1 = luaK_exp2anyreg(fs, e1);
1181 } 1181 }
1182 freeexps(fs, e1, e2); 1182 freeexps(fs, e1, e2);
1183 e1->u.info = luaK_codeABC(fs, op, 0, v1, v2); /* generate opcode */ 1183 e1->u.info = luaK_codeABC(fs, op, 0, v1, v2); /* generate opcode */
@@ -1188,12 +1188,12 @@ static void codebinexpval (FuncState *fs, OpCode op,
1188 1188
1189/* 1189/*
1190** Emit code for comparisons. 1190** Emit code for comparisons.
1191** 'e1' was already put in R/K form by 'luaK_infix'. 1191** 'e1' was already put in register by 'luaK_infix'.
1192*/ 1192*/
1193static void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { 1193static void codecomp (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) {
1194 int rk1 = (e1->k == VK) ? RKASK(e1->u.info) 1194 int rk1 = (e1->k == VK) ? RKASK(e1->u.info)
1195 : check_exp(e1->k == VNONRELOC, e1->u.info); 1195 : check_exp(e1->k == VNONRELOC, e1->u.info);
1196 int rk2 = luaK_exp2RK(fs, e2); 1196 int rk2 = luaK_exp2anyreg(fs, e2);
1197 freeexps(fs, e1, e2); 1197 freeexps(fs, e1, e2);
1198 switch (opr) { 1198 switch (opr) {
1199 case OPR_NE: { /* '(a ~= b)' ==> 'not (a == b)' */ 1199 case OPR_NE: { /* '(a ~= b)' ==> 'not (a == b)' */
@@ -1258,14 +1258,13 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
1258 case OPR_MOD: case OPR_POW: 1258 case OPR_MOD: case OPR_POW:
1259 case OPR_BAND: case OPR_BOR: case OPR_BXOR: 1259 case OPR_BAND: case OPR_BOR: case OPR_BXOR:
1260 case OPR_SHL: case OPR_SHR: { 1260 case OPR_SHL: case OPR_SHR: {
1261 if (!tonumeral(v, NULL)) 1261 if (tonumeral(v, NULL))
1262 luaK_exp2RK(fs, v); 1262 break; /* keep numeral, which may be folded with 2nd operand */
1263 /* else keep numeral, which may be folded with 2nd operand */ 1263 /* else *//* FALLTHROUGH */
1264 break;
1265 } 1264 }
1266 case OPR_EQ: case OPR_LT: case OPR_LE: 1265 case OPR_EQ: case OPR_LT: case OPR_LE:
1267 case OPR_NE: case OPR_GT: case OPR_GE: { 1266 case OPR_NE: case OPR_GT: case OPR_GE: {
1268 luaK_exp2RK(fs, v); 1267 luaK_exp2anyreg(fs, v);
1269 break; 1268 break;
1270 } 1269 }
1271 default: lua_assert(0); 1270 default: lua_assert(0);