diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-05 16:10:42 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-11-05 16:10:42 -0200 |
commit | 5e76a4fd313a8690d300085c4e8fcb9dca50c01a (patch) | |
tree | 3f4c0be6c09659d01eb14aadec1652d6428e29fa /lvm.c | |
parent | e8c779736f3029df353038352c14c8ab63728811 (diff) | |
download | lua-5e76a4fd313a8690d300085c4e8fcb9dca50c01a.tar.gz lua-5e76a4fd313a8690d300085c4e8fcb9dca50c01a.tar.bz2 lua-5e76a4fd313a8690d300085c4e8fcb9dca50c01a.zip |
New macros for arithmetic/bitwise operations in 'luaV_execute'
The repetitive code of the arithmetic and bitwise operators in
the main iterpreter loop was moved to appropriate macros.
(As a detail, the function 'luaV_div' was renamed 'luaV_idiv',
as it does an "integer division" (floor division).
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 368 |
1 files changed, 152 insertions, 216 deletions
@@ -620,7 +620,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
620 | ** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer, | 620 | ** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer, |
621 | ** otherwise 'floor(q) == trunc(q) - 1'. | 621 | ** otherwise 'floor(q) == trunc(q) - 1'. |
622 | */ | 622 | */ |
623 | lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | 623 | lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) { |
624 | if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ | 624 | if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ |
625 | if (n == 0) | 625 | if (n == 0) |
626 | luaG_runerror(L, "attempt to divide by zero"); | 626 | luaG_runerror(L, "attempt to divide by zero"); |
@@ -638,7 +638,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | |||
638 | /* | 638 | /* |
639 | ** Integer modulus; return 'm % n'. (Assume that C '%' with | 639 | ** Integer modulus; return 'm % n'. (Assume that C '%' with |
640 | ** negative operands follows C99 behavior. See previous comment | 640 | ** negative operands follows C99 behavior. See previous comment |
641 | ** about luaV_div.) | 641 | ** about luaV_idiv.) |
642 | */ | 642 | */ |
643 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { | 643 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { |
644 | if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ | 644 | if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ |
@@ -770,11 +770,126 @@ void luaV_finishOp (lua_State *L) { | |||
770 | 770 | ||
771 | /* | 771 | /* |
772 | ** {================================================================== | 772 | ** {================================================================== |
773 | ** Function 'luaV_execute': main interpreter loop | 773 | ** Macros for arithmetic/bitwise opcodes in 'luaV_execute' |
774 | ** =================================================================== | 774 | ** =================================================================== |
775 | */ | 775 | */ |
776 | 776 | ||
777 | 777 | ||
778 | #define l_addi(L,a,b) intop(+, a, b) | ||
779 | #define l_subi(L,a,b) intop(-, a, b) | ||
780 | #define l_muli(L,a,b) intop(*, a, b) | ||
781 | #define l_band(L,a,b) intop(&, a, b) | ||
782 | #define l_bor(L,a,b) intop(|, a, b) | ||
783 | #define l_bxor(L,a,b) intop(^, a, b) | ||
784 | |||
785 | |||
786 | /* | ||
787 | ** Auxiliary macro for arithmetic operations over floats and others | ||
788 | ** with immediate operand. 'fop' is the float operation; 'tm' is the | ||
789 | ** corresponding metamethod; 'flip' is true if operands were flipped. | ||
790 | */ | ||
791 | #define op_arithfI_aux(L,v1,imm,fop,tm,flip) { \ | ||
792 | lua_Number nb; \ | ||
793 | if (tonumberns(v1, nb)) { \ | ||
794 | setfltvalue(s2v(ra), fop(L, nb, cast_num(imm))); \ | ||
795 | } \ | ||
796 | else \ | ||
797 | Protect(luaT_trybiniTM(L, v1, imm, flip, ra, tm)); } | ||
798 | |||
799 | |||
800 | /* | ||
801 | ** Arithmetic operations over floats and others with immediate operand. | ||
802 | */ | ||
803 | #define op_arithfI(L,fop,tm) { \ | ||
804 | TValue *v1 = vRB(i); \ | ||
805 | int imm = GETARG_sC(i); \ | ||
806 | op_arithfI_aux(L, v1, imm, fop, tm, 0); } | ||
807 | |||
808 | /* | ||
809 | ** Arithmetic operations with immediate operands. 'iop' is the integer | ||
810 | ** operation. | ||
811 | */ | ||
812 | #define op_arithI(L,iop,fop,tm,flip) { \ | ||
813 | TValue *v1 = vRB(i); \ | ||
814 | int imm = GETARG_sC(i); \ | ||
815 | if (ttisinteger(v1)) { \ | ||
816 | setivalue(s2v(ra), iop(L, ivalue(v1), imm)); \ | ||
817 | } \ | ||
818 | else op_arithfI_aux(L, v1, imm, fop, tm, flip); } | ||
819 | |||
820 | |||
821 | /* | ||
822 | ** Auxiliary function for arithmetic operations over floats and others | ||
823 | ** with two register operands. | ||
824 | */ | ||
825 | #define op_arithf_aux(L,v1,v2,fop,tm) { \ | ||
826 | lua_Number n1; lua_Number n2; \ | ||
827 | if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \ | ||
828 | setfltvalue(s2v(ra), fop(L, n1, n2)); \ | ||
829 | } \ | ||
830 | else \ | ||
831 | Protect(luaT_trybinTM(L, v1, v2, ra, tm)); } | ||
832 | |||
833 | |||
834 | /* | ||
835 | ** Arithmetic operations over floats and others with register operands. | ||
836 | */ | ||
837 | #define op_arithf(L,fop,tm) { \ | ||
838 | TValue *v1 = vRB(i); \ | ||
839 | TValue *v2 = vRC(i); \ | ||
840 | op_arithf_aux(L, v1, v2, fop, tm); } | ||
841 | |||
842 | |||
843 | /* | ||
844 | ** Arithmetic operations with register operands. | ||
845 | */ | ||
846 | #define op_arith(L,iop,fop,tm) { \ | ||
847 | TValue *v1 = vRB(i); \ | ||
848 | TValue *v2 = vRC(i); \ | ||
849 | if (ttisinteger(v1) && ttisinteger(v2)) { \ | ||
850 | lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \ | ||
851 | setivalue(s2v(ra), iop(L, i1, i2)); \ | ||
852 | } \ | ||
853 | else op_arithf_aux(L, v1, v2, fop, tm); } | ||
854 | |||
855 | |||
856 | /* | ||
857 | ** Bitwise operations with constant operand. | ||
858 | */ | ||
859 | #define op_bitwiseK(L,op,tm) { \ | ||
860 | TValue *v1 = vRB(i); \ | ||
861 | TValue *v2 = KC(i); \ | ||
862 | lua_Integer i1; \ | ||
863 | lua_Integer i2 = ivalue(v2); \ | ||
864 | if (tointegerns(v1, &i1)) { \ | ||
865 | setivalue(s2v(ra), op(L, i1, i2)); \ | ||
866 | } \ | ||
867 | else \ | ||
868 | Protect(luaT_trybiniTM(L, v1, i2, TESTARG_k(i), ra, tm)); } | ||
869 | |||
870 | |||
871 | /* | ||
872 | ** Bitwise operations with register operands. | ||
873 | */ | ||
874 | #define op_bitwise(L,op,tm) { \ | ||
875 | TValue *v1 = vRB(i); \ | ||
876 | TValue *v2 = vRC(i); \ | ||
877 | lua_Integer i1; lua_Integer i2; \ | ||
878 | if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \ | ||
879 | setivalue(s2v(ra), op(L, i1, i2)); \ | ||
880 | } \ | ||
881 | else \ | ||
882 | Protect(luaT_trybinTM(L, v1, v2, ra, tm)); } | ||
883 | |||
884 | /* }================================================================== */ | ||
885 | |||
886 | |||
887 | /* | ||
888 | ** {================================================================== | ||
889 | ** Function 'luaV_execute': main interpreter loop | ||
890 | ** =================================================================== | ||
891 | */ | ||
892 | |||
778 | /* | 893 | /* |
779 | ** some macros for common tasks in 'luaV_execute' | 894 | ** some macros for common tasks in 'luaV_execute' |
780 | */ | 895 | */ |
@@ -1075,221 +1190,83 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1075 | vmbreak; | 1190 | vmbreak; |
1076 | } | 1191 | } |
1077 | vmcase(OP_ADDI) { | 1192 | vmcase(OP_ADDI) { |
1078 | TValue *rb = vRB(i); | 1193 | op_arithI(L, l_addi, luai_numadd, TM_ADD, GETARG_k(i)); |
1079 | int ic = GETARG_sC(i); | ||
1080 | lua_Number nb; | ||
1081 | if (ttisinteger(rb)) { | ||
1082 | setivalue(s2v(ra), intop(+, ivalue(rb), ic)); | ||
1083 | } | ||
1084 | else if (tonumberns(rb, nb)) { | ||
1085 | setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic))); | ||
1086 | } | ||
1087 | else | ||
1088 | Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_ADD)); | ||
1089 | vmbreak; | 1194 | vmbreak; |
1090 | } | 1195 | } |
1091 | vmcase(OP_SUBI) { | 1196 | vmcase(OP_SUBI) { |
1092 | TValue *rb = vRB(i); | 1197 | op_arithI(L, l_subi, luai_numsub, TM_SUB, 0); |
1093 | int ic = GETARG_sC(i); | ||
1094 | lua_Number nb; | ||
1095 | if (ttisinteger(rb)) { | ||
1096 | setivalue(s2v(ra), intop(-, ivalue(rb), ic)); | ||
1097 | } | ||
1098 | else if (tonumberns(rb, nb)) { | ||
1099 | setfltvalue(s2v(ra), luai_numsub(L, nb, cast_num(ic))); | ||
1100 | } | ||
1101 | else | ||
1102 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_SUB)); | ||
1103 | vmbreak; | 1198 | vmbreak; |
1104 | } | 1199 | } |
1105 | vmcase(OP_MULI) { | 1200 | vmcase(OP_MULI) { |
1106 | TValue *rb = vRB(i); | 1201 | op_arithI(L, l_muli, luai_nummul, TM_MUL, GETARG_k(i)); |
1107 | int ic = GETARG_sC(i); | ||
1108 | lua_Number nb; | ||
1109 | if (ttisinteger(rb)) { | ||
1110 | setivalue(s2v(ra), intop(*, ivalue(rb), ic)); | ||
1111 | } | ||
1112 | else if (tonumberns(rb, nb)) { | ||
1113 | setfltvalue(s2v(ra), luai_nummul(L, nb, cast_num(ic))); | ||
1114 | } | ||
1115 | else | ||
1116 | Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_MUL)); | ||
1117 | vmbreak; | 1202 | vmbreak; |
1118 | } | 1203 | } |
1119 | vmcase(OP_MODI) { | 1204 | vmcase(OP_MODI) { |
1120 | TValue *rb = vRB(i); | 1205 | op_arithI(L, luaV_mod, luaV_modf, TM_MOD, 0); |
1121 | int ic = GETARG_sC(i); | ||
1122 | lua_Number nb; | ||
1123 | if (ttisinteger(rb)) { | ||
1124 | setivalue(s2v(ra), luaV_mod(L, ivalue(rb), ic)); | ||
1125 | } | ||
1126 | else if (tonumberns(rb, nb)) { | ||
1127 | lua_Number nc = cast_num(ic); | ||
1128 | setfltvalue(s2v(ra), luaV_modf(L, nb, nc)); | ||
1129 | } | ||
1130 | else | ||
1131 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_MOD)); | ||
1132 | vmbreak; | 1206 | vmbreak; |
1133 | } | 1207 | } |
1134 | vmcase(OP_POWI) { | 1208 | vmcase(OP_POWI) { |
1135 | TValue *rb = vRB(i); | 1209 | op_arithfI(L, luai_numpow, TM_POW); |
1136 | int ic = GETARG_sC(i); | ||
1137 | lua_Number nb; | ||
1138 | if (tonumberns(rb, nb)) { | ||
1139 | lua_Number nc = cast_num(ic); | ||
1140 | setfltvalue(s2v(ra), luai_numpow(L, nb, nc)); | ||
1141 | } | ||
1142 | else | ||
1143 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_POW)); | ||
1144 | vmbreak; | 1210 | vmbreak; |
1145 | } | 1211 | } |
1146 | vmcase(OP_DIVI) { | 1212 | vmcase(OP_DIVI) { |
1147 | TValue *rb = vRB(i); | 1213 | op_arithfI(L, luai_numdiv, TM_DIV); |
1148 | int ic = GETARG_sC(i); | ||
1149 | lua_Number nb; | ||
1150 | if (tonumberns(rb, nb)) { | ||
1151 | lua_Number nc = cast_num(ic); | ||
1152 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); | ||
1153 | } | ||
1154 | else | ||
1155 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_DIV)); | ||
1156 | vmbreak; | 1214 | vmbreak; |
1157 | } | 1215 | } |
1158 | vmcase(OP_IDIVI) { | 1216 | vmcase(OP_IDIVI) { |
1159 | TValue *rb = vRB(i); | 1217 | op_arithI(L, luaV_idiv, luai_numidiv, TM_IDIV, 0); |
1160 | int ic = GETARG_sC(i); | ||
1161 | lua_Number nb; | ||
1162 | if (ttisinteger(rb)) { | ||
1163 | setivalue(s2v(ra), luaV_div(L, ivalue(rb), ic)); | ||
1164 | } | ||
1165 | else if (tonumberns(rb, nb)) { | ||
1166 | lua_Number nc = cast_num(ic); | ||
1167 | setfltvalue(s2v(ra), luai_numidiv(L, nb, nc)); | ||
1168 | } | ||
1169 | else | ||
1170 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_IDIV)); | ||
1171 | vmbreak; | 1218 | vmbreak; |
1172 | } | 1219 | } |
1173 | vmcase(OP_ADD) { | 1220 | vmcase(OP_ADD) { |
1174 | TValue *rb = vRB(i); | 1221 | op_arith(L, l_addi, luai_numadd, TM_ADD); |
1175 | TValue *rc = vRC(i); | ||
1176 | lua_Number nb; lua_Number nc; | ||
1177 | if (ttisinteger(rb) && ttisinteger(rc)) { | ||
1178 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | ||
1179 | setivalue(s2v(ra), intop(+, ib, ic)); | ||
1180 | } | ||
1181 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | ||
1182 | setfltvalue(s2v(ra), luai_numadd(L, nb, nc)); | ||
1183 | } | ||
1184 | else | ||
1185 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); | ||
1186 | vmbreak; | 1222 | vmbreak; |
1187 | } | 1223 | } |
1188 | vmcase(OP_SUB) { | 1224 | vmcase(OP_SUB) { |
1189 | TValue *rb = vRB(i); | 1225 | op_arith(L, l_subi, luai_numsub, TM_SUB); |
1190 | TValue *rc = vRC(i); | ||
1191 | lua_Number nb; lua_Number nc; | ||
1192 | if (ttisinteger(rb) && ttisinteger(rc)) { | ||
1193 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | ||
1194 | setivalue(s2v(ra), intop(-, ib, ic)); | ||
1195 | } | ||
1196 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | ||
1197 | setfltvalue(s2v(ra), luai_numsub(L, nb, nc)); | ||
1198 | } | ||
1199 | else | ||
1200 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); | ||
1201 | vmbreak; | 1226 | vmbreak; |
1202 | } | 1227 | } |
1203 | vmcase(OP_MUL) { | 1228 | vmcase(OP_MUL) { |
1204 | TValue *rb = vRB(i); | 1229 | op_arith(L, l_muli, luai_nummul, TM_MUL); |
1205 | TValue *rc = vRC(i); | 1230 | vmbreak; |
1206 | lua_Number nb; lua_Number nc; | 1231 | } |
1207 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1232 | vmcase(OP_MOD) { |
1208 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1233 | op_arith(L, luaV_mod, luaV_modf, TM_MOD); |
1209 | setivalue(s2v(ra), intop(*, ib, ic)); | 1234 | vmbreak; |
1210 | } | 1235 | } |
1211 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1236 | vmcase(OP_POW) { |
1212 | setfltvalue(s2v(ra), luai_nummul(L, nb, nc)); | 1237 | op_arithf(L, luai_numpow, TM_POW); |
1213 | } | ||
1214 | else | ||
1215 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); | ||
1216 | vmbreak; | 1238 | vmbreak; |
1217 | } | 1239 | } |
1218 | vmcase(OP_DIV) { /* float division (always with floats) */ | 1240 | vmcase(OP_DIV) { /* float division (always with floats) */ |
1219 | TValue *rb = vRB(i); | 1241 | op_arithf(L, luai_numdiv, TM_DIV); |
1220 | TValue *rc = vRC(i); | 1242 | vmbreak; |
1221 | lua_Number nb; lua_Number nc; | 1243 | } |
1222 | if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1244 | vmcase(OP_IDIV) { /* floor division */ |
1223 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); | 1245 | op_arith(L, luaV_idiv, luai_numidiv, TM_IDIV); |
1224 | } | ||
1225 | else | ||
1226 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); | ||
1227 | vmbreak; | 1246 | vmbreak; |
1228 | } | 1247 | } |
1229 | vmcase(OP_BANDK) { | 1248 | vmcase(OP_BANDK) { |
1230 | TValue *p1 = vRB(i); | 1249 | op_bitwiseK(L, l_band, TM_BAND); |
1231 | TValue *p2 = KC(i); | ||
1232 | lua_Integer i1; | ||
1233 | if (tointegerns(p1, &i1)) { | ||
1234 | setivalue(s2v(ra), intop(&, i1, ivalue(p2))); | ||
1235 | } | ||
1236 | else | ||
1237 | Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BAND)); | ||
1238 | vmbreak; | 1250 | vmbreak; |
1239 | } | 1251 | } |
1240 | vmcase(OP_BORK) { | 1252 | vmcase(OP_BORK) { |
1241 | TValue *p1 = vRB(i); | 1253 | op_bitwiseK(L, l_bor, TM_BOR); |
1242 | TValue *p2 = KC(i); | ||
1243 | lua_Integer i1; | ||
1244 | if (tointegerns(p1, &i1)) { | ||
1245 | setivalue(s2v(ra), intop(|, i1, ivalue(p2))); | ||
1246 | } | ||
1247 | else | ||
1248 | Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BOR)); | ||
1249 | vmbreak; | 1254 | vmbreak; |
1250 | } | 1255 | } |
1251 | vmcase(OP_BXORK) { | 1256 | vmcase(OP_BXORK) { |
1252 | TValue *p1 = vRB(i); | 1257 | op_bitwiseK(L, l_bxor, TM_BXOR); |
1253 | TValue *p2 = KC(i); | ||
1254 | lua_Integer i1; | ||
1255 | if (tointegerns(p1, &i1)) { | ||
1256 | setivalue(s2v(ra), intop(^, i1, ivalue(p2))); | ||
1257 | } | ||
1258 | else | ||
1259 | Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BXOR)); | ||
1260 | vmbreak; | 1258 | vmbreak; |
1261 | } | 1259 | } |
1262 | vmcase(OP_BAND) { | 1260 | vmcase(OP_BAND) { |
1263 | TValue *rb = vRB(i); | 1261 | op_bitwise(L, l_band, TM_BAND); |
1264 | TValue *rc = vRC(i); | ||
1265 | lua_Integer ib; lua_Integer ic; | ||
1266 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | ||
1267 | setivalue(s2v(ra), intop(&, ib, ic)); | ||
1268 | } | ||
1269 | else | ||
1270 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); | ||
1271 | vmbreak; | 1262 | vmbreak; |
1272 | } | 1263 | } |
1273 | vmcase(OP_BOR) { | 1264 | vmcase(OP_BOR) { |
1274 | TValue *rb = vRB(i); | 1265 | op_bitwise(L, l_bor, TM_BOR); |
1275 | TValue *rc = vRC(i); | ||
1276 | lua_Integer ib; lua_Integer ic; | ||
1277 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | ||
1278 | setivalue(s2v(ra), intop(|, ib, ic)); | ||
1279 | } | ||
1280 | else | ||
1281 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); | ||
1282 | vmbreak; | 1266 | vmbreak; |
1283 | } | 1267 | } |
1284 | vmcase(OP_BXOR) { | 1268 | vmcase(OP_BXOR) { |
1285 | TValue *rb = vRB(i); | 1269 | op_bitwise(L, l_bxor, TM_BXOR); |
1286 | TValue *rc = vRC(i); | ||
1287 | lua_Integer ib; lua_Integer ic; | ||
1288 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | ||
1289 | setivalue(s2v(ra), intop(^, ib, ic)); | ||
1290 | } | ||
1291 | else | ||
1292 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); | ||
1293 | vmbreak; | 1270 | vmbreak; |
1294 | } | 1271 | } |
1295 | vmcase(OP_SHRI) { | 1272 | vmcase(OP_SHRI) { |
@@ -1319,17 +1296,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1319 | Protect(luaT_trybiniTM(L, rb, ic, 1, ra, TM_SHL)); | 1296 | Protect(luaT_trybiniTM(L, rb, ic, 1, ra, TM_SHL)); |
1320 | vmbreak; | 1297 | vmbreak; |
1321 | } | 1298 | } |
1322 | vmcase(OP_SHL) { | ||
1323 | TValue *rb = vRB(i); | ||
1324 | TValue *rc = vRC(i); | ||
1325 | lua_Integer ib; lua_Integer ic; | ||
1326 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | ||
1327 | setivalue(s2v(ra), luaV_shiftl(ib, ic)); | ||
1328 | } | ||
1329 | else | ||
1330 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); | ||
1331 | vmbreak; | ||
1332 | } | ||
1333 | vmcase(OP_SHR) { | 1299 | vmcase(OP_SHR) { |
1334 | TValue *rb = vRB(i); | 1300 | TValue *rb = vRB(i); |
1335 | TValue *rc = vRC(i); | 1301 | TValue *rc = vRC(i); |
@@ -1341,45 +1307,15 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1341 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); | 1307 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); |
1342 | vmbreak; | 1308 | vmbreak; |
1343 | } | 1309 | } |
1344 | vmcase(OP_MOD) { | 1310 | vmcase(OP_SHL) { |
1345 | TValue *rb = vRB(i); | ||
1346 | TValue *rc = vRC(i); | ||
1347 | lua_Number nb; lua_Number nc; | ||
1348 | if (ttisinteger(rb) && ttisinteger(rc)) { | ||
1349 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | ||
1350 | setivalue(s2v(ra), luaV_mod(L, ib, ic)); | ||
1351 | } | ||
1352 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | ||
1353 | setfltvalue(s2v(ra), luaV_modf(L, nb, nc)); | ||
1354 | } | ||
1355 | else | ||
1356 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); | ||
1357 | vmbreak; | ||
1358 | } | ||
1359 | vmcase(OP_IDIV) { /* floor division */ | ||
1360 | TValue *rb = vRB(i); | ||
1361 | TValue *rc = vRC(i); | ||
1362 | lua_Number nb; lua_Number nc; | ||
1363 | if (ttisinteger(rb) && ttisinteger(rc)) { | ||
1364 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | ||
1365 | setivalue(s2v(ra), luaV_div(L, ib, ic)); | ||
1366 | } | ||
1367 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | ||
1368 | setfltvalue(s2v(ra), luai_numidiv(L, nb, nc)); | ||
1369 | } | ||
1370 | else | ||
1371 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); | ||
1372 | vmbreak; | ||
1373 | } | ||
1374 | vmcase(OP_POW) { | ||
1375 | TValue *rb = vRB(i); | 1311 | TValue *rb = vRB(i); |
1376 | TValue *rc = vRC(i); | 1312 | TValue *rc = vRC(i); |
1377 | lua_Number nb; lua_Number nc; | 1313 | lua_Integer ib; lua_Integer ic; |
1378 | if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1314 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { |
1379 | setfltvalue(s2v(ra), luai_numpow(L, nb, nc)); | 1315 | setivalue(s2v(ra), luaV_shiftl(ib, ic)); |
1380 | } | 1316 | } |
1381 | else | 1317 | else |
1382 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); | 1318 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); |
1383 | vmbreak; | 1319 | vmbreak; |
1384 | } | 1320 | } |
1385 | vmcase(OP_UNM) { | 1321 | vmcase(OP_UNM) { |