diff options
| -rw-r--r-- | llimits.h | 57 |
1 files changed, 1 insertions, 56 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.103 2013/02/20 14:08:56 roberto Exp roberto $ | 2 | ** $Id: llimits.h,v 1.104 2013/04/25 21:15:37 roberto Exp roberto $ |
| 3 | ** Limits, basic types, and some other `installation-dependent' definitions | 3 | ** Limits, basic types, and some other `installation-dependent' definitions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -202,52 +202,6 @@ typedef lu_int32 Instruction; | |||
| 202 | ** both small and large values (outside the range of integers). | 202 | ** both small and large values (outside the range of integers). |
| 203 | */ | 203 | */ |
| 204 | 204 | ||
| 205 | #if defined(MS_ASMTRICK) || defined(LUA_MSASMTRICK) /* { */ | ||
| 206 | /* trick with Microsoft assembler for X86 */ | ||
| 207 | |||
| 208 | #define lua_number2int(i,n) __asm {__asm fld n __asm fistp i} | ||
| 209 | #define lua_number2integer(i,n) lua_number2int(i, n) | ||
| 210 | #define lua_number2unsigned(i,n) \ | ||
| 211 | {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;} | ||
| 212 | |||
| 213 | |||
| 214 | #elif defined(LUA_IEEE754TRICK) /* }{ */ | ||
| 215 | /* the next trick should work on any machine using IEEE754 with | ||
| 216 | a 32-bit int type */ | ||
| 217 | |||
| 218 | union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; | ||
| 219 | |||
| 220 | #if !defined(LUA_IEEEENDIAN) /* { */ | ||
| 221 | #define LUAI_EXTRAIEEE \ | ||
| 222 | static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)}; | ||
| 223 | #define LUA_IEEEENDIANLOC (ieeeendian.l_p[1] == 33) | ||
| 224 | #else | ||
| 225 | #define LUA_IEEEENDIANLOC LUA_IEEEENDIAN | ||
| 226 | #define LUAI_EXTRAIEEE /* empty */ | ||
| 227 | #endif /* } */ | ||
| 228 | |||
| 229 | #define lua_number2int32(i,n,t) \ | ||
| 230 | { LUAI_EXTRAIEEE \ | ||
| 231 | volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \ | ||
| 232 | (i) = (t)u.l_p[LUA_IEEEENDIANLOC]; } | ||
| 233 | |||
| 234 | #define luai_hashnum(i,n) \ | ||
| 235 | { volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \ | ||
| 236 | (i) = u.l_p[0]; (i) += u.l_p[1]; } /* add double bits for his hash */ | ||
| 237 | |||
| 238 | #define lua_number2int(i,n) lua_number2int32(i, n, int) | ||
| 239 | #define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned) | ||
| 240 | |||
| 241 | /* the trick can be expanded to lua_Integer when it is a 32-bit value */ | ||
| 242 | #if defined(LUA_IEEELL) | ||
| 243 | #define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer) | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #endif /* } */ | ||
| 247 | |||
| 248 | |||
| 249 | /* the following definitions always work, but may be slow */ | ||
| 250 | |||
| 251 | #if !defined(lua_number2int) | 205 | #if !defined(lua_number2int) |
| 252 | #define lua_number2int(i,n) ((i)=(int)(n)) | 206 | #define lua_number2int(i,n) ((i)=(int)(n)) |
| 253 | #endif | 207 | #endif |
| @@ -269,15 +223,6 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; }; | |||
| 269 | #endif /* } */ | 223 | #endif /* } */ |
| 270 | 224 | ||
| 271 | 225 | ||
| 272 | #if !defined(lua_unsigned2number) | ||
| 273 | /* on several machines, coercion from unsigned to double is slow, | ||
| 274 | so it may be worth to avoid */ | ||
| 275 | #define lua_unsigned2number(u) \ | ||
| 276 | (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u)) | ||
| 277 | #endif | ||
| 278 | |||
| 279 | |||
| 280 | |||
| 281 | #if defined(ltable_c) && !defined(luai_hashnum) | 226 | #if defined(ltable_c) && !defined(luai_hashnum) |
| 282 | 227 | ||
| 283 | #include <float.h> | 228 | #include <float.h> |
