mirror of https://github.com/rusefi/lua.git
Optimization/simplification of 'getbaseline'
By producing absolute line information at regular intervals, a simple division can compute the correct entry for a given instruction.
This commit is contained in:
parent
949187b049
commit
e500892e18
4
lcode.c
4
lcode.c
|
@ -328,13 +328,13 @@ void luaK_patchtohere (FuncState *fs, int list) {
|
||||||
static void savelineinfo (FuncState *fs, Proto *f, int line) {
|
static void savelineinfo (FuncState *fs, Proto *f, int line) {
|
||||||
int linedif = line - fs->previousline;
|
int linedif = line - fs->previousline;
|
||||||
int pc = fs->pc - 1; /* last instruction coded */
|
int pc = fs->pc - 1; /* last instruction coded */
|
||||||
if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ > MAXIWTHABS) {
|
if (abs(linedif) >= LIMLINEDIFF || fs->iwthabs++ >= MAXIWTHABS) {
|
||||||
luaM_growvector(fs->ls->L, f->abslineinfo, fs->nabslineinfo,
|
luaM_growvector(fs->ls->L, f->abslineinfo, fs->nabslineinfo,
|
||||||
f->sizeabslineinfo, AbsLineInfo, MAX_INT, "lines");
|
f->sizeabslineinfo, AbsLineInfo, MAX_INT, "lines");
|
||||||
f->abslineinfo[fs->nabslineinfo].pc = pc;
|
f->abslineinfo[fs->nabslineinfo].pc = pc;
|
||||||
f->abslineinfo[fs->nabslineinfo++].line = line;
|
f->abslineinfo[fs->nabslineinfo++].line = line;
|
||||||
linedif = ABSLINEINFO; /* signal that there is absolute information */
|
linedif = ABSLINEINFO; /* signal that there is absolute information */
|
||||||
fs->iwthabs = 0; /* restart counter */
|
fs->iwthabs = 1; /* restart counter */
|
||||||
}
|
}
|
||||||
luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte,
|
luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte,
|
||||||
MAX_INT, "opcodes");
|
MAX_INT, "opcodes");
|
||||||
|
|
35
ldebug.c
35
ldebug.c
|
@ -46,10 +46,14 @@ static int currentpc (CallInfo *ci) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Get a "base line" to find the line corresponding to an instruction.
|
** Get a "base line" to find the line corresponding to an instruction.
|
||||||
** For that, search the array of absolute line info for the largest saved
|
** Base lines are regularly placed at MAXIWTHABS intervals, so usually
|
||||||
** instruction smaller or equal to the wanted instruction. A special
|
** an integer division gets the right place. When the source file has
|
||||||
** case is when there is no absolute info or the instruction is before
|
** large sequences of empty/comment lines, it may need extra entries,
|
||||||
** the first absolute one.
|
** so the original estimate needs a correction.
|
||||||
|
** The assertion that the estimate is a lower bound for the correct base
|
||||||
|
** is valid as long as the debug info has been generated with the same
|
||||||
|
** value for MAXIWTHABS or smaller. (Previous releases use a little
|
||||||
|
** smaller value.)
|
||||||
*/
|
*/
|
||||||
static int getbaseline (const Proto *f, int pc, int *basepc) {
|
static int getbaseline (const Proto *f, int pc, int *basepc) {
|
||||||
if (f->sizeabslineinfo == 0 || pc < f->abslineinfo[0].pc) {
|
if (f->sizeabslineinfo == 0 || pc < f->abslineinfo[0].pc) {
|
||||||
|
@ -57,20 +61,11 @@ static int getbaseline (const Proto *f, int pc, int *basepc) {
|
||||||
return f->linedefined;
|
return f->linedefined;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
unsigned int i;
|
int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */
|
||||||
if (pc >= f->abslineinfo[f->sizeabslineinfo - 1].pc)
|
/* estimate must be a lower bond of the correct base */
|
||||||
i = f->sizeabslineinfo - 1; /* instruction is after last saved one */
|
lua_assert(i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc);
|
||||||
else { /* binary search */
|
while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc)
|
||||||
unsigned int j = f->sizeabslineinfo - 1; /* pc < anchorlines[j] */
|
i++; /* low estimate; adjust it */
|
||||||
i = 0; /* abslineinfo[i] <= pc */
|
|
||||||
while (i < j - 1) {
|
|
||||||
unsigned int m = (j + i) / 2;
|
|
||||||
if (pc >= f->abslineinfo[m].pc)
|
|
||||||
i = m;
|
|
||||||
else
|
|
||||||
j = m;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*basepc = f->abslineinfo[i].pc;
|
*basepc = f->abslineinfo[i].pc;
|
||||||
return f->abslineinfo[i].line;
|
return f->abslineinfo[i].line;
|
||||||
}
|
}
|
||||||
|
@ -303,8 +298,8 @@ static void collectvalidlines (lua_State *L, Closure *f) {
|
||||||
sethvalue2s(L, L->top, t); /* push it on stack */
|
sethvalue2s(L, L->top, t); /* push it on stack */
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
setbtvalue(&v); /* boolean 'true' to be the value of all indices */
|
setbtvalue(&v); /* boolean 'true' to be the value of all indices */
|
||||||
for (i = 0; i < p->sizelineinfo; i++) { /* for all lines with code */
|
for (i = 0; i < p->sizelineinfo; i++) { /* for all instructions */
|
||||||
currentline = nextline(p, currentline, i);
|
currentline = nextline(p, currentline, i); /* get its line */
|
||||||
luaH_setint(L, t, currentline, &v); /* table[line] = true */
|
luaH_setint(L, t, currentline, &v); /* table[line] = true */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
ldebug.h
4
ldebug.h
|
@ -29,10 +29,10 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** MAXimum number of successive Instructions WiTHout ABSolute line
|
** MAXimum number of successive Instructions WiTHout ABSolute line
|
||||||
** information.
|
** information. (A power of two allows fast divisions.)
|
||||||
*/
|
*/
|
||||||
#if !defined(MAXIWTHABS)
|
#if !defined(MAXIWTHABS)
|
||||||
#define MAXIWTHABS 120
|
#define MAXIWTHABS 128
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue