lua-users home
lua-l archive

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


On 4/22/2013 2:58 PM, Ross Bencina wrote:
On 22/04/2013 6:26 AM, [ex] wrote:
The problem I suspect is that the code under the MS_ASMTRICK is not
correct (llimits.h:204):
this block:
     __asm {__asm fld n   __asm fistp i}

that is used in:
     #define lua_number2unsigned(i,n)  \
          {__int64 l; __asm {__asm fld n   __asm fistp l} i =
(unsigned
int)l;}

it's not guaranteed to floor a number, it depends on the FPU
rounding mode.
as explained here: http://stereopsis.com/FPU.html

It is true that the behavior of fistp depends on the current
rounding mode.

However I think you will find that the default rounding mode is
usually fixed by the platform ABI (or even the C language spec?)
so the behavior should at least be predictable.

Don't try adding .5 to fix this either, since round to nearest on
1.5 and 2.5 etc rounds in opposite directions.

I suspect this is a bug because the slow alternative is not
giving me
the same result, but I can be missing something.

If you have an SSE capable processor I think there is a fast
alternative using SSE.

Some discussion here:
http://www.musicdsp.org/showone.php?id=246

You'll need SSE2 for double precision.

Also I was looking around, does the settings for MXCSR in MSVC++ [1] need to be changed in this case? Which may impact other type conversion activities in other parts of the code.

I have a feeling that this has already been addressed in LuaJIT...

[1] http://msdn.microsoft.com/en-us/library/yxty7t75(v=vs.110).aspx

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