aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-02-24 11:14:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-02-24 11:14:44 -0300
commit59c88f846d1dcd901a4420651aedf27816618923 (patch)
tree0e76a066c383cbc99cc2f60b8b4f97c5df45e479 /ldo.c
parentc03c527fd207b4ad8f5a8e0f4f2c176bd227c979 (diff)
downloadlua-59c88f846d1dcd901a4420651aedf27816618923.tar.gz
lua-59c88f846d1dcd901a4420651aedf27816618923.tar.bz2
lua-59c88f846d1dcd901a4420651aedf27816618923.zip
Broadening the use of branch hints
More uses of macros 'likely'/'unlikely' (renamed to 'l_likely'/'l_unlikely'), both in range (extended to the libraries) and in scope (extended to hooks, stack growth).
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/ldo.c b/ldo.c
index 5587b602..7c9ce06e 100644
--- a/ldo.c
+++ b/ldo.c
@@ -184,7 +184,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
184 StkId newstack = luaM_reallocvector(L, L->stack, 184 StkId newstack = luaM_reallocvector(L, L->stack,
185 lim + EXTRA_STACK, newsize + EXTRA_STACK, StackValue); 185 lim + EXTRA_STACK, newsize + EXTRA_STACK, StackValue);
186 lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE); 186 lua_assert(newsize <= LUAI_MAXSTACK || newsize == ERRORSTACKSIZE);
187 if (unlikely(newstack == NULL)) { /* reallocation failed? */ 187 if (l_unlikely(newstack == NULL)) { /* reallocation failed? */
188 if (raiseerror) 188 if (raiseerror)
189 luaM_error(L); 189 luaM_error(L);
190 else return 0; /* do not raise an error */ 190 else return 0; /* do not raise an error */
@@ -204,7 +204,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
204*/ 204*/
205int luaD_growstack (lua_State *L, int n, int raiseerror) { 205int luaD_growstack (lua_State *L, int n, int raiseerror) {
206 int size = stacksize(L); 206 int size = stacksize(L);
207 if (unlikely(size > LUAI_MAXSTACK)) { 207 if (l_unlikely(size > LUAI_MAXSTACK)) {
208 /* if stack is larger than maximum, thread is already using the 208 /* if stack is larger than maximum, thread is already using the
209 extra space reserved for errors, that is, thread is handling 209 extra space reserved for errors, that is, thread is handling
210 a stack error; cannot grow further than that. */ 210 a stack error; cannot grow further than that. */
@@ -220,7 +220,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) {
220 newsize = LUAI_MAXSTACK; 220 newsize = LUAI_MAXSTACK;
221 if (newsize < needed) /* but must respect what was asked for */ 221 if (newsize < needed) /* but must respect what was asked for */
222 newsize = needed; 222 newsize = needed;
223 if (likely(newsize <= LUAI_MAXSTACK)) 223 if (l_likely(newsize <= LUAI_MAXSTACK))
224 return luaD_reallocstack(L, newsize, raiseerror); 224 return luaD_reallocstack(L, newsize, raiseerror);
225 else { /* stack overflow */ 225 else { /* stack overflow */
226 /* add extra size to be able to handle the error message */ 226 /* add extra size to be able to handle the error message */
@@ -376,7 +376,7 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {
376void luaD_tryfuncTM (lua_State *L, StkId func) { 376void luaD_tryfuncTM (lua_State *L, StkId func) {
377 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); 377 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL);
378 StkId p; 378 StkId p;
379 if (unlikely(ttisnil(tm))) 379 if (l_unlikely(ttisnil(tm)))
380 luaG_callerror(L, s2v(func)); /* nothing to call */ 380 luaG_callerror(L, s2v(func)); /* nothing to call */
381 for (p = L->top; p > func; p--) /* open space for metamethod */ 381 for (p = L->top; p > func; p--) /* open space for metamethod */
382 setobjs2s(L, p, p-1); 382 setobjs2s(L, p, p-1);
@@ -444,7 +444,7 @@ static void moveresults (lua_State *L, StkId res, int nres, int wanted) {
444*/ 444*/
445void luaD_poscall (lua_State *L, CallInfo *ci, int nres) { 445void luaD_poscall (lua_State *L, CallInfo *ci, int nres) {
446 int wanted = ci->nresults; 446 int wanted = ci->nresults;
447 if (L->hookmask && !hastocloseCfunc(wanted)) 447 if (l_unlikely(L->hookmask && !hastocloseCfunc(wanted)))
448 rethook(L, ci, nres); 448 rethook(L, ci, nres);
449 /* move results to proper place */ 449 /* move results to proper place */
450 moveresults(L, ci->func, nres, wanted); 450 moveresults(L, ci->func, nres, wanted);
@@ -510,7 +510,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
510 ci->top = L->top + LUA_MINSTACK; 510 ci->top = L->top + LUA_MINSTACK;
511 ci->func = func; 511 ci->func = func;
512 lua_assert(ci->top <= L->stack_last); 512 lua_assert(ci->top <= L->stack_last);
513 if (L->hookmask & LUA_MASKCALL) { 513 if (l_unlikely(L->hookmask & LUA_MASKCALL)) {
514 int narg = cast_int(L->top - func) - 1; 514 int narg = cast_int(L->top - func) - 1;
515 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg); 515 luaD_hook(L, LUA_HOOKCALL, -1, 1, narg);
516 } 516 }
@@ -556,7 +556,7 @@ CallInfo *luaD_precall (lua_State *L, StkId func, int nresults) {
556static void ccall (lua_State *L, StkId func, int nResults, int inc) { 556static void ccall (lua_State *L, StkId func, int nResults, int inc) {
557 CallInfo *ci; 557 CallInfo *ci;
558 L->nCcalls += inc; 558 L->nCcalls += inc;
559 if (unlikely(getCcalls(L) >= LUAI_MAXCCALLS)) 559 if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
560 luaE_checkcstack(L); 560 luaE_checkcstack(L);
561 if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */ 561 if ((ci = luaD_precall(L, func, nResults)) != NULL) { /* Lua function? */
562 ci->callstatus = CIST_FRESH; /* mark that it is a "fresh" execute */ 562 ci->callstatus = CIST_FRESH; /* mark that it is a "fresh" execute */
@@ -600,7 +600,7 @@ void luaD_callnoyield (lua_State *L, StkId func, int nResults) {
600*/ 600*/
601static int finishpcallk (lua_State *L, CallInfo *ci) { 601static int finishpcallk (lua_State *L, CallInfo *ci) {
602 int status = getcistrecst(ci); /* get original status */ 602 int status = getcistrecst(ci); /* get original status */
603 if (status == LUA_OK) /* no error? */ 603 if (l_likely(status == LUA_OK)) /* no error? */
604 status = LUA_YIELD; /* was interrupted by an yield */ 604 status = LUA_YIELD; /* was interrupted by an yield */
605 else { /* error */ 605 else { /* error */
606 StkId func = restorestack(L, ci->u2.funcidx); 606 StkId func = restorestack(L, ci->u2.funcidx);
@@ -774,7 +774,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
774 status = luaD_rawrunprotected(L, resume, &nargs); 774 status = luaD_rawrunprotected(L, resume, &nargs);
775 /* continue running after recoverable errors */ 775 /* continue running after recoverable errors */
776 status = precover(L, status); 776 status = precover(L, status);
777 if (likely(!errorstatus(status))) 777 if (l_likely(!errorstatus(status)))
778 lua_assert(status == L->status); /* normal end or yield */ 778 lua_assert(status == L->status); /* normal end or yield */
779 else { /* unrecoverable error */ 779 else { /* unrecoverable error */
780 L->status = cast_byte(status); /* mark thread as 'dead' */ 780 L->status = cast_byte(status); /* mark thread as 'dead' */
@@ -800,7 +800,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
800 lua_lock(L); 800 lua_lock(L);
801 ci = L->ci; 801 ci = L->ci;
802 api_checknelems(L, nresults); 802 api_checknelems(L, nresults);
803 if (unlikely(!yieldable(L))) { 803 if (l_unlikely(!yieldable(L))) {
804 if (L != G(L)->mainthread) 804 if (L != G(L)->mainthread)
805 luaG_runerror(L, "attempt to yield across a C-call boundary"); 805 luaG_runerror(L, "attempt to yield across a C-call boundary");
806 else 806 else
@@ -853,7 +853,7 @@ int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status) {
853 struct CloseP pcl; 853 struct CloseP pcl;
854 pcl.level = restorestack(L, level); pcl.status = status; 854 pcl.level = restorestack(L, level); pcl.status = status;
855 status = luaD_rawrunprotected(L, &closepaux, &pcl); 855 status = luaD_rawrunprotected(L, &closepaux, &pcl);
856 if (likely(status == LUA_OK)) /* no more errors? */ 856 if (l_likely(status == LUA_OK)) /* no more errors? */
857 return pcl.status; 857 return pcl.status;
858 else { /* an error occurred; restore saved state and repeat */ 858 else { /* an error occurred; restore saved state and repeat */
859 L->ci = old_ci; 859 L->ci = old_ci;
@@ -876,7 +876,7 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
876 ptrdiff_t old_errfunc = L->errfunc; 876 ptrdiff_t old_errfunc = L->errfunc;
877 L->errfunc = ef; 877 L->errfunc = ef;
878 status = luaD_rawrunprotected(L, func, u); 878 status = luaD_rawrunprotected(L, func, u);
879 if (unlikely(status != LUA_OK)) { /* an error occurred? */ 879 if (l_unlikely(status != LUA_OK)) { /* an error occurred? */
880 L->ci = old_ci; 880 L->ci = old_ci;
881 L->allowhook = old_allowhooks; 881 L->allowhook = old_allowhooks;
882 status = luaD_closeprotected(L, old_top, status); 882 status = luaD_closeprotected(L, old_top, status);