better(?) handling of '#define's for IEEE-related tricks + avoid using
IEEE trick for 64-bit integer types (lua_Integer on 64-bit machines)
This commit is contained in:
15
llimits.h
15
llimits.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: llimits.h,v 1.96 2012/01/25 21:05:40 roberto Exp roberto $
|
** $Id: llimits.h,v 1.97 2012/03/28 18:27:25 roberto Exp roberto $
|
||||||
** Limits, basic types, and some other `installation-dependent' definitions
|
** Limits, basic types, and some other `installation-dependent' definitions
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -209,31 +209,36 @@ typedef lu_int32 Instruction;
|
|||||||
|
|
||||||
#elif defined(LUA_IEEE754TRICK) /* }{ */
|
#elif defined(LUA_IEEE754TRICK) /* }{ */
|
||||||
/* the next trick should work on any machine using IEEE754 with
|
/* the next trick should work on any machine using IEEE754 with
|
||||||
a 32-bit integer type */
|
a 32-bit int type */
|
||||||
|
|
||||||
union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
||||||
|
|
||||||
#if !defined(LUA_IEEEENDIAN) /* { */
|
#if !defined(LUA_IEEEENDIAN) /* { */
|
||||||
#define LUAI_EXTRAIEEE \
|
#define LUAI_EXTRAIEEE \
|
||||||
static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
|
static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
|
||||||
#define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
|
#define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33)
|
||||||
#else
|
#else
|
||||||
|
#define LUA_IEEEENDIANLOC LUA_IEEEENDIAN
|
||||||
#define LUAI_EXTRAIEEE /* empty */
|
#define LUAI_EXTRAIEEE /* empty */
|
||||||
#endif /* } */
|
#endif /* } */
|
||||||
|
|
||||||
#define lua_number2int32(i,n,t) \
|
#define lua_number2int32(i,n,t) \
|
||||||
{ LUAI_EXTRAIEEE \
|
{ LUAI_EXTRAIEEE \
|
||||||
volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
|
volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
|
||||||
(i) = (t)u.l_p[LUA_IEEEENDIAN]; }
|
(i) = (t)u.l_p[LUA_IEEEENDIANLOC]; }
|
||||||
|
|
||||||
#define luai_hashnum(i,n) \
|
#define luai_hashnum(i,n) \
|
||||||
{ volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
|
{ volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
|
||||||
(i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */
|
(i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */
|
||||||
|
|
||||||
#define lua_number2int(i,n) lua_number2int32(i, n, int)
|
#define lua_number2int(i,n) lua_number2int32(i, n, int)
|
||||||
#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
|
|
||||||
#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
|
#define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
|
||||||
|
|
||||||
|
/* the trick can be expanded to lua_Integer when it is a 32-bit value */
|
||||||
|
#if defined(LUA_IEEELL)
|
||||||
|
#define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* } */
|
#endif /* } */
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
37
lobject.h
37
lobject.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lobject.h,v 2.68 2012/01/25 21:05:40 roberto Exp roberto $
|
** $Id: lobject.h,v 2.69 2012/05/08 13:53:33 roberto Exp roberto $
|
||||||
** Type definitions for Lua objects
|
** Type definitions for Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -266,6 +266,8 @@ typedef struct lua_TValue TValue;
|
|||||||
#define setsvalue2n setsvalue
|
#define setsvalue2n setsvalue
|
||||||
|
|
||||||
|
|
||||||
|
/* check whether a number is valid (useful only for NaN trick) */
|
||||||
|
#define luai_checknum(L,o,c) { /* empty */ }
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -273,10 +275,7 @@ typedef struct lua_TValue TValue;
|
|||||||
** NaN Trick
|
** NaN Trick
|
||||||
** =======================================================
|
** =======================================================
|
||||||
*/
|
*/
|
||||||
|
#if defined(LUA_NANTRICK)
|
||||||
#if defined(LUA_NANTRICK) \
|
|
||||||
|| defined(LUA_NANTRICK_LE) \
|
|
||||||
|| defined(LUA_NANTRICK_BE)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** numbers are represented in the 'd_' field. All other values have the
|
** numbers are represented in the 'd_' field. All other values have the
|
||||||
@@ -284,15 +283,23 @@ typedef struct lua_TValue TValue;
|
|||||||
** a "signaled NaN", which is never generated by regular operations by
|
** a "signaled NaN", which is never generated by regular operations by
|
||||||
** the CPU (nor by 'strtod')
|
** the CPU (nor by 'strtod')
|
||||||
*/
|
*/
|
||||||
#if !defined(NNMARK)
|
|
||||||
|
/* allows for external implementation for part of the trick */
|
||||||
|
#if !defined(NNMARK) /* { */
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(LUA_IEEEENDIAN)
|
||||||
|
#error option 'LUA_NANTRICK' needs 'LUA_IEEEENDIAN'
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define NNMARK 0x7FF7A500
|
#define NNMARK 0x7FF7A500
|
||||||
#define NNMASK 0x7FFFFF00
|
#define NNMASK 0x7FFFFF00
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef TValuefields
|
#undef TValuefields
|
||||||
#undef NILCONSTANT
|
#undef NILCONSTANT
|
||||||
|
|
||||||
#if defined(LUA_NANTRICK_LE)
|
#if (LUA_IEEEENDIAN == 0) /* { */
|
||||||
|
|
||||||
/* little endian */
|
/* little endian */
|
||||||
#define TValuefields \
|
#define TValuefields \
|
||||||
@@ -303,7 +310,7 @@ typedef struct lua_TValue TValue;
|
|||||||
#define d_(o) ((o)->u.d__)
|
#define d_(o) ((o)->u.d__)
|
||||||
#define tt_(o) ((o)->u.i.tt__)
|
#define tt_(o) ((o)->u.i.tt__)
|
||||||
|
|
||||||
#elif defined(LUA_NANTRICK_BE)
|
#else /* }{ */
|
||||||
|
|
||||||
/* big endian */
|
/* big endian */
|
||||||
#define TValuefields \
|
#define TValuefields \
|
||||||
@@ -314,10 +321,9 @@ typedef struct lua_TValue TValue;
|
|||||||
#define d_(o) ((o)->u.d__)
|
#define d_(o) ((o)->u.d__)
|
||||||
#define tt_(o) ((o)->u.i.tt__)
|
#define tt_(o) ((o)->u.i.tt__)
|
||||||
|
|
||||||
#elif !defined(TValuefields)
|
#endif /* } */
|
||||||
#error option 'LUA_NANTRICK' needs declaration for 'TValuefields'
|
|
||||||
|
|
||||||
#endif
|
#endif /* } */
|
||||||
|
|
||||||
|
|
||||||
/* correspondence with standard representation */
|
/* correspondence with standard representation */
|
||||||
@@ -367,14 +373,9 @@ typedef struct lua_TValue TValue;
|
|||||||
(ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))
|
(ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2)))
|
||||||
|
|
||||||
|
|
||||||
|
#undef luai_checknum
|
||||||
#define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; }
|
#define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; }
|
||||||
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#define luai_checknum(L,o,c) { /* empty */ }
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
/* }====================================================== */
|
/* }====================================================== */
|
||||||
|
|
||||||
|
|||||||
98
luaconf.h
98
luaconf.h
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: luaconf.h,v 1.169 2011/11/30 12:35:05 roberto Exp roberto $
|
** $Id: luaconf.h,v 1.170 2011/12/06 16:58:36 roberto Exp roberto $
|
||||||
** Configuration file for Lua
|
** Configuration file for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -453,36 +453,69 @@
|
|||||||
#define LUA_UNSIGNED unsigned LUA_INT32
|
#define LUA_UNSIGNED unsigned LUA_INT32
|
||||||
|
|
||||||
|
|
||||||
#if defined(LUA_CORE) /* { */
|
|
||||||
|
|
||||||
#if defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
|
/*
|
||||||
|
** Some tricks with doubles
|
||||||
|
*/
|
||||||
|
|
||||||
/* On a Microsoft compiler on a Pentium, use assembler to avoid clashes
|
#if defined(LUA_CORE) && \
|
||||||
with a DirectX idiosyncrasy */
|
defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
|
||||||
|
/*
|
||||||
|
** The next definitions activate some tricks to speed up the
|
||||||
|
** conversion from doubles to integer types, mainly to LUA_UNSIGNED.
|
||||||
|
**
|
||||||
|
@@ MS_ASMTRICK uses Microsoft assembler to avoid clashes with a
|
||||||
|
** DirectX idiosyncrasy.
|
||||||
|
**
|
||||||
|
@@ LUA_IEEE754TRICK uses a trick that should work on any machine
|
||||||
|
** using IEEE754 with a 32-bit integer type.
|
||||||
|
**
|
||||||
|
@@ LUA_IEEELL extends the trick to LUA_INTEGER; should only be
|
||||||
|
** defined when LUA_INTEGER is a 32-bit integer.
|
||||||
|
**
|
||||||
|
@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
|
||||||
|
** (0 for little endian, 1 for big endian); if not defined, Lua will
|
||||||
|
** check it dynamically for LUA_IEEE754TRICK (but not for LUA_NANTRICK).
|
||||||
|
**
|
||||||
|
@@ LUA_NANTRICK controls the use of a trick to pack all types into
|
||||||
|
** a single double value, using NaN values to represent non-number
|
||||||
|
** values. The trick only works on 32-bit machines (ints and pointers
|
||||||
|
** are 32-bit values) with numbers represented as IEEE 754-2008 doubles
|
||||||
|
** with conventional endianess (12345678 or 87654321), in CPUs that do
|
||||||
|
** not produce signaling NaN values (all NaNs are quiet).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Microsoft compiler on a Pentium (32 bit) ? */
|
||||||
#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
|
#if defined(LUA_WIN) && defined(_MSC_VER) && defined(_M_IX86) /* { */
|
||||||
|
|
||||||
#define MS_ASMTRICK
|
#define MS_ASMTRICK
|
||||||
|
#define LUA_IEEEENDIAN 0
|
||||||
|
#define LUA_NANTRICK
|
||||||
|
|
||||||
#else /* }{ */
|
|
||||||
/* the next definition uses a trick that should work on any machine
|
/* pentium 32 bits? */
|
||||||
using IEEE754 with a 32-bit integer type */
|
#elif defined(__i386__) || defined(__i386) || defined(__X86__) /* }{ */
|
||||||
|
|
||||||
#define LUA_IEEE754TRICK
|
#define LUA_IEEE754TRICK
|
||||||
|
#define LUA_IEEELL
|
||||||
/*
|
|
||||||
@@ LUA_IEEEENDIAN is the endianness of doubles in your machine
|
|
||||||
** (0 for little endian, 1 for big endian); if not defined, Lua will
|
|
||||||
** check it dynamically.
|
|
||||||
*/
|
|
||||||
/* check for known architectures */
|
|
||||||
#if defined(__i386__) || defined(__i386) || defined(__X86__) || \
|
|
||||||
defined (__x86_64)
|
|
||||||
#define LUA_IEEEENDIAN 0
|
#define LUA_IEEEENDIAN 0
|
||||||
#elif defined(__POWERPC__) || defined(__ppc__)
|
#define LUA_NANTRICK
|
||||||
#define LUA_IEEEENDIAN 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* } */
|
/* pentium 64 bits? */
|
||||||
|
#elif defined(__x86_64) /* }{ */
|
||||||
|
|
||||||
|
#define LUA_IEEE754TRICK
|
||||||
|
#define LUA_IEEEENDIAN 0
|
||||||
|
|
||||||
|
#elif defined(__POWERPC__) || defined(__ppc__) /* }{ */
|
||||||
|
|
||||||
|
#define LUA_IEEE754TRICK
|
||||||
|
#define LUA_IEEEENDIAN 1
|
||||||
|
|
||||||
|
#else /* }{ */
|
||||||
|
|
||||||
|
/* assume IEEE754 and a 32-bit integer type */
|
||||||
|
#define LUA_IEEE754TRICK
|
||||||
|
|
||||||
#endif /* } */
|
#endif /* } */
|
||||||
|
|
||||||
@@ -491,29 +524,6 @@
|
|||||||
/* }================================================================== */
|
/* }================================================================== */
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
@@ LUA_NANTRICK_LE/LUA_NANTRICK_BE controls the use of a trick to
|
|
||||||
** pack all types into a single double value, using NaN values to
|
|
||||||
** represent non-number values. The trick only works on 32-bit machines
|
|
||||||
** (ints and pointers are 32-bit values) with numbers represented as
|
|
||||||
** IEEE 754-2008 doubles with conventional endianess (12345678 or
|
|
||||||
** 87654321), in CPUs that do not produce signaling NaN values (all NaNs
|
|
||||||
** are quiet).
|
|
||||||
*/
|
|
||||||
#if defined(LUA_CORE) && \
|
|
||||||
defined(LUA_NUMBER_DOUBLE) && !defined(LUA_ANSI) /* { */
|
|
||||||
|
|
||||||
/* little-endian architectures that satisfy those conditions */
|
|
||||||
#if defined(__i386__) || defined(__i386) || defined(__X86__) || \
|
|
||||||
defined(_M_IX86)
|
|
||||||
|
|
||||||
#define LUA_NANTRICK_LE
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* } */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* =================================================================== */
|
/* =================================================================== */
|
||||||
|
|||||||
Reference in New Issue
Block a user