3 ms·
That we might expect compilers to boil this statement down to calloc(n, s) is astonishing. The subtilty compilers is amazing.
by topspin 5y ago
That we might expect compilers to boil this statement down to calloc(n, s) is astonishing. The subtilty compilers is amazing.
- tialaramex 5y agoIf you write some of the "clever" pop count algorithms in C or C++, good compilers will go "Oh you're doing bit counting" and on a modern platform with a bit counting CPU instruction your whole algorithm turns into one CPU instruction. [In Rust the standard library provides count_ones() on integer types, and that's actually safely wrapping an intrinsic pop count feature]
- madmoose 5y agoC++ also has std::popcount since C++20. It should probably have had that from the beginning.
- the8472 5y agoIn this case it's a combination of compiler magic and specializations in the rust standard library to make it easy for the compiler to understand that this particular iterator shape is a NOP.