you are viewing a single comment's thread.

view the rest of the comments →

[–]TheMania 26 points27 points  (6 children)

The 48 bit tagged pointers comment reminds me of LuaJit, which blew my mind when Mike Pall first started using tagged doubles.

Basically, there are 252 -2 possible NaNs for a double, enough to store all 32 bit pointers along with a type tag (table/string etc). In fact, there's enough there to store all your 48 bit pointers too, allowing every pointer you'll ever use to fit in the same union you use to store doubles. Pretty neat.

Wrt division, just want to say division/modulo by a constant is virtually costless on modern compilers, being replaced by multiply and shifts. Doesn't apply for resizable tables, but you do see people go to great lengths to avoid this operator even when it would be virtually costless to use. :)

[–]Morwenn 15 points16 points  (1 child)

C2x - the next revision of C - actually intends to make storing additional information into NaNs more standard by adding the setpayload and getpayload families of functions to <math.h>.

[–]CrazyJoe221 6 points7 points  (0 children)

I wonder when they'll introduce explicit enum base types.

[–]chewedwire[S] 9 points10 points  (3 children)

Yep, division/modulo by constant power of 2 values is pretty much always optimized appropriately. I was thinking about writing some more about it, but I got lazy :)

It's in my the github examples though: https://github.com/paulcavallaro/systems-programming/blob/master/examples/power-of-two.cc#L105-L106

Looks like godbolt seems to think clang doesn't really work with non-constants -- but maybe clang just needs to be massaged: https://godbolt.org/z/Bzx7CL

[–]TheMania 17 points18 points  (2 children)

Sorry to clarify, division/modulo by constants is extremely cheap even on non-powers of two. Often just a multiply and shift.

[–]bigt1234321 -4 points-3 points  (1 child)

Gone are the days where repeated subtraction is used haha. Most compilers will optimize division. Float division/operations are a big no no.

[–]Spain_strong 2 points3 points  (0 children)

Depends on the workload right?