-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Everything is a float and NaN packing #9
Comments
I have no problem with this gross performance hack 😀 |
I'm using it right now in a little domain specific language right now. But i'm thinking about dropping boxed pointers in favour of |
So you get 52 bits free in a NaN less one value reserved for infinity (assuming actual NaNs are converted to runtime errors). So you could encode a 51-bit integer in there (for actual integers) and a 32-bit handle (for all other values, including larger integers if supported). |
Since f64 has a native precise integer range of 52 bits, i don't know if its useful to create an additional integer type. You'd gain the overflow into BigInteger (instead of the non-integer floating point range). But if there are not other numerical types than float, we could just go ahead with all numerical operations and defer the typechecks of the input into a branch if the result is NaN. If that single branch is predicted correctly, that could speed up numerical operations considerately. |
I'm playing around with ideas for a Lua-alike but with type-specific ops (
I haven't benchmarked these costs, though (except the mental and debugging load, which I do have experience with). My Lua-alike is at the level of fantasy, just a patchwork of ideas I'm building up based on the defensive style I've ended up using in Lua and improvements for various Lua frustrations. It seems to me that Lua makes too much of a sacrifice for surface simplicity sometimes. However this all does depend on the domain your scripting language is oriented towards. Maybe all-FP is fine for that. |
That wouldn't be a big problem if the language has iterator like constructs and doesn't rely on explicit iteration variables. Explicit integers for indexing could be an implementation detail of the iterator and not exposed to the language.
That definitely a good reason if you want to have backed in bit operations. Imo they are a niche usecase in my interpretation of a scripting language.
I think thats the best contra argument. But you want to avoid the FP-weirdness, i think i'd be better to not center the data representation around floats. |
A lot of scripting languages choose IEEE 754 doubles as the only numeric type and then encode all other possible values in the range of redundant NaN values. There is enough room for pointers in there since current 64 bit architectures only use 48 bits.
There are obvious downsides:
In summery, this is an overreaching performance hack and it totally grosses me out.
But, it works surprisingly well in practice:
I‘m not really sure language design should be driven by a performance hack, but its used succesfully im practice. Imo we should at least discuss if should consider such a design.
The text was updated successfully, but these errors were encountered: