diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-08-17 15:53:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-08-17 15:53:39 -0300 |
commit | 3dcd04ad610d151afbe8cd92c43e2232e621fbb5 (patch) | |
tree | 730a90a686d4b5430791b6e6e61dbc2acbe87334 | |
parent | faaf7e481fbadc2ef520a96b638dd910f3c9ff14 (diff) | |
download | lua-3dcd04ad610d151afbe8cd92c43e2232e621fbb5.tar.gz lua-3dcd04ad610d151afbe8cd92c43e2232e621fbb5.tar.bz2 lua-3dcd04ad610d151afbe8cd92c43e2232e621fbb5.zip |
details
Minor optimizations in 'lvm.c'. (Not exactly optimizations, but more
chances for optimizations.)
-rw-r--r-- | lvm.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.359 2018/06/18 17:58:21 roberto Exp roberto $ | 2 | ** $Id: lvm.c $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -621,8 +621,8 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
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_div (lua_State *L, lua_Integer m, lua_Integer n) { |
624 | if (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 (unlikely(n == 0)) | 625 | if (n == 0) |
626 | luaG_runerror(L, "attempt to divide by zero"); | 626 | luaG_runerror(L, "attempt to divide by zero"); |
627 | return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ | 627 | return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ |
628 | } | 628 | } |
@@ -641,14 +641,14 @@ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | |||
641 | ** about luaV_div.) | 641 | ** about luaV_div.) |
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 (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ | 644 | if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ |
645 | if (unlikely(n == 0)) | 645 | if (n == 0) |
646 | luaG_runerror(L, "attempt to perform 'n%%0'"); | 646 | luaG_runerror(L, "attempt to perform 'n%%0'"); |
647 | return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ | 647 | return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ |
648 | } | 648 | } |
649 | else { | 649 | else { |
650 | lua_Integer r = m % n; | 650 | lua_Integer r = m % n; |
651 | if (r != 0 && (m ^ n) < 0) /* 'm/n' would be non-integer negative? */ | 651 | if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */ |
652 | r += n; /* correct result for different rounding */ | 652 | r += n; /* correct result for different rounding */ |
653 | return r; | 653 | return r; |
654 | } | 654 | } |