lua-users home
lua-l archive

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


Hi,

Rici Lake wrote:
> By the way, I don't think MS VC aligns doubles to doublewords by 
> default, otherwise Glenn wouldn't have that problem. (Unless the fact 
> that it's in a union somehow defeats the default, which would be really 
> wierd.) That page you pointed to helpfully says that it depends on the 

The SYSV x86 ABI (on which all POSIX based x86 OS depend)
requires 4 byte alignment for doubles. The Windows x86 ABI (aka
WIN32) requires 8 byte alignment.

This is not an issue of the compiler. GCC with a WIN32 target
(MinGW or CygWin) aligns to 8 bytes just like MSVC/WIN32.

Glenn Maynard wrote:
> I tried __attribute__((aligned(16)) in various places around lua_TValue,
> on lua_Number, and adding a dummy field to Value so TValue is 16 bytes,
> but it didn't help.  Not sure what's wrong, I'm not familiar enough with
> the code.

See the patch below. This comes standard with LuaJIT because the
effect is much more pronounced there.

> I'm also not sure if VC has an equivalent to attribute(aligned).

Sort of. But you won't need it.

Bye,
     Mike
--- lua-5.1.1/src/luaconf.h	2006-04-10 20:27:23 +0200
+++ lua-5.1.1-aligned/src/luaconf.h	2006-09-25 12:00:00 +0200
@@ -581,6 +581,23 @@
 
 #endif
 
+
+/*
+@@ LUA_TVALUE_ALIGN specifies extra alignment constraints for the
+@@ tagged value structure to get better lua_Number alignment.
+** CHANGE it to an empty define if you want to save some space
+** at the cost of execution time. Note that this is only needed
+** for the x86 ABI on most POSIX systems, but not on Windows and
+** not for most other CPUs.
+*/
+
+#if defined(LUA_NUMBER_DOUBLE) && defined(__GNUC__) && \
+    (defined(__i386) || defined(__i386__)) && !defined(_WIN32)
+#define LUA_TVALUE_ALIGN	__attribute__ ((aligned(8)))
+#else
+#define LUA_TVALUE_ALIGN
+#endif
+
 /* }================================================================== */
 
 
--- lua-5.1.1/src/lobject.h	2006-01-18 12:37:34 +0100
+++ lua-5.1.1-aligned/src/lobject.h	2006-09-25 12:00:00 +0200
@@ -72,7 +72,7 @@
 
 typedef struct lua_TValue {
   TValuefields;
-} TValue;
+} LUA_TVALUE_ALIGN TValue;
 
 
 /* Macros to test type */