aboutsummaryrefslogtreecommitdiff
path: root/lvm.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 /lvm.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 'lvm.c')
-rw-r--r--lvm.c64
1 files changed, 31 insertions, 33 deletions
diff --git a/lvm.c b/lvm.c
index a41b44d6..75eb8fe4 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.292 2017/09/13 19:50:08 roberto Exp roberto $ 2** $Id: lvm.c,v 2.293 2017/09/19 18:38:14 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*/
@@ -739,8 +739,6 @@ void luaV_finishOp (lua_State *L) {
739#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i)) 739#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
740#define vRC(i) s2v(RC(i)) 740#define vRC(i) s2v(RC(i))
741#define KC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k+GETARG_C(i)) 741#define KC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k+GETARG_C(i))
742#define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
743 (GETARG_Bk(i)) ? k + GETARG_Br(i) : s2v(base + GETARG_Br(i)))
744#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \ 742#define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
745 (GETARG_Ck(i)) ? k + GETARG_Cr(i) : s2v(base + GETARG_Cr(i))) 743 (GETARG_Ck(i)) ? k + GETARG_Cr(i) : s2v(base + GETARG_Cr(i)))
746 744
@@ -1013,8 +1011,8 @@ void luaV_execute (lua_State *L) {
1013 vmbreak; 1011 vmbreak;
1014 } 1012 }
1015 vmcase(OP_ADD) { 1013 vmcase(OP_ADD) {
1016 TValue *rb = RKB(i); 1014 TValue *rb = vRB(i);
1017 TValue *rc = RKC(i); 1015 TValue *rc = vRC(i);
1018 lua_Number nb; lua_Number nc; 1016 lua_Number nb; lua_Number nc;
1019 if (ttisinteger(rb) && ttisinteger(rc)) { 1017 if (ttisinteger(rb) && ttisinteger(rc)) {
1020 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); 1018 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
@@ -1027,8 +1025,8 @@ void luaV_execute (lua_State *L) {
1027 vmbreak; 1025 vmbreak;
1028 } 1026 }
1029 vmcase(OP_SUB) { 1027 vmcase(OP_SUB) {
1030 TValue *rb = RKB(i); 1028 TValue *rb = vRB(i);
1031 TValue *rc = RKC(i); 1029 TValue *rc = vRC(i);
1032 lua_Number nb; lua_Number nc; 1030 lua_Number nb; lua_Number nc;
1033 if (ttisinteger(rb) && ttisinteger(rc)) { 1031 if (ttisinteger(rb) && ttisinteger(rc)) {
1034 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); 1032 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
@@ -1041,8 +1039,8 @@ void luaV_execute (lua_State *L) {
1041 vmbreak; 1039 vmbreak;
1042 } 1040 }
1043 vmcase(OP_MUL) { 1041 vmcase(OP_MUL) {
1044 TValue *rb = RKB(i); 1042 TValue *rb = vRB(i);
1045 TValue *rc = RKC(i); 1043 TValue *rc = vRC(i);
1046 lua_Number nb; lua_Number nc; 1044 lua_Number nb; lua_Number nc;
1047 if (ttisinteger(rb) && ttisinteger(rc)) { 1045 if (ttisinteger(rb) && ttisinteger(rc)) {
1048 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); 1046 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
@@ -1055,8 +1053,8 @@ void luaV_execute (lua_State *L) {
1055 vmbreak; 1053 vmbreak;
1056 } 1054 }
1057 vmcase(OP_DIV) { /* float division (always with floats) */ 1055 vmcase(OP_DIV) { /* float division (always with floats) */
1058 TValue *rb = RKB(i); 1056 TValue *rb = vRB(i);
1059 TValue *rc = RKC(i); 1057 TValue *rc = vRC(i);
1060 lua_Number nb; lua_Number nc; 1058 lua_Number nb; lua_Number nc;
1061 if (tonumberns(rb, nb) && tonumberns(rc, nc)) { 1059 if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
1062 setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); 1060 setfltvalue(s2v(ra), luai_numdiv(L, nb, nc));
@@ -1065,8 +1063,8 @@ void luaV_execute (lua_State *L) {
1065 vmbreak; 1063 vmbreak;
1066 } 1064 }
1067 vmcase(OP_BAND) { 1065 vmcase(OP_BAND) {
1068 TValue *rb = RKB(i); 1066 TValue *rb = vRB(i);
1069 TValue *rc = RKC(i); 1067 TValue *rc = vRC(i);
1070 lua_Integer ib; lua_Integer ic; 1068 lua_Integer ib; lua_Integer ic;
1071 if (tointeger(rb, &ib) && tointeger(rc, &ic)) { 1069 if (tointeger(rb, &ib) && tointeger(rc, &ic)) {
1072 setivalue(s2v(ra), intop(&, ib, ic)); 1070 setivalue(s2v(ra), intop(&, ib, ic));
@@ -1075,8 +1073,8 @@ void luaV_execute (lua_State *L) {
1075 vmbreak; 1073 vmbreak;
1076 } 1074 }
1077 vmcase(OP_BOR) { 1075 vmcase(OP_BOR) {
1078 TValue *rb = RKB(i); 1076 TValue *rb = vRB(i);
1079 TValue *rc = RKC(i); 1077 TValue *rc = vRC(i);
1080 lua_Integer ib; lua_Integer ic; 1078 lua_Integer ib; lua_Integer ic;
1081 if (tointeger(rb, &ib) && tointeger(rc, &ic)) { 1079 if (tointeger(rb, &ib) && tointeger(rc, &ic)) {
1082 setivalue(s2v(ra), intop(|, ib, ic)); 1080 setivalue(s2v(ra), intop(|, ib, ic));
@@ -1085,8 +1083,8 @@ void luaV_execute (lua_State *L) {
1085 vmbreak; 1083 vmbreak;
1086 } 1084 }
1087 vmcase(OP_BXOR) { 1085 vmcase(OP_BXOR) {
1088 TValue *rb = RKB(i); 1086 TValue *rb = vRB(i);
1089 TValue *rc = RKC(i); 1087 TValue *rc = vRC(i);
1090 lua_Integer ib; lua_Integer ic; 1088 lua_Integer ib; lua_Integer ic;
1091 if (tointeger(rb, &ib) && tointeger(rc, &ic)) { 1089 if (tointeger(rb, &ib) && tointeger(rc, &ic)) {
1092 setivalue(s2v(ra), intop(^, ib, ic)); 1090 setivalue(s2v(ra), intop(^, ib, ic));
@@ -1095,8 +1093,8 @@ void luaV_execute (lua_State *L) {
1095 vmbreak; 1093 vmbreak;
1096 } 1094 }
1097 vmcase(OP_SHL) { 1095 vmcase(OP_SHL) {
1098 TValue *rb = RKB(i); 1096 TValue *rb = vRB(i);
1099 TValue *rc = RKC(i); 1097 TValue *rc = vRC(i);
1100 lua_Integer ib; lua_Integer ic; 1098 lua_Integer ib; lua_Integer ic;
1101 if (tointeger(rb, &ib) && tointeger(rc, &ic)) { 1099 if (tointeger(rb, &ib) && tointeger(rc, &ic)) {
1102 setivalue(s2v(ra), luaV_shiftl(ib, ic)); 1100 setivalue(s2v(ra), luaV_shiftl(ib, ic));
@@ -1105,8 +1103,8 @@ void luaV_execute (lua_State *L) {
1105 vmbreak; 1103 vmbreak;
1106 } 1104 }
1107 vmcase(OP_SHR) { 1105 vmcase(OP_SHR) {
1108 TValue *rb = RKB(i); 1106 TValue *rb = vRB(i);
1109 TValue *rc = RKC(i); 1107 TValue *rc = vRC(i);
1110 lua_Integer ib; lua_Integer ic; 1108 lua_Integer ib; lua_Integer ic;
1111 if (tointeger(rb, &ib) && tointeger(rc, &ic)) { 1109 if (tointeger(rb, &ib) && tointeger(rc, &ic)) {
1112 setivalue(s2v(ra), luaV_shiftl(ib, -ic)); 1110 setivalue(s2v(ra), luaV_shiftl(ib, -ic));
@@ -1115,8 +1113,8 @@ void luaV_execute (lua_State *L) {
1115 vmbreak; 1113 vmbreak;
1116 } 1114 }
1117 vmcase(OP_MOD) { 1115 vmcase(OP_MOD) {
1118 TValue *rb = RKB(i); 1116 TValue *rb = vRB(i);
1119 TValue *rc = RKC(i); 1117 TValue *rc = vRC(i);
1120 lua_Number nb; lua_Number nc; 1118 lua_Number nb; lua_Number nc;
1121 if (ttisinteger(rb) && ttisinteger(rc)) { 1119 if (ttisinteger(rb) && ttisinteger(rc)) {
1122 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); 1120 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
@@ -1131,8 +1129,8 @@ void luaV_execute (lua_State *L) {
1131 vmbreak; 1129 vmbreak;
1132 } 1130 }
1133 vmcase(OP_IDIV) { /* floor division */ 1131 vmcase(OP_IDIV) { /* floor division */
1134 TValue *rb = RKB(i); 1132 TValue *rb = vRB(i);
1135 TValue *rc = RKC(i); 1133 TValue *rc = vRC(i);
1136 lua_Number nb; lua_Number nc; 1134 lua_Number nb; lua_Number nc;
1137 if (ttisinteger(rb) && ttisinteger(rc)) { 1135 if (ttisinteger(rb) && ttisinteger(rc)) {
1138 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); 1136 lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc);
@@ -1145,8 +1143,8 @@ void luaV_execute (lua_State *L) {
1145 vmbreak; 1143 vmbreak;
1146 } 1144 }
1147 vmcase(OP_POW) { 1145 vmcase(OP_POW) {
1148 TValue *rb = RKB(i); 1146 TValue *rb = vRB(i);
1149 TValue *rc = RKC(i); 1147 TValue *rc = vRC(i);
1150 lua_Number nb; lua_Number nc; 1148 lua_Number nb; lua_Number nc;
1151 if (tonumberns(rb, nb) && tonumberns(rc, nc)) { 1149 if (tonumberns(rb, nb) && tonumberns(rc, nc)) {
1152 setfltvalue(s2v(ra), luai_numpow(L, nb, nc)); 1150 setfltvalue(s2v(ra), luai_numpow(L, nb, nc));
@@ -1212,8 +1210,8 @@ void luaV_execute (lua_State *L) {
1212 vmbreak; 1210 vmbreak;
1213 } 1211 }
1214 vmcase(OP_EQ) { 1212 vmcase(OP_EQ) {
1215 TValue *rb = RKB(i); 1213 TValue *rb = vRB(i);
1216 TValue *rc = RKC(i); 1214 TValue *rc = vRC(i);
1217 Protect( 1215 Protect(
1218 if (luaV_equalobj(L, rb, rc) != GETARG_A(i)) 1216 if (luaV_equalobj(L, rb, rc) != GETARG_A(i))
1219 pc++; 1217 pc++;
@@ -1223,8 +1221,8 @@ void luaV_execute (lua_State *L) {
1223 vmbreak; 1221 vmbreak;
1224 } 1222 }
1225 vmcase(OP_LT) { 1223 vmcase(OP_LT) {
1226 TValue *rb = RKB(i); 1224 TValue *rb = vRB(i);
1227 TValue *rc = RKC(i); 1225 TValue *rc = vRC(i);
1228 int res; 1226 int res;
1229 if (ttisinteger(rb) && ttisinteger(rc)) 1227 if (ttisinteger(rb) && ttisinteger(rc))
1230 res = (ivalue(rb) < ivalue(rc)); 1228 res = (ivalue(rb) < ivalue(rc));
@@ -1238,8 +1236,8 @@ void luaV_execute (lua_State *L) {
1238 vmbreak; 1236 vmbreak;
1239 } 1237 }
1240 vmcase(OP_LE) { 1238 vmcase(OP_LE) {
1241 TValue *rb = RKB(i); 1239 TValue *rb = vRB(i);
1242 TValue *rc = RKC(i); 1240 TValue *rc = vRC(i);
1243 int res; 1241 int res;
1244 if (ttisinteger(rb) && ttisinteger(rc)) 1242 if (ttisinteger(rb) && ttisinteger(rc))
1245 res = (ivalue(rb) <= ivalue(rc)); 1243 res = (ivalue(rb) <= ivalue(rc));