lua-users home
lua-l archive

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


On Sun, 2011-05-22 at 20:37 +0200, Jerome Vuarand wrote:
> 2011/5/20 François Perrad <francois.perrad@gadz.org>:
> >
> > when I see the implementation of math.log and math.log10 in LuaJIT2 and in
> > Lua 5.1 :
> >
> >     LuaJIT2
> >         LJLIB_ASM_(math_log)            LJLIB_REC(math_unary IRFPM_LOG)
> >         LJLIB_ASM_(math_log10)          LJLIB_REC(math_unary IRFPM_LOG10)
> >
> >     Lua 5.1.4
> >         static int math_log (lua_State *L) {
> >           lua_pushnumber(L, log(luaL_checknumber(L, 1)));
> >           return 1;
> >         }
> >         static int math_log10 (lua_State *L) {
> >           lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
> >           return 1;
> >         }
> >
> > I don't understand the rational of the removal of math.log10 and the
> > addition of optional second parameter in math.log
> >
> > It's a general implementation of log, but all opportunities of optimization
> > are lost.

The amount of optimisation is almost none. The only log that can be
computed natively is the base 2 log, and all the others are calculated
by dividing by a constant, which is log2(base). x86 processors have a
special constant load (eg FLDLG2) for loading 1/log2(10), 1/log2(e) for
this operation, which is a simple optimisation that would be easy for
LUAJIT to support.

Justin