lua-users home
lua-l archive

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


On Thu, May 25, 2006 at 12:52:47PM -0300, Roberto Ierusalimschy wrote:
> 1) change lua_number2int in luaconf.h to this:
> 
>   #define lua_number2int(i,d)   __asm fld d   __asm fistp i
> 
> (Should have no performance penalty, but only works on selected compilers.)

A fast C99 solution is lrint/lrintf.

FWIW, I'd recommend trying C99, then VC inline, then a cast, and dropping
the problematic union hack.  (For every thread this starts, there are
probably half a dozen more people spending two hours figuring it out ...)

> 2) change lua_number2int in luaconf.h to its default definition:
> 
>   #define lua_number2int(i,d)     ((i)=(int)(d))
> 
> (Should always work, but may have a performance penalty in Lua; but
> how much??)

For anyone wanting a quick intro about some of the performance problems
with casting to int, see:

 http://mega-nerd.com/FPcast/

The quick summary is that on x86, the floating point mode has to be
changed from round to truncate for the cast, then back to rounding for
other math, and changing these modes hurts performance badly on some
(older) CPUs.

-- 
Glenn Maynard