mirror of https://github.com/rusefi/lua.git
more efficient hash for numbers in IEEE754 machines
This commit is contained in:
parent
551b076f1c
commit
0b3f4e254e
17
llimits.h
17
llimits.h
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
** $Id: llimits.h,v 1.84 2010/11/08 16:33:20 roberto Exp roberto $
|
||||
** $Id: llimits.h,v 1.85 2010/12/10 13:40:22 roberto Exp roberto $
|
||||
** Limits, basic types, and some other `installation-dependent' definitions
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
|
@ -174,6 +174,9 @@ typedef lu_int32 Instruction;
|
|||
** lua_number2integer is a macro to convert lua_Number to lua_Integer.
|
||||
** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
|
||||
** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
|
||||
** luai_hashnum is a macro to hash a lua_Number value into an integer.
|
||||
** The hash must be deterministic and give reasonable values for
|
||||
** both small and large values (outside the range of integers).
|
||||
*/
|
||||
|
||||
#if defined(MS_ASMTRICK) /* { */
|
||||
|
@ -204,6 +207,10 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
|||
volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
|
||||
(i) = (t)u.l_p[LUA_IEEEENDIAN]; }
|
||||
|
||||
#define luai_hashnum(i,n) \
|
||||
{ volatile union luai_Cast u; u.l_d = (n) + 1.0; /* avoid -0 */ \
|
||||
(i) = u.l_p[0] + u.l_p[1]; } /* add double bits for his hash */
|
||||
|
||||
#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)
|
||||
|
@ -242,14 +249,8 @@ union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
|
|||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** luai_hashnum is a macro do hash a lua_Number value into an integer.
|
||||
** The hash must be deterministic and give reasonable values for
|
||||
** both small and large values (outside the range of integers).
|
||||
** It is used only in ltable.c.
|
||||
*/
|
||||
|
||||
#if !defined(luai_hashnum) /* { */
|
||||
#if defined(ltable_c) && !defined(luai_hashnum) /* { */
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
|
Loading…
Reference in New Issue