[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: NaN trick
- From: "Michael Rose" <michael.h.rose@...>
- Date: Wed, 6 Jul 2011 17:57:06 +0200 (CEST)
The NaN trick is very nice!
I think it should also work on current AMD 64bit platforms. This would reduce a Lua value
from 16 bytes down to 8 bytes on the Lua stack and within tables!
As far as I've learned, the current 64bit processors for these platforms only use 48 bit's for a pointer
(the highest bit number 47 -- counting from 0 -- has to be sign extended to 64 bit, dividing the virtual
ram into 2^47 bytes of user data and 2^47 bytes of system data), because the address bus is
only 48 bits long.
Mike Pall uses this NaN trick in Luajit as well and he packs pointers for light user data
into a double with just enough bits left to represent all the different Lua types.
Because he restricts Lua pointers to be within the lower Gig of memory (32 bit),
he only needs this trick for external C pointers, but it could be as well applied to
all pointers Lua has to work with.
For details have a look into his sources, especially into "lj_obj.h".
Regards,
Michael Rose
-----Ursprüngliche Nachricht-----
Von: "Roberto Ierusalimschy" <roberto@inf.puc-rio.br>
Gesendet: 06.07.2011 16:45:09
An: "Lua list" <lua-l@lists.lua.org>
Betreff: NaN trick
>Lua 5.2 beta implements the "NaN trick": it packs all Lua values into a
>single double value by representing non-numeric values as signaled NaNs,
>which are (usually) not produced by the system.
>
>This trick should work on most 32-bit machines that follow IEEE
>754-2008 for double representation. However, currently it is being
>enabled only by predefined macro __i386__ (and similars). We would
>like to know what other platforms could benefit from this trick
>(and what macros should we check in luaconf.h). You can force the
>trick by compiling Lua with -DLUA_NANTRICKLE (for little endian
>systems) or -DLUA_NANTRICKBE (for big endian).
>
>(Of course, we would also like to know whether there are problems
>with this implementation.)
>
>-- Roberto
>
___________________________________________________________
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://produkte.web.de/go/toolbar