diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-05-30 11:25:52 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-05-30 11:25:52 -0300 |
commit | 34aa0c5bd7493b6e01983df28f04af46a3d99967 (patch) | |
tree | eb58cf48a015be8b9b9c0b3f8c1da14d39f8a065 /lvm.c | |
parent | 97e394ba1805fbe394a5704de660403901559e54 (diff) | |
download | lua-34aa0c5bd7493b6e01983df28f04af46a3d99967.tar.gz lua-34aa0c5bd7493b6e01983df28f04af46a3d99967.tar.bz2 lua-34aa0c5bd7493b6e01983df28f04af46a3d99967.zip |
new macros 'likely'/'unlikely' with hints for jump predictions
(used only in errors for now)
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.354 2018/05/02 18:17:59 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.355 2018/05/22 12:02:36 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 | */ |
@@ -196,7 +196,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, | |||
196 | if (slot == NULL) { /* 't' is not a table? */ | 196 | if (slot == NULL) { /* 't' is not a table? */ |
197 | lua_assert(!ttistable(t)); | 197 | lua_assert(!ttistable(t)); |
198 | tm = luaT_gettmbyobj(L, t, TM_INDEX); | 198 | tm = luaT_gettmbyobj(L, t, TM_INDEX); |
199 | if (notm(tm)) | 199 | if (unlikely(notm(tm))) |
200 | luaG_typeerror(L, t, "index"); /* no metamethod */ | 200 | luaG_typeerror(L, t, "index"); /* no metamethod */ |
201 | /* else will try the metamethod */ | 201 | /* else will try the metamethod */ |
202 | } | 202 | } |
@@ -253,7 +253,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | |||
253 | } | 253 | } |
254 | else { /* not a table; check metamethod */ | 254 | else { /* not a table; check metamethod */ |
255 | tm = luaT_gettmbyobj(L, t, TM_NEWINDEX); | 255 | tm = luaT_gettmbyobj(L, t, TM_NEWINDEX); |
256 | if (notm(tm)) | 256 | if (unlikely(notm(tm))) |
257 | luaG_typeerror(L, t, "index"); | 257 | luaG_typeerror(L, t, "index"); |
258 | } | 258 | } |
259 | /* try the metamethod */ | 259 | /* try the metamethod */ |
@@ -561,7 +561,7 @@ void luaV_concat (lua_State *L, int total) { | |||
561 | /* collect total length and number of strings */ | 561 | /* collect total length and number of strings */ |
562 | for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { | 562 | for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { |
563 | size_t l = vslen(s2v(top - n - 1)); | 563 | size_t l = vslen(s2v(top - n - 1)); |
564 | if (l >= (MAX_SIZE/sizeof(char)) - tl) | 564 | if (unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) |
565 | luaG_runerror(L, "string length overflow"); | 565 | luaG_runerror(L, "string length overflow"); |
566 | tl += l; | 566 | tl += l; |
567 | } | 567 | } |
@@ -605,7 +605,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
605 | } | 605 | } |
606 | default: { /* try metamethod */ | 606 | default: { /* try metamethod */ |
607 | tm = luaT_gettmbyobj(L, rb, TM_LEN); | 607 | tm = luaT_gettmbyobj(L, rb, TM_LEN); |
608 | if (notm(tm)) /* no metamethod? */ | 608 | if (unlikely(notm(tm))) /* no metamethod? */ |
609 | luaG_typeerror(L, rb, "get length of"); | 609 | luaG_typeerror(L, rb, "get length of"); |
610 | break; | 610 | break; |
611 | } | 611 | } |
@@ -622,7 +622,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { | |||
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 (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
625 | if (n == 0) | 625 | if (unlikely(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 | } |
@@ -642,7 +642,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) { | |||
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 (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
645 | if (n == 0) | 645 | if (unlikely(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 | } |
@@ -1665,7 +1665,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1665 | TValue *plimit = s2v(ra + 1); | 1665 | TValue *plimit = s2v(ra + 1); |
1666 | lua_Integer ilimit, initv; | 1666 | lua_Integer ilimit, initv; |
1667 | int stopnow; | 1667 | int stopnow; |
1668 | if (!forlimit(plimit, &ilimit, 1, &stopnow)) { | 1668 | if (unlikely(!forlimit(plimit, &ilimit, 1, &stopnow))) { |
1669 | savestate(L, ci); /* for the error message */ | 1669 | savestate(L, ci); /* for the error message */ |
1670 | luaG_runerror(L, "'for' limit must be a number"); | 1670 | luaG_runerror(L, "'for' limit must be a number"); |
1671 | } | 1671 | } |
@@ -1717,13 +1717,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1717 | else { /* try making all values floats */ | 1717 | else { /* try making all values floats */ |
1718 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; | 1718 | lua_Number ninit; lua_Number nlimit; lua_Number nstep; |
1719 | savestate(L, ci); /* in case of errors */ | 1719 | savestate(L, ci); /* in case of errors */ |
1720 | if (!tonumber(plimit, &nlimit)) | 1720 | if (unlikely(!tonumber(plimit, &nlimit))) |
1721 | luaG_runerror(L, "'for' limit must be a number"); | 1721 | luaG_runerror(L, "'for' limit must be a number"); |
1722 | setfltvalue(plimit, nlimit); | 1722 | setfltvalue(plimit, nlimit); |
1723 | if (!tonumber(pstep, &nstep)) | 1723 | if (unlikely(!tonumber(pstep, &nstep))) |
1724 | luaG_runerror(L, "'for' step must be a number"); | 1724 | luaG_runerror(L, "'for' step must be a number"); |
1725 | setfltvalue(pstep, nstep); | 1725 | setfltvalue(pstep, nstep); |
1726 | if (!tonumber(init, &ninit)) | 1726 | if (unlikely(!tonumber(init, &ninit))) |
1727 | luaG_runerror(L, "'for' initial value must be a number"); | 1727 | luaG_runerror(L, "'for' initial value must be a number"); |
1728 | setfltvalue(init, luai_numsub(L, ninit, nstep)); | 1728 | setfltvalue(init, luai_numsub(L, ninit, nstep)); |
1729 | } | 1729 | } |