lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi Daniel,

Daniel Silverstone wrote:
So instead I propose:
  if ((fs->pc == 0) ||
      (GET_OPCODE(f->code[fs->pc-1]) != OP_RETURN) ||
      (fs->lasttarget == fs->pc))
    luaK_codeABC(fs, OP_RETURN, 0, 1, 0);  /* final return */
It adds very little to the interpreter (a handful of bytes on x86) and
has the potential to save sizeof(Instruction)+sizeof(int) per Proto
which would otherwise end in an unconditional OP_RETURN
Aah well; I found this little detour informative and interesting and I
hope that some of you have too.

Nice analysis, very useful to me as I am studying the opcodes myself. Either way works for me; the extra instruction has no effect on performance -- no extra instruction is executed, moreover memory and disk space is cheap, and loading times are negligible.

Eliminating extra OP_RETURNs properly will eventually require basic block analysis, as you pointed out. So I think that generating perfect code isn't the aim of the parser from an engineering point of view. Bytecode size is rarely a problem in scripting languages.

From an *academic* point of view, it is impossible not to see them as imperfections, itches to scratch. But IMHO, Lua is very nicely balanced from an engineering point of view. Anyway, it would be nice to have the optimization as a power patch for people who want it...

Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia