Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is "the platform's preferred word size" meaningful? On x86_64, pointers are 8 bytes, but it's still faster to use smaller registers if you don't need the extra bits. For this system, at least, the correct type is the smallest one that is big enough to hold the maximum value your integer could be.


Bullshit, on x64 all 32 or 64 bit base arithmetic operations have the exact same cost, except the 64 bit version is one byte longer because of a REX prefix. This is why 32 bits is the natural int size for x64.


Well, at least division isn't. On reasonable recent Intel Broadwell, signed 64-bit division (IDIV) takes 59 cycles, while signed 32-bit division takes just 9 cycles.

Granted, divisions are rare, but that's still nearly an order of magnitude difference in that corner case.

32-bit and 64-bit addition, multiplication, comparison, logical operations etc. are in almost all cases just as fast.

You'll still need more storage on the stack for 64-bit variables. So more cache misses (and perhaps TLB misses and page faults) when corresponding boundary is crossed.


Being smaller usually results also in being faster for the cache effect.




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

Search: