lua-users home
lua-l archive

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


M Joonas Pihlaja wrote:
On Fri, 28 May 2010, KHMan wrote:

On Fri, May 28, 2010 at 12:14 PM, Dmitry Gapkalov wrote:

#define lua_number2int(i,n)  __asm {__asm fld n   __asm fistp i}

On x86, 0x80000000 is the "indefinite integer value" (x86's short answer for
"help! i can't convert this!") for 32-bit results when converting, for
example, when using CVTTSD2SI or FISTP. Compilers don't throw exceptions when
doing such casting... and boom!

Okay, but the code does a conversion from a double to an __int64, and that shouldn't be triggering an indefinite integer value when converting 0xFF000000. It then does a cast from the __int64 to an unsigned int, and that conversion is always well defined, so can't be the source of the 0x800... either. Another hypothesis is that the compiler is transforming the snippet "fistp m64; mov r32, mem" into "fistp m32; mov r32, mem" because it forgot that there can be side-effects from narrowing a 64 bit fistp into a 32 bit fistp, even if the upper 32 bits of the 64 bit result are never used.

Time to check the assembly output I guess, but this is MSVC which I am still avoiding installing... I do feel bad throwing about armchair hypotheses, so I'll slinker away for now and find some time later to see for myself the behaviour of fistp in compiler-generated code... :-)

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