'isIT'/'isOT' turned from macros to functions

This commit is contained in:
Roberto Ierusalimschy 2024-06-27 15:01:57 -03:00
parent 9904c253da
commit 6ac7219da3
6 changed files with 38 additions and 14 deletions

View File

@ -1844,7 +1844,9 @@ void luaK_finish (FuncState *fs) {
Proto *p = fs->f; Proto *p = fs->f;
for (i = 0; i < fs->pc; i++) { for (i = 0; i < fs->pc; i++) {
Instruction *pc = &p->code[i]; Instruction *pc = &p->code[i];
lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); /* avoid "not used" warnings when assert is off (for 'onelua.c') */
(void)luaP_isOT; (void)luaP_isIT;
lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc));
switch (GET_OPCODE(*pc)) { switch (GET_OPCODE(*pc)) {
case OP_RETURN0: case OP_RETURN1: { case OP_RETURN0: case OP_RETURN1: {
if (!(fs->needclose || (p->flag & PF_ISVARARG))) if (!(fs->needclose || (p->flag & PF_ISVARARG)))

View File

@ -939,7 +939,7 @@ int luaG_traceexec (lua_State *L, const Instruction *pc) {
ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */ ci->callstatus &= ~CIST_HOOKYIELD; /* erase mark */
return 1; /* do not call hook again (VM yielded, so it did not move) */ return 1; /* do not call hook again (VM yielded, so it did not move) */
} }
if (!isIT(*(ci->u.l.savedpc - 1))) /* top not being used? */ if (!luaP_isIT(*(ci->u.l.savedpc - 1))) /* top not being used? */
L->top.p = ci->top.p; /* correct top */ L->top.p = ci->top.p; /* correct top */
if (counthook) if (counthook)
luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */ luaD_hook(L, LUA_HOOKCOUNT, -1, 0, 0); /* call count hook */

View File

@ -13,6 +13,10 @@
#include "lopcodes.h" #include "lopcodes.h"
#define opmode(mm,ot,it,t,a,m) \
(((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m))
/* ORDER OP */ /* ORDER OP */
LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
@ -102,3 +106,27 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */
}; };
/*
** Check whether instruction sets top for next instruction, that is,
** it results in multiple values.
*/
int luaP_isOT (Instruction i) {
OpCode op = GET_OPCODE(i);
switch (op) {
case OP_TAILCALL: return 1;
default:
return testOTMode(op) && GETARG_C(i) == 0;
}
}
/*
** Check whether instruction uses top from previous instruction, that is,
** it accepts multiple results.
*/
int luaP_isIT (Instruction i) {
return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0;
}

View File

@ -8,6 +8,7 @@
#define lopcodes_h #define lopcodes_h
#include "llimits.h" #include "llimits.h"
#include "lobject.h"
/*=========================================================================== /*===========================================================================
@ -394,16 +395,9 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];)
#define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) #define testOTMode(m) (luaP_opmodes[m] & (1 << 6))
#define testMMMode(m) (luaP_opmodes[m] & (1 << 7)) #define testMMMode(m) (luaP_opmodes[m] & (1 << 7))
/* "out top" (set top for next instruction) */
#define isOT(i) \
((testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || \
GET_OPCODE(i) == OP_TAILCALL)
/* "in top" (uses top from previous instruction) */ LUAI_FUNC int luaP_isOT (Instruction i);
#define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0) LUAI_FUNC int luaP_isIT (Instruction i);
#define opmode(mm,ot,it,t,a,m) \
(((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m))
#endif #endif

View File

@ -278,7 +278,7 @@ static int equalkey (const TValue *k1, const Node *n2, int deadok) {
/* /*
** Returns the real size of the 'array' array ** Returns the real size of the 'array' array
*/ */
LUAI_FUNC unsigned int luaH_realasize (const Table *t) { unsigned int luaH_realasize (const Table *t) {
if (limitequalsasize(t)) if (limitequalsasize(t))
return t->alimit; /* this is the size */ return t->alimit; /* this is the size */
else { else {

4
lvm.c
View File

@ -1180,8 +1180,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
#endif #endif
lua_assert(base == ci->func.p + 1); lua_assert(base == ci->func.p + 1);
lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p); lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p);
/* invalidate top for instructions not expecting it */ /* for tests, invalidate top for instructions not expecting it */
lua_assert(isIT(i) || (cast_void(L->top.p = base), 1)); lua_assert(luaP_isIT(i) || (cast_void(L->top.p = base), 1));
vmdispatch (GET_OPCODE(i)) { vmdispatch (GET_OPCODE(i)) {
vmcase(OP_MOVE) { vmcase(OP_MOVE) {
StkId ra = RA(i); StkId ra = RA(i);