Hacker News new | past | comments | ask | show | jobs | submit login

While it is true that all JavaScript numbers appear to be floats, there's nothing stopping them from being optimized by the JIT compiler into 32-bit integers if possible.



I think the original comment about x + x + x there was not about JavaScript.

For JavaScript, you get all sorts of additional complications depending on how good your JIT is. For example, you have to check both integer addition and integer multiplication for overflow (at which point you have to recompile as doubles) unless your interval analysis is good enough. So the cost is more than just the cost of the machine add in some cases.

In practice, I'd be suprised if current JS JITs do strength-reduction in this case. They might get there sometime in the next few years, but there's lower-hanging fruit to be had so far.


Strength reduction in this vein is pretty trivial though, even if there is lower hanging fruit. For example this is what transforming some_int * a_power_of_two looks like in PyPy: https://bitbucket.org/pypy/pypy/src/default/pypy/jit/metaint...


It's trivial if you don't mind the extra compilation time.

If you're trying to make sure that your compile times are also short, it might not be worth it.... yet.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: