4 ms·
Thanks for sharing that, love the simplicity behind it which is more intuitive than the example I had gone with. I think the reason why I chose that particular
by juxhindb 5y ago
Thanks for sharing that, love the simplicity behind it which is more intuitive than the example I had gone with.
I think the reason why I chose that particular one was to show how thinking about a problem from an entirely different angle can yield great (and rewarding) results.
- saagarjha 5y agoIdeally, you'd want your compiler to use the hardware population count instructions though. So this might be one of the places where a simpler algorithm might win out because the compiler can recognize it.
- juxhindb 5y agoIn fact that is one of the follow-ups I want to have out of this. Have architecture-specific optimisations (popcnt on x86) either manually through something like the `asm` crate, or by having a simpler algorithm that the compiler can optimise away.
- juxhindb 5y agoAn extension to this infact is the following - https://github.com/llvm-mirror/llvm/blob/f36485f7ac2a8d72ad0e0f2134c17fd365272285/lib/Transforms/Scalar/LoopIdiomRecognize.cpp#L960 https://github.com/llvm-mirror/llvm/blob/f36485f7ac2a8d72ad0... So the original user's comment might infact get detected by this and get optimised down to using popcnt. Will need to try it out. :-)