lua-users home
lua-l archive

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



On 16-Aug-05, at 9:35 AM, Mike Pall wrote:

Of course compiling with -malign-double is the easiest thing to
solve this with GCC. Alas, this breaks the x86 ABI. I think this
doesn't matter since the whole Lua core never passes structures
or unions that contain doubles to C library functions or back.

Doesn't that change the stack alignment of double arguments? That would affect programs that called, for example, lua_pushnumber(), no? Or am I misreading something?

The only way I could make it work is with:

  typedef struct lua_TValue {
    TValuefields;
  } __attribute__ ((aligned(16))) TValue;

A bit awkward, but solves both the stack alignment and the array
alignment problem.

Wouldn't aligned(8) be sufficient? (At least, that wouldn't be lying to the compiler about the results of malloc() on x86 :) )

On a related note: the lua_number2int() optimization should be
turned off if __SSE2__ is defined (which is the case with
-march=pentium4).

I had to specify -msse2 for this to work on gcc 3.3.3

PS: Before anyone else notices that I'm fond of making an idiot of myself in public, it is quite clear why array alignment isn't important (but constant alignment is). The GETTABLE/SETTABLE ops (and the equivalent API calls) copy the table data onto the stack with a union copy (see the setobj macro in lobject.h), so the fp unit is presumably not involved. The key object, on the other hand, is not copied (if the constant is in the acceptable range for RK operands) and is then used directly as a number, so it's alignment is important.